* Query replace inrectangles
@ 2003-01-30 12:00 Thorsten Bucksch
2003-01-30 15:32 ` Kai Großjohann
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Bucksch @ 2003-01-30 12:00 UTC (permalink / raw)
Hello ,
since a long time I am missing a "query-replace-in-rectangles" for the
emacs. I found something in the web, but this does not work in emacs 21
(error: wrong number of arguments ...).
Since version 21 there is already a "string-in-rectangle". This is not to
bad. But replacing in a rectangular area is still not possible.
Can anyone help me with that topic?
Thanks a lot!
Thorsten
____________________________________________________________________________
_________
------------------------------------------------------------------------
; bind commands to ^xr% and ^xr&:
(define-key ctl-x-map "r&" `replace-string-in-rectangle)
(define-key ctl-x-map "r%" `query-replace-in-rectangle)
; ------------------------------------------------------------------------
(defun replace-string-in-rectangle-line (startpos ignore ignore)
; narrow to region:
(narrow-to-region startpos (point))
; do replace
(goto-char startpos)
(while (search-forward from-string nil t)
(replace-match to-string nil t))
(widen)
)
(defun replace-string-in-rectangle(from-string to-string &optional ignore)
"Replace occurrences of FROM-STRING with TO-STRING in a rectangle"
(interactive (query-replace-read-args "Replace string" nil))
(setq start (mark))
(setq end (point))
(operate-on-rectangle `replace-string-in-rectangle-line start end t)
"interactive do mode in load path"
(require 'ido)
(ido-mode t)
)
; ------------------------------------------------------------------------
(defun query-replace-in-rectangle-line (startpos ignore ignore)
(setq endpos (point))
(setq transient-mark-mode t)
(set-mark startpos)
(goto-char endpos)
(perform-replace from-string to-string t nil nil 1 nil)
(setq replace-count-rectangle-lines (+ replace-count-rectangle-lines 1))
)
(defun query-replace-in-rectangle(from-string to-string &optional ignore)
"Query-replace occurrences of FROM-STRING with TO-STRING in a rectangle.
query-replace is done on one line of the rectangle at a time. To
abort the query-replace for entire rectangle, use ESC-ESC-ESC or ^G."
(interactive (query-replace-read-args "Replace string" nil))
(setq start (mark))
(setq end (point))
(setq replace-count-rectangle 0)
(setq replace-count-rectangle-lines 0)
(apply-on-rectangle `query-replace-in-rectangle-line start end t)
(message "Completed query-replace in a rectangle of %d line%s"
replace-count-rectangle-lines
(if (= replace-count-rectangle-lines 1) "" "s")))
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Query replace inrectangles
2003-01-30 12:00 Query replace inrectangles Thorsten Bucksch
@ 2003-01-30 15:32 ` Kai Großjohann
0 siblings, 0 replies; 2+ messages in thread
From: Kai Großjohann @ 2003-01-30 15:32 UTC (permalink / raw)
I think that CUA mode might provide this. You start marking a
rectangle with S-<return>, then M-% is automatically restricted to
the rectangle. Not sure whether this works, though. Maybe I'm just
dreaming...
--
Ambibibentists unite!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-01-30 15:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-30 12:00 Query replace inrectangles Thorsten Bucksch
2003-01-30 15:32 ` Kai Großjohann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).