35
|
1 ;; Basic editing commands for Emacs
|
|
2 ;; Copyright (C) 1989 Free Software Foundation, Inc.
|
|
3
|
|
4 ;; This file is part of GNU Emacs.
|
|
5
|
|
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
7 ;; it under the terms of the GNU General Public License as published by
|
|
8 ;; the Free Software Foundation; either version 1, or (at your option)
|
|
9 ;; any later version.
|
|
10
|
|
11 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 ;; GNU General Public License for more details.
|
|
15
|
|
16 ;; You should have received a copy of the GNU General Public License
|
|
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
19
|
|
20
|
|
21 (defun copy-from-above-command (&optional arg)
|
|
22 "Copy characters from previous nonblank line, starting just above point.
|
|
23 Copy ARG characters, but not past the end of that line.
|
|
24 If no argument given, copy the entire rest of the line.
|
|
25 The characters copied are inserted in the buffer before point."
|
|
26 (interactive "P")
|
|
27 (let ((cc (current-column))
|
|
28 n
|
|
29 (string ""))
|
|
30 (save-excursion
|
|
31 (beginning-of-line)
|
|
32 (backward-char 1)
|
|
33 (skip-chars-backward "\ \t\n")
|
|
34 (move-to-column cc)
|
|
35 ;; Default is enough to copy the whole rest of the line.
|
|
36 (setq n (if arg (prefix-numeric-value arg) (point-max)))
|
|
37 ;; If current column winds up in middle of a tab,
|
|
38 ;; copy appropriate number of "virtual" space chars.
|
|
39 (if (< cc (current-column))
|
|
40 (if (= (preceding-char) ?\t)
|
|
41 (progn
|
|
42 (setq string (make-string (min n (- (current-column) cc)) ?\ ))
|
|
43 (setq n (- n (min n (- (current-column) cc)))))
|
|
44 ;; In middle of ctl char => copy that whole char.
|
|
45 (backward-char 1)))
|
|
46 (setq string (concat string
|
|
47 (buffer-substring
|
|
48 (point)
|
|
49 (min (save-excursion (end-of-line) (point))
|
|
50 (+ n (point)))))))
|
|
51 (insert string)))
|