aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1995-08-15 19:49:46 +0000
committerKarl Heuer1995-08-15 19:49:46 +0000
commit773500abf69ff95c1ad01cc74dd93d92a654e638 (patch)
tree410170e8424fba378e79fbb8bd7855dd0dea3d11
parent2c70c9923e328040c5dd32173610b28234ab5a0a (diff)
downloademacs-773500abf69ff95c1ad01cc74dd93d92a654e638.tar.gz
emacs-773500abf69ff95c1ad01cc74dd93d92a654e638.zip
(skeleton-pair-insert-maybe): Plain insert in Ovwrt mode
(skeleton-insert): If skeleton doesn't fit in window, put beginning at top before going to _ point. (skeleton-internal-list): Rewritten so that resume: sections pertain only to inferior skeletons and make str available there (skeleton-read): Don't quit and remove partial skeleton when empty string entered for outer iterator. Added implicit argument `input'. (define-skeleton, skeleton-insert, skeleton-internal-list): Use `x rather than backquote's (` x) or own (list 'x)
-rw-r--r--lisp/skeleton.el121
1 files changed, 60 insertions, 61 deletions
diff --git a/lisp/skeleton.el b/lisp/skeleton.el
index 7ee3c8fff6c..ed72d076c7e 100644
--- a/lisp/skeleton.el
+++ b/lisp/skeleton.el
@@ -86,11 +86,9 @@ which contains the skeleton, has a documentation to that effect.
86INTERACTOR and ELEMENT ... are as defined under `skeleton-insert'." 86INTERACTOR and ELEMENT ... are as defined under `skeleton-insert'."
87 (if skeleton-debug 87 (if skeleton-debug
88 (set command skeleton)) 88 (set command skeleton))
89 (require 'backquote) 89 `(progn
90 (`(progn 90 (defvar ,command ',skeleton ,documentation)
91 (defvar (, command) '(, skeleton) 91 (defalias ',command 'skeleton-proxy)))
92 (, documentation))
93 (defalias '(, command) 'skeleton-proxy))))
94 92
95 93
96 94
@@ -186,6 +184,7 @@ available:
186 str first time: read a string according to INTERACTOR 184 str first time: read a string according to INTERACTOR
187 then: insert previously read string once more 185 then: insert previously read string once more
188 help help-form during interaction with the user or `nil' 186 help help-form during interaction with the user or `nil'
187 input initial input (string or cons with index) while reading str
189 quit non-nil after resume: section is entered by keyboard quit 188 quit non-nil after resume: section is entered by keyboard quit
190 v1, v2 local variables for memorising anything you want" 189 v1, v2 local variables for memorising anything you want"
191 (and regions 190 (and regions
@@ -204,32 +203,35 @@ available:
204 (sort l2 '<)))) 203 (sort l2 '<))))
205 (goto-char (car regions)) 204 (goto-char (car regions))
206 (setq regions (cdr regions))) 205 (setq regions (cdr regions)))
207 (let (modified point resume: help quit v1 v2) 206 (let ((beg (point))
207 modified point resume: help input quit v1 v2)
208 (or no-newline 208 (or no-newline
209 (eolp) 209 (eolp)
210 ;;(save-excursion
211 ;; (indent-to (prog1
212 ;; (current-indentation)
213 ;; (newline))))
214 (goto-char (prog1 (point) 210 (goto-char (prog1 (point)
215 (indent-to (prog1 211 (indent-to (prog1 (current-indentation)
216 (current-indentation)
217 (newline)))))) 212 (newline))))))
218 (unwind-protect 213 (unwind-protect
219 (eval (list 'let skeleton-further-elements 214 (eval `(let ,skeleton-further-elements
220 '(skeleton-internal-list skeleton (car skeleton)))) 215 (skeleton-internal-list skeleton)))
216 (sit-for 0)
217 (or (pos-visible-in-window-p beg)
218 (progn
219 (goto-char beg)
220 (recenter 0)))
221 (if point 221 (if point
222 (goto-char point))))) 222 (goto-char point)))))
223 223
224 224
225 225
226(defun skeleton-read (str &optional initial-input recursive) 226(defun skeleton-read (str &optional initial-input recursive)
227 "Function for reading a string from the minibuffer in skeletons. 227 "Function for reading a string from the minibuffer within skeletons.
228PROMPT may contain a `%s' which will be replaced by `skeleton-subprompt'. 228PROMPT may contain a `%s' which will be replaced by `skeleton-subprompt'.
229If non-`nil' second arg INITIAL-INPUT is a string to insert before reading. 229If non-`nil' second arg INITIAL-INPUT or variable `input' is a string or
230While reading, the value of `minibuffer-help-form' is variable `help' if that is 230cons with index to insert before reading. If third arg RECURSIVE is non-`nil'
231non-`nil' or a default string if optional ITERATIVE is non-`nil'." 231i.e. we are handling the iterator of a subskeleton, returns empty string if
232 232user didn't modify input.
233While reading, the value of `minibuffer-help-form' is variable `help' if that
234is non-`nil' or a default string."
233 (or no-newline 235 (or no-newline
234 (eolp) 236 (eolp)
235 (goto-char (prog1 (point) 237 (goto-char (prog1 (point)
@@ -245,60 +247,56 @@ left, and the current one is removed as far as it has been entered.
245If you quit, the current subskeleton is removed as far as it has been 247If you quit, the current subskeleton is removed as far as it has been
246entered. No more of the skeleton will be inserted, except maybe for a 248entered. No more of the skeleton will be inserted, except maybe for a
247syntactically necessary termination." 249syntactically necessary termination."
248 " 250 "\
249You are inserting a skeleton. Standard text gets inserted into the buffer 251You are inserting a skeleton. Standard text gets inserted into the buffer
250automatically, and you are prompted to fill in the variable parts.")))) 252automatically, and you are prompted to fill in the variable parts."))))
251 (setq str (if (stringp str) 253 (setq str (if (stringp str)
252 (read-string (format str skeleton-subprompt) initial-input) 254 (read-string (format str skeleton-subprompt)
255 (setq initial-input (or initial-input input)))
253 (eval str)))) 256 (eval str))))
254 (if (or (null str) (string= str "")) 257 (if (and recursive
258 (or (null str)
259 (string= str "")
260 (equal str initial-input)
261 (equal str (car-safe initial-input))))
255 (signal 'quit t) 262 (signal 'quit t)
256 str)) 263 str))
257 264
258 265
259(defun skeleton-internal-list (skeleton &optional str recursive) 266(defun skeleton-internal-list (skeleton &optional recursive)
260 (let* ((start (save-excursion (beginning-of-line) (point))) 267 (let* ((start (save-excursion (beginning-of-line) (point)))
261 (column (current-column)) 268 (column (current-column))
262 (line (buffer-substring start 269 (line (buffer-substring start
263 (save-excursion (end-of-line) (point)))) 270 (save-excursion (end-of-line) (point))))
271 (str `(setq str (skeleton-read ',(car skeleton) nil ,recursive)))
264 opoint) 272 opoint)
265 (condition-case quit 273 (while (setq modified (eq opoint (point))
266 (progn 274 opoint (point)
267 '(setq str (list 'setq 'str 275 skeleton (cdr skeleton))
268 (if recursive 276 (condition-case quit
269 (list 'skeleton-read (list 'quote str)) 277 (skeleton-internal-1 (car skeleton))
270 (list (if (stringp str) 278 (quit
271 'read-string 279 (if (eq (cdr quit) 'recursive)
272 'eval) 280 (progn
273 str)))) 281 (setq recursive 'quit)
274 (setq str (list 'setq 'str 282 (while (if skeleton
275 (list 'skeleton-read 283 (not (eq (car (setq skeleton (cdr skeleton)))
276 (list 'quote str nil recursive)))) 284 'resume:)))))
277 (while (setq modified (eq opoint (point)) 285 ;; remove the subskeleton as far as it has been shown
278 opoint (point) 286 ;; the subskeleton shouldn't have deleted outside current line
279 skeleton (cdr skeleton)) 287 ;; problematic when wrapping text starting on same line
280 (skeleton-internal-1 (car skeleton))) 288 (end-of-line)
281 ;; maybe continue loop 289 (delete-region start (point))
282 recursive) 290 (insert line)
283 (quit ;; remove the subskeleton as far as it has been shown 291 (move-to-column column)
284 (if (eq (cdr quit) 'recursive) 292 (if (cdr quit)
285 () 293 (setq skeleton ()
286 ;; the subskeleton shouldn't have deleted outside current line 294 recursive nil)
287 (end-of-line) 295 (signal 'quit 'recursive)))))))
288 (delete-region start (point)) 296 ;; maybe continue loop or go on to next outer resume: section
289 (insert line) 297 (if (eq recursive 'quit)
290 (move-to-column column)) 298 (signal 'quit 'recursive)
291 (if (eq (cdr quit) t) 299 recursive))
292 ;; empty string entered
293 nil
294 (while (if skeleton
295 (not (eq (car (setq skeleton (cdr skeleton)))
296 'resume:))))
297 (if skeleton
298 (skeleton-internal-list skeleton)
299 ;; propagate signal we can't handle
300 (if recursive (signal 'quit 'recursive)))
301 (signal 'quit nil))))))
302 300
303 301
304(defun skeleton-internal-1 (element &optional literal) 302(defun skeleton-internal-1 (element &optional literal)
@@ -336,7 +334,7 @@ automatically, and you are prompted to fill in the variable parts."))))
336 ((if (consp element) 334 ((if (consp element)
337 (or (stringp (car element)) 335 (or (stringp (car element))
338 (consp (car element)))) 336 (consp (car element))))
339 (while (skeleton-internal-list element (car element) t))) 337 (while (skeleton-internal-list element t)))
340 ((if (consp element) 338 ((if (consp element)
341 (eq 'quote (car element))) 339 (eq 'quote (car element)))
342 (eval (nth 1 element))) 340 (eval (nth 1 element)))
@@ -410,6 +408,7 @@ the defaults are used. These are (), [], {}, <> and `' for the
410symmetrical ones, and the same character twice for the others." 408symmetrical ones, and the same character twice for the others."
411 (interactive "*P") 409 (interactive "*P")
412 (if (or arg 410 (if (or arg
411 overwrite-mode
413 (not skeleton-pair) 412 (not skeleton-pair)
414 (if (not skeleton-pair-on-word) (looking-at "\\w")) 413 (if (not skeleton-pair-on-word) (looking-at "\\w"))
415 (funcall skeleton-pair-filter)) 414 (funcall skeleton-pair-filter))