diff options
| author | Richard M. Stallman | 1997-04-16 19:41:21 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-04-16 19:41:21 +0000 |
| commit | 93c36a6dc791865b6ece2a628cb5328327484317 (patch) | |
| tree | accd23be91b36dd2951556faea30675d8a247c7a | |
| parent | e38eebc28051392f25273bc41fc43f0f8778c338 (diff) | |
| download | emacs-93c36a6dc791865b6ece2a628cb5328327484317.tar.gz emacs-93c36a6dc791865b6ece2a628cb5328327484317.zip | |
(skeleton-insert): Rename the function's argument
to `regions', and bind `skeleton-regions' with let.
(skeleton-read): Rename arg STR to PROMPT.
| -rw-r--r-- | lisp/skeleton.el | 119 |
1 files changed, 61 insertions, 58 deletions
diff --git a/lisp/skeleton.el b/lisp/skeleton.el index a5bacfeb1b0..47b4f7f9fe8 100644 --- a/lisp/skeleton.el +++ b/lisp/skeleton.el | |||
| @@ -231,20 +231,22 @@ ignored." | |||
| 231 | 231 | ||
| 232 | 232 | ||
| 233 | ;;;###autoload | 233 | ;;;###autoload |
| 234 | (defun skeleton-insert (skeleton &optional skeleton-regions str) | 234 | (defun skeleton-insert (skeleton &optional regions str) |
| 235 | "Insert the complex statement skeleton SKELETON describes very concisely. | 235 | "Insert the complex statement skeleton SKELETON describes very concisely. |
| 236 | 236 | ||
| 237 | With optional third REGIONS wrap first interesting point (`_') in skeleton | 237 | With optional second argument REGIONS, wrap first interesting point |
| 238 | around next REGIONS words, if REGIONS is positive. If REGIONS is negative, | 238 | \(`_') in skeleton around next REGIONS words, if REGIONS is positive. |
| 239 | wrap REGIONS preceding interregions into first REGIONS interesting positions | 239 | If REGIONS is negative, wrap REGIONS preceding interregions into first |
| 240 | \(successive `_'s) in skeleton. An interregion is the stretch of text between | 240 | REGIONS interesting positions \(successive `_'s) in skeleton. |
| 241 | two contiguous marked points. If you marked A B C [] (where [] is the cursor) | ||
| 242 | in alphabetical order, the 3 interregions are simply the last 3 regions. But | ||
| 243 | if you marked B A [] C, the interregions are B-A, A-[], []-C. | ||
| 244 | 241 | ||
| 245 | Optional fourth STR is the value for the variable `str' within the skeleton. | 242 | An interregion is the stretch of text between two contiguous marked |
| 246 | When this is non-`nil' the interactor gets ignored, and this should be a valid | 243 | points. If you marked A B C [] (where [] is the cursor) in |
| 247 | skeleton element. | 244 | alphabetical order, the 3 interregions are simply the last 3 regions. |
| 245 | But if you marked B A [] C, the interregions are B-A, A-[], []-C. | ||
| 246 | |||
| 247 | The optional third argument STR, if specified, is the value for the | ||
| 248 | variable `str' within the skeleton. When this is non-nil, the | ||
| 249 | interactor gets ignored, and this should be a valid skeleton element. | ||
| 248 | 250 | ||
| 249 | SKELETON is made up as (INTERACTOR ELEMENT ...). INTERACTOR may be nil if | 251 | SKELETON is made up as (INTERACTOR ELEMENT ...). INTERACTOR may be nil if |
| 250 | not needed, a prompt-string or an expression for complex read functions. | 252 | not needed, a prompt-string or an expression for complex read functions. |
| @@ -268,10 +270,10 @@ different inputs. The SKELETON is processed as often as the user enters a | |||
| 268 | non-empty string. \\[keyboard-quit] terminates skeleton insertion, but | 270 | non-empty string. \\[keyboard-quit] terminates skeleton insertion, but |
| 269 | continues after `resume:' and positions at `_' if any. If INTERACTOR in such | 271 | continues after `resume:' and positions at `_' if any. If INTERACTOR in such |
| 270 | a subskeleton is a prompt-string which contains a \".. %s ..\" it is | 272 | a subskeleton is a prompt-string which contains a \".. %s ..\" it is |
| 271 | formatted with `skeleton-subprompt'. Such an INTERACTOR may also a list of | 273 | formatted with `skeleton-subprompt'. Such an INTERACTOR may also be a list of |
| 272 | strings with the subskeleton being repeated once for each string. | 274 | strings with the subskeleton being repeated once for each string. |
| 273 | 275 | ||
| 274 | Quoted Lisp expressions are evaluated evaluated for their side-effect. | 276 | Quoted Lisp expressions are evaluated for their side-effects. |
| 275 | Other Lisp expressions are evaluated and the value treated as above. | 277 | Other Lisp expressions are evaluated and the value treated as above. |
| 276 | Note that expressions may not return `t' since this implies an | 278 | Note that expressions may not return `t' since this implies an |
| 277 | endless loop. Modes can define other symbols by locally setting them | 279 | endless loop. Modes can define other symbols by locally setting them |
| @@ -286,39 +288,40 @@ available: | |||
| 286 | 288 | ||
| 287 | When done with skeleton, but before going back to `_'-point call | 289 | When done with skeleton, but before going back to `_'-point call |
| 288 | `skeleton-end-hook' if that is non-`nil'." | 290 | `skeleton-end-hook' if that is non-`nil'." |
| 289 | (and skeleton-regions | 291 | (let ((skeleton-regions regions)) |
| 290 | (setq skeleton-regions | 292 | (and skeleton-regions |
| 291 | (if (> skeleton-regions 0) | 293 | (setq skeleton-regions |
| 292 | (list (point-marker) | 294 | (if (> skeleton-regions 0) |
| 293 | (save-excursion (forward-word skeleton-regions) | 295 | (list (point-marker) |
| 294 | (point-marker))) | 296 | (save-excursion (forward-word skeleton-regions) |
| 295 | (setq skeleton-regions (- skeleton-regions)) | 297 | (point-marker))) |
| 296 | ;; copy skeleton-regions - 1 elements from `mark-ring' | 298 | (setq skeleton-regions (- skeleton-regions)) |
| 297 | (let ((l1 (cons (mark-marker) mark-ring)) | 299 | ;; copy skeleton-regions - 1 elements from `mark-ring' |
| 298 | (l2 (list (point-marker)))) | 300 | (let ((l1 (cons (mark-marker) mark-ring)) |
| 299 | (while (and l1 (> skeleton-regions 0)) | 301 | (l2 (list (point-marker)))) |
| 300 | (setq l2 (cons (car l1) l2) | 302 | (while (and l1 (> skeleton-regions 0)) |
| 301 | skeleton-regions (1- skeleton-regions) | 303 | (setq l2 (cons (car l1) l2) |
| 302 | l1 (cdr l1))) | 304 | skeleton-regions (1- skeleton-regions) |
| 303 | (sort l2 '<)))) | 305 | l1 (cdr l1))) |
| 304 | (goto-char (car skeleton-regions)) | 306 | (sort l2 '<)))) |
| 305 | (setq skeleton-regions (cdr skeleton-regions))) | 307 | (goto-char (car skeleton-regions)) |
| 306 | (let ((beg (point)) | 308 | (setq skeleton-regions (cdr skeleton-regions))) |
| 307 | skeleton-modified skeleton-point resume: help input v1 v2) | 309 | (let ((beg (point)) |
| 308 | (setq skeleton-positions nil) | 310 | skeleton-modified skeleton-point resume: help input v1 v2) |
| 309 | (unwind-protect | 311 | (setq skeleton-positions nil) |
| 310 | (eval `(let ,skeleton-further-elements | 312 | (unwind-protect |
| 311 | (skeleton-internal-list skeleton str))) | 313 | (eval `(let ,skeleton-further-elements |
| 312 | (run-hooks 'skeleton-end-hook) | 314 | (skeleton-internal-list skeleton str))) |
| 313 | (sit-for 0) | 315 | (run-hooks 'skeleton-end-hook) |
| 314 | (or (pos-visible-in-window-p beg) | 316 | (sit-for 0) |
| 315 | (progn | 317 | (or (pos-visible-in-window-p beg) |
| 316 | (goto-char beg) | 318 | (progn |
| 317 | (recenter 0))) | 319 | (goto-char beg) |
| 318 | (if skeleton-point | 320 | (recenter 0))) |
| 319 | (goto-char skeleton-point))))) | 321 | (if skeleton-point |
| 320 | 322 | (goto-char skeleton-point)))))) | |
| 321 | (defun skeleton-read (str &optional initial-input recursive) | 323 | |
| 324 | (defun skeleton-read (PROMPT &optional initial-input recursive) | ||
| 322 | "Function for reading a string from the minibuffer within skeletons. | 325 | "Function for reading a string from the minibuffer within skeletons. |
| 323 | PROMPT may contain a `%s' which will be replaced by `skeleton-subprompt'. | 326 | PROMPT may contain a `%s' which will be replaced by `skeleton-subprompt'. |
| 324 | If non-`nil' second arg INITIAL-INPUT or variable `input' is a string or | 327 | If non-`nil' second arg INITIAL-INPUT or variable `input' is a string or |
| @@ -326,7 +329,7 @@ cons with index to insert before reading. If third arg RECURSIVE is non-`nil' | |||
| 326 | i.e. we are handling the iterator of a subskeleton, returns empty string if | 329 | i.e. we are handling the iterator of a subskeleton, returns empty string if |
| 327 | user didn't modify input. | 330 | user didn't modify input. |
| 328 | While reading, the value of `minibuffer-help-form' is variable `help' if that | 331 | While reading, the value of `minibuffer-help-form' is variable `help' if that |
| 329 | is non-`nil' or a default string." | 332 | is non-nil or a default string." |
| 330 | (let ((minibuffer-help-form (or (if (boundp 'help) (symbol-value 'help)) | 333 | (let ((minibuffer-help-form (or (if (boundp 'help) (symbol-value 'help)) |
| 331 | (if recursive "\ | 334 | (if recursive "\ |
| 332 | As long as you provide input you will insert another subskeleton. | 335 | As long as you provide input you will insert another subskeleton. |
| @@ -337,7 +340,7 @@ left, and the current one is removed as far as it has been entered. | |||
| 337 | If you quit, the current subskeleton is removed as far as it has been | 340 | If you quit, the current subskeleton is removed as far as it has been |
| 338 | entered. No more of the skeleton will be inserted, except maybe for a | 341 | entered. No more of the skeleton will be inserted, except maybe for a |
| 339 | syntactically necessary termination." | 342 | syntactically necessary termination." |
| 340 | "\ | 343 | "\ |
| 341 | You are inserting a skeleton. Standard text gets inserted into the buffer | 344 | You are inserting a skeleton. Standard text gets inserted into the buffer |
| 342 | automatically, and you are prompted to fill in the variable parts."))) | 345 | automatically, and you are prompted to fill in the variable parts."))) |
| 343 | (eolp (eolp))) | 346 | (eolp (eolp))) |
| @@ -345,19 +348,19 @@ automatically, and you are prompted to fill in the variable parts."))) | |||
| 345 | (or eolp | 348 | (or eolp |
| 346 | (open-line 1)) | 349 | (open-line 1)) |
| 347 | (unwind-protect | 350 | (unwind-protect |
| 348 | (setq str (if (stringp str) | 351 | (setq prompt (if (stringp prompt) |
| 349 | (read-string (format str skeleton-subprompt) | 352 | (read-string (format prompt skeleton-subprompt) |
| 350 | (setq initial-input | 353 | (setq initial-input |
| 351 | (or initial-input | 354 | (or initial-input |
| 352 | (symbol-value 'input)))) | 355 | (symbol-value 'input)))) |
| 353 | (eval str))) | 356 | (eval prompt))) |
| 354 | (or eolp | 357 | (or eolp |
| 355 | (delete-char 1)))) | 358 | (delete-char 1)))) |
| 356 | (if (and recursive | 359 | (if (and recursive |
| 357 | (or (null str) | 360 | (or (null prompt) |
| 358 | (string= str "") | 361 | (string= prompt "") |
| 359 | (equal str initial-input) | 362 | (equal prompt initial-input) |
| 360 | (equal str (car-safe initial-input)))) | 363 | (equal prompt (car-safe initial-input)))) |
| 361 | (signal 'quit t) | 364 | (signal 'quit t) |
| 362 | str)) | 365 | str)) |
| 363 | 366 | ||