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

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

[nongnu] elpa/crux bc859e4d6a 1/6: Add crux-with-region-or-sexp-or-line


From: ELPA Syncer
Subject: [nongnu] elpa/crux bc859e4d6a 1/6: Add crux-with-region-or-sexp-or-line
Date: Mon, 21 Nov 2022 03:58:59 -0500 (EST)

branch: elpa/crux
commit bc859e4d6a99efbf39f333239606baab9fb25bc1
Author: David Morgan <djm_uk@protonmail.com>
Commit: Bozhidar Batsov <bozhidar@batsov.dev>

    Add crux-with-region-or-sexp-or-line
---
 CHANGELOG.md |  2 ++
 README.md    |  9 +++++++++
 crux.el      | 10 ++++++++++
 3 files changed, 21 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 18199dc872..ae9b99d136 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
 
 ## master (unreleased)
 
+* [#94](https://github.com/bbatsov/crux/pull/94): Add 
`crux-with-region-or-sexp-or-line`.
+
 ## 0.4.0 (2021-08-10)
 
 ### New features
diff --git a/README.md b/README.md
index c496744a2a..a05dd44080 100644
--- a/README.md
+++ b/README.md
@@ -136,6 +136,15 @@ alternately act on the current line if the mark is not 
active:
 (crux-with-region-or-line comment-or-uncomment-region)
 ```
 
+#### `(crux-with-region-or-sexp-or-line)` ####
+
+Similarly, `crux-with-region-or-sexp-or-line` makes a command that acts on the 
active region, or else
+the current list (or string), or finally the current line:
+
+```el
+(crux-with-region-or-sexp-or-line kill-region)
+```
+
 #### `(crux-with-region-or-point-to-eol)` ####
 
 Sometimes you might want to act on the point until the end of the
diff --git a/crux.el b/crux.el
index 1d70a83ba4..f6f8420306 100644
--- a/crux.el
+++ b/crux.el
@@ -797,6 +797,16 @@ and the entire buffer (in the absense of a region)."
           (list (region-beginning) (region-end))
         (list (line-beginning-position) (line-beginning-position 2))))))
 
+(defmacro crux-with-region-or-sexp-or-line (func)
+  "When called with no active region, call FUNC on current sexp/string, or 
line."
+  `(defadvice ,func (before with-region-or-sexp-or-line activate compile)
+     (interactive
+      (cond
+       (mark-active (list (region-beginning) (region-end)))
+       ((in-string-p) (flatten-list (bounds-of-thing-at-point 'string)))
+       ((thing-at-point 'list) (flatten-list (bounds-of-thing-at-point 'list)))
+       (t (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)



reply via email to

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