[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/anzu 6dd966b4e2 186/288: Implement separator feature of Em
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/anzu 6dd966b4e2 186/288: Implement separator feature of Emacs 25 |
Date: |
Thu, 6 Jan 2022 03:58:51 -0500 (EST) |
branch: elpa/anzu
commit 6dd966b4e2231f05111708969a95c1e15ec17c6d
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
Implement separator feature of Emacs 25
---
anzu.el | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 51 insertions(+), 14 deletions(-)
diff --git a/anzu.el b/anzu.el
index 8e33bfee9a..a718f8ab48 100644
--- a/anzu.el
+++ b/anzu.el
@@ -130,6 +130,7 @@
(defvar anzu--last-search-state nil)
(defvar anzu--last-replaced-count nil)
(defvar anzu--outside-point nil)
+(defvar anzu--history nil)
(defun anzu--validate-regexp (regexp)
(condition-case nil
@@ -376,19 +377,38 @@
(anzu--count-and-highlight-matched buf input beg end use-regexp
overlay-limit nil)))))))
+(defconst anzu--from-to-separator
+ (propertize
+ (or (ignore-errors
+ (if (char-displayable-p ?\u2192) " \u2192 " " -> "))
+ " -> ")
+ 'face 'minibuffer-prompt))
+
+(defsubst anzu--separator ()
+ (propertize "\0" 'display anzu--from-to-separator 'separator t))
+
(defun anzu--check-minibuffer-input (buf beg end use-regexp overlay-limit)
(let* ((content (minibuffer-contents))
- (empty-p (string= content ""))
+ (to (when (and (anzu--emacs25-p)
+ (string-match (anzu--separator) content)
+ (get-text-property (match-beginning 0) 'separator
content))
+ (substring-no-properties content (match-end 0))))
+ (from (or (and to (substring-no-properties content 0 (match-beginning
0)))
+ (minibuffer-contents)))
+ (empty-p (string= from ""))
(overlayed (if empty-p
(setq anzu--cached-count 0)
- (anzu--count-and-highlight-matched buf content beg end
use-regexp
+ (anzu--count-and-highlight-matched buf from beg end
use-regexp
overlay-limit nil))))
(when anzu--outside-point
(setq anzu--outside-point nil)
(with-selected-window (get-buffer-window buf)
(goto-char beg)))
(when (and (not empty-p) (zerop overlayed))
- (anzu--search-outside-visible buf content beg end use-regexp))
+ (anzu--search-outside-visible buf from beg end use-regexp))
+ (when to
+ (setq anzu--last-replace-input "")
+ (anzu--append-replaced-string to buf beg end use-regexp overlay-limit
from))
(setq anzu--total-matched anzu--cached-count)
(force-mode-line-update)))
@@ -398,9 +418,23 @@
(when (overlay-get ov 'anzu-replace)
(delete-overlay ov)))))
+(defun anzu--transform-from-to-history ()
+ (let ((separator (anzu--separator)))
+ (append (mapcar (lambda (from-to)
+ (concat (query-replace-descr (car from-to))
+ separator
+ (query-replace-descr (cdr from-to))))
+ query-replace-defaults)
+ (symbol-value query-replace-from-history-variable))))
+
(defun anzu--read-from-string (prompt beg end use-regexp overlay-limit)
(let ((curbuf (current-buffer))
(blink-matching-paren nil)
+ (anzu--history (when (anzu--emacs25-p)
+ (anzu--transform-from-to-history)))
+ (history-var (if (anzu--emacs25-p)
+ 'anzu--history
+ query-replace-from-history-variable))
timer is-input)
(unwind-protect
(minibuffer-with-setup-hook
@@ -415,8 +449,7 @@
(anzu--check-minibuffer-input
curbuf beg end use-regexp overlay-limit))))))
(prog1 (read-from-minibuffer (format "%s: " prompt)
- nil nil nil
- query-replace-from-history-variable nil
t)
+ nil nil nil history-var nil t)
(setq is-input t)))
(when timer
(cancel-timer timer)
@@ -494,9 +527,8 @@
(when (string-match str from)
(replace-match replaced (not case-fold-search) nil str))))
-(defun anzu--append-replaced-string (buf beg end use-regexp overlay-limit from)
- (let ((content (minibuffer-contents))
- (replacements 0))
+(defun anzu--append-replaced-string (content buf beg end use-regexp
overlay-limit from)
+ (let ((replacements 0))
(unless (string= content anzu--last-replace-input)
(setq anzu--last-replace-input content)
(with-current-buffer buf
@@ -537,6 +569,7 @@
(with-selected-window (or
(active-minibuffer-window)
(minibuffer-window))
(anzu--append-replaced-string
+ (minibuffer-contents)
curbuf beg end use-regexp overlay-limit
from))))))
(prog1 (read-from-minibuffer to-prompt
nil nil nil
@@ -677,12 +710,16 @@
(setq delimited nil)
(anzu--query-from-at-cursor curbuf beg end
overlay-limit))
(anzu--query-from-string prompt beg end use-regexp
overlay-limit)))
- (to (if (consp from)
- (prog1 (cdr from)
- (setq from (car from)
- anzu--total-matched anzu--last-replaced-count))
- (anzu--query-replace-read-to
- from prompt beg end use-regexp overlay-limit))))
+ (to (cond ((string-match "\0" from)
+ (prog1 (substring-no-properties from (match-end 0))
+ (setq from (substring-no-properties from 0
(match-beginning 0)))))
+ ((consp from)
+ (prog1 (cdr from)
+ (setq from (car from)
+ anzu--total-matched
anzu--last-replaced-count)))
+ (t
+ (anzu--query-replace-read-to
+ from prompt beg end use-regexp overlay-limit)))))
(anzu--clear-overlays curbuf beg end)
(anzu--set-replaced-markers from beg end use-regexp)
(setq anzu--state 'replace anzu--current-position 0
- [nongnu] elpa/anzu 81b4eb6e29 093/288: Fix increasing anzu information in mode-line issue(#13), (continued)
- [nongnu] elpa/anzu 81b4eb6e29 093/288: Fix increasing anzu information in mode-line issue(#13), ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 1ea6980019 106/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu caf83591e4 134/288: Merge pull request #28 from syohex/improve-replace-mode-line, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 5d209726cd 156/288: Merge pull request #36 from syohex/case-sensitive-for-at-cursor-command, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu ee53798dc2 160/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 1c2705bb2c 164/288: Merge pull request #38 from syohex/improve-replacement, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu d4dcd76f47 190/288: Merge pull request #48 from syohex/improve-history, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 370b9f162f 181/288: Merge pull request #45 from syohex/fix-zero-width-replacement, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 8a1eb22317 174/288: Merge pull request #42 from syohex/fix-replace-command-bug, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu a1f56b6dad 193/288: Merge pull request #50 from syohex/fix-default-input-49, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 6dd966b4e2 186/288: Implement separator feature of Emacs 25,
ELPA Syncer <=
- [nongnu] elpa/anzu 5e87e8c07a 187/288: Use own history variable for maintenance, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 10a05eb50c 166/288: Disable blink-matching-paren for improvement, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 5abdc5b889 038/288: Update document, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 0418c2b6d4 041/288: Update document, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 218a63ce47 015/288: Highlight code and add screenshot explanation, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 7b3d95d495 183/288: Support Emacs 24 and 25, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 6b217a457f 182/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 3c178f75f3 197/288: Fix matching a literal string, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu b486075ab4 204/288: Update requirement package version, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 5ee99678ca 229/288: Remove needless attribute, ELPA Syncer, 2022/01/06