mirror of
https://github.com/jimeh/yank-indent.git
synced 2026-02-19 09:36:40 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
8fe8de468f
|
|||
|
7844288143
|
|||
| 15fd7271bd | |||
|
|
c0ec1607fe | ||
| 290eb89fec | |||
|
b047e91b92
|
|||
| 28b7ef837d | |||
|
41f37e5726
|
|||
|
2256722539
|
|||
| a834f366c3 | |||
|
|
fe903d957d | ||
|
15c69ef8d7
|
|||
|
803374178f
|
|||
|
84f3b3e7c0
|
|||
|
c0b7531238
|
|||
| 2a2174fbf4 | |||
|
9b1d01b600
|
|||
|
e3fdaa7f67
|
|||
|
387f732f45
|
|||
|
7619fc6d91
|
|||
|
e5daa2d525
|
|||
|
81ffe1ff28
|
3
.github/.release-please-manifest.json
vendored
Normal file
3
.github/.release-please-manifest.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
".": "0.3.0"
|
||||||
|
}
|
||||||
16
.github/release-please-config.json
vendored
Normal file
16
.github/release-please-config.json
vendored
Normal 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
11
.github/workflows/release-please.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release-please:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: jimeh/release-please-manifest-action@v1
|
||||||
30
CHANGELOG.md
30
CHANGELOG.md
@@ -1,6 +1,34 @@
|
|||||||
# 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)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚠ 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
|
||||||
|
|
||||||
|
* **autoload:** do not autoload advice-add calls ([7619fc6](https://github.com/jimeh/yank-indent/commit/7619fc6d910a93697eb74236344632c161d0dcd5))
|
||||||
|
|
||||||
## 0.1.0 (2023-04-18)
|
## 0.1.0 (2023-04-18)
|
||||||
|
|
||||||
|
|||||||
46
README.md
46
README.md
@@ -1,5 +1,5 @@
|
|||||||
<h1 align="center">
|
<h1 align="center">
|
||||||
<img width="72px" src="https://github.com/emacs-mirror/emacs/raw/emacs-28.2/etc/images/icons/hicolor/scalable/apps/emacs.svg" alt="Logo"><br />
|
<img width="128px" src="https://raw.githubusercontent.com/jimeh/yank-indent/main/img/yank-indent.svg" alt="Logo"><br />
|
||||||
yank-indent
|
yank-indent
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
@@ -9,17 +9,34 @@
|
|||||||
</strong>
|
</strong>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
---
|
<p align="center">
|
||||||
|
<a href="https://github.com/jimeh/yank-indent/releases">
|
||||||
|
<img src="https://img.shields.io/github/v/tag/jimeh/yank-indent?label=release" alt="GitHub tag (latest SemVer)">
|
||||||
|
</a>
|
||||||
|
<a href="https://github.com/jimeh/yank-indent/issues">
|
||||||
|
<img src="https://img.shields.io/github/issues-raw/jimeh/yank-indent.svg?style=flat&logo=github&logoColor=white" alt="GitHub issues">
|
||||||
|
</a>
|
||||||
|
<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">
|
||||||
|
</a>
|
||||||
|
<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">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
Do you often find yourself fixing the indentation of a code snippet right after
|
Do you often find yourself fixing the indentation of a code snippet right after
|
||||||
pasting it somewhere? Never again! yank-indent is the answer.
|
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
|
||||||
|
|
||||||
@@ -68,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.
|
||||||
|
|||||||
1
img/yank-indent.svg
Normal file
1
img/yank-indent.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 500 500" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"><g><path id="shadow" d="M220.4,29.01l39.112,-1.643c6.068,-13.723 -12.369,-30.63 -1.738,-24.626c1.849,1.044 37.535,30.776 38.854,33.759l17.321,2.536l100.598,-3.818c7.935,7.828 19.232,18.835 23.365,23.393c3.636,4.009 5.853,9.329 5.853,15.163l-0,403.641c-0,12.465 -10.12,22.585 -22.585,22.585l-303.18,-0c-5.892,-0 -11.26,-2.261 -15.283,-5.962c-4.488,-4.128 -15.062,-15.105 -24.195,-24.287l16.893,-395.977c-0,-12.465 10.12,-22.585 22.585,-22.585l102.4,-22.179Z" style="fill-opacity:0.08;"/><path id="clipboard" d="M421.585,51.594c0,-12.465 -10.12,-22.584 -22.585,-22.584l-303.18,-0c-12.465,-0 -22.585,10.119 -22.585,22.584l0,403.642c0,12.464 10.12,22.584 22.585,22.584l303.18,0c12.465,0 22.585,-10.12 22.585,-22.584l0,-403.642Z" style="fill:url(#_Linear1);"/><path id="paper-shadow" serif:id="paper shadow" d="M405.929,460.86l-290.944,-0l-13.047,-13.047l13.047,-351.348c-0,-13.467 10.934,-24.401 24.401,-24.401l245.747,-6.475c7.023,6.523 9.752,9.448 14.206,14.204c4.087,4.364 6.59,10.228 6.59,16.672l0,364.395Z" style="fill-opacity:0.08;"/><rect id="paper" x="101.938" y="100.767" width="290.944" height="347.046" style="fill:#fff;"/><path d="M327.648,59.017l40.833,0c13.467,0 24.401,10.934 24.401,24.402l0,17.348l-290.944,0l0,-17.348c0,-13.468 10.934,-24.402 24.401,-24.402l40.833,0l0,-19.595c0,-4.534 3.681,-8.214 8.214,-8.214l144.048,-0c4.534,-0 8.214,3.68 8.214,8.214l0,19.595Z" style="fill:#54575f;"/><path d="M219.823,30.314l7.072,-15.994c8.442,-19.093 32.588,-19.093 41.03,0l7.072,15.994l27.311,0c3.185,0 5.77,2.586 5.77,5.77l-0,27.529c-0,3.184 -2.585,5.77 -5.77,5.77l-109.796,-0c-3.184,-0 -5.77,-2.586 -5.77,-5.77l0,-27.529c0,-3.184 2.586,-5.77 5.77,-5.77l27.311,0Zm27.587,-25.936c-5.357,0 -9.706,4.349 -9.706,9.707c-0,5.357 4.349,9.706 9.706,9.706c5.357,-0 9.707,-4.349 9.707,-9.706c-0,-5.358 -4.35,-9.707 -9.707,-9.707Z" style="fill:#e9e9e9;"/><path d="M313.949,32.513c0,-3.601 -2.923,-6.524 -6.523,-6.524l-120.031,0c-3.601,0 -6.524,2.923 -6.524,6.524c0,3.6 2.923,6.523 6.524,6.523l120.031,0c3.6,0 6.523,-2.923 6.523,-6.523Z" style="fill:url(#_Linear2);"/><g><path d="M133.903,280.813l15.656,0l-0,127.679l-15.656,0l-0,-127.679Z" style="fill:#aaded6;"/><path d="M177.14,349.653l178.778,-0c2.759,-0 5,-2.241 5,-5c-0,-2.76 -2.241,-5 -5,-5l-178.79,-0l41.615,-41.458c1.955,-1.948 1.961,-5.116 0.014,-7.071c-1.948,-1.955 -5.116,-1.961 -7.071,-0.013l-50.19,50c-0.942,0.938 -1.472,2.214 -1.471,3.544c0,1.33 0.53,2.605 1.473,3.542l50.261,50c1.956,1.947 5.125,1.938 7.071,-0.018c1.946,-1.956 1.938,-5.125 -0.019,-7.071l-41.671,-41.455Z" style="fill:#8e90a6;"/></g><g><path d="M345.261,140.088l15.657,-0l-0,127.678l-15.657,0l0,-127.678Z" style="fill:#aaded6;"/><path d="M317.677,208.927l-178.777,0c-2.76,0 -5,-2.24 -5,-5c0,-2.76 2.24,-5 5,-5l178.79,0l-41.616,-41.458c-1.955,-1.947 -1.961,-5.116 -0.013,-7.071c1.947,-1.955 5.116,-1.961 7.071,-0.013l50.19,50c0.942,0.938 1.472,2.214 1.471,3.544c-0,1.33 -0.531,2.605 -1.474,3.543l-50.26,50c-1.957,1.946 -5.125,1.938 -7.071,-0.019c-1.946,-1.956 -1.938,-5.124 0.018,-7.071l41.671,-41.455Z" style="fill:#8e90a6;"/></g></g><defs><linearGradient id="_Linear1" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(-7.21743e-14,448.811,-448.811,-7.21743e-14,247.41,29.0095)"><stop offset="0" style="stop-color:#f1c58f;stop-opacity:1"/><stop offset="1" style="stop-color:#f0c48f;stop-opacity:1"/></linearGradient><linearGradient id="_Linear2" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(6.22035e-16,13.0468,-10.1586,7.98888e-16,255.029,25.9893)"><stop offset="0" style="stop-color:#f2f2f2;stop-opacity:1"/><stop offset="0.14" style="stop-color:#ededed;stop-opacity:1"/><stop offset="0.2" style="stop-color:#e2e3e3;stop-opacity:1"/><stop offset="0.25" style="stop-color:#d8d9d9;stop-opacity:1"/><stop offset="0.7" style="stop-color:#a6a7a7;stop-opacity:1"/><stop offset="0.87" style="stop-color:#9e9f9f;stop-opacity:1"/><stop offset="1" style="stop-color:#7f7f7f;stop-opacity:1"/></linearGradient></defs></svg>
|
||||||
|
After Width: | Height: | Size: 4.4 KiB |
130
yank-indent.el
130
yank-indent.el
@@ -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.
|
||||||
|
|
||||||
@@ -52,11 +54,15 @@ If the yanked region contains more characters than the value
|
|||||||
specified by `yank-indent-threshold', the automatic indentation
|
specified by `yank-indent-threshold', the automatic indentation
|
||||||
will not occur. This helps prevent performance issues when
|
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)
|
||||||
:group 'yank-indent)
|
|
||||||
|
|
||||||
(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
|
||||||
@@ -64,54 +70,62 @@ listed in this variable. This is useful when you want to enable
|
|||||||
`yank-indent-mode' for all modes that inherit from a specific
|
`yank-indent-mode' for all modes that inherit from a specific
|
||||||
mode, such as `prog-mode' for programming modes or `text-mode'
|
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))
|
||||||
:group 'yank-indent)
|
|
||||||
|
|
||||||
(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))
|
||||||
:group 'yank-indent)
|
|
||||||
|
|
||||||
(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
|
||||||
:type '(repeat symbol)
|
`yank-indent-mode' enabled."
|
||||||
:group 'yank-indent)
|
: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
|
||||||
@@ -122,33 +136,31 @@ 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)
|
:group 'yank-indent
|
||||||
|
(if yank-indent-mode
|
||||||
(defun yank-indent--enable ()
|
(add-hook 'post-command-hook #'yank-indent--post-command-hook nil 'local)
|
||||||
"Enable `yank-indent-mode' if the current buffer meets the criteria."
|
(remove-hook 'post-command-hook #'yank-indent--post-command-hook 'local)))
|
||||||
(when (yank-indent--should-enable-p)
|
|
||||||
(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 ()
|
||||||
:group 'yank-indent)
|
(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))
|
||||||
@@ -156,11 +168,5 @@ functions."
|
|||||||
(if (<= (- end beg) yank-indent-threshold)
|
(if (<= (- end beg) yank-indent-threshold)
|
||||||
(indent-region beg end)))))
|
(indent-region beg end)))))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(advice-add #'yank :after #'yank-indent--after-yank-advice)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(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
|
||||||
|
|||||||
Reference in New Issue
Block a user