[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)
- [nongnu] elpa/crux updated (6bfd212a7f -> b70649b91c), ELPA Syncer, 2022/11/21
- [nongnu] elpa/crux bc859e4d6a 1/6: Add crux-with-region-or-sexp-or-line,
ELPA Syncer <=
- [nongnu] elpa/crux f258bef9bb 3/6: Fix `sudo` not found error in OpenBSD and Alpine Linux (#93), ELPA Syncer, 2022/11/21
- [nongnu] elpa/crux 2c7143de47 5/6: More robust `crux-rename-file-and-buffer`., ELPA Syncer, 2022/11/21
- [nongnu] elpa/crux 6ef681d853 4/6: Ensure `vc-rename-file` gets the local file paths (#91), ELPA Syncer, 2022/11/21
- [nongnu] elpa/crux 6ee63c7c2b 2/6: Use `derived-mode-p` for functions to also work for derived modes (#92), ELPA Syncer, 2022/11/21
- [nongnu] elpa/crux b70649b91c 6/6: Tweak the changelog, ELPA Syncer, 2022/11/21