[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/el-search ef5faf2 095/332: Improve history handling
From: |
Stefan Monnier |
Subject: |
[elpa] externals/el-search ef5faf2 095/332: Improve history handling |
Date: |
Tue, 1 Dec 2020 15:48:19 -0500 (EST) |
branch: externals/el-search
commit ef5faf233b3b28c7a6f8bf43e040bedd8ee09df4
Author: Michael Heerdegen <michael_heerdegen@web.de>
Commit: Michael Heerdegen <michael_heerdegen@web.de>
Improve history handling
---
el-search.el | 48 +++++++++++++++++++++++++++++++++++++++---------
1 file changed, 39 insertions(+), 9 deletions(-)
diff --git a/el-search.el b/el-search.el
index 1f4014a..b3c5891 100644
--- a/el-search.el
+++ b/el-search.el
@@ -345,11 +345,27 @@ error."
(defvar el-search--initial-mb-contents nil)
-(defun el-search--read-pattern (prompt &optional default read histvar)
+(defun el-search--pushnew-to-history (input histvar)
+ (let ((hist-head (car (symbol-value histvar))))
+ (unless (or (string-match-p "\\`\\'" input)
+ (and (stringp hist-head)
+ (or (string= input hist-head)
+ (ignore-errors (equal (read input) (read
hist-head))))))
+ (push (if (string-match-p "\\`.+\n" input)
+ (with-temp-buffer
+ (emacs-lisp-mode)
+ (insert "\n" input)
+ (indent-region 1 (point))
+ (buffer-string))
+ input)
+ (symbol-value histvar)))))
+
+(defun el-search--read-pattern (prompt &optional default histvar)
(cl-callf or histvar 'el-search-history)
(let ((input (el-search-read-expression
- prompt el-search--initial-mb-contents histvar default read)))
- (if (or read (not (string= input ""))) input (car (symbol-value
histvar)))))
+ prompt el-search--initial-mb-contents histvar default)))
+ (el-search--pushnew-to-history input histvar)
+ (if (not (string= input "")) input (car (symbol-value histvar)))))
(defun el-search--end-of-sexp ()
;;Point must be at sexp beginning
@@ -967,16 +983,18 @@ The following additional pattern types are currently
defined:"
(interactive (list (if (and (eq this-command last-command)
el-search-success)
el-search-current-pattern
- (let ((pattern
- (el-search--read-pattern "Find pcase pattern: "
- (car el-search-history)
- t)))
+ (let* ((input (el-search--read-pattern "Find pcase
pattern: "
+ (car
el-search-history)))
+ (pattern (read input)))
;; A very common mistake: input "foo" instead of
"'foo"
(when (and (symbolp pattern)
(not (eq pattern '_))
(or (not (boundp pattern))
(not (eq (symbol-value pattern)
pattern))))
(error "Please don't forget the quote when
searching for a symbol"))
+ ;; Make input available also in query-replace history
+ (el-search--pushnew-to-history input
'el-search-query-replace-history)
+ ;; and wrap the PATTERN
(el-search--wrap-pattern pattern)))))
(if (not (called-interactively-p 'any))
(el-search--search-pattern pattern no-error)
@@ -1121,7 +1139,7 @@ Hit any key to proceed."
(or el-search--initial-mb-contents
(and (eq last-command 'el-search-pattern)
(car el-search-history)))))
- (el-search--read-pattern "Query replace pattern: " nil
nil
+ (el-search--read-pattern "Query replace pattern: " nil
'el-search-query-replace-history)))
from to)
(with-temp-buffer
@@ -1144,8 +1162,20 @@ Hit any key to proceed."
(unless (and el-search-query-replace-history
(not (string= from from-input))
(string= from-input (car el-search-query-replace-history)))
- (push (format "%s -> %s" from to) ;FIXME: add line break when FROM or TO
is multiline?
+ (push (with-temp-buffer
+ (emacs-lisp-mode)
+ (insert (let ((newline-in-from (string-match-p "\n" from))
+ (newline-in-to (string-match-p "\n" to)))
+ (format "%s%s%s ->%s%s"
+ (if (and (or newline-in-from newline-in-to)
+ (not (string-match-p "\\`\n" from)))
"\n" "")
+ (if newline-in-from
"\n" "" ) from
+ (if (and (or newline-in-from newline-in-to)
+ (not (string-match-p "\\`\n" to)))
"\n" " ") to)))
+ (indent-region 1 (point-max))
+ (buffer-string))
el-search-query-replace-history))
+ (el-search--pushnew-to-history from 'el-search-history)
(list (el-search--wrap-pattern (read from)) (read to) to)))
;;;###autoload
- [elpa] externals/el-search 2dc14bb 075/332: Rewrite replacement layout restoration, (continued)
- [elpa] externals/el-search 2dc14bb 075/332: Rewrite replacement layout restoration, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 14c7cf9 074/332: el-search--check-pattern-args: make arg TYPE a string, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search fc46701 076/332: Replacing: make C-g an alternative key for quitting, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search a61e0eb 079/332: Handle replacements containing another match, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 4325b91 080/332: Rename two functions, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search ba17f50 086/332: Give el-search--s a more meaningful name, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search d25f4d8 082/332: Address compiler warnings, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 2358b72 088/332: Small fix in el-search--setup-minibuffer, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 75b5849 083/332: Clarify the operation scope of replacing, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search e1797d3 087/332: Use `pp-to-string' to print replacement expression, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search ef5faf2 095/332: Improve history handling,
Stefan Monnier <=
- [elpa] externals/el-search 4d6b361 097/332: el-search--ensure-sexp-start: don't assume point-min==1, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search e38bea8 106/332: Add calling convention to el-search-defpattern's docstring, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search e54336d 104/332: Fix el-search-query-replace reindent wrongly in narrowed buffer, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search e2f56c7 109/332: Simplify nested backquotes, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search e7dda1b 118/332: Call el-search--wrap-pattern at better places, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 922281a 112/332: Fix replacement verification for splicing mode, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 6de72a5 121/332: `change', `changed': make "HEAD" as default explicit, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 7fe5fb7 126/332: Some details, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 2a0773f 134/332: Use jka-compr-load-suffixes instead of hardcoded suffixes, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 644b04d 139/332: el-search: bump version to 1.2.2, Stefan Monnier, 2020/12/01