From: Arnaldo Mandel <am@ime.usp.br>
Cc: Gareth Walker <gw115@york.ac.uk>
Subject: RE: commenting lines
Date: Tue, 2 Jul 2002 09:16:21 -0300 [thread overview]
Message-ID: <15649.39317.672794.731652@gargle.gargle.HOWL> (raw)
In-Reply-To: <3D21958D.7020503@york.ac.uk>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1516 bytes --]
Gareth Walker wrote (on Jul 2, 2002):
> Hi all -- I know it is possible to comment out text in Emacs with
> `comment-region', but is it possible to specify what goes at the
> beginning of each line? I would like to `label' regions of my text
> files with different things.
This oldie is quite reliable, useful enough to deserve a key-binding.
;; 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))
)))
Enjoy,
am
--
Arnaldo Mandel
Departamento de Ciência da Computação - Computer Science Department
Universidade de São Paulo, Bra[sz]il
am@ime.usp.br
next prev parent reply other threads:[~2002-07-02 12:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-02 11:59 commenting lines Gareth Walker
2002-07-02 12:16 ` Arnaldo Mandel [this message]
2002-07-02 18:03 ` Greg Hill
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=15649.39317.672794.731652@gargle.gargle.HOWL \
--to=am@ime.usp.br \
--cc=gw115@york.ac.uk \
/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).