9 Commits
v0.2.0 ... 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
7 changed files with 41 additions and 79 deletions

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

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

View File

@@ -1,6 +1,4 @@
{ {
"bootstrap-sha": "e3fdaa7f673a8b8d43c2ac16f8a3cdfe8b3ab6c1",
"last-release-sha": "e3fdaa7f673a8b8d43c2ac16f8a3cdfe8b3ab6c1",
"packages": { "packages": {
".": { ".": {
"release-type": "simple", "release-type": "simple",

View File

@@ -1,16 +1,11 @@
--- ---
on: push on:
push:
branches:
- main
jobs: jobs:
release-please: release-please:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
outputs:
release_created: ${{ steps.release-please.outputs.release_created }}
tag_name: ${{ steps.release-please.outputs.tag_name }} # e.g. v1.0.0
version: ${{ steps.release-please.outputs.version }} # e.g. 1.0.0
steps: steps:
- uses: google-github-actions/release-please-action@v3 - uses: jimeh/release-please-manifest-action@v1
id: release-please
with:
command: manifest

View File

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

View File

@@ -1,6 +1,15 @@
# 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)
### ⚠ 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) ## [0.2.0](https://github.com/jimeh/yank-indent/compare/v0.1.1...v0.2.0) (2023-04-25)
@@ -14,7 +23,7 @@ All notable changes to this project will be documented in this file. See [standa
* **customization:** rename customize variables related to global mode ([84f3b3e](https://github.com/jimeh/yank-indent/commit/84f3b3e7c05413b4e9a7a7d3b81457cd1511f4ac)) * **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)) * **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) ## [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>
@@ -59,14 +59,6 @@ Place `yank-indent.el` somewhere in your `load-path` and require it. For example
(global-yank-indent-mode t) (global-yank-indent-mode t)
``` ```
## Setup & Teardown
Required setup that registers advice on `yank` and `yank-pop` commands is
automatically done the first time that `yank-indent-mode` is enabled.
Should you want to though you can manually add/remove the required advice with
`yank-indent-setup` and `yank-indent-teardown`.
## Usage ## Usage
### `global-yank-indent-mode` ### `global-yank-indent-mode`
@@ -93,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

@@ -5,7 +5,7 @@
;; Keywords: convenience, yank, indent ;; Keywords: convenience, yank, indent
;; Package-Requires: ((emacs "25.1")) ;; Package-Requires: ((emacs "25.1"))
;; x-release-please-start-version ;; x-release-please-start-version
;; Version: 0.2.0 ;; Version: 0.3.0
;; x-release-please-end ;; x-release-please-end
;; This file is not part of GNU Emacs. ;; This file is not part of GNU Emacs.
@@ -127,37 +127,6 @@ specific modes and their derived modes from having
(or (member major-mode yank-indent-global-exact-modes) (or (member major-mode yank-indent-global-exact-modes)
(apply #'derived-mode-p yank-indent-global-derived-modes)))) (apply #'derived-mode-p yank-indent-global-derived-modes))))
(defvar yank-indent--initial-setup nil)
(defun yank-indent--is-setup-p ()
"Return non-nil if required advice is setup."
(and (advice-member-p #'yank-indent--after-yank-advice #'yank)
(advice-member-p #'yank-indent--after-yank-advice #'yank-pop)))
;;;###autoload
(defun yank-indent-setup ()
"Setup advice on `yank' and `yank-pop' as required by `yank-indent-mode'.
First time `yank-indent-mode' is enabled it will automatically
call `yank-indent-setup' if needed.
Setup can be undone with `yank-indent-teardown', but enabling
`yank-indent-mode' again after that will not run setup again."
(interactive)
(advice-add #'yank :after #'yank-indent--after-yank-advice)
(advice-add #'yank-pop :after #'yank-indent--after-yank-advice)
(setq yank-indent--initial-setup t))
;;;###autoload
(defun yank-indent-teardown ()
"Undo `yank-indent-setup' by removing advice from `yank' and `yank-pop'.
If this is used, `yank-indent-setup' must be explicitly called
before `yank-indent-mode' will work again."
(interactive)
(advice-remove #'yank #'yank-indent--after-yank-advice)
(advice-remove #'yank-pop #'yank-indent--after-yank-advice))
;;;###autoload ;;;###autoload
(define-minor-mode yank-indent-mode (define-minor-mode yank-indent-mode
"Minor mode for automatically indenting yanked text. "Minor mode for automatically indenting yanked text.
@@ -169,13 +138,8 @@ prefix argument is given during yanking."
:lighter " YI" :lighter " YI"
:group 'yank-indent :group 'yank-indent
(if yank-indent-mode (if yank-indent-mode
;; Auto-run advice setup if needed first time mode is enabled. Display (add-hook 'post-command-hook #'yank-indent--post-command-hook nil 'local)
;; warning if advice setup has been undone. (remove-hook 'post-command-hook #'yank-indent--post-command-hook 'local)))
(when (not (yank-indent--is-setup-p))
(if yank-indent--initial-setup
(message (concat "Warning: yank-indent-mode not available, "
"run `M-x yank-indent-setup' to setup."))
(yank-indent-setup)))))
;;;###autoload ;;;###autoload
(define-globalized-minor-mode global-yank-indent-mode (define-globalized-minor-mode global-yank-indent-mode
@@ -184,20 +148,19 @@ prefix argument is given during yanking."
(when (yank-indent--should-enable-p) (when (yank-indent--should-enable-p)
(yank-indent-mode 1)))) (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))