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: Sat, 25 Oct 2014 23:52:18 +0300 Organization: JURTA Message-ID: <87k33nyirh.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> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1414270765 27735 80.91.229.3 (25 Oct 2014 20:59:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 25 Oct 2014 20:59:25 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 25 22:59:17 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 1Xi8Qe-0005NW-S1 for ged-emacs-devel@m.gmane.org; Sat, 25 Oct 2014 22:59:17 +0200 Original-Received: from localhost ([::1]:54615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xi8Qe-0004Xi-HE for ged-emacs-devel@m.gmane.org; Sat, 25 Oct 2014 16:59:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xi8QM-0004XX-Q5 for emacs-devel@gnu.org; Sat, 25 Oct 2014 16:59:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xi8QC-0004RW-8N for emacs-devel@gnu.org; Sat, 25 Oct 2014 16:58:54 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.222.226]:33151 helo=ps18281.dreamhostps.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xi8QB-0004RQ-WC for emacs-devel@gnu.org; Sat, 25 Oct 2014 16:58:48 -0400 Original-Received: from localhost.jurta.org (ps18281.dreamhostps.com [69.163.222.226]) by ps18281.dreamhostps.com (Postfix) with ESMTP id D8ADE369F26F0D; Sat, 25 Oct 2014 13:58:45 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Wed, 22 Oct 2014 08:58:14 -0400") 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:175839 Archived-At: > The widget library is definitely too heavy. And I don't like the idea > of making it read-only either. Just use a special character/string, and > give it a special appearance via text-properties (make sure the user > can't delete just a part of it, so a single char is best, probably with > a display property), so that the user can tell it's not just text and so > that Elisp can reliably recognize it as well. > E.g. (propertize "\0" 'display (propertize " -> " 'face 'my-face)) Currently there are two user variables `query-replace-from-history-variable' and `query-replace-to-history-variable' by default both pointing to the same history variable `query-replace-history'. The simplest solution would be to add another history variable named `query-replace-from-to-history', so the users could easily customize `query-replace-from-history-variable' either to the old value `query-replace-history' to restore the current functionality, or customize it to the new from-to pair history. Below is a preliminary implementation. However, there is a problem that after saving it to the desktop or savehist, and restoring back FROM-TO string pairs in the history lose text-properties. If there is no way to save text properties then perhaps we should have two history variables: one with cons pairs (FROM . TO) to save in the desktop, and another with a list of strings "FROMTO" to use in `read-from-minibuffer', and keep these two variables in sync. === modified file 'lisp/replace.el' --- lisp/replace.el 2014-08-25 02:36:45 +0000 +++ lisp/replace.el 2014-10-25 20:48:10 +0000 @@ -54,10 +54,11 @@ (defvar query-replace-history nil See `query-replace-from-history-variable' and `query-replace-to-history-variable'.") -(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.") +(defvar query-replace-from-to-history nil + "Default history list of FROM-TO strings for `query-replace'. +This is a list of string pairs of FROM-STRING and TO-STRING +separated by `query-replace-from-to-separator', or nil +if there is no history. See `query-replace-from-history-variable'.") (defvar query-replace-interactive nil "Non-nil means `query-replace' uses the last search string. @@ -67,14 +68,24 @@ (make-obsolete-variable 'query-replace-i to the minibuffer that reads the string to replace, or invoke replacements from Isearch by using a key sequence like `C-s C-s M-%'." "24.3") -(defcustom query-replace-from-history-variable 'query-replace-history +(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 `query-replace-from-to-history'.") + +(defcustom query-replace-from-history-variable 'query-replace-from-to-history "History list to use for the FROM argument of `query-replace' commands. The value of this variable should be a symbol; that symbol is used as a variable to hold a history list for the strings or patterns to be replaced." :group 'matching - :type 'symbol - :version "20.3") + :type '(choice + (const :tag "History of FROM-TO pairs" query-replace-from-to-history) + (const :tag "History of FROM strings" query-replace-history) + (symbol :tag "Your choice of history list")) + :version "24.5") (defcustom query-replace-to-history-variable 'query-replace-history "History list to use for the TO argument of `query-replace' commands. @@ -132,11 +143,10 @@ (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) + (default (car query-replace-from-to-history)) (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 query-replace-from-to-history + (format "%s (default %s): " prompt default) (format "%s: " prompt))) (from ;; The save-excursion here is in case the user marks and copies @@ -148,11 +158,25 @@ (defun query-replace-read-from (prompt r (read-from-minibuffer prompt nil nil nil query-replace-from-history-variable (car (if regexp-flag regexp-search-ring search-ring)) t))))) - (if (and (zerop (length from)) query-replace-defaults) - (cons (car query-replace-defaults) + (if (or + ;; Default value + (and (zerop (length from)) query-replace-from-to-history + (string-match query-replace-from-to-separator default)) + ;; History of FROM-TO pairs + (and (eq query-replace-from-history-variable + 'query-replace-from-to-history) + (string-match query-replace-from-to-separator from))) + (let ((from-string (substring (if (zerop (length from)) default from) 0 (match-beginning 0))) + (to-string (substring (if (zerop (length from)) default from) (match-end 0)))) + (unless (zerop (length from)) + (add-to-history query-replace-from-history-variable from nil t)) + (cons from-string (query-replace-compile-replacement - (cdr query-replace-defaults) regexp-flag)) - (add-to-history query-replace-from-history-variable from nil t) + to-string regexp-flag))) + ;; Just FROM string + (unless (eq query-replace-from-history-variable + 'query-replace-from-to-history) + (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 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from) @@ -216,7 +240,9 @@ (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)) + (add-to-history 'query-replace-from-to-history + (concat from query-replace-from-to-separator to) + nil t) to)) regexp-flag))