17 Commits
v0.1.1 ... main

Author SHA1 Message Date
8fe8de468f docs(readme): update description for alternative package snap-indent 2023-11-16 15:24:43 +00:00
7844288143 docs(readme): add alternative package section 2023-06-13 01:41:32 +01:00
15fd7271bd Merge pull request #6 from jimeh/release-please--branches--main 2023-06-13 00:47:09 +01:00
github-actions[bot]
c0ec1607fe chore(main): release 0.3.0 2023-06-12 23:46:28 +00:00
290eb89fec Merge pull request #5 from jimeh/use-post-command-hook 2023-06-13 00:46:02 +01:00
b047e91b92 fix(setup)!: simplify package/load setup by not using a global advice
Use buffer-local post-commad-hook instead of global function advice on
yank and yank-pop. This avoids any global changes to Emacs' runtime
environment outside of the specific buffers within which
yank-indent-mode is enabled.

BREAKING CHANGE: Removed yank-indent-setup and yank-indent-teardown functions.
2023-06-13 00:40:50 +01:00
28b7ef837d ci(release): simplify release-please setup (#4) 2023-06-13 00:38:10 +01:00
41f37e5726 ci(release): remove bootstrap config
Remove initial bootstrap config required before first release is cut
with release-please.
2023-04-25 01:31:13 +01:00
2256722539 chore(changelog): fix formatting and remove mention of standard-version 2023-04-25 01:20:30 +01:00
a834f366c3 Merge pull request #3 from jimeh/release-please--branches--main 2023-04-25 01:16:07 +01:00
github-actions[bot]
fe903d957d chore(main): release 0.2.0 2023-04-25 00:14:28 +00:00
15c69ef8d7 ci(release): setup release-please
Setup release-please to handle version bumping, changelog generation,
and creating releases on GitHub.
2023-04-25 01:09:53 +01:00
803374178f docs(readme): reword Features section, add Setup & Teardown section 2023-04-25 01:03:12 +01:00
84f3b3e7c0 fix(customization)!: rename customize variables related to global mode
Rename variables that control how the global mode works, adding
"-global" to their names:

- `yank-indent-derived-modes` -> `yank-indent-global-derived-modes`
- `yank-indent-exact-modes` -> `yank-indent-global-exact-modes`
- `yank-indent-excluded-modes` -> `yank-indent-global-excluded-modes`

BREAKING CHANGE: Rename global mode customization variables.
2023-04-25 01:03:12 +01:00
c0b7531238 chore: fix indentation 2023-04-25 01:03:11 +01:00
2a2174fbf4 Merge pull request #2 from jimeh/setup-advice-on-first-use 2023-04-25 00:43:40 +01:00
9b1d01b600 fix(internal): do not add advice on package load
Instead advice yank and yank-pop the first time that yank-indent-mode
is enabled.

Also add new yank-indent-setup and yank-indent-teardown functions which
enable manual control over adding and removing the advice on yank and
yank-pop.
2023-04-25 00:17:55 +01:00
6 changed files with 138 additions and 63 deletions

3
.github/.release-please-manifest.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
".": "0.3.0"
}

16
.github/release-please-config.json vendored Normal file
View File

@@ -0,0 +1,16 @@
{
"packages": {
".": {
"release-type": "simple",
"changelog-path": "CHANGELOG.md",
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"draft": false,
"prerelease": false,
"extra-files": [
"yank-indent.el"
]
}
},
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
}

11
.github/workflows/release-please.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
---
on:
push:
branches:
- main
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: jimeh/release-please-manifest-action@v1

View File

@@ -1,8 +1,29 @@
# Changelog # Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. ## [0.3.0](https://github.com/jimeh/yank-indent/compare/v0.2.0...v0.3.0) (2023-06-12)
### [0.1.1](https://github.com/jimeh/yank-indent/compare/v0.1.0...v0.1.1) (2023-04-23)
### ⚠ BREAKING CHANGES
* **setup:** Removed yank-indent-setup and yank-indent-teardown functions.
### Bug Fixes
* **setup:** simplify package/load setup by not using a global advice ([b047e91](https://github.com/jimeh/yank-indent/commit/b047e91b9235308f76a94dacdf40f160bee6758e))
## [0.2.0](https://github.com/jimeh/yank-indent/compare/v0.1.1...v0.2.0) (2023-04-25)
### ⚠ BREAKING CHANGES
* **customization:** Rename global mode customization variables.
### Bug Fixes
* **customization:** rename customize variables related to global mode ([84f3b3e](https://github.com/jimeh/yank-indent/commit/84f3b3e7c05413b4e9a7a7d3b81457cd1511f4ac))
* **internal:** do not add advice on package load ([9b1d01b](https://github.com/jimeh/yank-indent/commit/9b1d01b600f9da0139dddb19485177ccee99f1ee))
## [0.1.1](https://github.com/jimeh/yank-indent/compare/v0.1.0...v0.1.1) (2023-04-23)
### Bug Fixes ### Bug Fixes

View File

@@ -19,7 +19,7 @@
<a href="https://github.com/jimeh/yank-indent/pulls"> <a href="https://github.com/jimeh/yank-indent/pulls">
<img src="https://img.shields.io/github/issues-pr-raw/jimeh/yank-indent.svg?style=flat&logo=github&logoColor=white" alt="GitHub pull requests"> <img src="https://img.shields.io/github/issues-pr-raw/jimeh/yank-indent.svg?style=flat&logo=github&logoColor=white" alt="GitHub pull requests">
</a> </a>
<a href="https://github.com/jimeh/yank-indent/blob/master/LICENSE"> <a href="https://github.com/jimeh/yank-indent/blob/main/LICENSE">
<img src="https://img.shields.io/github/license/jimeh/yank-indent.svg?style=flat" alt="License Status"> <img src="https://img.shields.io/github/license/jimeh/yank-indent.svg?style=flat" alt="License Status">
</a> </a>
</p> </p>
@@ -29,10 +29,14 @@ pasting it somewhere? Never again! yank-indent is the answer.
## Features ## Features
- A fire-and-forget style global mode that does the right thing most of time. - `yank-indent-mode` minor-mode that automatically calls `indent-region` on
Can be customized if you find it enables `yank-indent-mode` when it shouldn't. yanked/pasted text.
- Configurable size threshold to prevent triggering indentation on very large - `global-yank-indent-mode` which is a set-it-and-forget-it style global mode
regions which may cause performance issues in with some major-modes. that enables `yank-indent-mode` in relevant buffers, with a sensible default
list of major-modes to exclude.
- By default does not trigger `indent-region` if pasted text is longer than 5000
characters. This threshold can be can be customized with
`yank-indent-threshold`.
## Installation ## Installation
@@ -81,10 +85,15 @@ global mode and which buffers it enables `yank-indent-mode` in. If you
explicitly enable `yank-indent-mode` in a buffer, it will operate like normal explicitly enable `yank-indent-mode` in a buffer, it will operate like normal
regardless of what major-mode the buffer is using. regardless of what major-mode the buffer is using.
## Under the Hood ## Alternative Packages
`yank-indent` registers an advice for after `yank` and `yank-pop` commands. The - [snap-indent](https://github.com/jeffvalk/snap-indent)
advice function verifies that `yank-indent-mode` mode is enabled in the current ([melpa](https://melpa.org/#/snap-indent)): Very similar with the addition of
buffer, prefix argument was not given, and the yanked/pasted text was within the being able to trigger indentation on save, and extra custom formatting
`yank-indent-threshold` in size. If all true, it will trigger indentation, functions to run right after indentation.
otherwise it does nothing. - [auto-indent-mode](https://github.com/mattfidler/auto-indent-mode.el)
([melpa](https://melpa.org/#/auto-indent-mode)): Triggers indentation in a
whole suite of scenarios, more or less trying to ensure everything is always
correctly indented. This also includes indenting any yanked regions. Does not
seem to support any thresholds to avoid triggering indentation for large
buffers/yanked text.

View File

@@ -3,8 +3,10 @@
;; Author: Jim Myhrberg <contact@jimeh.me> ;; Author: Jim Myhrberg <contact@jimeh.me>
;; URL: https://github.com/jimeh/yank-indent ;; URL: https://github.com/jimeh/yank-indent
;; Keywords: convenience, yank, indent ;; Keywords: convenience, yank, indent
;; Version: 0.1.0
;; Package-Requires: ((emacs "25.1")) ;; Package-Requires: ((emacs "25.1"))
;; x-release-please-start-version
;; Version: 0.3.0
;; x-release-please-end
;; This file is not part of GNU Emacs. ;; This file is not part of GNU Emacs.
@@ -54,8 +56,13 @@ will not occur. This helps prevent performance issues when
working with large blocks of text." working with large blocks of text."
:type 'number) :type 'number)
(defcustom yank-indent-derived-modes '(prog-mode tex-mode) (define-obsolete-variable-alias
"Derived major modes where `yank-indent-mode' should be enabled. 'yank-indent-derived-modes
'yank-indent-global-derived-modes
"yank-indent 0.2.0")
(defcustom yank-indent-global-derived-modes '(prog-mode tex-mode)
"Derived major modes where `global-yank-indent-mode' enables `yank-indent-mode'.
When `global-yank-indent-mode' is enabled, it activates When `global-yank-indent-mode' is enabled, it activates
`yank-indent-mode' in buffers with major modes derived from those `yank-indent-mode' in buffers with major modes derived from those
@@ -65,49 +72,60 @@ mode, such as `prog-mode' for programming modes or `text-mode'
for text editing modes." for text editing modes."
:type '(repeat symbol)) :type '(repeat symbol))
(defcustom yank-indent-exact-modes '() (define-obsolete-variable-alias
"Major modes where `yank-indent-mode' should be enabled. 'yank-indent-exact-modes
'yank-indent-global-exact-modes
"yank-indent 0.2.0")
(defcustom yank-indent-global-exact-modes '()
"Major modes where `global-yank-indent-mode' enables `yank-indent-mode'.
When `global-yank-indent-mode' is enabled, it activates When `global-yank-indent-mode' is enabled, it activates
`yank-indent-mode' in buffers with major modes listed in this `yank-indent-mode' in buffers with major modes listed in this
variable. Unlike `yank-indent-derived-modes', `yank-indent-mode' variable. Unlike `yank-indent-global-derived-modes',
will not be activated in modes derived from those listed here. `yank-indent-mode' will not be activated in modes derived from
Use this variable to list specific modes where you want those listed here. Use this variable to list specific modes where
`yank-indent-mode' to be enabled without affecting their derived you want `yank-indent-mode' to be enabled without affecting their
modes." derived modes."
:type '(repeat symbol)) :type '(repeat symbol))
(defcustom yank-indent-excluded-modes '(cmake-ts-mode (define-obsolete-variable-alias
coffee-mode 'yank-indent-excluded-modes
conf-mode 'yank-indent-global-excluded-modes
haml-mode "yank-indent 0.2.0")
makefile-automake-mode
makefile-bsdmake-mode (defcustom yank-indent-global-excluded-modes '(cmake-ts-mode
makefile-gmake-mode coffee-mode
makefile-imake-mode conf-mode
makefile-makepp-mode haml-mode
makefile-mode makefile-automake-mode
python-mode makefile-bsdmake-mode
python-ts-mode makefile-gmake-mode
slim-mode makefile-imake-mode
yaml-mode makefile-makepp-mode
yaml-ts-mode) makefile-mode
"Major modes where `yank-indent-mode' should not be enabled. python-mode
python-ts-mode
slim-mode
yaml-mode
yaml-ts-mode)
"Major modes where `global-yank-indent-mode' does not enable `yank-indent-mode'.
`global-yank-indent-mode' will not activate `yank-indent-mode' in `global-yank-indent-mode' will not activate `yank-indent-mode' in
buffers with major modes listed in this variable or their derived buffers with major modes listed in this variable or their derived
modes. This list takes precedence over modes. This list takes precedence over
`yank-indent-derived-modes' and `yank-indent-exact-modes'. Use `yank-indent-global-derived-modes' and
this variable to exclude specific modes and their derived modes `yank-indent-global-exact-modes'. Use this variable to exclude
from having `yank-indent-mode' enabled." specific modes and their derived modes from having
`yank-indent-mode' enabled."
:type '(repeat symbol)) :type '(repeat symbol))
(defun yank-indent--should-enable-p () (defun yank-indent--should-enable-p ()
"Return non-nil if current mode should be indented." "Return non-nil if current mode should be indented."
(and (not (minibufferp)) (and (not (minibufferp))
(not (member major-mode yank-indent-excluded-modes)) (not (member major-mode yank-indent-global-excluded-modes))
(or (member major-mode yank-indent-exact-modes) (or (member major-mode yank-indent-global-exact-modes)
(apply #'derived-mode-p yank-indent-derived-modes)))) (apply #'derived-mode-p yank-indent-global-derived-modes))))
;;;###autoload ;;;###autoload
(define-minor-mode yank-indent-mode (define-minor-mode yank-indent-mode
@@ -117,32 +135,32 @@ When enabled, this mode indents the yanked region according to
the current mode's indentation rules, provided that the region the current mode's indentation rules, provided that the region
size is less than or equal to `yank-indent-threshold' and no size is less than or equal to `yank-indent-threshold' and no
prefix argument is given during yanking." prefix argument is given during yanking."
:lighter " YI") :lighter " YI"
:group 'yank-indent
(defun yank-indent--enable () (if yank-indent-mode
"Enable `yank-indent-mode' if the current buffer meets the criteria." (add-hook 'post-command-hook #'yank-indent--post-command-hook nil 'local)
(when (yank-indent--should-enable-p) (remove-hook 'post-command-hook #'yank-indent--post-command-hook 'local)))
(yank-indent-mode 1)))
;;;###autoload ;;;###autoload
(define-globalized-minor-mode global-yank-indent-mode (define-globalized-minor-mode global-yank-indent-mode
yank-indent-mode yank-indent-mode
yank-indent--enable) (lambda ()
(when (yank-indent--should-enable-p)
(yank-indent-mode 1))))
(defun yank-indent--after-yank-advice (&optional _) (defun yank-indent--post-command-hook ()
"Conditionally indent the region (yanked text) after yanking. "Conditionally indent yanked text.
Indentation is triggered only if all of the following conditions Indentation is triggered only if all of the following conditions
are met: are met:
- `yank-indent-mode' minor-mode is enabled in the current buffer. - `this-command' is `yank' or `yank-pop'.
- `yank-indent-mode' is enabled.
- Prefix argument was not provided. - Prefix argument was not provided.
- Region size that was yanked is less than or equal to - Region size that was yanked is less than or equal to
`yank-indent-threshold'. `yank-indent-threshold'."
(if (and (memq this-command '(yank yank-pop))
This function is used as advice for `yank' and `yank-pop' yank-indent-mode
functions."
(if (and yank-indent-mode
(not current-prefix-arg)) (not current-prefix-arg))
(let ((beg (region-beginning)) (let ((beg (region-beginning))
(end (region-end)) (end (region-end))
@@ -150,8 +168,5 @@ functions."
(if (<= (- end beg) yank-indent-threshold) (if (<= (- end beg) yank-indent-threshold)
(indent-region beg end))))) (indent-region beg end)))))
(advice-add #'yank :after #'yank-indent--after-yank-advice)
(advice-add #'yank-pop :after #'yank-indent--after-yank-advice)
(provide 'yank-indent) (provide 'yank-indent)
;;; yank-indent.el ends here ;;; yank-indent.el ends here