diff options
| author | Alan Mackenzie | 2014-02-17 18:16:32 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2014-02-17 18:16:32 +0000 |
| commit | 29238d289dc33b70059bdfd82588db84254004a1 (patch) | |
| tree | 39091b337797af9b617cdc0f2d2500523e993ad3 | |
| parent | 6faf982a0e21895e1a3aa682a5cecd74b609a30d (diff) | |
| download | emacs-29238d289dc33b70059bdfd82588db84254004a1.tar.gz emacs-29238d289dc33b70059bdfd82588db84254004a1.zip | |
Connect electric-indent-mode up with CC Mode. Bug #15478.
* progmodes/cc-mode.el (c-initialize-cc-mode): add CC Mode hooks
to electric-indent-{,local-}-mode.
(c-basic-common-init): Set electric-indent-inhibit. Initialise
c-electric-flag from electric-indent-mode.
(c-electric-indent-mode-hook, c-electric-indent-local-mode-hook):
New hook functions which propagate electric-indent-mode to CC Mode.
* progmodes/cc-cmds.el (c-toggle-electric-state): When C-c C-l is
hit, toggle electric-indent-local-moode.
* electric.el (electric-indent-mode-has-been-called): New variable.
| -rw-r--r-- | lisp/ChangeLog | 17 | ||||
| -rw-r--r-- | lisp/electric.el | 5 | ||||
| -rw-r--r-- | lisp/progmodes/cc-cmds.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 39 |
4 files changed, 61 insertions, 2 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 27a0ffd30a5..5dad77bcdf9 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,20 @@ | |||
| 1 | 2014-02-17 Alan Mackenzie <acm@muc.de> | ||
| 2 | |||
| 3 | Connect electric-indent-mode up with CC Mode. Bug #15478. | ||
| 4 | * progmodes/cc-mode.el (c-initialize-cc-mode): add CC Mode hooks | ||
| 5 | to electric-indent-{,local-}-mode. | ||
| 6 | (c-basic-common-init): Set electric-indent-inhibit. Initialise | ||
| 7 | c-electric-flag from electric-indent-mode. | ||
| 8 | (c-electric-indent-mode-hook, c-electric-indent-local-mode-hook): | ||
| 9 | New hook functions which propagate electric-indent-mode to CC | ||
| 10 | Mode. | ||
| 11 | |||
| 12 | * progmodes/cc-cmds.el (c-toggle-electric-state): When C-c C-l is | ||
| 13 | hit, toggle electric-indent-local-moode. | ||
| 14 | |||
| 15 | * electric.el (electric-indent-mode-has-been-called): New | ||
| 16 | variable. | ||
| 17 | |||
| 1 | 2014-02-17 Juanma Barranquero <lekktu@gmail.com> | 18 | 2014-02-17 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 19 | ||
| 3 | * frameset.el (frameset-cfg-id): New function. | 20 | * frameset.el (frameset-cfg-id): New function. |
diff --git a/lisp/electric.el b/lisp/electric.el index 32c4a824491..4549fcad83c 100644 --- a/lisp/electric.el +++ b/lisp/electric.el | |||
| @@ -286,6 +286,9 @@ mode set `electric-indent-inhibit', but this can be used as a workaround.") | |||
| 286 | (let ((electric-indent-mode nil)) | 286 | (let ((electric-indent-mode nil)) |
| 287 | (newline arg 'interactive))) | 287 | (newline arg 'interactive))) |
| 288 | 288 | ||
| 289 | (defvar electric-indent-mode-has-been-called 0 | ||
| 290 | "How many times has `electric-indent-mode' been called? | ||
| 291 | It's > 1 if it's been called at least once by the user.") | ||
| 289 | ;;;###autoload | 292 | ;;;###autoload |
| 290 | (define-minor-mode electric-indent-mode | 293 | (define-minor-mode electric-indent-mode |
| 291 | "Toggle on-the-fly reindentation (Electric Indent mode). | 294 | "Toggle on-the-fly reindentation (Electric Indent mode). |
| @@ -299,6 +302,8 @@ insert a character from `electric-indent-chars'." | |||
| 299 | :global t :group 'electricity | 302 | :global t :group 'electricity |
| 300 | :initialize 'custom-initialize-delay | 303 | :initialize 'custom-initialize-delay |
| 301 | :init-value t | 304 | :init-value t |
| 305 | (setq electric-indent-mode-has-been-called | ||
| 306 | (1+ electric-indent-mode-has-been-called)) | ||
| 302 | (if (not electric-indent-mode) | 307 | (if (not electric-indent-mode) |
| 303 | (progn | 308 | (progn |
| 304 | (when (eq (lookup-key global-map [?\C-j]) | 309 | (when (eq (lookup-key global-map [?\C-j]) |
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index bf651f8ae99..4f205d62a4c 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el | |||
| @@ -356,6 +356,8 @@ left out." | |||
| 356 | (interactive "P") | 356 | (interactive "P") |
| 357 | (setq c-electric-flag (c-calculate-state arg c-electric-flag)) | 357 | (setq c-electric-flag (c-calculate-state arg c-electric-flag)) |
| 358 | (c-update-modeline) | 358 | (c-update-modeline) |
| 359 | (when (fboundp 'electric-indent-local-mode) ; Emacs 24.4 or later. | ||
| 360 | (electric-indent-local-mode (if c-electric-flag 1 0))) | ||
| 359 | (c-keep-region-active)) | 361 | (c-keep-region-active)) |
| 360 | 362 | ||
| 361 | 363 | ||
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index e8d447cd1fa..9b18bbf82a9 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -188,7 +188,13 @@ control). See \"cc-mode.el\" for more info." | |||
| 188 | (setq c-block-comment-prefix | 188 | (setq c-block-comment-prefix |
| 189 | (symbol-value 'c-comment-continuation-stars))) | 189 | (symbol-value 'c-comment-continuation-stars))) |
| 190 | (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode) | 190 | (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode) |
| 191 | (setq c-initialization-ok t)) | 191 | (setq c-initialization-ok t) |
| 192 | ;; Connect up with Emacs's electric-indent-mode, for >= Emacs 24.4 | ||
| 193 | (when (fboundp 'electric-indent-mode) | ||
| 194 | (add-hook 'electric-indent-mode-hook 'c-electric-indent-mode-hook) | ||
| 195 | (when (fboundp 'electric-indent-local-mode) | ||
| 196 | (add-hook 'electric-indent-local-mode-hook | ||
| 197 | 'c-electric-indent-local-mode-hook)))) | ||
| 192 | ;; Will try initialization hooks again if they failed. | 198 | ;; Will try initialization hooks again if they failed. |
| 193 | (put 'c-initialize-cc-mode initprop c-initialization-ok)))) | 199 | (put 'c-initialize-cc-mode initprop c-initialization-ok)))) |
| 194 | 200 | ||
| @@ -578,6 +584,14 @@ that requires a literal mode spec at compile time." | |||
| 578 | ;; setup the comment indent variable in a Emacs version portable way | 584 | ;; setup the comment indent variable in a Emacs version portable way |
| 579 | (set (make-local-variable 'comment-indent-function) 'c-comment-indent) | 585 | (set (make-local-variable 'comment-indent-function) 'c-comment-indent) |
| 580 | 586 | ||
| 587 | ;; In Emacs 24.4 onwards, prevent Emacs's built in electric indentation from | ||
| 588 | ;; messing up CC Mode's, and set `c-electric-flag' if `electric-indent-mode' | ||
| 589 | ;; has been called by the user. | ||
| 590 | (when (boundp 'electric-indent-inhibit) (setq electric-indent-inhibit t)) | ||
| 591 | (when (and (boundp 'electric-indent-mode-has-been-called) | ||
| 592 | (> electric-indent-mode-has-been-called 1)) | ||
| 593 | (setq c-electric-flag electric-indent-mode)) | ||
| 594 | |||
| 581 | ;; ;; Put submode indicators onto minor-mode-alist, but only once. | 595 | ;; ;; Put submode indicators onto minor-mode-alist, but only once. |
| 582 | ;; (or (assq 'c-submode-indicators minor-mode-alist) | 596 | ;; (or (assq 'c-submode-indicators minor-mode-alist) |
| 583 | ;; (setq minor-mode-alist | 597 | ;; (setq minor-mode-alist |
| @@ -807,7 +821,7 @@ Note that the style variables are always made local to the buffer." | |||
| 807 | `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks)))) | 821 | `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks)))) |
| 808 | 822 | ||
| 809 | 823 | ||
| 810 | ;;; Change hooks, linking with Font Lock. | 824 | ;;; Change hooks, linking with Font Lock and electric-indent-mode. |
| 811 | 825 | ||
| 812 | ;; Buffer local variables recording Beginning/End-of-Macro position before a | 826 | ;; Buffer local variables recording Beginning/End-of-Macro position before a |
| 813 | ;; change, when a macro straddles, respectively, the BEG or END (or both) of | 827 | ;; change, when a macro straddles, respectively, the BEG or END (or both) of |
| @@ -1238,6 +1252,27 @@ This function is called from `c-common-init', once per mode initialization." | |||
| 1238 | ;; function. | 1252 | ;; function. |
| 1239 | (cons c-new-BEG c-new-END)) | 1253 | (cons c-new-BEG c-new-END)) |
| 1240 | 1254 | ||
| 1255 | ;; Connect up to `electric-indent-mode' (Emacs 24.4 and later). | ||
| 1256 | (defun c-electric-indent-mode-hook () | ||
| 1257 | ;; Emacs has en/disabled `electric-indent-mode'. Propagate this through to | ||
| 1258 | ;; each CC Mode buffer. | ||
| 1259 | (when (and (boundp 'electric-indent-mode-has-been-called) | ||
| 1260 | (> electric-indent-mode-has-been-called 1)) | ||
| 1261 | (mapc (lambda (buf) | ||
| 1262 | (with-current-buffer buf | ||
| 1263 | (when c-buffer-is-cc-mode | ||
| 1264 | ;; Don't use `c-toggle-electric-state' here due to recursion. | ||
| 1265 | (setq c-electric-flag electric-indent-mode) | ||
| 1266 | (c-update-modeline)))) | ||
| 1267 | (buffer-list)))) | ||
| 1268 | |||
| 1269 | (defun c-electric-indent-local-mode-hook () | ||
| 1270 | ;; Emacs has en/disabled `electric-indent-local-mode' for this buffer. | ||
| 1271 | ;; Propagate this through to this buffer's value of `c-electric-flag' | ||
| 1272 | (when c-buffer-is-cc-mode | ||
| 1273 | (setq c-electric-flag electric-indent-mode) | ||
| 1274 | (c-update-modeline))) | ||
| 1275 | |||
| 1241 | 1276 | ||
| 1242 | ;; Support for C | 1277 | ;; Support for C |
| 1243 | 1278 | ||