emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 78725e4: (electric-layout-post-self-insert-function


From: Stefan Monnier
Subject: [Emacs-diffs] master 78725e4: (electric-layout-post-self-insert-function-1): Simplify.
Date: Fri, 18 Jan 2019 17:20:32 -0500 (EST)

branch: master
commit 78725e49d2802d907c5b54417e6a91ed868c7c6e
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    (electric-layout-post-self-insert-function-1): Simplify.
    
    Call electric--after-char-pos right from the start, and take advantage of 
the
    fact that it guarantees to return the right position or nil.
---
 lisp/electric.el | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/lisp/electric.el b/lisp/electric.el
index 6977a95..e2f9f70 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -394,28 +394,23 @@ If multiple rules match, only first one is executed.")
 
 ;; for edebug's sake, a separate function
 (defun electric-layout-post-self-insert-function-1 ()
-  (let* (pos
+  (let* ((pos (electric--after-char-pos))
          probe
          (rules electric-layout-rules)
          (rule
           (catch 'done
-            (while (setq probe (pop rules))
-              (cond ((and (consp probe)
-                          (eq (car probe) last-command-event))
-                     (throw 'done (cdr probe)))
-                    ((functionp probe)
-                     (let ((res
-                            (save-excursion
-                              (goto-char
-                               (or pos (setq pos (electric--after-char-pos))))
-                              ;; Ensure probe is called at the
-                              ;; promised place. FIXME: maybe warn if
-                              ;; it isn't
-                              (when (eq (char-before) last-command-event)
-                                (funcall probe last-command-event)))))
-                       (when res (throw 'done res)))))))))
+            (when pos
+              (while (setq probe (pop rules))
+                (cond ((and (consp probe)
+                            (eq (car probe) last-command-event))
+                       (throw 'done (cdr probe)))
+                      ((functionp probe)
+                       (let ((res
+                              (save-excursion
+                                (goto-char pos)
+                                (funcall probe last-command-event))))
+                         (when res (throw 'done res))))))))))
     (when (and rule
-               (or pos (setq pos (electric--after-char-pos)))
                ;; Not in a string or comment.
                (not (nth 8 (save-excursion (syntax-ppss pos)))))
       (goto-char pos)



reply via email to

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