* RE: commenting lines
2002-07-02 11:59 commenting lines Gareth Walker
@ 2002-07-02 12:16 ` Arnaldo Mandel
2002-07-02 18:03 ` Greg Hill
1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Mandel @ 2002-07-02 12:16 UTC (permalink / raw)
Cc: Gareth Walker
[-- 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: commenting lines
2002-07-02 11:59 commenting lines Gareth Walker
2002-07-02 12:16 ` Arnaldo Mandel
@ 2002-07-02 18:03 ` Greg Hill
1 sibling, 0 replies; 3+ messages in thread
From: Greg Hill @ 2002-07-02 18:03 UTC (permalink / raw)
Gareth,
I have the following in my .emacs, which I use for that sort of
thing. Just set mark at the beginning of the first line you want to
comment out, move point to the beginning of the last line, invoke the
command, and type in the string you want to use as a comment.
(global-set-key [?\C-\A-\M-s] (lambda (string start end)
(interactive "sString: \nr")
(string-rectangle start
end string)))
I use the following for removing those comments. Set mark at the
beginning of the first line you want to uncomment, move point to the
last line just after the last character of the comment, and invoke
the command.
(global-set-key [?\C-\A-\M-d] (lambda (start end)
(interactive "r")
(delete-rectangle start end)))
--Greg
At 12:59 PM +0100 7/2/02, Gareth Walker wrote:
>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.
>
>best wishes
>
>Gareth
>
>
>
>_______________________________________________
>Help-gnu-emacs mailing list
>Help-gnu-emacs@gnu.org
>http://mail.gnu.org/mailman/listinfo/help-gnu-emacs
^ permalink raw reply [flat|nested] 3+ messages in thread