emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r114994: * lisp/electric.el (electric-indent-local-m


From: Stefan Monnier
Subject: [Emacs-diffs] trunk r114994: * lisp/electric.el (electric-indent-local-mode): New minor mode.
Date: Wed, 06 Nov 2013 02:10:25 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114994
revision-id: address@hidden
parent: address@hidden
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Tue 2013-11-05 21:10:18 -0500
message:
  * lisp/electric.el (electric-indent-local-mode): New minor mode.
  (electric-indent-functions-without-reindent): New var.
  (electric-indent-post-self-insert-function): Use it.
  * lisp/emacs-lisp/gv.el (buffer-local-value): Add setter.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/electric.el               electric.el-20091113204419-o5vbwnq5f7feedwu-47
  lisp/emacs-lisp/gv.el          setf.el-20120531120738-6w8114hk2anryyud-1
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-11-05 16:36:37 +0000
+++ b/lisp/ChangeLog    2013-11-06 02:10:18 +0000
@@ -1,3 +1,10 @@
+2013-11-06  Stefan Monnier  <address@hidden>
+
+       * electric.el (electric-indent-local-mode): New minor mode.
+       (electric-indent-functions-without-reindent): New var.
+       (electric-indent-post-self-insert-function): Use it.
+       * emacs-lisp/gv.el (buffer-local-value): Add setter.
+
 2013-11-05  Eli Zaretskii  <address@hidden>
 
        * international/quail.el (quail-help): Be more explicit about the

=== modified file 'lisp/electric.el'
--- a/lisp/electric.el  2013-11-04 20:04:25 +0000
+++ b/lisp/electric.el  2013-11-06 02:10:18 +0000
@@ -207,6 +207,15 @@
 This should be set by major modes such as `python-mode' since
 Python does not lend itself to fully automatic indentation.")
 
+(defvar electric-indent-functions-without-reindent
+  '(indent-relative indent-to-left-margin indent-relative-maybe
+    py-indent-line coffee-indent-line org-indent-line
+    haskell-indentation-indent-line haskell-indent-cycle haskell-simple-indent)
+  "List of indent functions that can't reindent.
+If `line-indent-function' is one of those, then `electric-indent-mode' will
+not try to reindent lines.  It is normally better to make the major
+mode set `electric-indent-inhibit', but this can be used as a workaround.")
+
 (defun electric-indent-post-self-insert-function ()
   ;; FIXME: This reindents the current line, but what we really want instead is
   ;; to reindent the whole affected text.  That's the current line for simple
@@ -238,8 +247,7 @@
         (let ((before (copy-marker (1- pos) t)))
           (save-excursion
             (unless (or (memq indent-line-function
-                              '(indent-relative indent-to-left-margin
-                                                indent-relative-maybe))
+                              electric-indent-functions-without-reindent)
                         electric-indent-inhibit)
               ;; Don't reindent the previous line if the indentation function
               ;; is not a real one.
@@ -255,9 +263,8 @@
              ;; Remove the trailing whitespace after indentation because
              ;; indentation may (re)introduce the whitespace.
              (delete-horizontal-space t)))))
-      (unless (or (memq indent-line-function '(indent-to-left-margin))
-                  (and electric-indent-inhibit
-                       (> pos (line-beginning-position))))
+      (unless (and electric-indent-inhibit
+                   (> pos (line-beginning-position)))
         (indent-according-to-mode)))))
 
 ;;;###autoload
@@ -289,6 +296,19 @@
                          (delq #'electric-indent-post-self-insert-function
                                (cdr bp))))))))
 
+;;;###autoload
+(define-minor-mode electric-indent-local-mode
+  "Toggle `electric-indent-mode' only in this buffer."
+  :variable (buffer-local-value 'electric-indent-mode (current-buffer))
+  (cond
+   ((eq electric-indent-mode (default-value 'electric-indent-mode))
+    (kill-local-variable 'electric-indent-mode))
+   ((not (default-value 'electric-indent-mode))
+    ;; Locally enabled, but globally disabled.
+    (electric-indent-mode 1)                ; Setup the hooks.
+    (setq-default electric-indent-mode nil) ; But keep it globally disabled.
+    )))
+
 ;;; Electric pairing.
 
 (defcustom electric-pair-pairs

=== modified file 'lisp/emacs-lisp/gv.el'
--- a/lisp/emacs-lisp/gv.el     2013-09-04 20:03:52 +0000
+++ b/lisp/emacs-lisp/gv.el     2013-11-06 02:10:18 +0000
@@ -346,6 +346,10 @@
 (gv-define-simple-setter window-point set-window-point)
 (gv-define-simple-setter window-start set-window-start)
 
+(gv-define-setter buffer-local-value (val var buf)
+  (macroexp-let2 nil v val
+    `(with-current-buffer ,buf (set (make-local-variable ,var) ,v))))
+
 ;;; Some occasionally handy extensions.
 
 ;; While several of the "places" below are not terribly useful for direct use,


reply via email to

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