aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1995-11-03 03:29:04 +0000
committerKarl Heuer1995-11-03 03:29:04 +0000
commitda6a884fdd81e5e26d156c45a92c6693f69cd83a (patch)
tree838217e42009db714e55434e077ce687abed87ca
parent7874dacdaaf9eb2e120474e969510663ce382917 (diff)
downloademacs-da6a884fdd81e5e26d156c45a92c6693f69cd83a.tar.gz
emacs-da6a884fdd81e5e26d156c45a92c6693f69cd83a.zip
(skeleton-end-hook): Now defvared and responsible for
pushing out anything following skeleton to next line. Thus this behaviour can now be controlled by modes. (skeleton-insert): Parameter `no-newline' removed. (skeleton-read): Take this into account. (skeleton-internal-1): Less spurious empty lines when wrapping.
-rw-r--r--lisp/skeleton.el65
1 files changed, 35 insertions, 30 deletions
diff --git a/lisp/skeleton.el b/lisp/skeleton.el
index 86ae2ba7a1b..d9c8d40f841 100644
--- a/lisp/skeleton.el
+++ b/lisp/skeleton.el
@@ -48,6 +48,14 @@ Typical examples might be `upcase' or `capitalize'.")
48 48
49 49
50 50
51(defvar skeleton-end-hook
52 (lambda ()
53 (or (eolp) (newline-and-indent)))
54 "Hook called at end of skeleton but before going to point of interest.
55By default this moves out anything following to next line.
56The variables `v1' and `v2' are still set when calling this.")
57
58
51;;;###autoload 59;;;###autoload
52(defvar skeleton-filter 'identity 60(defvar skeleton-filter 'identity
53 "Function for transforming a skeleton-proxy's aliases' variable value.") 61 "Function for transforming a skeleton-proxy's aliases' variable value.")
@@ -123,10 +131,10 @@ ignored."
123 expand-abbrev)) 131 expand-abbrev))
124 (setq buffer-undo-list (primitive-undo 1 buffer-undo-list))) 132 (setq buffer-undo-list (primitive-undo 1 buffer-undo-list)))
125 (skeleton-insert function 133 (skeleton-insert function
126 nil
127 (if (setq skeleton-abbrev-cleanup 134 (if (setq skeleton-abbrev-cleanup
128 (or (eq this-command 'self-insert-command) 135 (or (eq this-command 'self-insert-command)
129 (eq this-command 'skeleton-pair-insert-maybe))) 136 (eq this-command
137 'skeleton-pair-insert-maybe)))
130 () 138 ()
131 ;; Pretend C-x a e passed its prefix arg to us 139 ;; Pretend C-x a e passed its prefix arg to us
132 (if (or arg current-prefix-arg) 140 (if (or arg current-prefix-arg)
@@ -151,9 +159,8 @@ ignored."
151 159
152 160
153;;;###autoload 161;;;###autoload
154(defun skeleton-insert (skeleton &optional no-newline skeleton-regions str) 162(defun skeleton-insert (skeleton &optional skeleton-regions str)
155 "Insert the complex statement skeleton SKELETON describes very concisely. 163 "Insert the complex statement skeleton SKELETON describes very concisely.
156If optional NO-NEWLINE is nil the skeleton will end on a line of its own.
157 164
158With optional third REGIONS wrap first interesting point (`_') in skeleton 165With optional third REGIONS wrap first interesting point (`_') in skeleton
159around next REGIONS words, if REGIONS is positive. If REGIONS is negative, 166around next REGIONS words, if REGIONS is positive. If REGIONS is negative,
@@ -225,11 +232,6 @@ When done with skeleton, but before going back to `_'-point call
225 (setq skeleton-regions (cdr skeleton-regions))) 232 (setq skeleton-regions (cdr skeleton-regions)))
226 (let ((beg (point)) 233 (let ((beg (point))
227 skeleton-modified skeleton-point resume: help input v1 v2) 234 skeleton-modified skeleton-point resume: help input v1 v2)
228 (or no-newline
229 (eolp)
230 (goto-char (prog1 (point)
231 (indent-to (prog1 (current-indentation)
232 (newline))))))
233 (unwind-protect 235 (unwind-protect
234 (eval `(let ,skeleton-further-elements 236 (eval `(let ,skeleton-further-elements
235 (skeleton-internal-list skeleton str))) 237 (skeleton-internal-list skeleton str)))
@@ -242,8 +244,6 @@ When done with skeleton, but before going back to `_'-point call
242 (if skeleton-point 244 (if skeleton-point
243 (goto-char skeleton-point))))) 245 (goto-char skeleton-point)))))
244 246
245
246
247(defun skeleton-read (str &optional initial-input recursive) 247(defun skeleton-read (str &optional initial-input recursive)
248 "Function for reading a string from the minibuffer within skeletons. 248 "Function for reading a string from the minibuffer within skeletons.
249PROMPT may contain a `%s' which will be replaced by `skeleton-subprompt'. 249PROMPT may contain a `%s' which will be replaced by `skeleton-subprompt'.
@@ -253,15 +253,8 @@ i.e. we are handling the iterator of a subskeleton, returns empty string if
253user didn't modify input. 253user didn't modify input.
254While reading, the value of `minibuffer-help-form' is variable `help' if that 254While reading, the value of `minibuffer-help-form' is variable `help' if that
255is non-`nil' or a default string." 255is non-`nil' or a default string."
256 (setq skeleton-newline nil) 256 (let ((minibuffer-help-form (or (if (boundp 'help) (symbol-value 'help))
257 (or (symbol-value 'no-newline) ; cheat on compiler warning 257 (if recursive "\
258 (eolp)
259 (goto-char (prog1 (point)
260 (if recursive (setq skeleton-newline 2))
261 (indent-to (prog1
262 (current-indentation)
263 (newline))))))
264 (let ((minibuffer-help-form (or (symbol-value 'help) (if recursive "\
265As long as you provide input you will insert another subskeleton. 258As long as you provide input you will insert another subskeleton.
266 259
267If you enter the empty string, the loop inserting subskeletons is 260If you enter the empty string, the loop inserting subskeletons is
@@ -272,12 +265,20 @@ entered. No more of the skeleton will be inserted, except maybe for a
272syntactically necessary termination." 265syntactically necessary termination."
273 "\ 266 "\
274You are inserting a skeleton. Standard text gets inserted into the buffer 267You are inserting a skeleton. Standard text gets inserted into the buffer
275automatically, and you are prompted to fill in the variable parts.")))) 268automatically, and you are prompted to fill in the variable parts.")))
276 (setq str (if (stringp str) 269 (eolp (eolp)))
277 (read-string (format str skeleton-subprompt) 270 ;; since Emacs doesn't show main window's cursor, do something noticeable
278 (setq initial-input (or initial-input 271 (or eolp
279 (symbol-value 'input)))) 272 (open-line 1))
280 (eval str)))) 273 (unwind-protect
274 (setq str (if (stringp str)
275 (read-string (format str skeleton-subprompt)
276 (setq initial-input
277 (or initial-input
278 (symbol-value 'input))))
279 (eval str)))
280 (or eolp
281 (delete-char 1))))
281 (if (and recursive 282 (if (and recursive
282 (or (null str) 283 (or (null str)
283 (string= str "") 284 (string= str "")
@@ -305,7 +306,7 @@ automatically, and you are prompted to fill in the variable parts."))))
305 skeleton (memq 'resume: skeleton)) 306 skeleton (memq 'resume: skeleton))
306 ;; remove the subskeleton as far as it has been shown 307 ;; remove the subskeleton as far as it has been shown
307 ;; the subskeleton shouldn't have deleted outside current line 308 ;; the subskeleton shouldn't have deleted outside current line
308 (end-of-line skeleton-newline) 309 (end-of-line)
309 (delete-region start (point)) 310 (delete-region start (point))
310 (insert line) 311 (insert line)
311 (move-to-column column) 312 (move-to-column column)
@@ -351,7 +352,10 @@ automatically, and you are prompted to fill in the variable parts."))))
351 (if skeleton-regions 352 (if skeleton-regions
352 (progn 353 (progn
353 (goto-char (car skeleton-regions)) 354 (goto-char (car skeleton-regions))
354 (setq skeleton-regions (cdr skeleton-regions))) 355 (setq skeleton-regions (cdr skeleton-regions))
356 (and (<= (current-column) (current-indentation))
357 (eq (nth 1 skeleton) '\n)
358 (end-of-line 0)))
355 (or skeleton-point 359 (or skeleton-point
356 (setq skeleton-point (point))))) 360 (setq skeleton-point (point)))))
357 ((eq element '&) 361 ((eq element '&)
@@ -451,8 +455,9 @@ symmetrical ones, and the same character twice for the others."
451 () 455 ()
452 ;; (preceding-char) is stripped of any Meta-stuff in last-command-char 456 ;; (preceding-char) is stripped of any Meta-stuff in last-command-char
453 (if (setq arg (assq (preceding-char) skeleton-pair-alist)) 457 (if (setq arg (assq (preceding-char) skeleton-pair-alist))
454 ;; typed char is inserted, and car means no interactor 458 ;; typed char is inserted (car is no real interactor)
455 (skeleton-insert arg t) 459 (let (skeleton-end-hook)
460 (skeleton-insert arg))
456 (save-excursion 461 (save-excursion
457 (insert (or (cdr (assq (preceding-char) 462 (insert (or (cdr (assq (preceding-char)
458 '((?( . ?)) 463 '((?( . ?))