all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: emacs-devel@gnu.org
Subject: Re: `Q' in Dired - be able to skip the rest of one file and move onto the next
Date: Tue, 15 Jul 2008 03:27:32 +0300	[thread overview]
Message-ID: <87vdz8yp9f.fsf@jurta.org> (raw)
In-Reply-To: <87prwigx01.fsf@bzg.ath.cx> (Bastien's message of "Fri, 04 Jan 2008 03:11:58 +0100")

>>> Even so, it might not be bad to provide a key to skip to the next file
>>> without exiting query-replace.
>>
>> Another problem I have with `Q' is that it requires typing `!' in every
>> file to replace all occurrences.  So if I want to replace all occurrences
>> in ALL marked files at once without a query, I need typing `!' as many times
>> as there are marked files.
>>
>> Maybe, when started by `Q', query-replace should apply `!' to all marked files,
>> and a new key `Y' should replace all remaining occurrences in the current file,
>> and a new key `N' should skip the current file as Miles has already proposed.
>
> Agreed.

I see that this useful feature is not yet implemented, so I have
made a patch that implements multi-file query-replace UI.

It defines a new keymap `multi-query-replace-map' that inherits from
`query-replace-map' and defines two multi-file keys "Y" and "N".
"Y" means to replace all remaining matches in all remaining buffers,
(this key is better than redefining the old behavior of "!").
And "N" skips remaining matches in the current buffer and continues
with the next buffer (so in addition to "No for this file" it also has
"Next file" mnemonics).

Index: lisp/replace.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/replace.el,v
retrieving revision 1.273
diff -c -r1.273 replace.el
*** lisp/replace.el	29 Jun 2008 16:09:08 -0000	1.273
--- lisp/replace.el	15 Jul 2008 00:27:02 -0000
***************
*** 1372,1377 ****
--- 1372,1391 ----
  `exit', `act-and-exit', `edit', `delete-and-edit', `recenter',
  `automatic', `backup', `exit-prefix', and `help'.")
  
+ (defvar multi-query-replace-map
+   (let ((map (make-sparse-keymap)))
+     (set-keymap-parent map query-replace-map)
+     (define-key map "Y" 'automatic-all)
+     (define-key map "N" 'exit-current)
+     map)
+   "Keymap that defines additional bindings for multi-buffer operations.
+ It extends its parent map `query-replace-map' with new bindings to
+ operate on a set of buffers/files.  The difference with its parent map
+ is the additional answers `automatic-all' to replace all remaining
+ matches in all remaining buffers with no more questions, and
+ `exit-current' to skip remaining matches in the current buffer
+ and to continue with the next buffer in the sequence.")
+ 
  (defun replace-match-string-symbols (n)
    "Process a list (and any sub-lists), expanding certain symbols.
  Symbol  Expands To
***************
*** 1702,1708 ****
  				     query-replace-help)))
  			   (with-current-buffer standard-output
  			     (help-mode))))
! 			((eq def 'exit)
  			 (setq keep-going nil)
  			 (setq done t))
  			((eq def 'backup)
--- 1716,1722 ----
  				     query-replace-help)))
  			   (with-current-buffer standard-output
  			     (help-mode))))
! 			((or (eq def 'exit) (eq def 'exit-current))
  			 (setq keep-going nil)
  			 (setq done t))
  			((eq def 'backup)
***************
*** 1744,1750 ****
  				   real-match-data (replace-match-data
  						    t real-match-data)
  				   replaced t)))
! 			((eq def 'automatic)
  			 (or replaced
  			     (setq noedit
  				   (replace-match-maybe-edit
--- 1758,1764 ----
  				   real-match-data (replace-match-data
  						    t real-match-data)
  				   replaced t)))
! 			((or (eq def 'automatic) (eq def 'automatic-all))
  			 (or replaced
  			     (setq noedit
  				   (replace-match-maybe-edit

Index: lisp/progmodes/etags.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/progmodes/etags.el,v
retrieving revision 1.211
diff -c -r1.211 etags.el
*** lisp/progmodes/etags.el	7 Jun 2008 02:37:37 -0000	1.211
--- lisp/progmodes/etags.el	15 Jul 2008 00:27:08 -0000
***************
*** 1865,1872 ****
  			      ;; to the beginning of it so perform-replace
  			      ;; will see it.
  			      (goto-char (match-beginning 0))))
! 	tags-loop-operate `(perform-replace ',from ',to t t ',delimited))
    (tags-loop-continue (or file-list-form t)))
  \f
  (defun tags-complete-tags-table-file (string predicate what) ; Doc string?
    (save-excursion
--- 1865,1896 ----
  			      ;; to the beginning of it so perform-replace
  			      ;; will see it.
  			      (goto-char (match-beginning 0))))
! 	tags-loop-operate `(tags-query-replace-loop-operate
! 			    ',from ',to ',delimited))
    (tags-loop-continue (or file-list-form t)))
+ 
+ (defun tags-query-replace-loop-operate (from to delimited)
+   "Call `perform-replace' with the logic of multi-file operations.
+ Used for `tags-loop-operate' in `tags-query-replace'."
+   (let* (
+ 	 ;; def-pre is a key typed in the previous call of perform-replace
+ 	 (def-pre (lookup-key multi-query-replace-map
+ 			      (vector last-input-char)))
+ 	 ;; If the last typed key was automatic-all, don't ask
+ 	 ;; more questions in next files
+ 	 (query-flag (not (eq def-pre 'automatic-all)))
+ 	 (ret (perform-replace from to query-flag t delimited nil
+ 			       multi-query-replace-map))
+ 	 ;; def-post is a key typed in the new call of perform-replace
+ 	 (def-post (lookup-key multi-query-replace-map
+ 			       (vector last-input-char))))
+     (or
+      ;; Return non-nil exit code from `perform-replace'
+      ret
+      ;; Or return t if a multi-file operation key was typed
+      (eq def-post 'exit-current)
+      (eq def-post 'automatic-all))))
+ 
  \f
  (defun tags-complete-tags-table-file (string predicate what) ; Doc string?
    (save-excursion

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




  reply	other threads:[~2008-07-15  0:27 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-02  7:34 `Q' in Dired - be able to skip the rest of one file and move on to the next Drew Adams
2008-01-03  9:50 ` Richard Stallman
2008-01-03 10:11   ` Andreas Schwab
2008-01-03 10:27     ` Miles Bader
2008-01-03 16:17       ` Drew Adams
2008-01-03 15:56   ` Luc Teirlinck
2008-01-03 16:18     ` `Q' in Dired - be able to skip the rest of one file and move onto " Drew Adams
2008-01-03 21:32       ` Juri Linkov
2008-01-04  2:11         ` Bastien
2008-07-15  0:27           ` Juri Linkov [this message]
2008-07-15  7:38             ` Lennart Borgman (gmail)
2008-07-20  0:33               ` Juri Linkov
2008-01-05  5:54       ` Richard Stallman
2008-01-08  0:21         ` Juri Linkov
2008-01-08  0:33           ` Drew Adams
2008-01-08 19:08             ` Richard Stallman
2008-01-09  0:48             ` Juri Linkov
2008-01-09  1:47               ` Drew Adams
2008-01-08  2:12           ` Luc Teirlinck
2008-01-09  0:54             ` Juri Linkov

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=87vdz8yp9f.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    /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.