Path: utzoo!utgpu!water!watmath!clyde!rutgers!cmcl2!yale!Ram-Ashwin From: Ram-Ashwin@cs.yale.edu (Ashwin Ram) Newsgroups: comp.emacs Subject: Re: Need mlisp for "prefix-region" Message-ID: <22140@yale-celray.yale.UUCP> Date: 29 Jan 88 02:05:26 GMT References: <3910015@nucsrl.UUCP> Sender: root@yale.UUCP Reply-To: Ram-Ashwin@cs.yale.edu (Ashwin Ram) Organization: Computer Science, Yale University, New Haven, CT 06520-2158 Lines: 27 In-reply-to: naim@nucsrl.UUCP (Naim Abdullah) In article <3910015@nucsrl.UUCP>, naim@nucsrl (Naim Abdullah) writes: > One thing I frequently find myself needing to > do is prefix a region with some character. Mg has a nice function > called "prefix-region" to do that [...] The following function should do what you want: (defun prefix-region (begin end prefix) "Prefix every line in the region between BEGIN and END with the string PREFIX." (interactive "r\nsPrefix: ") (save-excursion (save-restriction (narrow-to-region begin end) (goto-char (point-min)) (while (re-search-forward "^" nil t) (replace-match prefix t t))))) One problem is that if the region starts from a point in the middle of a line (rather than at the beginning of a line), the prefix will be inserted at that point in the middle of the line too. This is pretty easy to fix if it's a problem (I don't know what MG's prefix-region does in this situation). -- Ashwin Ram -- ARPA: Ram-Ashwin@cs.yale.edu UUCP: {decvax,ucbvax,harvard,cmcl2,...}!yale!Ram-Ashwin BITNET: Ram@yalecs