aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2011-11-11 10:55:24 -0500
committerStefan Monnier2011-11-11 10:55:24 -0500
commit65bd19ff8af487f16c55d250967321c0ee3e58a0 (patch)
treeaaca9068680d57d77519b9a579f925baae1fd5dd
parent5e92ca23ec308f2f72736ca2767f5329707ce5f3 (diff)
downloademacs-65bd19ff8af487f16c55d250967321c0ee3e58a0.tar.gz
emacs-65bd19ff8af487f16c55d250967321c0ee3e58a0.zip
* 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.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/electric.el31
2 files changed, 23 insertions, 14 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0e617e9c66d..6cd58cd3d22 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12011-11-11 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * electric.el (electric-indent-post-self-insert-function): Make it
4 possible for a char to only indent in some circumstances.
5 (electric-indent-mode): Simplify.
6
12011-11-11 Martin Rudalics <rudalics@gmx.at> 72011-11-11 Martin Rudalics <rudalics@gmx.at>
2 8
3 * window.el (windows-with-parameter): Remove unused function. 9 * window.el (windows-with-parameter): Remove unused function.
diff --git a/lisp/electric.el b/lisp/electric.el
index 3d7c1fd8ac4..69acb773648 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -197,7 +197,11 @@ Returns nil when we can't find this char."
197;; value, which only works well if the variable is preloaded. 197;; value, which only works well if the variable is preloaded.
198;;;###autoload 198;;;###autoload
199(defvar electric-indent-chars '(?\n) 199(defvar electric-indent-chars '(?\n)
200 "Characters that should cause automatic reindentation.") 200 "Characters that should cause automatic reindentation.
201Each entry of the list can be either a character or a cons of the
202form (CHAR . PREDICATE) which means that CHAR should cause reindentation
203only if PREDICATE returns non-nil. PREDICATE is called with no arguments
204and with point before the inserted char.")
201 205
202(defun electric-indent-post-self-insert-function () 206(defun electric-indent-post-self-insert-function ()
203 ;; FIXME: This reindents the current line, but what we really want instead is 207 ;; FIXME: This reindents the current line, but what we really want instead is
@@ -208,7 +212,12 @@ Returns nil when we can't find this char."
208 ;; There might be a way to get it working by analyzing buffer-undo-list, but 212 ;; There might be a way to get it working by analyzing buffer-undo-list, but
209 ;; it looks challenging. 213 ;; it looks challenging.
210 (let (pos) 214 (let (pos)
211 (when (and (memq last-command-event electric-indent-chars) 215 (when (and (or (memq last-command-event electric-indent-chars)
216 (let ((cp (assq last-command-event electric-indent-chars)))
217 (and cp (setq pos (electric--after-char-pos))
218 (save-excursion
219 (goto-char (1- pos))
220 (funcall (cdr cp))))))
212 ;; Don't reindent while inserting spaces at beginning of line. 221 ;; Don't reindent while inserting spaces at beginning of line.
213 (or (not (memq last-command-event '(?\s ?\t))) 222 (or (not (memq last-command-event '(?\s ?\t)))
214 (save-excursion (skip-chars-backward " \t") (not (bolp)))) 223 (save-excursion (skip-chars-backward " \t") (not (bolp))))
@@ -253,19 +262,13 @@ in `electric-indent-chars'."
253 :group 'electricity 262 :group 'electricity
254 (if electric-indent-mode 263 (if electric-indent-mode
255 (add-hook 'post-self-insert-hook 264 (add-hook 'post-self-insert-hook
256 #'electric-indent-post-self-insert-function) 265 #'electric-indent-post-self-insert-function
266 ;; post-self-insert-hooks interact in non-trivial ways.
267 ;; It turns out that electric-indent-mode generally works
268 ;; better last.
269 'append)
257 (remove-hook 'post-self-insert-hook 270 (remove-hook 'post-self-insert-hook
258 #'electric-indent-post-self-insert-function)) 271 #'electric-indent-post-self-insert-function)))
259 ;; FIXME: electric-indent-mode and electric-layout-mode interact
260 ;; in non-trivial ways. It turns out that electric-indent-mode works
261 ;; better if it is run *after* electric-layout-mode's hook.
262 (when (memq #'electric-layout-post-self-insert-function
263 (memq #'electric-indent-post-self-insert-function
264 (default-value 'post-self-insert-hook)))
265 (remove-hook 'post-self-insert-hook
266 #'electric-layout-post-self-insert-function)
267 (add-hook 'post-self-insert-hook
268 #'electric-layout-post-self-insert-function)))
269 272
270;; Electric pairing. 273;; Electric pairing.
271 274