From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: History for query replace pairs Date: Tue, 04 Nov 2014 01:46:47 +0200 Organization: JURTA Message-ID: <87ioivx2xk.fsf@mail.jurta.org> References: <87a97ejxuo.fsf@mail.jurta.org> <87lhovik5c.fsf@lifelogs.com> <87wq8egh3r.fsf@lifelogs.com> <87ppe4zv0t.fsf@mail.jurta.org> <87k34ba5sn.fsf@mail.jurta.org> <87siiq4gpv.fsf@mail.jurta.org> <87iojduj9n.fsf@mail.jurta.org> <87k33nyirh.fsf@mail.jurta.org> <87sii0becx.fsf@lifelogs.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1415058872 12509 80.91.229.3 (3 Nov 2014 23:54:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 3 Nov 2014 23:54:32 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Nov 04 00:54:23 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XlRS0-0006BN-5F for ged-emacs-devel@m.gmane.org; Tue, 04 Nov 2014 00:54:20 +0100 Original-Received: from localhost ([::1]:37813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlRRz-0008An-Ra for ged-emacs-devel@m.gmane.org; Mon, 03 Nov 2014 18:54:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlRRq-00083t-MZ for emacs-devel@gnu.org; Mon, 03 Nov 2014 18:54:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XlRRk-0002Y0-6n for emacs-devel@gnu.org; Mon, 03 Nov 2014 18:54:10 -0500 Original-Received: from ps18281.dreamhost.com ([69.163.222.226]:56863 helo=ps18281.dreamhostps.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlRRj-0002Xr-Vo for emacs-devel@gnu.org; Mon, 03 Nov 2014 18:54:04 -0500 Original-Received: from localhost.jurta.org (ps18281.dreamhostps.com [69.163.222.226]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 2FC33369BC368C for ; Mon, 3 Nov 2014 15:54:01 -0800 (PST) In-Reply-To: <87sii0becx.fsf@lifelogs.com> (Ted Zlatanov's message of "Mon, 03 Nov 2014 08:30:54 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 69.163.222.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:176325 Archived-At: > This feature seems stalled, is this issue the only thing blocking it? The only blocking thing is to decide whether to move through the history of replacements using M-p or M-n. This patch implements a sequence of M-= n to insert replacement pairs, but it's easy to change just one line from (read-from-minibuffer prompt nil nil nil query-replace-from-history-variable defaults t))))) to (read-from-minibuffer prompt nil nil nil 'defaults nil t) then M-p will move through replacement pairs instead of previous single history strings `from' or `to'. Maybe this choice should be customizable? =3D=3D=3D modified file 'lisp/replace.el' --- lisp/replace.el 2014-08-25 02:36:45 +0000 +++ lisp/replace.el 2014-11-03 23:27:28 +0000 @@ -56,8 +56,8 @@ (defvar query-replace-history nil =20 (defvar query-replace-defaults nil "Default values of FROM-STRING and TO-STRING for `query-replace'. -This is a cons cell (FROM-STRING . TO-STRING), or nil if there is -no default value.") +This is a list of cons cells (FROM-STRING . TO-STRING), +or nil if there is no default values.") =20 (defvar query-replace-interactive nil "Non-nil means `query-replace' uses the last search string. @@ -67,6 +67,13 @@ (make-obsolete-variable 'query-replace-i to the minibuffer that reads the string to replace, or invoke replacemen= ts from Isearch by using a key sequence like `C-s C-s M-%'." "24.3") =20 +(defvar query-replace-from-to-separator + (propertize + "\0" 'display (propertize + (if (char-displayable-p ?\u2192) " \u2192 " " -> ") + 'face 'minibuffer-prompt)) + "String that separates FROM and TO in the default replacements.") + (defcustom query-replace-from-history-variable 'query-replace-history "History list to use for the FROM argument of `query-replace' commands= . The value of this variable should be a symbol; that symbol @@ -132,11 +139,15 @@ (defun query-replace-read-from (prompt r (if query-replace-interactive (car (if regexp-flag regexp-search-ring search-ring)) (let* ((history-add-new-input nil) + (defaults (mapcar (lambda (from-to) + (concat (query-replace-descr (car from-to)) + query-replace-from-to-separator + (query-replace-descr (cdr from-to)))) + query-replace-defaults)) (prompt - (if query-replace-defaults - (format "%s (default %s -> %s): " prompt - (query-replace-descr (car query-replace-defaults)) - (query-replace-descr (cdr query-replace-defaults))) + (if defaults + (format "%s (default %s): " prompt + (car defaults)) (format "%s: " prompt))) (from ;; The save-excursion here is in case the user marks and copies @@ -144,14 +155,18 @@ (defun query-replace-read-from (prompt r ;; That should not clobber the region for the query-replace itself. (save-excursion (if regexp-flag - (read-regexp prompt nil query-replace-from-history-variable) + (read-regexp prompt defaults query-replace-from-history-variable) (read-from-minibuffer - prompt nil nil nil query-replace-from-history-variable - (car (if regexp-flag regexp-search-ring search-ring)) t))))) + prompt nil nil nil query-replace-from-history-variable + defaults t))))) (if (and (zerop (length from)) query-replace-defaults) - (cons (car query-replace-defaults) + (cons (caar query-replace-defaults) + (query-replace-compile-replacement + (cdar query-replace-defaults) regexp-flag)) + (let* ((to (if (string-match query-replace-from-to-separator from) (query-replace-compile-replacement - (cdr query-replace-defaults) regexp-flag)) + (substring from (match-end 0)) regexp-flag))) + (from (if to (substring from 0 (match-beginning 0)) from))) (add-to-history query-replace-from-history-variable from nil t) ;; Warn if user types \n or \t, but don't reject the input. (and regexp-flag @@ -163,7 +178,11 @@ (defun query-replace-read-from (prompt r ((string=3D match "\\t") (message "Note: `\\t' here doesn't match a tab; to do that, just type= TAB"))) (sit-for 2))) - from)))) + (if (not to) + from + (add-to-history query-replace-to-history-variable to nil t) + (push (cons from to) query-replace-defaults) + (cons from to))))))) =20 (defun query-replace-compile-replacement (to regexp-flag) "Maybe convert a regexp replacement TO to Lisp. @@ -216,7 +235,7 @@ (defun query-replace-read-to (from promp nil nil nil query-replace-to-history-variable from t))) (add-to-history query-replace-to-history-variable to nil t) - (setq query-replace-defaults (cons from to)) + (push (cons from to) query-replace-defaults) to)) regexp-flag)) =20 > You could use a Unicode character (RIGHT ARROW =E2=86=92 for instance),= it's > unlikely to occur in a normal search and replace, and could be speciall= y > encoded to "=E2=86=92=E2=86=92" in those cases. So you'd store "X=E2=86= =92=E2=86=92Y=E2=86=92A=E2=86=92=E2=86=92=E2=86=92=E2=86=92B" to record > FROM=3D"X=E2=86=92Y" and TO=3D"A=E2=86=92=E2=86=92B". It's an unambigu= ous encoding. If that's too > hacky, let's find another way, and let me know how I can help. The patch uses "\0" as a separator that is highly unlikely to occur in the replacement strings. Also for better displaying of special characters in the minibuffer, the following patch modifies isearch-text-char-description used by query-replace-descr to put a formatted display property on special charac= ters instead of changing them. This patch also works better for isearch, because it keep the faces on the special characters in the failed string. =3D=3D=3D modified file 'lisp/isearch.el' --- lisp/isearch.el 2014-09-04 16:14:26 +0000 +++ lisp/isearch.el 2014-11-03 23:22:06 +0000 @@ -2873,8 +2873,12 @@ (defun isearch-no-upper-case-p (string r =20 (defun isearch-text-char-description (c) (cond - ((< c ?\s) (propertize (format "^%c" (+ c 64)) 'face 'escape-glyph)) - ((=3D c ?\^?) (propertize "^?" 'face 'escape-glyph)) + ((< c ?\s) (propertize + (char-to-string c) + 'display (propertize (format "^%c" (+ c 64)) 'face 'escape-glyph= ))) + ((=3D c ?\^?) (propertize + (char-to-string c) + 'display (propertize "^?" 'face 'escape-glyph))) (t (char-to-string c)))) =20 ;; General function to unread characters or events.