]> git.eshelyaron.com Git - emacs.git/commitdiff
Clean up description of new semantics of electric-layout-rules
authorJoão Távora <joaotavora@gmail.com>
Mon, 24 Dec 2018 12:15:46 +0000 (12:15 +0000)
committerJoão Távora <joaotavora@gmail.com>
Mon, 24 Dec 2018 12:15:46 +0000 (12:15 +0000)
* lisp/electric.el (electric-layout-rules): Describe function
elements.
(electric-layout-post-self-insert-function-1): Fix handling of
function elements.  Describe that e-l-m is good enough to handle
electric-pair-open-newline-between-pairs.

lisp/electric.el

index fb0a913f3bec4b6a1d2982d57f62fd1f8a22af2a..27d2bd83d497bef6426f5247b895deef41ffd465 100644 (file)
@@ -373,7 +373,8 @@ CHAR or if the function return non-nil.
 
 WHERE and can be:
 
-* one of the symbols `before', `after', `around' and `after-stay';
+* one of the symbols `before', `after', `around', `after-stay' or
+  nil;
 
 * a list of the preceding symbols, processed in order of
   appearance to insert multiple newlines;
@@ -386,6 +387,10 @@ the character inserted, the newline character(s) should be
 inserted.  `after-stay' means insert a newline after POS but stay
 in the same place.
 
+Instead of the (MATCHER . WHERE) form, a rule can also be just a
+function of no arguments.  It should return a value compatible
+with WHERE if the rule matches, or nil if it doesn't match.
+
 If multiple rules match, only first one is executed.")
 
 (defun electric-layout-post-self-insert-function ()
@@ -406,7 +411,8 @@ If multiple rules match, only first one is executed.")
                                    (funcall (car probe)))))
                      (throw 'done (cdr probe)))
                     ((functionp probe)
-                     (throw 'done (funcall probe))))))))
+                     (let ((res (funcall probe)))
+                       (when res (throw 'done res)))))))))
     (when (and rule
                (setq pos (electric--after-char-pos))
                ;; Not in a string or comment.
@@ -415,28 +421,27 @@ If multiple rules match, only first one is executed.")
       (when (functionp rule) (setq rule (funcall rule)))
       (dolist (sym (if (symbolp rule) (list rule) rule))
         (let* ((nl-after
-                  (lambda ()
-                    ;; FIXME: we use `newline', which calls
-                    ;; `self-insert-command' and ran
-                    ;; `post-self-insert-hook' recursively.  It
-                    ;; happened to make `electric-indent-mode' work
-                    ;; automatically with `electric-layout-mode' (at
-                    ;; the cost of re-indenting lines multiple times),
-                    ;; but I'm not sure it's what we want.
-                    ;;
-                    ;; FIXME: when `newline'ing, we exceptionally
-                    ;; prevent a specific behaviour of
-                    ;; `eletric-pair-mode', that of opening an extra
-                    ;; newline between newly inserted matching paris.
-                    ;; In theory that behaviour should be provided by
-                    ;; `electric-layout-mode' instead, but its API is
-                    ;; not powerful enough to detect the exact
-                    ;; situation.
-                    ;;
-                    ;; FIXME: check eolp before inserting \n?
-                    (let ((electric-layout-mode nil)
-                          (electric-pair-open-newline-between-pairs nil))
-                      (newline 1 t))))
+                (lambda ()
+                  ;; FIXME: we use `newline', which calls
+                  ;; `self-insert-command' and ran
+                  ;; `post-self-insert-hook' recursively.  It
+                  ;; happened to make `electric-indent-mode' work
+                  ;; automatically with `electric-layout-mode' (at
+                  ;; the cost of re-indenting lines multiple times),
+                  ;; but I'm not sure it's what we want.
+                  ;;
+                  ;; FIXME: when `newline'ing, we exceptionally
+                  ;; prevent a specific behaviour of
+                  ;; `eletric-pair-mode', that of opening an extra
+                  ;; newline between newly inserted matching paris.
+                  ;; In theory that behaviour should be provided by
+                  ;; `electric-layout-mode' instead, which should be
+                  ;; possible given the current API.
+                  ;;
+                  ;; FIXME: check eolp before inserting \n?
+                  (let ((electric-layout-mode nil)
+                        (electric-pair-open-newline-between-pairs nil))
+                    (newline 1 t))))
                  (nl-before (lambda ()
                               (save-excursion
                                 (goto-char (1- pos)) (skip-chars-backward " \t")