home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / mutt / indent.mut < prev    next >
Lisp/Scheme  |  1988-10-05  |  1KB  |  47 lines

  1.   ;; indent.mut : Shift a block left or right
  2.   ;; A block is all the lines of text between the dot and mark inclusive.
  3.   ;; With no arg: asks for the amount to shift the region.  Positive
  4.   ;;   for right shift, negative for left shift.
  5.   ;; With arg (ie ^U): shifts the region by the difference between
  6.   ;;   the dot and the first nonblank character on that line.
  7.   ;;   eg use this to shift the top line of the region over to the dot.
  8.   ;; Removes white space from blank lines.
  9.   ;; C Durland
  10.  
  11. (include me.h)
  12. (include wspace.mut)
  13.  
  14. (defun indent
  15. {
  16.   (int shift-count col)
  17.   (byte type)(int left-edge width height)(INT size)
  18.  
  19.   (region-stats (loc type))
  20.   (if (arg-flag)
  21.     {
  22.       (col (current-column))
  23.       (beginning-of-line)(skip-whitespace)
  24.       (shift-count (- col (current-column)))
  25.     }
  26.     (shift-count (atoi (ask "indent region by n spaces.  n = ")))
  27.   )
  28.   (if (== shift-count 0)(done))
  29.  
  30.   (if (== type MARK-ABOVE-DOT)(exchange-dot-and-mark))    ; move to top of region
  31.  
  32.   (beginning-of-line)
  33.   (while (!= 0 height)
  34.   {
  35.     (skip-whitespace)(col (current-column))    ; count blanks
  36.     (arg-prefix 0)(kill-line)            ; move text to left margin
  37.     (end-of-line)
  38.     (if (!= 1 (current-column))            ; indent if line not blank
  39.     {
  40.       (beginning-of-line)
  41.       (to-col (+ col shift-count))        ; indent text n more columns
  42.     })
  43.     (forward-line 1)        ; move to the next line
  44.     (-= height 1)
  45.   })
  46. })
  47.