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

[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



reply via email to

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