[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/anzu 4d50eb8274 072/288: Implement anzu-query-replace-at-c
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/anzu 4d50eb8274 072/288: Implement anzu-query-replace-at-cursor-thing |
Date: |
Thu, 6 Jan 2022 03:58:41 -0500 (EST) |
branch: elpa/anzu
commit 4d50eb82742cfc3e04309541492dd61ff95dcf76
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
Implement anzu-query-replace-at-cursor-thing
And code re-factoring
---
anzu.el | 53 ++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 42 insertions(+), 11 deletions(-)
diff --git a/anzu.el b/anzu.el
index 3c3b44deb4..0f2710c365 100644
--- a/anzu.el
+++ b/anzu.el
@@ -92,6 +92,11 @@
:type 'boolean
:group 'anzu)
+(defcustom anzu-replace-at-cursor-thing 'defun
+ "Replace thing. This parameter is same as `thing-at-point'"
+ :type 'symbol
+ :group 'anzu)
+
(defface anzu-mode-line
'((t (:foreground "magenta" :weight bold)))
"face of anzu modeline"
@@ -432,34 +437,55 @@
(defun anzu--query-from-at-cursor (prompt buf beg end overlay-limit)
(let* ((symbol (thing-at-point 'symbol))
- (symbol-regexp (concat "\\b" (regexp-quote symbol) "\\b")))
+ (symbol-regexp (concat "\\_<" (regexp-quote symbol) "\\_>")))
(setq anzu--total-matched
(anzu--count-matched buf symbol-regexp beg end t overlay-limit))
(force-mode-line-update)
symbol))
-(defun anzu--symbol-begin ()
- (let ((bound (bounds-of-thing-at-point 'symbol)))
+(defun anzu--thing-begin (thing)
+ (let ((bound (bounds-of-thing-at-point thing)))
(and bound (car bound))))
-(defun anzu--query-replace-common (use-regexp &optional at-cursor)
+(defun anzu--thing-end (thing)
+ (let ((bound (bounds-of-thing-at-point thing)))
+ (and bound (cdr bound))))
+
+(defun anzu--region-begin (use-region thing)
+ (if thing
+ (or (anzu--thing-begin thing) (point))
+ (if use-region
+ (region-beginning)
+ (point))))
+
+(defun anzu--region-end (use-region thing)
+ (if thing
+ (or (anzu--thing-end thing) (point-max))
+ (if use-region
+ (region-end)
+ (point-max))))
+
+(defun anzu--begin-thing (at-cursor thing)
+ (cond ((and at-cursor thing) thing)
+ ((and at-cursor (not thing)) 'symbol)
+ (t nil)))
+
+(defun anzu--query-replace-common (use-regexp &optional at-cursor thing)
(anzu--cons-mode-line 'replace)
(let* ((use-region (use-region-p))
(overlay-limit (anzu--overlay-limit))
- (beg (if use-region (region-beginning) (point)))
- (end (if use-region (region-end) (point-max)))
+ (beg (anzu--region-begin use-region (anzu--begin-thing at-cursor
thing)))
+ (end (anzu--region-end use-region thing))
(prompt (anzu--query-prompt use-region use-regexp))
- (symbol-beg (and at-cursor (anzu--symbol-begin)))
(delimited current-prefix-arg)
(curbuf (current-buffer))
(clear-overlay nil))
(when (and anzu-deactivate-region use-region)
(deactivate-mark t))
(unwind-protect
- (let* ((from (if symbol-beg
+ (let* ((from (if (and at-cursor beg)
(progn
- (setq beg symbol-beg
- delimited nil)
+ (setq delimited nil)
(anzu--query-from-at-cursor prompt curbuf beg end
overlay-limit))
(anzu--query-from-string prompt beg end use-regexp
overlay-limit)))
(to (if (consp from)
@@ -480,7 +506,12 @@
;;;###autoload
(defun anzu-query-replace-at-cursor ()
(interactive)
- (anzu--query-replace-common nil t))
+ (anzu--query-replace-common t t))
+
+;;;###autoload
+(defun anzu-query-replace-at-cursor-thing ()
+ (interactive)
+ (anzu--query-replace-common t t anzu-replace-at-cursor-thing))
;;;###autoload
(defun anzu-query-replace ()
- [nongnu] elpa/anzu f4618cd335 023/288: Bump up version and update Changes, (continued)
- [nongnu] elpa/anzu f4618cd335 023/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu cc427254a0 040/288: Introduce search threshold, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 591b27621c 047/288: Merge pull request #11 from syohex/support-query-replace, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 1fc36f460c 046/288: Implement anzu-query-regexp and anzu-query-regexp, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu cdee5811bb 048/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 28953f86f9 051/288: bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 2bcd549c5a 054/288: Re-factoring: reduce global variables, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 9a055d9b0b 056/288: Add replacement feature like evil replace, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu ce021b7234 057/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 602aa46fe7 070/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 4d50eb8274 072/288: Implement anzu-query-replace-at-cursor-thing,
ELPA Syncer <=
- [nongnu] elpa/anzu ad0d7bce91 073/288: Update document, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 5718f08dc6 066/288: Fix case fold issue, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 17b3ab244b 074/288: Fix case, no symbol at cursor, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu c324833756 080/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu f50be69c0f 082/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu eb2b4ec103 084/288: fix link, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 156980dc69 092/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu c7ecd57c24 095/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 91f3478003 097/288: Merge pull request #15 from syohex/fix-nonprefix-case, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 189c0eaf9f 101/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06