From 0c50c2bcc65d902b937db8a4ad5466bd48c66320 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 29 Apr 2023 14:02:16 +0100 Subject: [PATCH] feat: add option to skip indent on yank when prefix arg is given New option is disabled by default, ensuring no change in behavior. --- README.md | 13 +++++++------ snap-indent.el | 11 ++++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 492aeb1..f1276f6 100644 --- a/README.md +++ b/README.md @@ -52,12 +52,13 @@ To configure via `use-package`, adapt the following example as desired: ### Customization -| Variable | Type | Default | Description | -| :--------------------------- | :--------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------- | -| `snap-indent-excluded-modes` | symbol list | `(cmake-ts-mode coffee-mode conf-mode elm-mode haml-mode haskell-mode makefile-automake-mode makefile-bsdmake-mode makefile-gmake-mode makefile-imake-mode makefile-makepp-mode makefile-mode occam-mode python-mode python-ts-mode slim-mode yaml-mode yaml-ts-mode)` | Major modes in which to ignore activation | -| `snap-indent-format` | function or list | `nil` | Additional formatting to apply when indenting | -| `snap-indent-on-save` | boolean | `nil` | Whether to indent the entire buffer on save | -| `snap-indent-yank-threshold` | boolean | `nil` | Do not indent yanked text if its length exceeds the threshold. | +| Variable | Type | Default | Description | +| :--------------------------------------------- | :--------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------- | +| `snap-indent-excluded-modes` | symbol list | `(cmake-ts-mode coffee-mode conf-mode elm-mode haml-mode haskell-mode makefile-automake-mode makefile-bsdmake-mode makefile-gmake-mode makefile-imake-mode makefile-makepp-mode makefile-mode occam-mode python-mode python-ts-mode slim-mode yaml-mode yaml-ts-mode)` | Major modes in which to ignore activation | +| `snap-indent-format` | function or list | `nil` | Additional formatting to apply when indenting | +| `snap-indent-on-save` | boolean | `nil` | Whether to indent the entire buffer on save | +| `snap-indent-yank-threshold` | boolean | `nil` | Do not indent yanked text if its length exceeds the threshold | +| `snap-indent-yank-skip-indent-with-prefix-arg` | boolean | `nil` | Do not indent yanked text if yank was invoked with a prefix arg | ### Additional formatting diff --git a/snap-indent.el b/snap-indent.el index 2106ae8..bfcf43c 100644 --- a/snap-indent.el +++ b/snap-indent.el @@ -105,6 +105,13 @@ blocks of text. When nil, no threshold is applied." :type 'number) +(defcustom snap-indent-yank-skip-indent-with-prefix-arg nil + "Do not indent yanked text if yank was invoked with a prefix arg. + +This can be useful as it lets you skip indent for a single yank +operation without disabling `snap-indent-mode'." + :type 'boolean) + (defun snap-indent-as-list (function-or-list) "Return FUNCTION-OR-LIST as a list, treating lambda forms as atoms." (if (or (not (listp function-or-list)) (functionp function-or-list)) @@ -130,7 +137,9 @@ When nil, no threshold is applied." When `snap-indent-yank-threshold' is not nil, do not trigger snap-indent if the region length exceeds the threshold." - (when (memq this-command '(yank yank-pop)) + (when (and (memq this-command '(yank yank-pop)) + (or (not snap-indent-yank-skip-indent-with-prefix-arg) + (not current-prefix-arg))) (let ((beg (region-beginning)) (end (region-end))) (when (or (not snap-indent-yank-threshold)