From: "Thorsten Bucksch" <thorsten.bucksch@infineon.com>
Subject: Query replace inrectangles
Date: Thu, 30 Jan 2003 13:00:49 +0100 [thread overview]
Message-ID: <b1b46a$djl$1@newssrv.hl.siemens.de> (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")))
next reply other threads:[~2003-01-30 12:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-30 12:00 Thorsten Bucksch [this message]
2003-01-30 15:32 ` Query replace inrectangles Kai Großjohann
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='b1b46a$djl$1@newssrv.hl.siemens.de' \
--to=thorsten.bucksch@infineon.com \
/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.
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).