all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Hrvoje Niksic <hniksic@xemacs.org>
Subject: prefix-region
Date: Mon, 24 Oct 2005 22:28:31 +0200	[thread overview]
Message-ID: <87hdb6accw.fsf@xemacs.org> (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))))))

             reply	other threads:[~2005-10-24 20:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-24 20:28 Hrvoje Niksic [this message]
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

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=87hdb6accw.fsf@xemacs.org \
    --to=hniksic@xemacs.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.