emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/crux 4c90762 026/112: Add complementary `with-region-or-li


From: ELPA Syncer
Subject: [nongnu] elpa/crux 4c90762 026/112: Add complementary `with-region-or-line` & `with-region-or-point-to-eol`
Date: Wed, 11 Aug 2021 09:57:47 -0400 (EDT)

branch: elpa/crux
commit 4c907626d39f6c513ba2304cff4a73868520f314
Author: justin talbott <justin@waymondo.com>
Commit: justin talbott <justin@waymondo.com>

    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 e1274c7..97485a0 100644
--- a/README.md
+++ b/README.md
@@ -76,10 +76,10 @@ Here's how you'd bind some of the commands to keycombos:
 
 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
@@ -87,6 +87,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 8a13173..4ecd279 100644
--- a/crux.el
+++ b/crux.el
@@ -364,5 +364,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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]