[comp.text.tex] prefix function

templon@copper.ucs.indiana.edu (jeffrey templon) (05/24/91)

In article <16491@helios.TAMU.EDU> jdm5548@tamsun.tamu.edu 
(James Darrell McCauley) writes:

>Perhaps some of you lispers and TeXies could add a function to
>tex-mode.el: TeX-comment-region (and possibly TeX-uncomment-region)
>so that it would insert %'s.   
>

Try the following, 'prefix-region'.  It is very general, so you can
comment out C code, TeX, Fortran, mail excerpts, etc. etc.  Just
specify '%' for the prefix-string.

					JT

(defun prefix-region (point mark string)
  "Prefix the region between POINT and MARK with STRING."
  (interactive "*r\nsPrefix: ")
  (save-excursion
    (save-restriction
      (narrow-to-region point mark)
      (goto-char point)
      (replace-regexp "^" string))))