diff options
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/bindings.el | 1 | ||||
| -rw-r--r-- | lisp/electric.el | 24 |
3 files changed, 25 insertions, 7 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8b93411269f..857c086790e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,12 @@ 2014-03-20 Stefan Monnier <monnier@iro.umontreal.ca> + * electric.el (electric-newline-and-maybe-indent): New command. + Bind it globally to C-j. + (electric-indent-mode): Don't mess with the global map any more. + Don't drop the post-self-insert-hook is some buffer is still using it + (bug#16770). + * bindings.el (global-map): Remove C-j binding. + * emacs-lisp/nadvice.el (advice--make-docstring): Try harder to find the docstring of functions advised before dumping (bug#16993). diff --git a/lisp/bindings.el b/lisp/bindings.el index fac34ed4106..7093b8e662f 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -795,7 +795,6 @@ if `inhibit-field-text-motion' is non-nil." ;; suspend only the relevant terminal. (substitute-key-definition 'suspend-emacs 'suspend-frame global-map) -(define-key global-map "\C-j" 'newline-and-indent) (define-key global-map "\C-m" 'newline) (define-key global-map "\C-o" 'open-line) (define-key esc-map "\C-o" 'split-line) diff --git a/lisp/electric.el b/lisp/electric.el index 7debe0b7f98..4e24101dd6a 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -286,6 +286,20 @@ mode set `electric-indent-inhibit', but this can be used as a workaround.") (let ((electric-indent-mode nil)) (newline arg 'interactive))) +;;;###autoload(define-key global-map "\C-j" 'electric-newline-and-maybe-indent) +;;;###autoload +(defun electric-newline-and-maybe-indent () + "Insert a newline. +If `electric-indent-mode' is enabled, that's that, but if it +is *disabled* then additionally indent according to major mode. +Indentation is done using the value of `indent-line-function'. +In programming language modes, this is the same as TAB. +In some text modes, where TAB inserts a tab, this command indents to the +column specified by the function `current-left-margin'." + (interactive "*") + (if electric-indent-mode + (electric-indent-just-newline nil) + (newline-and-indent))) ;;;###autoload (define-minor-mode electric-indent-mode @@ -303,14 +317,12 @@ use `electric-indent-local-mode'." :initialize 'custom-initialize-delay :init-value t (if (not electric-indent-mode) - (progn - (when (eq (lookup-key global-map [?\C-j]) - 'electric-indent-just-newline) - (define-key global-map [?\C-j] 'newline-and-indent)) + (unless (catch 'found + (dolist (buf (buffer-list)) + (with-current-buffer buf + (if electric-indent-mode (throw 'found t))))) (remove-hook 'post-self-insert-hook #'electric-indent-post-self-insert-function)) - (when (eq (lookup-key global-map [?\C-j]) 'newline-and-indent) - (define-key global-map [?\C-j] 'electric-indent-just-newline)) (add-hook 'post-self-insert-hook #'electric-indent-post-self-insert-function) (electric--sort-post-self-insertion-hook))) |
