aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/skeleton.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/skeleton.el')
-rw-r--r--lisp/skeleton.el101
1 files changed, 53 insertions, 48 deletions
diff --git a/lisp/skeleton.el b/lisp/skeleton.el
index 8c694c128b5..ea4e5dbc227 100644
--- a/lisp/skeleton.el
+++ b/lisp/skeleton.el
@@ -1,4 +1,4 @@
1;;; skeleton.el --- Lisp language extension for writing statement skeletons 1;;; skeleton.el --- Lisp language extension for writing statement skeletons -*- lexical-binding: t; -*-
2 2
3;; Copyright (C) 1993-1996, 2001-2020 Free Software Foundation, Inc. 3;; Copyright (C) 1993-1996, 2001-2020 Free Software Foundation, Inc.
4 4
@@ -135,7 +135,8 @@ A prefix argument of -1 says to wrap around region, even if not highlighted.
135A prefix argument of zero says to wrap around zero words---that is, nothing. 135A prefix argument of zero says to wrap around zero words---that is, nothing.
136This is a way of overriding the use of a highlighted region.") 136This is a way of overriding the use of a highlighted region.")
137 (interactive "*P\nP") 137 (interactive "*P\nP")
138 (skeleton-proxy-new ',skeleton str arg)))) 138 (atomic-change-group
139 (skeleton-proxy-new ',skeleton str arg)))))
139 140
140;;;###autoload 141;;;###autoload
141(defun skeleton-proxy-new (skeleton &optional str arg) 142(defun skeleton-proxy-new (skeleton &optional str arg)
@@ -154,8 +155,7 @@ of `str' whereas the skeleton's interactor is then ignored."
154 (prefix-numeric-value (or arg 155 (prefix-numeric-value (or arg
155 current-prefix-arg)) 156 current-prefix-arg))
156 (and skeleton-autowrap 157 (and skeleton-autowrap
157 (or (eq last-command 'mouse-drag-region) 158 (use-region-p)
158 (and transient-mark-mode mark-active))
159 ;; Deactivate the mark, in case one of the 159 ;; Deactivate the mark, in case one of the
160 ;; elements of the skeleton is sensitive 160 ;; elements of the skeleton is sensitive
161 ;; to such situations (e.g. it is itself a 161 ;; to such situations (e.g. it is itself a
@@ -258,23 +258,25 @@ available:
258 (goto-char (car skeleton-regions)) 258 (goto-char (car skeleton-regions))
259 (setq skeleton-regions (cdr skeleton-regions))) 259 (setq skeleton-regions (cdr skeleton-regions)))
260 (let ((beg (point)) 260 (let ((beg (point))
261 skeleton-modified skeleton-point resume: help input v1 v2) 261 skeleton-modified skeleton-point) ;; resume:
262 (setq skeleton-positions nil) 262 (with-suppressed-warnings ((lexical help input v1 v2))
263 (unwind-protect 263 (dlet (help input v1 v2)
264 (cl-progv 264 (setq skeleton-positions nil)
265 (mapcar #'car skeleton-further-elements) 265 (unwind-protect
266 (mapcar (lambda (x) (eval (cadr x))) skeleton-further-elements) 266 (cl-progv
267 (skeleton-internal-list skeleton str)) 267 (mapcar #'car skeleton-further-elements)
268 (or (eolp) (not skeleton-end-newline) (newline-and-indent)) 268 (mapcar (lambda (x) (eval (cadr x) t)) skeleton-further-elements)
269 (run-hooks 'skeleton-end-hook) 269 (skeleton-internal-list skeleton str))
270 (sit-for 0) 270 (or (eolp) (not skeleton-end-newline) (newline-and-indent))
271 (or (not (eq (window-buffer) (current-buffer))) 271 (run-hooks 'skeleton-end-hook)
272 (pos-visible-in-window-p beg) 272 (sit-for 0)
273 (progn 273 (or (not (eq (window-buffer) (current-buffer)))
274 (goto-char beg) 274 (pos-visible-in-window-p beg)
275 (recenter 0))) 275 (progn
276 (if skeleton-point 276 (goto-char beg)
277 (goto-char skeleton-point)))))) 277 (recenter 0)))
278 (if skeleton-point
279 (goto-char skeleton-point))))))))
278 280
279(defun skeleton-read (prompt &optional initial-input recursive) 281(defun skeleton-read (prompt &optional initial-input recursive)
280 "Function for reading a string from the minibuffer within skeletons. 282 "Function for reading a string from the minibuffer within skeletons.
@@ -327,36 +329,39 @@ automatically, and you are prompted to fill in the variable parts.")))
327 (signal 'quit t) 329 (signal 'quit t)
328 prompt)) 330 prompt))
329 331
330(defun skeleton-internal-list (skeleton-il &optional str recursive) 332(defun skeleton-internal-list (skeleton &optional str recursive)
331 (let* ((start (line-beginning-position)) 333 (let* ((start (line-beginning-position))
332 (column (current-column)) 334 (column (current-column))
333 (line (buffer-substring start (line-end-position))) 335 (line (buffer-substring start (line-end-position)))
334 opoint) 336 (skeleton-il skeleton)
335 (or str 337 opoint)
336 (setq str `(setq str 338 (with-suppressed-warnings ((lexical str))
337 (skeleton-read ',(car skeleton-il) nil ,recursive)))) 339 (dlet ((str (or str
338 (when (and (eq (cadr skeleton-il) '\n) (not recursive) 340 `(setq str
339 (save-excursion (skip-chars-backward " \t") (bolp))) 341 (skeleton-read ',(car skeleton-il)
340 (setq skeleton-il (cons nil (cons '> (cddr skeleton-il))))) 342 nil ,recursive)))))
341 (while (setq skeleton-modified (eq opoint (point)) 343 (when (and (eq (cadr skeleton-il) '\n) (not recursive)
342 opoint (point) 344 (save-excursion (skip-chars-backward " \t") (bolp)))
343 skeleton-il (cdr skeleton-il)) 345 (setq skeleton-il (cons nil (cons '> (cddr skeleton-il)))))
344 (condition-case quit 346 (while (setq skeleton-modified (eq opoint (point))
345 (skeleton-internal-1 (car skeleton-il) nil recursive) 347 opoint (point)
346 (quit 348 skeleton-il (cdr skeleton-il))
347 (if (eq (cdr quit) 'recursive) 349 (condition-case quit
348 (setq recursive 'quit 350 (skeleton-internal-1 (car skeleton-il) nil recursive)
349 skeleton-il (memq 'resume: skeleton-il)) 351 (quit
350 ;; Remove the subskeleton as far as it has been shown 352 (if (eq (cdr quit) 'recursive)
351 ;; the subskeleton shouldn't have deleted outside current line. 353 (setq recursive 'quit
352 (end-of-line) 354 skeleton-il (memq 'resume: skeleton-il))
353 (delete-region start (point)) 355 ;; Remove the subskeleton as far as it has been shown
354 (insert line) 356 ;; the subskeleton shouldn't have deleted outside current line.
355 (move-to-column column) 357 (end-of-line)
356 (if (cdr quit) 358 (delete-region start (point))
357 (setq skeleton-il () 359 (insert line)
358 recursive nil) 360 (move-to-column column)
359 (signal 'quit 'recursive))))))) 361 (if (cdr quit)
362 (setq skeleton-il ()
363 recursive nil)
364 (signal 'quit 'recursive)))))))))
360 ;; maybe continue loop or go on to next outer resume: section 365 ;; maybe continue loop or go on to next outer resume: section
361 (if (eq recursive 'quit) 366 (if (eq recursive 'quit)
362 (signal 'quit 'recursive) 367 (signal 'quit 'recursive)