home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / emacs / 2666 < prev    next >
Encoding:
Text File  |  1992-07-21  |  1.9 KB  |  50 lines

  1. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!yale!gumby!wupost!uwm.edu!linac!att!rutgers!ub!dsinc!bagate!cbmvax!snark!esr
  2. From: esr@snark.thyrsus.com (Eric S. Raymond)
  3. Newsgroups: comp.emacs
  4. Subject: Can anyone identify this code?
  5. Message-ID: <1hBdv1#4TF1G93cw80Y2lKydp0qPJ0Z=esr@snark.thyrsus.com>
  6. Date: 21 Jul 92 14:47:32 GMT
  7. Followup-To: poster
  8. Lines: 40
  9.  
  10. This was found in a dusty corner of the Emacs 19 distribution.  Both its
  11. authorship and its intended use are obscure.  Can anyone shed any light?
  12.  
  13. ------------------------------- CUT HERE --------------------------------------
  14.  
  15. (defun copy-from-above-command (&optional arg)
  16.   "Copy characters from previous nonblank line, starting just above point.
  17. Copy ARG characters, but not past the end of that line.
  18. If no argument given, copy the entire rest of the line.
  19. The characters copied are inserted in the buffer before point."
  20.   (interactive "P")
  21.   (let ((cc (current-column))
  22.     n
  23.     (string ""))
  24.     (save-excursion
  25.       (beginning-of-line)
  26.       (backward-char 1)
  27.       (skip-chars-backward "\ \t\n")
  28.       (move-to-column cc)
  29.       ;; Default is enough to copy the whole rest of the line.
  30.       (setq n (if arg (prefix-numeric-value arg) (point-max)))
  31.       ;; If current column winds up in middle of a tab,
  32.       ;; copy appropriate number of "virtual" space chars.
  33.       (if (< cc (current-column))
  34.       (if (= (preceding-char) ?\t)
  35.           (progn
  36.         (setq string (make-string (min n (- (current-column) cc)) ?\ ))
  37.         (setq n (- n (min n (- (current-column) cc)))))
  38.         ;; In middle of ctl char => copy that whole char.
  39.         (backward-char 1)))
  40.       (setq string (concat string
  41.                (buffer-substring
  42.                 (point)
  43.                 (min (save-excursion (end-of-line) (point))
  44.                  (+ n (point)))))))
  45.     (insert string)))
  46.  
  47. ------------------------------- CUT HERE --------------------------------------
  48. -- 
  49.                           Eric S. Raymond = esr@snark.thyrsus.com
  50.