Article View: gnu.emacs.help
Article #189417Re: Adding a prefix in the beginning of each line in a region
From: Gabriel
Date: Sat, 16 Feb 1991 19:42
Date: Sat, 16 Feb 1991 19:42
60 lines
2835 bytes
2835 bytes
=> Does anybody know or can write an emacs-lisp routine which can add a
=> pre-set prefix in the beginning of each line in a region? I know
=> that once a prefix is set, it can be added in the beginning of each
=> NEW line. I am talking about putting the prefix in an existed text
=> region....
Here's the function I wrote for this:
(defun indent-reply (prompt begin end &optional string)
"Fills the left margin of region with the string \">\". With prefix
argument, prompts for the string with which to fill the region.
Called from Lisp programs, takes arguments PROMPT, BEGIN, END, and
&optional STRING. BEGIN and END delimit the region. STRING is the
string to use. If PROMPT is non-nil, then prompts for string to use,
and STRING is the default."
(interactive "P\nr")
(unless string (setq string ">"))
(let ((default string))
(and prompt
(equal "" (setq string (read-from-minibuffer
(format "Pad on left: (default %s) " default))))
(setq string default))
(save-excursion
(save-restriction
(narrow-to-region begin end)
(goto-char (point-min))
(while (not (eobp))
(beginning-of-line)
(insert string)
(forward-line 1))))))
And a couple of related functions. These are useful because, after you
prefix a region, it is useful to justify it:
(defun get-fill-prefix ()
(save-excursion
(buffer-substring (progn (re-search-backward "^.+$")
(beginning-of-line)
(point))
(progn (re-search-forward "[a-z]")
(1- (point))))))
(defun fill-paragraph-with-prefix ()
(interactive)
(let ((fill-prefix (get-fill-prefix)))
(fill-paragraph nil)))
`fill-paragraph-with-prefix' is just like `fill-paragraph', except that
it assumes the first set of non-alphabetic characters on the current
line to be the `fill-prefix'.
--
Raul Acevedo
acevedo@athena.mit.edu
"Remember, Information is not knowledge; Knowledge is not Wisdom;
Wisdom is not truth; Truth is not beauty; Beauty is not love;
Love is not music; Music is the best."
- Frank Zappa
Technical Details
Message-ID:
<ACEVEDO.91Feb16144241@hydrox-cookie.mit.edu>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!samsung!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!acevedoReferences:
<1991Feb12.165224.21098@math.ufl.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103b8b,74ec14ab197120e9,start X-Google-Attributes: gid103b8b,public X-Google-ArrivalTime: 1991-02-16 11:26:31 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!samsung!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!acevedo From: acevedo@athena.mit.edu (Gabriel) Newsgroups: gnu.emacs.help Subject: Re: Adding a prefix in the beginning of each line in a region Message-ID: <ACEVEDO.91Feb16144241@hydrox-cookie.mit.edu> Date: 16 Feb 91 19:42:41 GMT References: <1991Feb12.165224.21098@math.ufl.edu> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 60 In-Reply-To: wang@math.ufl.edu's message of 12 Feb 91 16:52:24 GMT