Skip to content

Commit

Permalink
feat: add option to skip indent on yank when prefix arg is given
Browse files Browse the repository at this point in the history
New option is disabled by default, ensuring no change in behavior.
  • Loading branch information
jimeh committed Apr 29, 2023
1 parent f730e1c commit 0c50c2b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion snap-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down

0 comments on commit 0c50c2b

Please sign in to comment.