all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
Cc: dann@ics.uci.edu, storm@cua.dk, emacs-devel@gnu.org
Subject: Re: query-replace in isearch (was Re: should search ring contain duplicates?)
Date: Thu, 11 May 2006 14:57:32 +0300	[thread overview]
Message-ID: <87wtcslqoj.fsf@jurta.org> (raw)
In-Reply-To: <E1Fe26u-0007uk-Ad@fencepost.gnu.org> (Richard Stallman's message of "Wed, 10 May 2006 23:45:08 -0400")

>     This reminds me of the fact that doing `query-replace' from isearch
>     does not put `query-replace' in the complex command history. IMHO it
>     should. i.e.: C-s FOO M-% BAR RET C-x ESC ESC should show the same
>     thing as M-% FOO RET BAR RET C-x ESC ESC
>
> Would someone please fix this and ack?

The following patch should do that.  It also uses `add-to-history'
to add the current search string to `query-replace-from-history-variable'
to improve code in the same function.  This requires adding a new
argument KEEP-ALL to `add-to-history'. Its meaning is the same as the
argument KEEP-ALL of `read-from-minibuffer'.

Index: lisp/isearch.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.288
diff -c -r1.288 isearch.el
*** lisp/isearch.el	5 May 2006 23:37:31 -0000	1.288
--- lisp/isearch.el	11 May 2006 11:55:45 -0000
***************
*** 1214,1220 ****
    (interactive)
    (barf-if-buffer-read-only)
    (if regexp-flag (setq isearch-regexp t))
!   (let ((case-fold-search isearch-case-fold-search))
      (isearch-done)
      (isearch-clean-overlays)
      (if (and isearch-other-end
--- 1229,1235 ----
    (interactive)
    (barf-if-buffer-read-only)
    (if regexp-flag (setq isearch-regexp t))
!   (let ((case-fold-search isearch-case-fold-search) to)
      (isearch-done)
      (isearch-clean-overlays)
      (if (and isearch-other-end
***************
*** 1222,1239 ****
               (not (and transient-mark-mode mark-active
                         (< (mark) (point)))))
          (goto-char isearch-other-end))
!     (set query-replace-from-history-variable
!          (cons isearch-string
!                (symbol-value query-replace-from-history-variable)))
      (perform-replace
       isearch-string
!      (query-replace-read-to
!       isearch-string
!       (if isearch-regexp "Query replace regexp" "Query replace")
!       isearch-regexp)
       t isearch-regexp isearch-word nil nil
       (if (and transient-mark-mode mark-active) (region-beginning))
!      (if (and transient-mark-mode mark-active) (region-end)))))
  
  (defun isearch-query-replace-regexp ()
    "Start query-replace-regexp with string to replace from last search string."
--- 1237,1258 ----
               (not (and transient-mark-mode mark-active
                         (< (mark) (point)))))
          (goto-char isearch-other-end))
!     (add-to-history query-replace-from-history-variable isearch-string nil t)
      (perform-replace
       isearch-string
!      (setq to (query-replace-read-to
! 	       isearch-string
! 	       (if isearch-regexp "Query replace regexp" "Query replace")
! 	       isearch-regexp))
       t isearch-regexp isearch-word nil nil
       (if (and transient-mark-mode mark-active) (region-beginning))
!      (if (and transient-mark-mode mark-active) (region-end)))
!     (add-to-history
!      'command-history
!      (list (if isearch-regexp 'query-replace-regexp 'query-replace)
! 	   isearch-string to isearch-word
! 	   '(if (and transient-mark-mode mark-active) (region-beginning))
! 	   '(if (and transient-mark-mode mark-active) (region-end))))))
  
  (defun isearch-query-replace-regexp ()
    "Start query-replace-regexp with string to replace from last search string."

Index: lisp/subr.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/subr.el,v
retrieving revision 1.507
diff -c -r1.507 subr.el
*** lisp/subr.el	7 May 2006 20:49:01 -0000	1.507
--- lisp/subr.el	11 May 2006 11:55:55 -0000
***************
*** 1123,1151 ****
  				(< oa ob)
  			      oa)))))))
  
! (defun add-to-history (history-var newelt &optional maxelt)
    "Add NEWELT to the history list stored in the variable HISTORY-VAR.
  Return the new history list.
  If MAXELT is non-nil, it specifies the maximum length of the history.
  Otherwise, the maximum history length is the value of the `history-length'
  property on symbol HISTORY-VAR, if set, or the value of the `history-length'
  variable.
! Remove duplicates of NEWELT unless `history-delete-duplicates' is nil."
    (unless maxelt
      (setq maxelt (or (get history-var 'history-length)
  		     history-length)))
    (let ((history (symbol-value history-var))
  	tail)
!     (if history-delete-duplicates
  	(setq history (delete newelt history)))
!     (setq history (cons newelt history))
!     (when (integerp maxelt)
!       (if (= 0 maxelt)
! 	  (setq history nil)
! 	(setq tail (nthcdr (1- maxelt) history))
! 	(when (consp tail)
! 	  (setcdr tail nil))))
!     (set history-var history)))
  
  \f
  ;;;; Mode hooks.
--- 1123,1154 ----
  				(< oa ob)
  			      oa)))))))
  
! (defun add-to-history (history-var newelt &optional maxelt keep-all)
    "Add NEWELT to the history list stored in the variable HISTORY-VAR.
  Return the new history list.
  If MAXELT is non-nil, it specifies the maximum length of the history.
  Otherwise, the maximum history length is the value of the `history-length'
  property on symbol HISTORY-VAR, if set, or the value of the `history-length'
  variable.
! Remove duplicates of NEWELT unless `history-delete-duplicates' is nil.
! KEEP-ALL, if non-nil, says to put all inputs in the history list,
! even empty or duplicate inputs."
    (unless maxelt
      (setq maxelt (or (get history-var 'history-length)
  		     history-length)))
    (let ((history (symbol-value history-var))
  	tail)
!     (if (and history-delete-duplicates (null keep-all))
  	(setq history (delete newelt history)))
!     (unless (and (null keep-all) history (equal (car history) newelt))
!       (setq history (cons newelt history))
!       (when (integerp maxelt)
! 	(if (= 0 maxelt)
! 	    (setq history nil)
! 	  (setq tail (nthcdr (1- maxelt) history))
! 	  (when (consp tail)
! 	    (setcdr tail nil))))
!       (set history-var history))))
  
  \f
  ;;;; Mode hooks.

-- 
Juri Linkov
http://www.jurta.org/emacs/

  reply	other threads:[~2006-05-11 11:57 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-03  0:54 should search ring contain duplicates? Drew Adams
2006-05-03  7:27 ` Dan Nicolaescu
2006-05-03  8:26   ` Kim F. Storm
2006-05-03 12:48     ` Juri Linkov
2006-05-03 13:53       ` Kim F. Storm
2006-05-04 10:12         ` Kim F. Storm
2006-05-04 10:29           ` David Kastrup
2006-05-04 12:00             ` Stefan Monnier
2006-05-04 12:19             ` Kim F. Storm
2006-05-04 12:25               ` David Kastrup
2006-05-05 22:14               ` Richard Stallman
2006-05-05 23:55                 ` Kim F. Storm
2006-05-06  8:00                   ` Eli Zaretskii
2006-05-06 23:36                     ` Richard Stallman
2006-05-07 20:41                       ` Kim F. Storm
2006-05-04 16:05             ` Stuart D. Herring
2006-05-04 16:23               ` David Kastrup
2006-05-04 16:36                 ` Stuart D. Herring
2006-05-04 21:55               ` Kim F. Storm
2006-05-03 15:04       ` query-replace in isearch (was Re: should search ring contain duplicates?) Dan Nicolaescu
2006-05-03 20:27         ` query-replace in isearch Juri Linkov
2006-05-03 20:43         ` query-replace in isearch (was Re: should search ring contain duplicates?) Richard Stallman
2006-05-11  3:45         ` Richard Stallman
2006-05-11 11:57           ` Juri Linkov [this message]
2006-05-11 14:10             ` Kim F. Storm
2006-05-11 21:52               ` Juri Linkov
2006-05-19  3:05                 ` Juri Linkov
2006-05-20 22:39                   ` Kim F. Storm
2006-05-21  4:27                     ` Juri Linkov
2006-05-21  0:55                   ` Richard Stallman
2006-05-23  5:17                     ` Juri Linkov
2006-05-24  2:18                       ` Richard Stallman
2006-05-25 22:47                         ` Juri Linkov
2006-05-29  6:39                           ` Richard Stallman
2006-05-30  9:28                             ` Juri Linkov
2006-05-31  0:40                               ` Richard Stallman
2006-05-12  4:15             ` Richard Stallman
2006-05-12 11:14               ` Juri Linkov
2006-05-13  4:52                 ` Richard Stallman
2006-05-13 23:13                   ` Kim F. Storm
2006-05-14 15:09                     ` Richard Stallman
2006-05-14 20:52                       ` Kim F. Storm
2006-05-09 20:47       ` should search ring contain duplicates? Juri Linkov
2006-05-10  9:34         ` Kim F. Storm
2006-05-10 22:55           ` Juri Linkov
2006-05-11 10:08             ` Kim F. Storm
2006-05-14 23:29             ` Richard Stallman
2006-05-15  9:54               ` Kim F. Storm
2006-05-16  4:29                 ` Richard Stallman
2006-05-16 11:07                   ` Kim F. Storm
2006-05-11 11:59       ` C-f in isearch minibuffer (was: should search ring contain duplicates?) Juri Linkov
2006-05-11 14:04         ` C-f in isearch minibuffer Miles Bader
2006-05-11 21:52           ` Juri Linkov
2006-05-12  4:15         ` C-f in isearch minibuffer (was: should search ring contain duplicates?) Richard Stallman
2006-05-12 11:12           ` C-f in isearch minibuffer Juri Linkov
2006-05-13  4:52             ` Richard Stallman
2006-05-03 14:18   ` should search ring contain duplicates? Stefan Monnier
2006-05-03 14:25     ` Kim F. Storm
2006-05-03 14:40     ` Drew Adams
2006-05-03 15:54       ` Drew Adams
2006-05-03 20:27         ` Juri Linkov
2006-05-03 23:08           ` Drew Adams
2006-05-04 14:17         ` Richard Stallman
2006-05-04 15:07           ` Kim F. Storm
2006-05-04 22:44             ` Kim F. Storm
2006-05-05 19:05             ` Richard Stallman
2006-05-05 19:14               ` Drew Adams
2006-05-05 19:25                 ` David Kastrup
2006-05-05 20:09                   ` Drew Adams
2006-05-06 14:25                   ` Richard Stallman
2006-05-05 23:22                 ` Juri Linkov
2006-05-05 23:32                   ` Kim F. Storm
2006-05-06  2:05                   ` Drew Adams
2006-05-03 14:43     ` Dan Nicolaescu
2006-05-04 19:41     ` Richard Stallman
2006-05-03 20:42   ` Richard Stallman
2006-05-03 22:41     ` Dan Nicolaescu
2006-05-04 19:41       ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wtcslqoj.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=dann@ics.uci.edu \
    --cc=emacs-devel@gnu.org \
    --cc=storm@cua.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.