emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] scratch/fix-33794-extend-electric-layout-mode 1299027 1/2:


From: João Távora
Subject: [Emacs-diffs] scratch/fix-33794-extend-electric-layout-mode 1299027 1/2: Clean up description of new semantics of electric-layout-rules
Date: Mon, 24 Dec 2018 07:43:07 -0500 (EST)

branch: scratch/fix-33794-extend-electric-layout-mode
commit 1299027eb2f58beba457b953fff3369f3cbad816
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Clean up description of new semantics of electric-layout-rules
    
    * 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 | 53 +++++++++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/lisp/electric.el b/lisp/electric.el
index fb0a913..27d2bd8 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -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")



reply via email to

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