diff options
| author | Richard M. Stallman | 1998-05-24 17:04:55 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-05-24 17:04:55 +0000 |
| commit | 3d1b97838e7b5f02237c89d45bd5de41350a03de (patch) | |
| tree | 7226cee086be48db406e2cf78cc96c59f9438c70 /lisp | |
| parent | bf92b5a4d6bb8743d515ea557d3306a5b7eaf6cc (diff) | |
| download | emacs-3d1b97838e7b5f02237c89d45bd5de41350a03de.tar.gz emacs-3d1b97838e7b5f02237c89d45bd5de41350a03de.zip | |
(string-rectangle-string): New variable.
(string-rectangle): Bind it.
(string-rectangle-line): Use it.
(operate-on-rectangle-lines): New variable.
(extract-rectangle-line): Update it.
(delete-extract-rectangle, extract-rectangle): Bind and use it.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/rect.el | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lisp/rect.el b/lisp/rect.el index b245e1102c5..895c3ae0078 100644 --- a/lisp/rect.el +++ b/lisp/rect.el | |||
| @@ -29,6 +29,10 @@ | |||
| 29 | 29 | ||
| 30 | ;;; Code: | 30 | ;;; Code: |
| 31 | 31 | ||
| 32 | ;; extract-rectangle-line stores lines into this list | ||
| 33 | ;; to accumulate them for extract-rectangle and delete-extract-rectangle. | ||
| 34 | (defvar operate-on-rectangle-lines) | ||
| 35 | |||
| 32 | (defun operate-on-rectangle (function start end coerce-tabs) | 36 | (defun operate-on-rectangle (function start end coerce-tabs) |
| 33 | "Call FUNCTION for each line of rectangle with corners at START, END. | 37 | "Call FUNCTION for each line of rectangle with corners at START, END. |
| 34 | If COERCE-TABS is non-nil, convert multi-column characters | 38 | If COERCE-TABS is non-nil, convert multi-column characters |
| @@ -95,7 +99,7 @@ Point is at the end of the segment of this line within the rectangle." | |||
| 95 | (setq line (concat (spaces-string begextra) | 99 | (setq line (concat (spaces-string begextra) |
| 96 | line | 100 | line |
| 97 | (spaces-string endextra)))) | 101 | (spaces-string endextra)))) |
| 98 | (setq lines (cons line lines)))) | 102 | (setq operate-on-rectangle-lines (cons line operate-on-rectangle-lines)))) |
| 99 | 103 | ||
| 100 | (defconst spaces-strings | 104 | (defconst spaces-strings |
| 101 | '["" " " " " " " " " " " " " " " " "]) | 105 | '["" " " " " " " " " " " " " " " " "]) |
| @@ -121,18 +125,18 @@ where the region begins and ending with the line where the region ends." | |||
| 121 | "Delete contents of rectangle and return it as a list of strings. | 125 | "Delete contents of rectangle and return it as a list of strings. |
| 122 | Arguments START and END are the corners of the rectangle. | 126 | Arguments START and END are the corners of the rectangle. |
| 123 | The value is list of strings, one for each line of the rectangle." | 127 | The value is list of strings, one for each line of the rectangle." |
| 124 | (let (lines) | 128 | (let (operate-on-rectangle-lines) |
| 125 | (operate-on-rectangle 'delete-extract-rectangle-line | 129 | (operate-on-rectangle 'delete-extract-rectangle-line |
| 126 | start end t) | 130 | start end t) |
| 127 | (nreverse lines))) | 131 | (nreverse operate-on-rectangle-lines))) |
| 128 | 132 | ||
| 129 | ;;;###autoload | 133 | ;;;###autoload |
| 130 | (defun extract-rectangle (start end) | 134 | (defun extract-rectangle (start end) |
| 131 | "Return contents of rectangle with corners at START and END. | 135 | "Return contents of rectangle with corners at START and END. |
| 132 | Value is list of strings, one for each line of the rectangle." | 136 | Value is list of strings, one for each line of the rectangle." |
| 133 | (let (lines) | 137 | (let (operate-on-rectangle-lines) |
| 134 | (operate-on-rectangle 'extract-rectangle-line start end nil) | 138 | (operate-on-rectangle 'extract-rectangle-line start end nil) |
| 135 | (nreverse lines))) | 139 | (nreverse operate-on-rectangle-lines))) |
| 136 | 140 | ||
| 137 | (defvar killed-rectangle nil | 141 | (defvar killed-rectangle nil |
| 138 | "Rectangle for yank-rectangle to insert.") | 142 | "Rectangle for yank-rectangle to insert.") |
| @@ -217,6 +221,9 @@ rectangle, all continuous whitespace starting at that column is deleted." | |||
| 217 | (point))))) | 221 | (point))))) |
| 218 | start end t)) | 222 | start end t)) |
| 219 | 223 | ||
| 224 | ;; string-rectangle uses this variable to pass the string | ||
| 225 | ;; to string-rectangle-line. | ||
| 226 | (defvar string-rectangle-string) | ||
| 220 | 227 | ||
| 221 | ;;;###autoload | 228 | ;;;###autoload |
| 222 | (defun string-rectangle (start end string) | 229 | (defun string-rectangle (start end string) |
| @@ -226,7 +233,8 @@ This command does not delete or overwrite any existing text. | |||
| 226 | 233 | ||
| 227 | Called from a program, takes three args; START, END and STRING." | 234 | Called from a program, takes three args; START, END and STRING." |
| 228 | (interactive "r\nsString rectangle: ") | 235 | (interactive "r\nsString rectangle: ") |
| 229 | (operate-on-rectangle 'string-rectangle-line start end t)) | 236 | (let ((string-rectangle-string string)) |
| 237 | (operate-on-rectangle 'string-rectangle-line start end t))) | ||
| 230 | 238 | ||
| 231 | (defun string-rectangle-line (startpos begextra endextra) | 239 | (defun string-rectangle-line (startpos begextra endextra) |
| 232 | (let (whitespace) | 240 | (let (whitespace) |
| @@ -238,7 +246,7 @@ Called from a program, takes three args; START, END and STRING." | |||
| 238 | ;; Delete the following whitespace. | 246 | ;; Delete the following whitespace. |
| 239 | (delete-region startpos (point)) | 247 | (delete-region startpos (point)) |
| 240 | ;; Insert the desired string. | 248 | ;; Insert the desired string. |
| 241 | (insert string) | 249 | (insert string-rectangle-string) |
| 242 | ;; Insert the same width of whitespace that we had before. | 250 | ;; Insert the same width of whitespace that we had before. |
| 243 | (indent-to (+ (current-column) whitespace)))) | 251 | (indent-to (+ (current-column) whitespace)))) |
| 244 | 252 | ||