[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/crux e4c539b 028/112: Merge pull request #9 from waymondo/
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/crux e4c539b 028/112: Merge pull request #9 from waymondo/with-region-or-line |
Date: |
Wed, 11 Aug 2021 09:57:47 -0400 (EDT) |
branch: elpa/crux
commit e4c539ba569901c1441bf007aa6f88a3f218bcf2
Merge: 86cabce 4c90762
Author: Bozhidar Batsov <bozhidar.batsov@gmail.com>
Commit: Bozhidar Batsov <bozhidar.batsov@gmail.com>
Merge pull request #9 from waymondo/with-region-or-line
Add complementary `with-region-or-line` & `with-region-or-point-to-eol`
---
README.md | 22 ++++++++++++++++++++--
crux.el | 16 ++++++++++++++++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 4b6aef7..840f85f 100644
--- a/README.md
+++ b/README.md
@@ -85,10 +85,10 @@ For `crux-ispell-word-then-abbrev` to be most effective
you'll also need to add
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
+#### `(crux-with-region-or-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
+normally on a region to operate on the entire buffer in the absence of
a region. Here are a few examples you can stuff in your config:
```el
@@ -96,6 +96,24 @@ a region. Here are a few examples you can stuff in your
config:
(crux-with-region-or-buffer untabify)
```
+#### `(crux-with-region-or-line)` ####
+
+Likewise, you can use `crux-with-region-or-line` to make a command
+alternately act on the current line if the mark is not active:
+
+```el
+(crux-with-region-or-line comment-or-uncomment-region)
+```
+
+#### `(crux-with-region-or-point-to-eol)` ####
+
+Sometimes you might want to act on the point until the end of the
+current line, rather than the whole line, in the absence of a region:
+
+``` el
+(crux-with-region-or-point-to-eol kill-ring-save)
+```
+
## License
Copyright © 2015 Bozhidar Batsov and [contributors][].
diff --git a/crux.el b/crux.el
index 46b46e0..9ff1a7b 100644
--- a/crux.el
+++ b/crux.el
@@ -404,5 +404,21 @@ and the entire buffer (in the absense of a region)."
(list (region-beginning) (region-end))
(list (point-min) (point-max))))))
+(defmacro crux-with-region-or-line (func)
+ "When called with no active region, call FUNC on current line."
+ `(defadvice ,func (before with-region-or-line activate compile)
+ (interactive
+ (if mark-active
+ (list (region-beginning) (region-end))
+ (list (line-beginning-position) (line-beginning-position 2))))))
+
+(defmacro crux-with-region-or-point-to-eol (func)
+ "When called with no active region, call FUNC from the point to the end of
line."
+ `(defadvice ,func (before with-region-or-point-to-eol activate compile)
+ (interactive
+ (if mark-active
+ (list (region-beginning) (region-end))
+ (list (point) (line-end-position))))))
+
(provide 'crux)
;;; crux.el ends here
- [nongnu] elpa/crux 86cabce 027/112: Merge pull request #10 from waymondo/file-and-buffer-naming-conventions, (continued)
- [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, 2021/08/11
- [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 <=
- [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
- [nongnu] elpa/crux 79e500e 030/112: Add multiple choice with completion for shell init files., ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e6c7421 035/112: Remove crux-swap-windows and alias it to crux-transpose-windows, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 5938c84 036/112: Merge pull request #21 from dgtized/transpose-windows, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 6d11d2e 039/112: When opening a line above, don't reindent the current line, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 1967a75 041/112: Allow users to create directories with crux-rename-file-and-buffer, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 582a68d 046/112: Fix the version header, ELPA Syncer, 2021/08/11