13 Commits

Author SHA1 Message Date
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
e3fdaa7f67 chore(release): 0.1.1 2023-04-23 12:06:23 +01:00
387f732f45 docs(readme): remove last commit time badge
This package is not likely to receive frequent updates, once fully
stable. So how long ago the last commit was does not indicate project
health.
2023-04-23 12:02:35 +01:00
7619fc6d91 fix(autoload): do not autoload advice-add calls
There's no need for yank and yank-pop to be adviced via an autoload, as
it means simply having the package installed will apply the advices.

Without autoloads on the advices, things still work as on first use of
yank-indent-mode or global-yank-indent-mode the advices will be applied.
2023-04-23 11:57:29 +01:00
e5daa2d525 chore(custom): remove needless :group property from defcustoms
Groups are tracked on a per-file basis with the
custom-current-group-alist variable, which is set by defgroup, and used
by defcustom to set the group property if it is not provided.
2023-04-23 11:55:03 +01:00
81ffe1ff28 docs(readme): add status badges and a bespoke yank-indent logo 2023-04-19 00:11:08 +01:00
7 changed files with 185 additions and 60 deletions

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

@@ -0,0 +1,16 @@
---
on: push
jobs:
release-please:
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:
- uses: google-github-actions/release-please-action@v3
id: release-please
with:
command: manifest

View File

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

View File

@@ -2,6 +2,25 @@
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.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)

View File

@@ -1,5 +1,5 @@
<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
</h1>
@@ -9,17 +9,34 @@
</strong>
</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/master/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
pasting it somewhere? Never again! yank-indent is the answer.
## Features
- A fire-and-forget style global mode that does the right thing most of time.
Can be customized if you find it enables `yank-indent-mode` when it shouldn't.
- Configurable size threshold to prevent triggering indentation on very large
regions which may cause performance issues in with some major-modes.
- `yank-indent-mode` minor-mode that automatically calls `indent-region` on
yanked/pasted text.
- `global-yank-indent-mode` which is a set-it-and-forget-it style global mode
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
@@ -42,6 +59,14 @@ Place `yank-indent.el` somewhere in your `load-path` and require it. For example
(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
### `global-yank-indent-mode`

1
img/yank-indent.svg Normal file
View 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

View File

@@ -0,0 +1,18 @@
{
"bootstrap-sha": "e3fdaa7f673a8b8d43c2ac16f8a3cdfe8b3ab6c1",
"last-release-sha": "e3fdaa7f673a8b8d43c2ac16f8a3cdfe8b3ab6c1",
"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"
}

View File

@@ -3,8 +3,10 @@
;; Author: Jim Myhrberg <contact@jimeh.me>
;; URL: https://github.com/jimeh/yank-indent
;; Keywords: convenience, yank, indent
;; Version: 0.1.0
;; Package-Requires: ((emacs "25.1"))
;; x-release-please-start-version
;; Version: 0.2.0
;; x-release-please-end
;; 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
will not occur. This helps prevent performance issues when
working with large blocks of text."
:type 'number
:group 'yank-indent)
:type 'number)
(defcustom yank-indent-derived-modes '(prog-mode tex-mode)
"Derived major modes where `yank-indent-mode' should be enabled.
(define-obsolete-variable-alias
'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
`yank-indent-mode' in buffers with major modes derived from those
@@ -64,54 +70,93 @@ listed in this variable. This is useful when you want to enable
`yank-indent-mode' for all modes that inherit from a specific
mode, such as `prog-mode' for programming modes or `text-mode'
for text editing modes."
:type '(repeat symbol)
:group 'yank-indent)
:type '(repeat symbol))
(defcustom yank-indent-exact-modes '()
"Major modes where `yank-indent-mode' should be enabled.
(define-obsolete-variable-alias
'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
`yank-indent-mode' in buffers with major modes listed in this
variable. Unlike `yank-indent-derived-modes', `yank-indent-mode'
will not be activated in modes derived from those listed here.
Use this variable to list specific modes where you want
`yank-indent-mode' to be enabled without affecting their derived
modes."
:type '(repeat symbol)
:group 'yank-indent)
variable. Unlike `yank-indent-global-derived-modes',
`yank-indent-mode' will not be activated in modes derived from
those listed here. Use this variable to list specific modes where
you want `yank-indent-mode' to be enabled without affecting their
derived modes."
:type '(repeat symbol))
(defcustom yank-indent-excluded-modes '(cmake-ts-mode
coffee-mode
conf-mode
haml-mode
makefile-automake-mode
makefile-bsdmake-mode
makefile-gmake-mode
makefile-imake-mode
makefile-makepp-mode
makefile-mode
python-mode
python-ts-mode
slim-mode
yaml-mode
yaml-ts-mode)
"Major modes where `yank-indent-mode' should not be enabled.
(define-obsolete-variable-alias
'yank-indent-excluded-modes
'yank-indent-global-excluded-modes
"yank-indent 0.2.0")
(defcustom yank-indent-global-excluded-modes '(cmake-ts-mode
coffee-mode
conf-mode
haml-mode
makefile-automake-mode
makefile-bsdmake-mode
makefile-gmake-mode
makefile-imake-mode
makefile-makepp-mode
makefile-mode
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
buffers with major modes listed in this variable or their derived
modes. This list takes precedence over
`yank-indent-derived-modes' and `yank-indent-exact-modes'. Use
this variable to exclude specific modes and their derived modes
from having `yank-indent-mode' enabled."
:type '(repeat symbol)
:group 'yank-indent)
`yank-indent-global-derived-modes' and
`yank-indent-global-exact-modes'. Use this variable to exclude
specific modes and their derived modes from having
`yank-indent-mode' enabled."
:type '(repeat symbol))
(defun yank-indent--should-enable-p ()
"Return non-nil if current mode should be indented."
(and (not (minibufferp))
(not (member major-mode yank-indent-excluded-modes))
(or (member major-mode yank-indent-exact-modes)
(apply #'derived-mode-p yank-indent-derived-modes))))
(not (member major-mode yank-indent-global-excluded-modes))
(or (member major-mode yank-indent-global-exact-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
(define-minor-mode yank-indent-mode
@@ -122,18 +167,22 @@ the current mode's indentation rules, provided that the region
size is less than or equal to `yank-indent-threshold' and no
prefix argument is given during yanking."
:lighter " YI"
:group 'yank-indent)
(defun yank-indent--enable ()
"Enable `yank-indent-mode' if the current buffer meets the criteria."
(when (yank-indent--should-enable-p)
(yank-indent-mode 1)))
:group 'yank-indent
(if yank-indent-mode
;; Auto-run advice setup if needed first time mode is enabled. Display
;; warning if advice setup has been undone.
(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
(define-globalized-minor-mode global-yank-indent-mode
yank-indent-mode
yank-indent--enable
:group 'yank-indent)
(lambda ()
(when (yank-indent--should-enable-p)
(yank-indent-mode 1))))
(defun yank-indent--after-yank-advice (&optional _)
"Conditionally indent the region (yanked text) after yanking.
@@ -156,11 +205,5 @@ functions."
(if (<= (- end beg) yank-indent-threshold)
(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)
;;; yank-indent.el ends here