unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* prefix-region
@ 2005-10-24 20:28 Hrvoje Niksic
  2005-10-24 21:39 ` prefix-region Andreas Schwab
  2005-10-31  1:14 ` prefix-region Richard M. Stallman
  0 siblings, 2 replies; 14+ messages in thread
From: Hrvoje Niksic @ 2005-10-24 20:28 UTC (permalink / raw)


I have found this function, originally from XEmacs, immensely useful:

    (prefix-region PREFIX)

    Insert PREFIX at the beginning of each line between mark and point.

It is useful for all kinds of editing jobs, including commenting out
pieces of code and quoting mail.  While some of these things can be
achieved using other Emacs functions, `M-x prefix-region' is often
much more convenient, especially when the more sophisticated
mechanisms are unavailable (such as when editing snippets of code in
mail messages).

This function is not as easy to write as it seems because there are
several corner cases that need to be gotten right (empty region,
whether mark precedes point or vice versa, mark/point at line start or
end positions).  Because of that I propose that you include the
function in Emacs.

I wasn't satisfied with the XEmacs implementation of this function so
I wrote and tested this one:

(defun prefix-region (prefix)
  "Insert PREFIX at the beginning of each line between mark and point."
  (interactive "sPrefix string: ")
  (let ((end (region-end)))
    (save-excursion
      (goto-char (region-beginning))
      (beginning-of-line)
      (save-restriction
	(narrow-to-region (point) end)
	(while (not (eobp))
	  (insert prefix)
	  (forward-line 1))))))

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2005-10-31  8:54 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-24 20:28 prefix-region Hrvoje Niksic
2005-10-24 21:39 ` prefix-region Andreas Schwab
2005-10-24 22:45   ` prefix-region Hrvoje Niksic
2005-10-25  8:24     ` prefix-region Romain Francoise
2005-10-25  9:54       ` prefix-region Hrvoje Niksic
2005-10-25 13:59         ` prefix-region Miles Bader
2005-10-25 19:15           ` prefix-region Hrvoje Niksic
2005-10-25 19:41             ` prefix-region Stefan Monnier
2005-10-25 19:47               ` prefix-region Romain Francoise
2005-10-25 20:29               ` prefix-region Edward O'Connor
2005-10-25 21:12             ` prefix-region Andreas Schwab
2005-10-25 21:24               ` prefix-region Hrvoje Niksic
2005-10-31  1:14 ` prefix-region Richard M. Stallman
2005-10-31  8:54   ` prefix-region Hrvoje Niksic

Code repositories for project(s) associated with this public inbox

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

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).