[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/fix-33794-extend-electric-layout-mode e4ef7a2 4/6:
From: |
João Távora |
Subject: |
[Emacs-diffs] scratch/fix-33794-extend-electric-layout-mode e4ef7a2 4/6: Handle entries of multiple symbols in electric-layout-rules |
Date: |
Sun, 23 Dec 2018 17:51:12 -0500 (EST) |
branch: scratch/fix-33794-extend-electric-layout-mode
commit e4ef7a2e2a480b9e1d6a8a869ffa8a7459abe9bd
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Handle entries of multiple symbols in electric-layout-rules
Instead of allowing multiple rules in electric-layout-rules, allow
rules to specify multiple symbols. This should be entirely
backward-compatible to existing customizations of that variable.
* lisp/electric.el (electric-layout-rules): a single entry can
specify multiple symbols.
(electric-layout-post-self-insert-function-1): rework.
* test/lisp/electric-tests.el: Update tests to work with new semantics
of electric-layout-rules.
---
lisp/electric.el | 49 +++++++++++++++++++++++++--------------------
test/lisp/electric-tests.el | 7 ++-----
2 files changed, 29 insertions(+), 27 deletions(-)
diff --git a/lisp/electric.el b/lisp/electric.el
index 6ea2eae..9646807 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -365,15 +365,21 @@ use `electric-indent-local-mode'."
Each rule has the form (CHAR . WHERE) where CHAR is the char that
was just inserted and WHERE specifies where to insert newlines
-and can be: nil, `before', `after', `around', `after-stay', or a
-function of no arguments that returns one of those symbols.
+and can be:
-The symbols specify where in relation to CHAR the newline
-character(s) should be inserted. `after-stay' means insert a
+* one of the symbols `before', `after', `around' and `after-stay';
+
+* a list of the preceding symbols, processed in order of
+ appearance to insert multiple newlines;
+
+* a function of no arguments that returns one of the previous
+ values.
+
+Each symbol specifies where in relation to CHAR the newline
+character(s) should be inserted. `after-stay' means insert a
newline after CHAR but stay in the same place.
-If multiple rules match, they are all executed in order of
-appearance.")
+If multiple rules match, only first one is executed.")
(defun electric-layout-post-self-insert-function ()
(when electric-layout-mode
@@ -381,25 +387,24 @@ appearance.")
;; for edebug's sake, a separate function
(defun electric-layout-post-self-insert-function-1 ()
- (let (pos end)
- (when (and (setq pos (electric--after-char-pos))
+ (let (pos
+ (rule (cdr (assq last-command-event electric-layout-rules))))
+ (when (and rule
+ (setq pos (electric--after-char-pos))
;; Not in a string or comment.
(not (nth 8 (save-excursion (syntax-ppss pos)))))
(goto-char pos)
- (setq end (point-marker))
- (dolist (rule electric-layout-rules)
- (when (eq last-command-event (car rule))
- (let* ((rule (cdr rule))
- (sym (if (functionp rule) (funcall rule) rule))
- (nl-after
+ (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: 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
@@ -422,7 +427,7 @@ appearance.")
('before (funcall nl-before))
('after (funcall nl-after))
('after-stay (save-excursion (funcall nl-after)))
- ('around (funcall nl-before) (funcall nl-after)))))))))
+ ('around (funcall nl-before) (funcall nl-after))))))))
(put 'electric-layout-post-self-insert-function 'priority 40)
diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el
index 971c3e9..b798a3f 100644
--- a/test/lisp/electric-tests.el
+++ b/test/lisp/electric-tests.el
@@ -823,8 +823,7 @@ baz\"\""
(electric-pair-local-mode 1)
(electric-indent-local-mode 1)
(setq-local electric-layout-rules
- '((?\{ . after)
- (?\{ . after-stay)))
+ '((?\{ . (after after-stay))))
(insert "int main () ")
(let ((last-command-event ?\{))
(call-interactively (key-binding `[,last-command-event])))
@@ -838,9 +837,7 @@ baz\"\""
(electric-pair-local-mode 1)
(electric-indent-local-mode 1)
(setq-local electric-layout-rules
- '((?\{ . before)
- (?\{ . after)
- (?\{ . after-stay)))
+ '((?\{ . (before after after-stay))))
(insert "int main () ")
(let ((last-command-event ?\{))
(call-interactively (key-binding `[,last-command-event])))
- [Emacs-diffs] branch scratch/fix-33794-extend-electric-layout-mode created (now 1173d50), João Távora, 2018/12/23
- [Emacs-diffs] scratch/fix-33794-extend-electric-layout-mode 6deb668 2/6: Rework electric-layout-post-self-insert-function (bug#33794), João Távora, 2018/12/23
- [Emacs-diffs] scratch/fix-33794-extend-electric-layout-mode cb1b4a8 1/6: Extend electric-layout-mode to handle more complex layouts, João Távora, 2018/12/23
- [Emacs-diffs] scratch/fix-33794-extend-electric-layout-mode e02256c 3/6: Minor cleanup in new electric-layout-mode after Stefan's feedback, João Távora, 2018/12/23
- [Emacs-diffs] scratch/fix-33794-extend-electric-layout-mode e4ef7a2 4/6: Handle entries of multiple symbols in electric-layout-rules,
João Távora <=
- [Emacs-diffs] scratch/fix-33794-extend-electric-layout-mode fae3e7c 5/6: Test electric.el in plainer c-mode without c-electric-{brace, paren}, João Távora, 2018/12/23
- [Emacs-diffs] scratch/fix-33794-extend-electric-layout-mode 1173d50 6/6: Slightly more powerful electric-layout-rules, João Távora, 2018/12/23