diff options
| author | Stefan Monnier | 2013-11-05 21:10:18 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2013-11-05 21:10:18 -0500 |
| commit | a35287ea23112e3e6dc73de6066f31fbe1cb269c (patch) | |
| tree | 4165edecbaeb4d526d8189cd7fea1c8db73c7ad3 /lisp | |
| parent | 798aef02223bdfdf4ff383e59590b2a44eaf3a0c (diff) | |
| download | emacs-a35287ea23112e3e6dc73de6066f31fbe1cb269c.tar.gz emacs-a35287ea23112e3e6dc73de6066f31fbe1cb269c.zip | |
* 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.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/electric.el | 30 | ||||
| -rw-r--r-- | lisp/emacs-lisp/gv.el | 4 |
3 files changed, 36 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9d5d97b3014..5b4cba44021 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2013-11-06 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * electric.el (electric-indent-local-mode): New minor mode. | ||
| 4 | (electric-indent-functions-without-reindent): New var. | ||
| 5 | (electric-indent-post-self-insert-function): Use it. | ||
| 6 | * emacs-lisp/gv.el (buffer-local-value): Add setter. | ||
| 7 | |||
| 1 | 2013-11-05 Eli Zaretskii <eliz@gnu.org> | 8 | 2013-11-05 Eli Zaretskii <eliz@gnu.org> |
| 2 | 9 | ||
| 3 | * international/quail.el (quail-help): Be more explicit about the | 10 | * international/quail.el (quail-help): Be more explicit about the |
diff --git a/lisp/electric.el b/lisp/electric.el index 1f95e68dbf5..9a89587ff93 100644 --- a/lisp/electric.el +++ b/lisp/electric.el | |||
| @@ -207,6 +207,15 @@ point right after that char, and it should return t to cause indentation, | |||
| 207 | This should be set by major modes such as `python-mode' since | 207 | This should be set by major modes such as `python-mode' since |
| 208 | Python does not lend itself to fully automatic indentation.") | 208 | Python does not lend itself to fully automatic indentation.") |
| 209 | 209 | ||
| 210 | (defvar electric-indent-functions-without-reindent | ||
| 211 | '(indent-relative indent-to-left-margin indent-relative-maybe | ||
| 212 | py-indent-line coffee-indent-line org-indent-line | ||
| 213 | haskell-indentation-indent-line haskell-indent-cycle haskell-simple-indent) | ||
| 214 | "List of indent functions that can't reindent. | ||
| 215 | If `line-indent-function' is one of those, then `electric-indent-mode' will | ||
| 216 | not try to reindent lines. It is normally better to make the major | ||
| 217 | mode set `electric-indent-inhibit', but this can be used as a workaround.") | ||
| 218 | |||
| 210 | (defun electric-indent-post-self-insert-function () | 219 | (defun electric-indent-post-self-insert-function () |
| 211 | ;; FIXME: This reindents the current line, but what we really want instead is | 220 | ;; FIXME: This reindents the current line, but what we really want instead is |
| 212 | ;; to reindent the whole affected text. That's the current line for simple | 221 | ;; to reindent the whole affected text. That's the current line for simple |
| @@ -238,8 +247,7 @@ Python does not lend itself to fully automatic indentation.") | |||
| 238 | (let ((before (copy-marker (1- pos) t))) | 247 | (let ((before (copy-marker (1- pos) t))) |
| 239 | (save-excursion | 248 | (save-excursion |
| 240 | (unless (or (memq indent-line-function | 249 | (unless (or (memq indent-line-function |
| 241 | '(indent-relative indent-to-left-margin | 250 | electric-indent-functions-without-reindent) |
| 242 | indent-relative-maybe)) | ||
| 243 | electric-indent-inhibit) | 251 | electric-indent-inhibit) |
| 244 | ;; Don't reindent the previous line if the indentation function | 252 | ;; Don't reindent the previous line if the indentation function |
| 245 | ;; is not a real one. | 253 | ;; is not a real one. |
| @@ -255,9 +263,8 @@ Python does not lend itself to fully automatic indentation.") | |||
| 255 | ;; Remove the trailing whitespace after indentation because | 263 | ;; Remove the trailing whitespace after indentation because |
| 256 | ;; indentation may (re)introduce the whitespace. | 264 | ;; indentation may (re)introduce the whitespace. |
| 257 | (delete-horizontal-space t))))) | 265 | (delete-horizontal-space t))))) |
| 258 | (unless (or (memq indent-line-function '(indent-to-left-margin)) | 266 | (unless (and electric-indent-inhibit |
| 259 | (and electric-indent-inhibit | 267 | (> pos (line-beginning-position))) |
| 260 | (> pos (line-beginning-position)))) | ||
| 261 | (indent-according-to-mode))))) | 268 | (indent-according-to-mode))))) |
| 262 | 269 | ||
| 263 | ;;;###autoload | 270 | ;;;###autoload |
| @@ -289,6 +296,19 @@ insert a character from `electric-indent-chars'." | |||
| 289 | (delq #'electric-indent-post-self-insert-function | 296 | (delq #'electric-indent-post-self-insert-function |
| 290 | (cdr bp)))))))) | 297 | (cdr bp)))))))) |
| 291 | 298 | ||
| 299 | ;;;###autoload | ||
| 300 | (define-minor-mode electric-indent-local-mode | ||
| 301 | "Toggle `electric-indent-mode' only in this buffer." | ||
| 302 | :variable (buffer-local-value 'electric-indent-mode (current-buffer)) | ||
| 303 | (cond | ||
| 304 | ((eq electric-indent-mode (default-value 'electric-indent-mode)) | ||
| 305 | (kill-local-variable 'electric-indent-mode)) | ||
| 306 | ((not (default-value 'electric-indent-mode)) | ||
| 307 | ;; Locally enabled, but globally disabled. | ||
| 308 | (electric-indent-mode 1) ; Setup the hooks. | ||
| 309 | (setq-default electric-indent-mode nil) ; But keep it globally disabled. | ||
| 310 | ))) | ||
| 311 | |||
| 292 | ;;; Electric pairing. | 312 | ;;; Electric pairing. |
| 293 | 313 | ||
| 294 | (defcustom electric-pair-pairs | 314 | (defcustom electric-pair-pairs |
diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index 8a5841a5fad..1a3800597a6 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el | |||
| @@ -346,6 +346,10 @@ The return value is the last VAL in the list. | |||
| 346 | (gv-define-simple-setter window-point set-window-point) | 346 | (gv-define-simple-setter window-point set-window-point) |
| 347 | (gv-define-simple-setter window-start set-window-start) | 347 | (gv-define-simple-setter window-start set-window-start) |
| 348 | 348 | ||
| 349 | (gv-define-setter buffer-local-value (val var buf) | ||
| 350 | (macroexp-let2 nil v val | ||
| 351 | `(with-current-buffer ,buf (set (make-local-variable ,var) ,v)))) | ||
| 352 | |||
| 349 | ;;; Some occasionally handy extensions. | 353 | ;;; Some occasionally handy extensions. |
| 350 | 354 | ||
| 351 | ;; While several of the "places" below are not terribly useful for direct use, | 355 | ;; While several of the "places" below are not terribly useful for direct use, |