help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: quoting a block of text with ">"


From: Arnaldo Mandel
Subject: Re: quoting a block of text with ">"
Date: Thu, 30 Sep 2010 06:54:07 -0300

On Wed, Sep 29, 2010 at 3:59 PM, Stever <steve@tripperjones.com> wrote:
> I can't seem to find this function in my version of emacs, but I assume
> there is one. is there any function where I can highlight a block of text
> and put a ">" in front of it. So something like:

I also like this functionality, and have had the command below bound
to a function key for two decades.
The comments are included for a correct attribution of authorship.

;From: erlkonig@walt.cc.utexas.edu (Christopher North-Keys)
;Newsgroups: comp.emacs
;Message-ID: <16516@ut-emx.UUCP>
;Date: 3 Aug 89 00:57:14 GMT

;; Prefix region (for rmail, in particular) -- simple & robust.
;; Christopher North-Keys, 1989
(defun prefix-region (start end string)
  "Insert STRING, default '> ', at the start of each line
in or intersecting region while preserving indentation.
Called from a program, takes three arguments,START, END and STRING."
  (interactive "r\nsString:  ")
  (if (or (equal string "") (equal string nil))
      (setq string "> "))
  ;; Adjust start and end to extremes of
  ;; lines so lines don't get broken.
  (goto-char end)
  (end-of-line)
  (setq end (point))
  (goto-char start)
  (beginning-of-line)
  (setq start (point))
  ;; There is another command, replace-regexp, that did not work well.
  ;; If you narrowed as one would expect, you could not widen to the
  ;; previous narrow.  Saving the old narrow extremes failed, as this
  ;; routine expands the region.  Sadmaking.
  (let (line)
    (setq lines (count-lines start end))
    (while (> lines 0)
      (insert string)
      (search-forward "\n")
      (setq lines (- lines 1))
      )))

Arnaldo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]