home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / functions / insert-box.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  2.2 KB  |  62 lines

  1. ;From: indetech!lrs@ai.mit.edu (Lynn Slater)
  2. ;Newsgroups: gnu.emacs
  3. ;Subject: Alternative to prefix-region
  4. ;Message-ID: <m0fq6S5-000213C@spinel.indetech.uucp>
  5. ;Date: 4 Aug 89 15:27:00 GMT
  6. ;Distribution: gnu
  7. ;Organization: GNUs Not Usenet
  8. ;Lines: 52
  9. ;
  10. ;Inclosed are two soimple functions which I have found to be very handy.
  11. ;The first, insert-box, does what prefix-region does except that it can
  12. ;insert into the middle of lines as well as at the front of the line.
  13.  
  14. (defun insert-box (start end text)
  15.   "Insert a text prefix at a column in all the lines in the region.
  16.    Called from a program, takes three arguments, START, END, and TEXT.
  17.    The column is taken from that of START.
  18.    The rough inverse of this function is kill-rectangle."
  19.   (interactive "r\nsText To Insert: ")
  20.   (save-excursion
  21.     (let (cc)
  22.       ;; the point-marker stuff is needed to keep the edits from changing
  23.       ;; where end is
  24.       (goto-char end)
  25.       (setq end (point-marker))
  26.       (goto-char start)
  27.       (setq cc  (current-column))
  28.       (while (< (point) end) ;; modified 2/2/88
  29.     ;; I should here check for tab chars
  30.     (insert text)
  31.     (forward-line 1)
  32.     (move-to-column cc)) ;; use move-to-column-force if you have it
  33.       (move-marker end nil))))
  34.  
  35. (defun insert-end (start end text)
  36.   "Insert a text prefix at the end in all the lines in the region.
  37.    Called from a program, takes three arguments, START, END, and TEXT.
  38.    The column is taken from that of START."
  39.   (interactive "r\nsText To Insert: ")
  40.   (save-excursion
  41.     (let (cc)
  42.       ;; the point-marker stuff is needed to keep the edits from changing
  43.       ;; where end is
  44.       (goto-char end)
  45.       (setq end (point-marker))
  46.       (goto-char start)
  47.       (end-of-line)    
  48.       (while (< (point) end);; modified 2/2/88
  49.     ;; I should here check for tab chars
  50.     (insert text)
  51.     (forward-line 1)
  52.     (end-of-line)    
  53.     )
  54.       (move-marker end nil))))
  55.  
  56. ;-- Happy Hacking 
  57. ;===============================================================
  58. ;Lynn Slater -- {sun, ames, pacbell}!indetech!lrs or lrs@indetech.uucp
  59. ;42075 Lawrence Place, Fremont Ca 94538
  60. ;Office (415) 438-2048; Home (415) 796-4149; Fax (415) 438-2034
  61. ;===============================================================
  62.