[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 5f9accc 18/24: Make query-replace accept FROM -> TO style
From: |
Michael Heerdegen |
Subject: |
[elpa] master 5f9accc 18/24: Make query-replace accept FROM -> TO style input |
Date: |
Thu, 19 May 2016 20:46:38 +0000 (UTC) |
branch: master
commit 5f9accc41fe4b6364b124cc9af9703e91fba3c81
Author: Michael Heerdegen <address@hidden>
Commit: Michael Heerdegen <address@hidden>
Make query-replace accept FROM -> TO style input
Use this format for history entries.
---
packages/el-search/el-search.el | 50 ++++++++++++++++++++++++++++++++-------
1 file changed, 42 insertions(+), 8 deletions(-)
diff --git a/packages/el-search/el-search.el b/packages/el-search/el-search.el
index 8e08571..0f40e83 100644
--- a/packages/el-search/el-search.el
+++ b/packages/el-search/el-search.el
@@ -333,14 +333,18 @@ error."
(or hist 'read-expression-history) default)))
(defvar el-search-history '()
- "List of input strings.")
+ "List of search input strings.")
+
+(defvar el-search-query-replace-history '()
+ "List of input strings from `el-search-query-replace'.")
(defvar el-search--initial-mb-contents nil)
-(defun el-search--read-pattern (prompt &optional default read)
+(defun el-search--read-pattern (prompt &optional default read histvar)
+ (cl-callf or histvar 'el-search-history)
(let ((input (el-search-read-expression
- prompt el-search--initial-mb-contents 'el-search-history
default read)))
- (if (or read (not (string= input ""))) input (car el-search-history))))
+ prompt el-search--initial-mb-contents histvar default read)))
+ (if (or read (not (string= input ""))) input (car (symbol-value
histvar)))))
(defun el-search--end-of-sexp ()
;;Point must be at sexp beginning
@@ -1102,9 +1106,31 @@ Hit any key to proceed."
(defun el-search-query-replace--read-args ()
(barf-if-buffer-read-only)
- (let* ((from (el-search--read-pattern "Query replace pattern: "))
- (to (let ((el-search--initial-mb-contents nil))
- (el-search--read-pattern "Replace with result of evaluation
of: " from))))
+ (let ((from-input (el-search--read-pattern "Query replace pattern: " nil nil
+ 'el-search-query-replace-history))
+ from to)
+ (with-temp-buffer
+ (emacs-lisp-mode)
+ (insert from-input)
+ (goto-char 1)
+ (forward-sexp)
+ (skip-chars-forward " \t\n")
+ ;; FIXME: maybe more sanity tests here...
+ (if (not (looking-at "->"))
+ (setq from from-input
+ to (let ((el-search--initial-mb-contents nil))
+ (el-search--read-pattern "Replace with result of
evaluation of: " from)))
+ (delete-char 2)
+ (goto-char 1)
+ (forward-sexp)
+ (setq from (buffer-substring 1 (point)))
+ (skip-chars-forward " \t\n")
+ (setq to (buffer-substring (point) (progn (forward-sexp) (point))))))
+ (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?
+ el-search-query-replace-history))
(list (el-search--wrap-pattern (read from)) (read to) to)))
;;;###autoload
@@ -1117,7 +1143,15 @@ produce a replacement expression. Operate from point
to (point-max).
As each match is found, the user must type a character saying
-what to do with it. For directions, type ? at that time."
+what to do with it. For directions, type ? at that time.
+
+As an alternative to enter FROM-PATTERN and TO-EXPR separately,
+you can also give an input of the form
+
+ FROM-PATTERN -> TO-EXPR
+
+to the first prompt and specify both expressions at once. This
+format is also used for history entries."
(interactive (el-search-query-replace--read-args))
(setq this-command 'el-search-query-replace) ;in case we come from isearch
(setq el-search-current-pattern from-pattern)
- [elpa] master 149acb9 07/24: Improve documentation and argument names of el-search-query-replace, (continued)
- [elpa] master 149acb9 07/24: Improve documentation and argument names of el-search-query-replace, Michael Heerdegen, 2016/05/19
- [elpa] master 3d0a12e 13/24: Fix el-search--ensure-sexp-start error at bob, Michael Heerdegen, 2016/05/19
- [elpa] master 03dd4e7 06/24: Comment and whitespace changes only, Michael Heerdegen, 2016/05/19
- [elpa] master b885ef1 03/24: el-search--check-pattern-args: make arg TYPE a string, Michael Heerdegen, 2016/05/19
- [elpa] master 3d72d1d 11/24: Address compiler warnings, Michael Heerdegen, 2016/05/19
- [elpa] master 536fab6 15/24: Give el-search--s a more meaningful name, Michael Heerdegen, 2016/05/19
- [elpa] master 4b11cb8 09/24: Rename two functions, Michael Heerdegen, 2016/05/19
- [elpa] master 8d7b29c 21/24: Make sure not to lose the minibuffer-prompt face, Michael Heerdegen, 2016/05/19
- [elpa] master c356b2d 19/24: Rename a local variable, Michael Heerdegen, 2016/05/19
- [elpa] master bb98a1d 04/24: Rewrite replacement layout restoration, Michael Heerdegen, 2016/05/19
- [elpa] master 5f9accc 18/24: Make query-replace accept FROM -> TO style input,
Michael Heerdegen <=
- [elpa] master 99e8724 08/24: Handle replacements containing another match, Michael Heerdegen, 2016/05/19
- [elpa] master b09bb1b 16/24: Use `pp-to-string' to print replacement expression, Michael Heerdegen, 2016/05/19
- [elpa] master c835174 24/24: Improve history handling, Michael Heerdegen, 2016/05/19
- [elpa] master bace971 02/24: Rewrite `string' pattern definition, Michael Heerdegen, 2016/05/19