[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need some Elisp help

From: Jim McCloskey
Subject: Re: Need some Elisp help
Date: Wed, 04 Jul 2001 10:08:20 -0700

|> I am not very familiar with elisp. I was wondering whether it is
|> possible to write a small macro that would insert a string (given
|> interactively by the user) at the beginning of every line within a
|> region.

The supercite package is the ultimate solution to this problem (for
mail and news anyway). Talk about bells and whistles ....

I picked up the elisp below from a gnu mailing-list many years ago and
have been using it since. I'm afraid I don't know who originally wrote

;; The first function here does quoting and citation; useful in mail,
;; TeX-documents and Elisp files. With no argument it prefixes |> to
;; the front of each line. With an argument it prompts the user for
;; what prefix string to use. 

(defun quote-region (beg end &optional flag)
  "Preface each line of region with string.  With no argument, the
prefix is \"\|> \".  With an argument, the prefix must be entered."
  (interactive "r\nP")
  (setq prefix
  (if (not flag) "\|> " (read-string "Prefix string: ")))
      (narrow-to-region beg end)
      (goto-char (point-min))
      (replace-regexp "^\\([ \t]*\\S-\\)" (concat prefix "\\1")))))

The wonderful AucTeX package also has a function called
tex-comment-out-region which prefixes % to the beginnings of all the
lines in a region. That could probably be adapted to your purposes


reply via email to

[Prev in Thread] Current Thread [Next in Thread]