[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/crux 3088be2 012/112: Add a way to make commands operate o
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/crux 3088be2 012/112: Add a way to make commands operate on either a region or a buffer |
Date: |
Wed, 11 Aug 2021 09:57:44 -0400 (EDT) |
branch: elpa/crux
commit 3088be246ee18c5dccaf70afbf6f33a137654639
Author: Bozhidar Batsov <bozhidar@batsov.com>
Commit: Bozhidar Batsov <bozhidar@batsov.com>
Add a way to make commands operate on either a region or a buffer
---
README.md | 15 +++++++++++++++
crux.el | 11 +++++++++++
2 files changed, 26 insertions(+)
diff --git a/README.md b/README.md
index a7a141e..3eecb43 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,21 @@ Command | Suggested
Keybinding(s) |
`crux-kill-whole-line` | <kbd>Super-k</kbd> | Kill whole
line
`crux-kill-line-backwards` | <kbd>C-Backspace</kbd> | Kill
line backwards
+## Using the bundled advices
+
+crux ships with some handy advises that can enhance the operation of existing
commands.
+
+### Make a function operate on a region or the entire buffer
+
+You can use `crux-with-region-or-buffer` to make a command acting
+normally on a region to operate on the entire buffer in the absense of
+a region. Here are a few examples you can stuff in your config:
+
+```el
+(crux-with-region-or-buffer indent-region)
+(crux-with-region-or-buffer untabify)
+```
+
## License
Copyright © 2015 Bozhidar Batsov and [contributors][].
diff --git a/crux.el b/crux.el
index 57a015a..d099438 100644
--- a/crux.el
+++ b/crux.el
@@ -348,5 +348,16 @@ Doesn't mess with special buffers."
(t (error "Unknown shell")))))
(find-file-other-window (expand-file-name shell-init-file (getenv
"HOME")))))
+(defmacro crux-with-region-or-buffer (func)
+ "When called with no active region, call FUNC on current buffer.
+
+Use to make commands like `indent-region' work on both the region
+and the entire buffer (in the absense of a region)."
+ `(defadvice ,func (before with-region-or-buffer activate compile)
+ (interactive
+ (if mark-active
+ (list (region-beginning) (region-end))
+ (list (point-min) (point-max))))))
+
(provide 'crux)
;;; crux.el ends here
- [nongnu] elpa/crux 61bf2bd 003/112: Code style, (continued)
- [nongnu] elpa/crux 61bf2bd 003/112: Code style, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 66f4292 006/112: Code style, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux aafcf48 009/112: Introduce some customization options, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux c174247 014/112: Change crux-kill-like-backward to crux-kill-line-backward, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 0f04d98 015/112: Fix unbound var reference, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 3009713 018/112: Update the copyright, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 86cabce 027/112: Merge pull request #10 from waymondo/file-and-buffer-naming-conventions, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 5ee7dc9 032/112: Require tramp for `tramp-tramp-file-p`, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux b07b31a 005/112: Move a function around, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux b5eac2a 008/112: Code style, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 3088be2 012/112: Add a way to make commands operate on either a region or a buffer,
ELPA Syncer <=
- [nongnu] elpa/crux 16eb56d 011/112: Kill crux-setup-default-keybindings, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux d2643ae 019/112: Add crux-ispell-word-then-abbrev, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 382834e 020/112: Fix contributors link, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e6e3221 025/112: Fix crux-*-file-and-buffer commands inconsistencies and alias the inverse, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 4c90762 026/112: Add complementary `with-region-or-line` & `with-region-or-point-to-eol`, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e4c539b 028/112: Merge pull request #9 from waymondo/with-region-or-line, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux dc1606b 034/112: Add crux-transpose-windows for swapping the buffers between two windows, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 2be95ea 040/112: Use read-from-minibuffer for the new file name, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e2124c8 023/112: Merge pull request #6 from verdammelt/patch-1, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 3c14b4a 024/112: Merge pull request #13 from jiegec/master, ELPA Syncer, 2021/08/11