

GitHub - jimeh/yank-indent: Emacs minor-mode that ensures pasted (yanked) text h...
source link: https://github.com/jimeh/yank-indent
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

yank-indent
Emacs minor-mode that ensures pasted (yanked) text has the correct indentation level.
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
yank-indent-mode
minor-mode that automatically callsindent-region
on yanked/pasted text.global-yank-indent-mode
which is a set-it-and-forget-it style global mode that enablesyank-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 withyank-indent-threshold
.
Installation
use-package + straight.el
(use-package yank-indent
:straight (:host github :repo "jimeh/yank-indent")
:config (global-yank-indent-mode t))
Manual
Place yank-indent.el
somewhere in your load-path
and require it. For example
~/.emacs.d/vendor
:
(add-to-list 'load-path "~/.emacs.d/vendor")
(require 'yank-indent)
(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
With global-yank-indent-mode
enabled, you will find that yank-indent-mode
is
automatically enabled in relevant buffers. The defaults will specifically
exclude common languages which are indentation sensitive like Python, YAML,
Makefile, etc.
For fine-grained control over which major-modes it is enabled in or not, see
customization options with M-x customize-group RET yank-indent
.
yank-indent-mode
If you prefer not to use the global mode, you can add yank-indent-mode
as a
hook to relevant major-modes, or even manually toggle it on and off with
M-x yank-indent-mode
.
To skip the indent operation for a single yank command, use a prefix command, so
C-u C-y
instead of just C-y
.
Keep in mind that the include/exclude major-mode customizations only affect the
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
regardless of what major-mode the buffer is using.
Under the Hood
yank-indent
registers an advice for after yank
and yank-pop
commands. The
advice function verifies that yank-indent-mode
mode is enabled in the current
buffer, prefix argument was not given, and the yanked/pasted text was within the
yank-indent-threshold
in size. If all true, it will trigger indentation,
otherwise it does nothing.
Recommend
-
31
I'd like to paste yanked text into Vim command line. Is it possible?
-
19
cargo-audit is a command-line utility which inspects Cargo.lock files and compares them against the RustSec Advisory Databas...
-
11
This message cannot be pasted into the Signal app HTML perverts far too many things in the world. Web browsers are used instead of native apps, and it means bloated and laggy experiences. Then there's the problem you get w...
-
7
Pasted garbage says to contentEditable; "Hey! I'd really like to become part of you" and contentEditable says back; "Not so fast, you! First we got to rinse you down!". And thus begins a story of how to make co...
-
5
Frequently Copied and PastedJanuary 8, 2016 · 2 min · Benjamin BengfortI have a bit of catch up to do — and I think that this notepad and development journal is the perfect resource to do it. You see, I am constantly
-
9
PasteSorcerer.vim You can now paste regardless of how it is Yanked. Yanked Entire Line, and now wanted to paste it inline, then no worries, PasteSorcerer.vim got your back. Features Paste Yanked Lines inline.
-
6
Sandra Rossi August 29, 2022 Less than a 1 mi...
-
7
-
7
India antitrust suit allegedly copy pasted EU rulings more than 50 times...
-
12
Stupid simple script copied and pasted from reg.py/lookupsid and inspired from itm4n's session enum via registry · GitHub ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK