aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-04-16 19:41:21 +0000
committerRichard M. Stallman1997-04-16 19:41:21 +0000
commit93c36a6dc791865b6ece2a628cb5328327484317 (patch)
treeaccd23be91b36dd2951556faea30675d8a247c7a
parente38eebc28051392f25273bc41fc43f0f8778c338 (diff)
downloademacs-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.el119
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
237With optional third REGIONS wrap first interesting point (`_') in skeleton 237With optional second argument REGIONS, wrap first interesting point
238around next REGIONS words, if REGIONS is positive. If REGIONS is negative, 238\(`_') in skeleton around next REGIONS words, if REGIONS is positive.
239wrap REGIONS preceding interregions into first REGIONS interesting positions 239If REGIONS is negative, wrap REGIONS preceding interregions into first
240\(successive `_'s) in skeleton. An interregion is the stretch of text between 240REGIONS interesting positions \(successive `_'s) in skeleton.
241two contiguous marked points. If you marked A B C [] (where [] is the cursor)
242in alphabetical order, the 3 interregions are simply the last 3 regions. But
243if you marked B A [] C, the interregions are B-A, A-[], []-C.
244 241
245Optional fourth STR is the value for the variable `str' within the skeleton. 242An interregion is the stretch of text between two contiguous marked
246When this is non-`nil' the interactor gets ignored, and this should be a valid 243points. If you marked A B C [] (where [] is the cursor) in
247skeleton element. 244alphabetical order, the 3 interregions are simply the last 3 regions.
245But if you marked B A [] C, the interregions are B-A, A-[], []-C.
246
247The optional third argument STR, if specified, is the value for the
248variable `str' within the skeleton. When this is non-nil, the
249interactor gets ignored, and this should be a valid skeleton element.
248 250
249SKELETON is made up as (INTERACTOR ELEMENT ...). INTERACTOR may be nil if 251SKELETON is made up as (INTERACTOR ELEMENT ...). INTERACTOR may be nil if
250not needed, a prompt-string or an expression for complex read functions. 252not 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
268non-empty string. \\[keyboard-quit] terminates skeleton insertion, but 270non-empty string. \\[keyboard-quit] terminates skeleton insertion, but
269continues after `resume:' and positions at `_' if any. If INTERACTOR in such 271continues after `resume:' and positions at `_' if any. If INTERACTOR in such
270a subskeleton is a prompt-string which contains a \".. %s ..\" it is 272a subskeleton is a prompt-string which contains a \".. %s ..\" it is
271formatted with `skeleton-subprompt'. Such an INTERACTOR may also a list of 273formatted with `skeleton-subprompt'. Such an INTERACTOR may also be a list of
272strings with the subskeleton being repeated once for each string. 274strings with the subskeleton being repeated once for each string.
273 275
274Quoted Lisp expressions are evaluated evaluated for their side-effect. 276Quoted Lisp expressions are evaluated for their side-effects.
275Other Lisp expressions are evaluated and the value treated as above. 277Other Lisp expressions are evaluated and the value treated as above.
276Note that expressions may not return `t' since this implies an 278Note that expressions may not return `t' since this implies an
277endless loop. Modes can define other symbols by locally setting them 279endless loop. Modes can define other symbols by locally setting them
@@ -286,39 +288,40 @@ available:
286 288
287When done with skeleton, but before going back to `_'-point call 289When 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.
323PROMPT may contain a `%s' which will be replaced by `skeleton-subprompt'. 326PROMPT may contain a `%s' which will be replaced by `skeleton-subprompt'.
324If non-`nil' second arg INITIAL-INPUT or variable `input' is a string or 327If 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'
326i.e. we are handling the iterator of a subskeleton, returns empty string if 329i.e. we are handling the iterator of a subskeleton, returns empty string if
327user didn't modify input. 330user didn't modify input.
328While reading, the value of `minibuffer-help-form' is variable `help' if that 331While reading, the value of `minibuffer-help-form' is variable `help' if that
329is non-`nil' or a default string." 332is 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 "\
332As long as you provide input you will insert another subskeleton. 335As 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.
337If you quit, the current subskeleton is removed as far as it has been 340If you quit, the current subskeleton is removed as far as it has been
338entered. No more of the skeleton will be inserted, except maybe for a 341entered. No more of the skeleton will be inserted, except maybe for a
339syntactically necessary termination." 342syntactically necessary termination."
340 "\ 343 "\
341You are inserting a skeleton. Standard text gets inserted into the buffer 344You are inserting a skeleton. Standard text gets inserted into the buffer
342automatically, and you are prompted to fill in the variable parts."))) 345automatically, 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