[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master ae95810 43/51: ; Try to get more info about 873/919

From: Noam Postavsky
Subject: [elpa] master ae95810 43/51: ; Try to get more info about 873/919
Date: Sun, 13 May 2018 13:11:46 -0400 (EDT)

branch: master
commit ae9581028942dd0237a007fdc0a49a76ef8c3e11
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    ; Try to get more info about 873/919
    * yasnippet.el (yas--watch-auto-fill): New variable watcher to catch
    the problem.
    (yas--auto-fill): If `yas--original-auto-fill-function' is nil, print
    a warning with some info instead of signaling an error.
 yasnippet.el | 42 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/yasnippet.el b/yasnippet.el
index b36c422..bfce53c 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -582,6 +582,15 @@ override bindings from other packages (e.g., 
   "The original value of `auto-fill-function'.")
 (make-variable-buffer-local 'yas--original-auto-fill-function)
+(defun yas--watch-auto-fill (_sym newval _op _where)
+  (when (and (null newval) (eq auto-fill-function 'yas--auto-fill))
+    (debug nil "`yas--original-auto-fill-function' unexpectedly nil! Please 
report this backtrace (hit `c' to continue)")) )
+;; Try to get more info on #873/919 (this only works for Emacs 26+).
+(when (fboundp 'add-variable-watcher)
+  (add-variable-watcher 'yas--original-auto-fill-function
+                        #'yas--watch-auto-fill))
 (defun yas--snippet-next-id ()
   (let ((id yas--snippet-id-seed))
     (cl-incf yas--snippet-id-seed)
@@ -3683,7 +3692,38 @@ field start.  This hook does nothing if an undo is in 
     (goto-char orig-point)
     (let ((yas--inhibit-overlay-hooks t))
-      (funcall yas--original-auto-fill-function))
+      (if (null yas--original-auto-fill-function)
+          ;; Try to get more info on #873/919.
+          (let ((yas--fill-fun-values `((t ,(default-value 
+                (fill-fun-values `((t ,(default-value 'auto-fill-function))))
+                ;; Listing 2 buffers with the same value is enough
+                (print-length 3))
+            (save-current-buffer
+              (dolist (buf (let ((bufs (buffer-list)))
+                             ;; List the current buffer first.
+                             (setq bufs (cons (current-buffer)
+                                              (remq (current-buffer) bufs)))))
+                (set-buffer buf)
+                (let* ((yf-cell (assq yas--original-auto-fill-function
+                                      yas--fill-fun-values))
+                       (af-cell (assq auto-fill-function fill-fun-values)))
+                  (when (local-variable-p 'yas--original-auto-fill-function)
+                    (if yf-cell (setcdr yf-cell (cons buf (cdr yf-cell)))
+                      (push (list yas--original-auto-fill-function buf) 
+                  (when (local-variable-p 'auto-fill-function)
+                    (if af-cell (setcdr af-cell (cons buf (cdr af-cell)))
+                      (push (list auto-fill-function buf) fill-fun-values))))))
+                 (lwarn '(yasnippet auto-fill bug) :error
+                        "`yas--original-auto-fill-function' unexpectedly nil 
in %S!  Disabling auto-fill.
+  %S
+  `auto-fill-function': %S"
+                        (current-buffer) yas--fill-fun-values fill-fun-values)
+                 ;; Try to avoid repeated triggering of this bug.
+                 (auto-fill-mode -1)
+                 ;; Don't pop up more than once in a session (still log 
+                 (defvar warning-suppress-types) ; `warnings' is autoloaded by 
+                 (add-to-list 'warning-suppress-types '(yasnippet auto-fill 
+        (funcall yas--original-auto-fill-function)))
       (setq end (progn (forward-paragraph) (point)))
       (setq beg (progn (backward-paragraph) (point))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]