mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 13:13:03 +00:00
yasnippet.el: Use setq-local
and defvar-local
This commit is contained in:
parent
bcefd0a1c1
commit
66db827a86
63
yasnippet.el
63
yasnippet.el
@ -763,7 +763,7 @@ expanded.")
|
|||||||
:help "Display some information about YASnippet"]))
|
:help "Display some information about YASnippet"]))
|
||||||
|
|
||||||
(define-obsolete-variable-alias 'yas-extra-modes 'yas--extra-modes "0.9.1")
|
(define-obsolete-variable-alias 'yas-extra-modes 'yas--extra-modes "0.9.1")
|
||||||
(defvar yas--extra-modes nil
|
(defvar yas--extra-modes nil ;FIXME: Use `defvar-local'?
|
||||||
"An internal list of modes for which to also lookup snippets.
|
"An internal list of modes for which to also lookup snippets.
|
||||||
|
|
||||||
This variable probably makes more sense as buffer-local, so
|
This variable probably makes more sense as buffer-local, so
|
||||||
@ -906,9 +906,8 @@ activate snippets associated with that mode."
|
|||||||
(list (intern
|
(list (intern
|
||||||
(completing-read
|
(completing-read
|
||||||
"Deactivate mode: " (mapcar #'list yas--extra-modes) nil t))))
|
"Deactivate mode: " (mapcar #'list yas--extra-modes) nil t))))
|
||||||
(set (make-local-variable 'yas--extra-modes)
|
(setq-local yas--extra-modes
|
||||||
(remove mode
|
(remove mode yas--extra-modes)))
|
||||||
yas--extra-modes)))
|
|
||||||
|
|
||||||
(defun yas-temp-buffer-p (&optional buffer)
|
(defun yas-temp-buffer-p (&optional buffer)
|
||||||
(eq (aref (buffer-name buffer) 0) ?\s))
|
(eq (aref (buffer-name buffer) 0) ?\s))
|
||||||
@ -993,9 +992,9 @@ Honour `yas-dont-activate-functions', which see."
|
|||||||
(define-derived-mode snippet-mode prog-mode "Snippet"
|
(define-derived-mode snippet-mode prog-mode "Snippet"
|
||||||
"A mode for editing yasnippets"
|
"A mode for editing yasnippets"
|
||||||
(setq font-lock-defaults '(yas--font-lock-keywords))
|
(setq font-lock-defaults '(yas--font-lock-keywords))
|
||||||
(set (make-local-variable 'require-final-newline) nil)
|
(setq-local require-final-newline nil)
|
||||||
(set (make-local-variable 'comment-start) "#")
|
(setq-local comment-start "#")
|
||||||
(set (make-local-variable 'comment-start-skip) "#+[\t ]*")
|
(setq-local comment-start-skip "#+[\t ]*")
|
||||||
(add-hook 'after-save-hook #'yas-maybe-load-snippet-buffer nil t))
|
(add-hook 'after-save-hook #'yas-maybe-load-snippet-buffer nil t))
|
||||||
|
|
||||||
(defun yas-snippet-mode-buffer-p ()
|
(defun yas-snippet-mode-buffer-p ()
|
||||||
@ -2524,7 +2523,7 @@ visited file in `snippet-mode'."
|
|||||||
(cond ((and file (file-readable-p file))
|
(cond ((and file (file-readable-p file))
|
||||||
(find-file-other-window file)
|
(find-file-other-window file)
|
||||||
(snippet-mode)
|
(snippet-mode)
|
||||||
(set (make-local-variable 'yas--editing-template) template))
|
(setq-local yas--editing-template template))
|
||||||
(file
|
(file
|
||||||
(message "Original file %s no longer exists!" file))
|
(message "Original file %s no longer exists!" file))
|
||||||
(t
|
(t
|
||||||
@ -2546,9 +2545,10 @@ visited file in `snippet-mode'."
|
|||||||
(pp-to-string (yas--template-content template))
|
(pp-to-string (yas--template-content template))
|
||||||
(yas--template-content template))))
|
(yas--template-content template))))
|
||||||
(snippet-mode)
|
(snippet-mode)
|
||||||
(set (make-local-variable 'yas--editing-template) template)
|
(setq-local yas--editing-template template)
|
||||||
(set (make-local-variable 'default-directory)
|
(setq-local default-directory
|
||||||
(car (cdr (car (yas--guess-snippet-directories (yas--template-table template))))))))))
|
(car (cdr (car (yas--guess-snippet-directories
|
||||||
|
(yas--template-table template))))))))))
|
||||||
|
|
||||||
(defun yas--guess-snippet-directories-1 (table)
|
(defun yas--guess-snippet-directories-1 (table)
|
||||||
"Guess possible snippet subdirectories for TABLE."
|
"Guess possible snippet subdirectories for TABLE."
|
||||||
@ -2624,11 +2624,11 @@ NO-TEMPLATE is non-nil."
|
|||||||
(kill-all-local-variables)
|
(kill-all-local-variables)
|
||||||
(snippet-mode)
|
(snippet-mode)
|
||||||
(yas-minor-mode 1)
|
(yas-minor-mode 1)
|
||||||
(set (make-local-variable 'yas--guessed-modes)
|
(setq-local yas--guessed-modes
|
||||||
(mapcar (lambda (d) (yas--table-mode (car d)))
|
(mapcar (lambda (d) (yas--table-mode (car d)))
|
||||||
guessed-directories))
|
guessed-directories))
|
||||||
(set (make-local-variable 'default-directory)
|
(setq-local default-directory
|
||||||
(car (cdr (car guessed-directories))))
|
(car (cdr (car guessed-directories))))
|
||||||
(if (and (not no-template) yas-new-snippet-default)
|
(if (and (not no-template) yas-new-snippet-default)
|
||||||
(yas-expand-snippet yas-new-snippet-default))))
|
(yas-expand-snippet yas-new-snippet-default))))
|
||||||
|
|
||||||
@ -2678,8 +2678,8 @@ neither do the elements of PARENTS."
|
|||||||
ido-mode)
|
ido-mode)
|
||||||
'ido-completing-read 'completing-read)))
|
'ido-completing-read 'completing-read)))
|
||||||
(unless yas--guessed-modes
|
(unless yas--guessed-modes
|
||||||
(set (make-local-variable 'yas--guessed-modes)
|
(setq-local yas--guessed-modes
|
||||||
(or (yas--compute-major-mode-and-parents buffer-file-name))))
|
(yas--compute-major-mode-and-parents buffer-file-name)))
|
||||||
(intern
|
(intern
|
||||||
(funcall prompt (format "Choose or enter a table (yas guesses %s): "
|
(funcall prompt (format "Choose or enter a table (yas guesses %s): "
|
||||||
(if yas--guessed-modes
|
(if yas--guessed-modes
|
||||||
@ -2711,11 +2711,12 @@ Return the `yas--template' object created"
|
|||||||
;;
|
;;
|
||||||
(t
|
(t
|
||||||
(unless yas--guessed-modes
|
(unless yas--guessed-modes
|
||||||
(set (make-local-variable 'yas--guessed-modes) (or (yas--compute-major-mode-and-parents buffer-file-name))))
|
(setq-local yas--guessed-modes
|
||||||
|
(or (yas--compute-major-mode-and-parents buffer-file-name))))
|
||||||
(let* ((table (yas--table-get-create table)))
|
(let* ((table (yas--table-get-create table)))
|
||||||
(set (make-local-variable 'yas--editing-template)
|
(setq-local yas--editing-template
|
||||||
(yas--define-snippets-1 (yas--parse-template buffer-file-name)
|
(yas--define-snippets-1 (yas--parse-template buffer-file-name)
|
||||||
table)))))
|
table)))))
|
||||||
(when interactive
|
(when interactive
|
||||||
(yas--message 3 "Snippet \"%s\" loaded for %s."
|
(yas--message 3 "Snippet \"%s\" loaded for %s."
|
||||||
(yas--template-name yas--editing-template)
|
(yas--template-name yas--editing-template)
|
||||||
@ -3072,14 +3073,13 @@ other fields."
|
|||||||
|
|
||||||
;;; Snippet expansion and field management
|
;;; Snippet expansion and field management
|
||||||
|
|
||||||
(defvar yas--active-field-overlay nil
|
(defvar-local yas--active-field-overlay nil
|
||||||
"Overlays the currently active field.")
|
"Overlays the currently active field.")
|
||||||
|
|
||||||
(defvar yas--active-snippets nil
|
(defvar-local yas--active-snippets nil
|
||||||
"List of currently active snippets")
|
"List of currently active snippets")
|
||||||
(make-variable-buffer-local 'yas--active-snippets)
|
|
||||||
|
|
||||||
(defvar yas--field-protection-overlays nil
|
(defvar-local yas--field-protection-overlays nil
|
||||||
"Two overlays protect the current active field.")
|
"Two overlays protect the current active field.")
|
||||||
|
|
||||||
(defvar yas-selected-text nil
|
(defvar yas-selected-text nil
|
||||||
@ -3088,8 +3088,6 @@ other fields."
|
|||||||
(defvar yas--start-column nil
|
(defvar yas--start-column nil
|
||||||
"The column where the snippet expansion started.")
|
"The column where the snippet expansion started.")
|
||||||
|
|
||||||
(make-variable-buffer-local 'yas--active-field-overlay)
|
|
||||||
(make-variable-buffer-local 'yas--field-protection-overlays)
|
|
||||||
(put 'yas--active-field-overlay 'permanent-local t)
|
(put 'yas--active-field-overlay 'permanent-local t)
|
||||||
(put 'yas--field-protection-overlays 'permanent-local t)
|
(put 'yas--field-protection-overlays 'permanent-local t)
|
||||||
|
|
||||||
@ -3469,8 +3467,7 @@ This renders the snippet as ordinary text."
|
|||||||
|
|
||||||
(yas--message 4 "Snippet %s exited." (yas--snippet-id snippet)))
|
(yas--message 4 "Snippet %s exited." (yas--snippet-id snippet)))
|
||||||
|
|
||||||
(defvar yas--snippets-to-move nil)
|
(defvar-local yas--snippets-to-move nil)
|
||||||
(make-variable-buffer-local 'yas--snippets-to-move)
|
|
||||||
|
|
||||||
(defun yas--prepare-snippets-for-move (beg end buf pos)
|
(defun yas--prepare-snippets-for-move (beg end buf pos)
|
||||||
"Gather snippets in BEG..END for moving to POS in BUF."
|
"Gather snippets in BEG..END for moving to POS in BUF."
|
||||||
@ -3740,8 +3737,7 @@ BEG, END and LENGTH like overlay modification hooks."
|
|||||||
(delete-consecutive-dups
|
(delete-consecutive-dups
|
||||||
(cl-merge 'list list1 list2 cmp :key key)))
|
(cl-merge 'list list1 list2 cmp :key key)))
|
||||||
|
|
||||||
(defvar yas--before-change-modified-snippets nil)
|
(defvar-local yas--before-change-modified-snippets nil)
|
||||||
(make-variable-buffer-local 'yas--before-change-modified-snippets)
|
|
||||||
|
|
||||||
(defun yas--gather-active-snippets (overlay beg end then-delete)
|
(defun yas--gather-active-snippets (overlay beg end then-delete)
|
||||||
;; Add active snippets in BEG..END into an OVERLAY keyed entry of
|
;; Add active snippets in BEG..END into an OVERLAY keyed entry of
|
||||||
@ -3766,8 +3762,7 @@ BEG, END and LENGTH like overlay modification hooks."
|
|||||||
(when then-delete
|
(when then-delete
|
||||||
(cl-callf2 delq old yas--before-change-modified-snippets)))))
|
(cl-callf2 delq old yas--before-change-modified-snippets)))))
|
||||||
|
|
||||||
(defvar yas--todo-snippet-indent nil nil)
|
(defvar-local yas--todo-snippet-indent nil nil)
|
||||||
(make-variable-buffer-local 'yas--todo-snippet-indent)
|
|
||||||
|
|
||||||
(defun yas--on-field-overlay-modification (overlay after? beg end &optional length)
|
(defun yas--on-field-overlay-modification (overlay after? beg end &optional length)
|
||||||
"Clears the field and updates mirrors, conditionally.
|
"Clears the field and updates mirrors, conditionally.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user