From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Arnaldo Mandel Newsgroups: gmane.emacs.help Subject: RE: commenting lines Date: Tue, 2 Jul 2002 09:16:21 -0300 Sender: help-gnu-emacs-admin@gnu.org Message-ID: <15649.39317.672794.731652@gargle.gargle.HOWL> References: <3D21958D.7020503@york.ac.uk> NNTP-Posting-Host: localhost.gmane.org X-Trace: main.gmane.org 1025612326 7437 127.0.0.1 (2 Jul 2002 12:18:46 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 2 Jul 2002 12:18:46 +0000 (UTC) Cc: Gareth Walker Return-path: Original-Received: from fencepost.gnu.org ([199.232.76.164]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 17PMcH-0001vj-00 for ; Tue, 02 Jul 2002 14:18:46 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 17PMbc-000774-00; Tue, 02 Jul 2002 08:18:04 -0400 Original-Received: from bidu.ime.usp.br ([143.107.45.12]) by fencepost.gnu.org with smtp (Exim 3.34 #1 (Debian)) id 17PMa1-00071d-00 for ; Tue, 02 Jul 2002 08:16:26 -0400 Original-Received: (qmail 16675 invoked from network); 2 Jul 2002 12:16:23 -0000 Original-Received: from benavuya.ime.usp.br (143.107.45.38) by bidu.ime.usp.br with SMTP; 2 Jul 2002 12:16:23 -0000 Original-Received: (qmail 27295 invoked by uid 201); 2 Jul 2002 12:16:22 -0000 Original-To: help-gnu-emacs@gnu.org In-Reply-To: <3D21958D.7020503@york.ac.uk> X-Mailer: VM 7.03 under Emacs 21.1.9 Full-Name: Arnaldo Mandel Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:564 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:564 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