Skip to content

Commit 6ae1554

Browse files
committed
[upstreamed] Fixes for yank-indent behavior
Squashed commit of the following: commit 2437b6c Author: Aaron L. Zeng <azeng@janestreet.com> Date: Thu Feb 26 15:04:23 2026 -0500 [defaults] Consider derived modes for yank-indent behavior Specifically, this allows the user to disable the behavior completely by setting spacemacs-yank-indent-modes to nil. commit 2b9e1b4 Author: Aaron L. Zeng <azeng@janestreet.com> Date: Thu Feb 26 15:03:18 2026 -0500 [defaults] Improve spacemacs//yank-indent-region docstring commit 7e1f6a8 Author: Aaron L. Zeng <azeng@janestreet.com> Date: Thu Feb 26 14:37:33 2026 -0500 [defaults] Refactor spacemacs//yank-indent-region to use undo step macro commit a41827a Author: Aaron L. Zeng <azeng@janestreet.com> Date: Thu Feb 26 14:36:07 2026 -0500 [defaults] Fix arguments passed to yank function commit b96d3ac Author: Aaron L. Zeng <azeng@janestreet.com> Date: Thu Feb 26 14:19:21 2026 -0500 [defaults] Remove let binding of undefined variable save-undo commit 4d7c01d Author: SpacemacsBot <86630153+SpacemacsBot@users.noreply.github.com> Date: Sat Feb 21 01:43:53 2026 +0200 [bot] "documentation_updates" Fri Feb 20 23:33:16 UTC 2026 (syl20bnr#17224) Co-authored-by: SpacemacsBot <not@an.actual.email.beep.boop> commit 0064333 Author: Aaron Zeng <me@bcc32.com> Date: Fri Feb 20 18:30:52 2026 -0500 [mermaid] Add some layer tags to README.org (syl20bnr#17237) commit 0fb57c8 Author: Aaron Zeng <me@bcc32.com> Date: Fri Feb 20 15:52:07 2026 -0500 [systemd] Clean up systemd layer and fix completion (syl20bnr#17232) * [systemd] Fix company configuration * [systemd] Fix typos in README * [systemd] Remove unnecessary explicit autoload * [systemd] Enable lexical-binding in packages.el commit 8de1122 Merge: 4a2e2e5 d5b453f Author: Aaron L. Zeng <azeng@janestreet.com> Date: Fri Feb 20 15:50:26 2026 -0500 Merge branch 'refactor-write-custom' into develop commit d5b453f Author: Aaron L. Zeng <me@bcc32.com> Date: Sat Jan 31 13:43:41 2026 +0800 [core] Read custom settings directly from buffer ... instead of going through a separate string copy. commit f767066 Author: Aaron L. Zeng <me@bcc32.com> Date: Sat Jan 31 13:41:26 2026 +0800 [core] Message when writing Custom settings is done commit 4befbad Author: Aaron L. Zeng <me@bcc32.com> Date: Sat Jan 31 13:37:35 2026 +0800 [core] Indent Customize settings properly Even if the user has disabled auto indentation of Elisp files on save. commit 8806603 Author: Aaron L. Zeng <me@bcc32.com> Date: Sat Jan 31 13:33:55 2026 +0800 [core] Do not kill dotfile buffer when writing Customize settings A user might be visiting it, in which case this behavior is quite annoying, and in any case this is simply not necessary. `enable-command` does not kill the buffer, as an example of convention. commit a99645a Author: Aaron L. Zeng <me@bcc32.com> Date: Sat Jan 31 13:33:05 2026 +0800 [core] Insert directly into buffer instead of using princ commit dababbb Author: Aaron L. Zeng <me@bcc32.com> Date: Sat Jan 31 13:28:39 2026 +0800 [core] Tweak docstrings in core-custom-settings.el commit 4a2e2e5 Author: SpacemacsBot <86630153+SpacemacsBot@users.noreply.github.com> Date: Fri Feb 20 22:48:33 2026 +0200 [bot] "built_in_updates" Fri Feb 20 18:28:45 UTC 2026 (syl20bnr#17236) Co-authored-by: SpacemacsBot <not@an.actual.email.beep.boop> commit d1ac570 Author: Aaron L. Zeng <azeng@janestreet.com> Date: Fri Feb 20 13:27:54 2026 -0500 Fix a few documentation typos in core-customization.el commit 6908891 Author: Aaron Zeng <me@bcc32.com> Date: Mon Feb 9 15:55:34 2026 -0500 [csharp] Remove obsolete omnisharp backend (syl20bnr#17229) Declare csharp-mode as a built-in package in newer Emacs versions where it is in core, so that we can set up the LSP backend appropriately during layer initialization. commit f04d1c7 Author: lin.sun <sunlin7@hotmail.com> Date: Mon Feb 9 12:54:59 2026 -0800 [version-control] Fix toggle margin detection (syl20bnr#17231) commit a064d6f Author: Aaron L. Zeng <me@bcc32.com> Date: Sun Feb 1 07:21:56 2026 -0500 [shell-scripts] Move insert-shebang state file into spacemacs-cache-directory commit c35a671 Author: Aaron L. Zeng <me@bcc32.com> Date: Mon Feb 2 16:55:52 2026 -0500 Enable lexical-binding in all layers.el files These files are relatively simple, and none of them depended on dynamic binding. [defaults] Consider derived modes for yank-indent behavior Specifically, this allows the user to disable the behavior completely by setting spacemacs-yank-indent-modes to nil.
1 parent 94c9847 commit 6ae1554

File tree

1 file changed

+29
-22
lines changed
  • layers/+spacemacs/spacemacs-defaults

1 file changed

+29
-22
lines changed

layers/+spacemacs/spacemacs-defaults/funcs.el

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ A COUNT argument matches the indentation to the next COUNT lines."
8686
:type '(repeat symbol)
8787
:group 'spacemacs)
8888

89-
(defcustom spacemacs-yank-indent-modes '(latex-mode)
90-
"Modes in which to indent regions that are yanked (or yank-popped).
91-
Only modes that don't derive from `prog-mode' should be listed here."
89+
(defcustom spacemacs-yank-indent-modes '(prog-mode latex-mode)
90+
"Modes in which to indent regions that are yanked (or yank-popped)."
9291
:type '(repeat symbol)
9392
:group 'spacemacs)
9493

@@ -1665,26 +1664,34 @@ Compare them on count first,and in case of tie sort them alphabetically."
16651664
(if (<= (- end beg) spacemacs-yank-indent-threshold)
16661665
(indent-region beg end nil)))
16671666

1667+
;; This advice assumes that the advised function interactive spec passes
1668+
;; `current-prefix-arg' as its first argument.
16681669
(defun spacemacs//yank-indent-region (yank-func &rest args)
1669-
"Indent yanked text, unless `major-mode' is in `spacemacs-indent-sensitive-modes'.
1670-
1671-
With prefix \\[universal-argument], don't indent."
1672-
(evil-start-undo-step)
1673-
(prog1
1674-
(let ((prefix (car args))
1675-
(enable (and (not (member major-mode spacemacs-indent-sensitive-modes))
1676-
(or (derived-mode-p 'prog-mode)
1677-
(member major-mode spacemacs-yank-indent-modes)))))
1678-
(when (and enable (equal '(4) prefix))
1679-
(setq args (cdr args)))
1680-
(prog1
1681-
(apply yank-func args)
1682-
(when (and enable (not (equal '(4) prefix)))
1683-
(let ((transient-mark-mode nil)
1684-
(save-undo buffer-undo-list))
1685-
(spacemacs/yank-advised-indent-function (region-beginning)
1686-
(region-end))))))
1687-
(evil-end-undo-step)))
1670+
"Indent text yanked by YANK-FUNC.
1671+
1672+
Indentation is only applied if the major mode is derived from a mode in
1673+
`spacemacs-yank-indent-modes' and not derived from a mode in
1674+
`spacemacs-indent-sensitive-modes'.
1675+
1676+
With prefix \\[universal-argument], never indent.
1677+
1678+
ARGS is passed through unchanged to YANK-FUNC, except if the first
1679+
argument is \\='(4) (a single prefix argument), in which case the first
1680+
argument is changed to nil. If the indentation would not be enabled
1681+
based on the major mode, ARGS (including the prefix argument) is passed
1682+
through unchanged."
1683+
(evil-with-single-undo
1684+
(let ((enable (and (not (derived-mode-p spacemacs-indent-sensitive-modes))
1685+
(derived-mode-p spacemacs-yank-indent-modes))))
1686+
(when (and enable (equal '(4) (car args)))
1687+
(setf (car args) nil
1688+
enable nil))
1689+
(prog1
1690+
(apply yank-func args)
1691+
(when enable
1692+
(let ((transient-mark-mode nil))
1693+
(spacemacs/yank-advised-indent-function (region-beginning)
1694+
(region-end))))))))
16881695

16891696
(dolist (func '(yank yank-pop evil-paste-before evil-paste-after))
16901697
(advice-add func :around #'spacemacs//yank-indent-region))

0 commit comments

Comments
 (0)