From: Eshel Yaron Date: Mon, 26 Aug 2024 14:27:29 +0000 (+0200) Subject: Simplify 'electric-indent-mode' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ad2a15c5463ab15481b42314a878354b7d02422b;p=emacs.git Simplify 'electric-indent-mode' --- diff --git a/doc/misc/vip.texi b/doc/misc/vip.texi index 6907966f861..e87627cde5c 100644 --- a/doc/misc/vip.texi +++ b/doc/misc/vip.texi @@ -1572,9 +1572,6 @@ Set mark and push previous mark on mark ring (@code{set-mark-command}). @item @key{TAB} @kindex 011 TAB @r{(}@code{indent-for-tab-command}@r{)} Indent line for current major mode (@code{indent-for-tab-command}). -@item C-j -@kindex 012 C-j @r{(}@code{electric-newline-and-maybe-indent}@r{)} -Insert a newline, and maybe indent according to mode. @item C-k @kindex 013 C-k @r{(}@code{kill-line}@r{)} Kill the rest of the current line; before a newline, kill the newline. diff --git a/lisp/delsel.el b/lisp/delsel.el index df99a56d7bc..3c0206bda92 100644 --- a/lisp/delsel.el +++ b/lisp/delsel.el @@ -308,7 +308,6 @@ to `delete-selection-mode'." (put 'reindent-then-newline-and-indent 'delete-selection t) (put 'newline-and-indent 'delete-selection t) (put 'newline 'delete-selection t) -(put 'electric-newline-and-maybe-indent 'delete-selection t) (put 'open-line 'delete-selection t) ;; This is very useful for canceling a selection in the minibuffer without diff --git a/lisp/electric.el b/lisp/electric.el index eaa65f86f37..7722e10fa59 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -155,70 +155,19 @@ or comment." (indent-according-to-mode) (error (throw 'indent-error nil))))))))) -(defun electric-indent-just-newline (arg) - "Insert just a newline, without any auto-indentation." - (interactive "*P") - (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 - "Toggle on-the-fly reindentation of text lines (Electric Indent mode). - -When enabled, this reindents whenever the hook `electric-indent-functions' -returns non-nil, or if you insert one of the \"electric characters\". -The electric characters normally include the newline, but can -also include other characters as needed by the major mode; see -`electric-indent-chars' for the actual list. - -By \"reindent\" we mean remove any existing indentation, and then -indent the line according to context and rules of the major mode. - -This is a global minor mode. To toggle the mode in a single buffer, -use `electric-indent-local-mode'." - :global t :group 'electricity - :initialize 'custom-initialize-delay - :init-value t - (if (not electric-indent-mode) - (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)) - (add-hook 'post-self-insert-hook - #'electric-indent-post-self-insert-function - 60))) - ;;;###autoload (define-minor-mode electric-indent-local-mode "Toggle `electric-indent-mode' only in this buffer." - :variable ( electric-indent-mode . - (lambda (val) (setq-local electric-indent-mode val))) - (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. - ))) + :light nil + (if electric-indent-local-mode + (add-hook 'post-self-insert-hook + #'electric-indent-post-self-insert-function 60 t) + (remove-hook 'post-self-insert-hook + #'electric-indent-post-self-insert-function t))) + +;;;###autoload +(define-globalized-minor-mode electric-indent-mode + electric-indent-local-mode electric-indent-local-mode) ;;; Electric newlines after/before/around some chars.