Minor code shuffling and commenting

* yasnippet.el (yas--do-todo-snippet-indent): Renamed from
yas--do-todo-snippet-indent.
This commit is contained in:
Noam Postavsky 2019-05-02 18:14:52 -04:00
parent 55c448b991
commit f056a4def8

View File

@ -3778,10 +3778,6 @@ BEG, END and LENGTH like overlay modification hooks."
(= beg (yas--field-start field)) ; Insertion at field start? (= beg (yas--field-start field)) ; Insertion at field start?
(not (yas--field-modified-p field)))) (not (yas--field-modified-p field))))
(defvar yas--todo-snippet-indent nil nil)
(make-variable-buffer-local 'yas--todo-snippet-indent)
(defvar yas--before-change-modified-snippets nil)
(defun yas--merge-and-drop-dups (list1 list2 cmp key) (defun yas--merge-and-drop-dups (list1 list2 cmp key)
;; `delete-consecutive-dups' + `cl-merge'. ;; `delete-consecutive-dups' + `cl-merge'.
@ -3790,6 +3786,9 @@ BEG, END and LENGTH like overlay modification hooks."
#'delete-dups) #'delete-dups)
(cl-merge 'list list1 list2 cmp :key key))) (cl-merge 'list list1 list2 cmp :key key)))
(defvar 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
;; `yas--before-change-modified-snippets'. Return accumulated list. ;; `yas--before-change-modified-snippets'. Return accumulated list.
@ -3813,6 +3812,8 @@ 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)
(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.
@ -3866,7 +3867,9 @@ field start. This hook does nothing if an undo is in progress."
(lwarn '(yasnippet zombie) :warning "Killing zombie snippet!") (lwarn '(yasnippet zombie) :warning "Killing zombie snippet!")
(delete-overlay overlay))))) (delete-overlay overlay)))))
(defun yas--do-todo-field-updates () (defun yas--do-todo-snippet-indent ()
;; Do pending indentation of snippet fields, called from
;; `yas--post-command-handler'.
(when yas--todo-snippet-indent (when yas--todo-snippet-indent
(save-excursion (save-excursion
(cl-loop for snippet in yas--todo-snippet-indent (cl-loop for snippet in yas--todo-snippet-indent
@ -3875,6 +3878,7 @@ field start. This hook does nothing if an undo is in progress."
(setq yas--todo-snippet-indent nil)))) (setq yas--todo-snippet-indent nil))))
(defun yas--auto-fill () (defun yas--auto-fill ()
;; Preserve snippet markers during auto-fill.
(let* ((orig-point (point)) (let* ((orig-point (point))
(end (progn (forward-paragraph) (point))) (end (progn (forward-paragraph) (point)))
(beg (progn (backward-paragraph) (point))) (beg (progn (backward-paragraph) (point)))
@ -3890,44 +3894,44 @@ field start. This hook does nothing if an undo is in progress."
reoverlays)) reoverlays))
(goto-char orig-point) (goto-char orig-point)
(let ((yas--inhibit-overlay-hooks t)) (let ((yas--inhibit-overlay-hooks t))
(if (null yas--original-auto-fill-function) (if yas--original-auto-fill-function
;; Try to get more info on #873/919. (funcall yas--original-auto-fill-function)
(let ((yas--fill-fun-values `((t ,(default-value 'yas--original-auto-fill-function)))) ;; Shouldn't happen, gather more info about it (see #873/919).
(fill-fun-values `((t ,(default-value 'auto-fill-function)))) (let ((yas--fill-fun-values `((t ,(default-value 'yas--original-auto-fill-function))))
;; Listing 2 buffers with the same value is enough (fill-fun-values `((t ,(default-value 'auto-fill-function))))
(print-length 3)) ;; Listing 2 buffers with the same value is enough
(save-current-buffer (print-length 3))
(dolist (buf (let ((bufs (buffer-list))) (save-current-buffer
;; List the current buffer first. (dolist (buf (let ((bufs (buffer-list)))
(setq bufs (cons (current-buffer) ;; List the current buffer first.
(remq (current-buffer) bufs))))) (setq bufs (cons (current-buffer)
(set-buffer buf) (remq (current-buffer) bufs)))))
(let* ((yf-cell (assq yas--original-auto-fill-function (set-buffer buf)
yas--fill-fun-values)) (let* ((yf-cell (assq yas--original-auto-fill-function
(af-cell (assq auto-fill-function fill-fun-values))) yas--fill-fun-values))
(when (local-variable-p 'yas--original-auto-fill-function) (af-cell (assq auto-fill-function fill-fun-values)))
(if yf-cell (setcdr yf-cell (cons buf (cdr yf-cell))) (when (local-variable-p 'yas--original-auto-fill-function)
(push (list yas--original-auto-fill-function buf) yas--fill-fun-values))) (if yf-cell (setcdr yf-cell (cons buf (cdr yf-cell)))
(when (local-variable-p 'auto-fill-function) (push (list yas--original-auto-fill-function buf) yas--fill-fun-values)))
(if af-cell (setcdr af-cell (cons buf (cdr af-cell))) (when (local-variable-p 'auto-fill-function)
(push (list auto-fill-function buf) fill-fun-values)))))) (if af-cell (setcdr af-cell (cons buf (cdr af-cell)))
(lwarn '(yasnippet auto-fill bug) :error (push (list auto-fill-function buf) fill-fun-values))))))
"`yas--original-auto-fill-function' unexpectedly nil in %S! Disabling auto-fill. (lwarn '(yasnippet auto-fill bug) :error
"`yas--original-auto-fill-function' unexpectedly nil in %S! Disabling auto-fill.
%S %S
`auto-fill-function': %S\n%s" `auto-fill-function': %S\n%s"
(current-buffer) yas--fill-fun-values fill-fun-values (current-buffer) yas--fill-fun-values fill-fun-values
(if (fboundp 'backtrace--print-frame) (if (fboundp 'backtrace--print-frame)
(with-output-to-string (with-output-to-string
(mapc (lambda (frame) (mapc (lambda (frame)
(apply #'backtrace--print-frame frame)) (apply #'backtrace--print-frame frame))
yas--watch-auto-fill-backtrace)) yas--watch-auto-fill-backtrace))
"")) ""))
;; Try to avoid repeated triggering of this bug. ;; Try to avoid repeated triggering of this bug.
(auto-fill-mode -1) (auto-fill-mode -1)
;; Don't pop up more than once in a session (still log though). ;; Don't pop up more than once in a session (still log though).
(defvar warning-suppress-types) ; `warnings' is autoloaded by `lwarn'. (defvar warning-suppress-types) ; `warnings' is autoloaded by `lwarn'.
(add-to-list 'warning-suppress-types '(yasnippet auto-fill bug))) (add-to-list 'warning-suppress-types '(yasnippet auto-fill bug)))))
(funcall yas--original-auto-fill-function)))
(save-excursion (save-excursion
(setq end (progn (forward-paragraph) (point))) (setq end (progn (forward-paragraph) (point)))
(setq beg (progn (backward-paragraph) (point)))) (setq beg (progn (backward-paragraph) (point))))
@ -4958,7 +4962,7 @@ When multiple expressions are found, only the last one counts."
;; Don't pop up more than once in a session (still log though). ;; Don't pop up more than once in a session (still log though).
(defvar warning-suppress-types) ; `warnings' is autoloaded by `lwarn'. (defvar warning-suppress-types) ; `warnings' is autoloaded by `lwarn'.
(add-to-list 'warning-suppress-types '(yasnippet auto-fill bug))) (add-to-list 'warning-suppress-types '(yasnippet auto-fill bug)))
(yas--do-todo-field-updates) (yas--do-todo-snippet-indent)
(condition-case err (condition-case err
(progn (yas--finish-moving-snippets) (progn (yas--finish-moving-snippets)
(cond ((eq 'undo this-command) (cond ((eq 'undo this-command)