home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / prefix-reg2.el < prev    next >
Encoding:
Text File  |  1990-03-21  |  1.7 KB  |  43 lines

  1. ;From: erlkonig@walt.cc.utexas.edu (Christopher North-Keys)
  2. ;Newsgroups: comp.emacs
  3. ;Subject: prefix-region command (rmail) update
  4. ;Message-ID: <16516@ut-emx.UUCP>
  5. ;Date: 3 Aug 89 00:57:14 GMT
  6. ;Reply-To: erlkonig@walt.cc.utexas.edu (Christopher North-Keys)
  7. ;Organization: Packaging/Interconnect, M.C.C.
  8. ;Lines: 32
  9. ;Keywords: prefix-region
  10.  
  11. ;; Prefix region (for rmail, in particular) -- simple & robust.
  12. ;; Christopher North-Keys, 1989
  13. (defun prefix-region (start end string)
  14.   "Insert STRING, default '> ', at the start of each line
  15. in or intersecting region while preserving indentation.
  16. Called from a program, takes three arguments,START, END and STRING."
  17.   (interactive "r\nsString:  ")
  18.   (if (or (equal string "") (equal string nil))
  19.       (setq string "> "))
  20.   ;; Adjust start and end to extremes of
  21.   ;; lines so lines don't get broken.
  22.   (goto-char end)
  23.   (end-of-line)
  24.   (setq end (point))
  25.   (goto-char start)
  26.   (beginning-of-line)
  27.   (setq start (point))
  28.   ;; There is another command, replace-regexp, that did not work well.
  29.   ;; If you narrowed as one would expect, you could not widen to the
  30.   ;; previous narrow.  Saving the old narrow extremes failed, as this
  31.   ;; routine expands the region.  Sadmaking.
  32.   (let (line)
  33.     (setq lines (count-lines start end))
  34.     (while (> lines 0)
  35.       (insert string)
  36.       (search-forward "\n")
  37.       (setq lines (- lines 1))
  38.       )))
  39. ;------------------------------------/\----------------------------------------
  40. ;Seo:  Harp[@Mcc.Com]               /  \/\ ^*^           Christopher North-Keys
  41. ;Tha mi gu trang a'cluich.         /    \ \          Systems Administrator, MCC
  42. ;------------------------------------------------------------------------------
  43.