emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r106351: * lisp/electric.el: Make ele


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r106351: * lisp/electric.el: Make electric-indent-mode better behaved.
Date: Fri, 11 Nov 2011 10:55:24 -0500
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 106351
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Fri 2011-11-11 10:55:24 -0500
message:
  * lisp/electric.el: Make electric-indent-mode better behaved.
  * lisp/electric.el (electric-indent-post-self-insert-function): Make it
  possible for a char to only indent in some circumstances.
  (electric-indent-mode): Simplify.
modified:
  lisp/ChangeLog
  lisp/electric.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-11-11 10:23:23 +0000
+++ b/lisp/ChangeLog    2011-11-11 15:55:24 +0000
@@ -1,3 +1,9 @@
+2011-11-11  Stefan Monnier  <address@hidden>
+
+       * electric.el (electric-indent-post-self-insert-function): Make it
+       possible for a char to only indent in some circumstances.
+       (electric-indent-mode): Simplify.
+
 2011-11-11  Martin Rudalics  <address@hidden>
 
        * window.el (windows-with-parameter): Remove unused function.

=== modified file 'lisp/electric.el'
--- a/lisp/electric.el  2011-11-09 15:10:25 +0000
+++ b/lisp/electric.el  2011-11-11 15:55:24 +0000
@@ -197,7 +197,11 @@
 ;; value, which only works well if the variable is preloaded.
 ;;;###autoload
 (defvar electric-indent-chars '(?\n)
-  "Characters that should cause automatic reindentation.")
+  "Characters that should cause automatic reindentation.
+Each entry of the list can be either a character or a cons of the
+form (CHAR . PREDICATE) which means that CHAR should cause reindentation
+only if PREDICATE returns non-nil.  PREDICATE is called with no arguments
+and with point before the inserted char.")
 
 (defun electric-indent-post-self-insert-function ()
   ;; FIXME: This reindents the current line, but what we really want instead is
@@ -208,7 +212,12 @@
   ;; There might be a way to get it working by analyzing buffer-undo-list, but
   ;; it looks challenging.
   (let (pos)
-    (when (and (memq last-command-event electric-indent-chars)
+    (when (and (or (memq last-command-event electric-indent-chars)
+                   (let ((cp (assq last-command-event electric-indent-chars)))
+                     (and cp (setq pos (electric--after-char-pos))
+                          (save-excursion
+                            (goto-char (1- pos))
+                            (funcall (cdr cp))))))
                ;; Don't reindent while inserting spaces at beginning of line.
                (or (not (memq last-command-event '(?\s ?\t)))
                    (save-excursion (skip-chars-backward " \t") (not (bolp))))
@@ -253,19 +262,13 @@
   :group 'electricity
   (if electric-indent-mode
       (add-hook 'post-self-insert-hook
-                #'electric-indent-post-self-insert-function)
-    (remove-hook 'post-self-insert-hook
-                 #'electric-indent-post-self-insert-function))
-  ;; FIXME: electric-indent-mode and electric-layout-mode interact
-  ;; in non-trivial ways.  It turns out that electric-indent-mode works
-  ;; better if it is run *after* electric-layout-mode's hook.
-  (when (memq #'electric-layout-post-self-insert-function
-              (memq #'electric-indent-post-self-insert-function
-                    (default-value 'post-self-insert-hook)))
-    (remove-hook 'post-self-insert-hook
-                 #'electric-layout-post-self-insert-function)
-    (add-hook 'post-self-insert-hook
-              #'electric-layout-post-self-insert-function)))
+                #'electric-indent-post-self-insert-function
+                ;; post-self-insert-hooks interact in non-trivial ways.
+                ;; It turns out that electric-indent-mode generally works
+                ;; better last.
+                'append)
+    (remove-hook 'post-self-insert-hook
+                 #'electric-indent-post-self-insert-function)))
 
 ;; Electric pairing.
 


reply via email to

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