• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/emacs-93/emacs/lisp/

Lines Matching refs:skeleton

0 ;;; skeleton.el --- Lisp language extension for writing statement skeletons
30 ;; skeleton insertion commands for programming language modes. This
37 ;; page 1: statement skeleton language definition & interpreter
42 (defvar skeleton-transformation-function 'identity
47 (defvaralias 'skeleton-transformation 'skeleton-transformation-function)
50 (put 'skeleton-transformation-function 'variable-interactive
54 (defvar skeleton-autowrap t
55 "Controls wrapping behavior of functions created with `define-skeleton'.
65 (defvar skeleton-end-newline t
66 "If non-nil, make sure that the skeleton inserted ends with a newline.
67 This just influences the way the default `skeleton-end-hook' behaves.")
69 (defvar skeleton-end-hook
71 (or (eolp) (not skeleton-end-newline) (newline-and-indent)))
72 "Hook called at end of skeleton but before going to point of interest.
74 unless `skeleton-end-newline' is set to nil.
79 (defvar skeleton-filter-function 'identity
80 "Function for transforming a skeleton proxy's aliases' variable value.")
81 (defvaralias 'skeleton-filter 'skeleton-filter-function)
83 (defvar skeleton-untabify t
86 (defvar skeleton-newline-indent-rigidly nil
90 (defvar skeleton-further-elements ()
91 "A buffer-local varlist (see `let') of mode specific skeleton elements.
92 These variables are bound while interpreting a skeleton. Their value may
93 in turn be any valid skeleton element if they are themselves to be used as
94 skeleton elements.")
95 (make-variable-buffer-local 'skeleton-further-elements)
98 (defvar skeleton-subprompt
104 (defvar skeleton-debug nil
105 "*If non-nil `define-skeleton' will override previous definition.")
107 (defvar skeleton-positions nil
108 "List of positions marked with @, after skeleton insertion.
109 The list describes the most recent skeleton insertion, and its elements
113 (defvar skeleton)
114 (defvar skeleton-modified)
115 (defvar skeleton-point)
116 (defvar skeleton-regions)
118 (def-edebug-spec skeleton-edebug-spec
121 ("quote" def-form) skeleton-edebug-spec def-form))
123 (defmacro define-skeleton (command documentation &rest skeleton)
124 "Define a user-configurable COMMAND that enters a statement skeleton.
126 SKELETON is as defined under `skeleton-insert'."
127 (declare (debug (&define name stringp skeleton-edebug-spec)))
128 (if skeleton-debug
129 (set command skeleton))
139 "This is a skeleton command (see `skeleton-insert').
140 Normally the skeleton text is inserted at point, with nothing \"inside\".
141 If there is a highlighted region, the skeleton text is wrapped
144 A prefix argument ARG says to wrap the skeleton around the next ARG words.
149 (skeleton-proxy-new ',skeleton str arg))))
152 (defun skeleton-proxy-new (skeleton &optional str arg)
154 Prefix ARG allows wrapping around words or regions (see `skeleton-insert').
156 on `skeleton-autowrap'. An ARG of M-0 will prevent this just for once.
161 of `str' whereas the skeleton's interactor is then ignored."
162 (skeleton-insert (funcall skeleton-filter-function skeleton)
167 (and skeleton-autowrap
171 ;; elements of the skeleton is sensitive
173 ;; skeleton).
183 (defun skeleton-insert (skeleton &optional regions str)
184 "Insert the complex statement skeleton SKELETON describes very concisely.
187 \(`_') in skeleton around next REGIONS words, if REGIONS is positive.
189 REGIONS interesting positions \(successive `_'s) in skeleton.
197 variable `str' within the skeleton. When this is non-nil, the
198 interactor gets ignored, and this should be a valid skeleton element.
204 `skeleton-transformation-function'). Other possibilities are:
211 @ add position to `skeleton-positions'
214 -num delete num preceding characters (see `skeleton-untabify')
221 Further elements can be defined via `skeleton-further-elements'. ELEMENT may
224 non-empty string. \\[keyboard-quit] terminates skeleton insertion, but
227 formatted with `skeleton-subprompt'. Such an INTERACTOR may also be a list of
234 to any valid skeleton element. The following local variables are
243 When done with skeleton, but before going back to `_'-point call
244 `skeleton-end-hook' if that is non-nil."
245 (let ((skeleton-regions regions))
246 (and skeleton-regions
247 (setq skeleton-regions
248 (if (> skeleton-regions 0)
250 (save-excursion (forward-word skeleton-regions)
252 (setq skeleton-regions (- skeleton-regions))
253 ;; copy skeleton-regions - 1 elements from `mark-ring'
256 (while (and l1 (> skeleton-regions 0))
258 (setq skeleton-regions (1- skeleton-regions)))
260 (goto-char (car skeleton-regions))
261 (setq skeleton-regions (cdr skeleton-regions)))
263 skeleton-modified skeleton-point resume: help input v1 v2)
264 (setq skeleton-positions nil)
266 (eval `(let ,skeleton-further-elements
267 (skeleton-internal-list skeleton str)))
268 (run-hooks 'skeleton-end-hook)
274 (if skeleton-point
275 (goto-char skeleton-point))))))
277 (defun skeleton-read (prompt &optional initial-input recursive)
281 It may contain a `%s' which will be replaced by `skeleton-subprompt'.
296 entered. No more of the skeleton will be inserted, except maybe for a
299 You are inserting a skeleton. Standard text gets inserted into the buffer
307 (read-string (format prompt skeleton-subprompt)
322 (defun skeleton-internal-list (skeleton &optional str recursive)
328 (setq str `(setq str (skeleton-read ',(car skeleton) nil ,recursive))))
329 (when (and (eq (cadr skeleton) '\n) (not recursive)
331 (setq skeleton (cons nil (cons '> (cddr skeleton)))))
332 (while (setq skeleton-modified (eq opoint (point))
334 skeleton (cdr skeleton))
336 (skeleton-internal-1 (car skeleton) nil recursive)
340 skeleton (memq 'resume: skeleton))
348 (setq skeleton ()
356 (defun skeleton-internal-1 (element &optional literal recursive)
361 (if skeleton-untabify
365 (funcall skeleton-transformation-function element)
370 (and (eq element '>) (eq (nth 1 skeleton) '\n) (pop skeleton)))
373 ((and skeleton-regions (eq (nth 1 skeleton) '_))
377 (car skeleton-regions) nil))
379 ((and (null (cdr skeleton)) (not recursive) (eolp))
381 (skeleton-newline-indent-rigidly
392 (if (and skeleton-regions (eq (nth 1 skeleton) '_))
394 (car skeleton-regions) nil)
397 (if skeleton-regions
399 (goto-char (pop skeleton-regions))
401 (eq (nth 1 skeleton) '\n)
403 (or skeleton-point
404 (setq skeleton-point (point)))))
406 (setq skeleton-point (point)))
408 (when skeleton-modified (pop skeleton)))
410 (unless skeleton-modified (pop skeleton)))
412 (push (point) skeleton-positions))
419 (while (and (skeleton-internal-list element nil t)
424 (skeleton-internal-list element (car literal))
427 (t (skeleton-internal-1 (eval element) t recursive))))
432 ;; (define-skeleton local-variables-section
445 ;; ( (completing-read (format "Variable, %s: " skeleton-subprompt)
461 (defvar skeleton-pair nil
463 Otherwise modes with `skeleton-pair-insert-maybe' on some keys
467 (defvar skeleton-pair-on-word nil
471 (defvar skeleton-pair-filter-function (lambda () nil)
476 (defvar skeleton-pair-alist ()
479 `skeleton-insert' with no interactor. Variable `str' does nothing.
483 (defvar skeleton-pair-default-alist '((?( _ ?)) (?\))
491 (defun skeleton-pair-insert-maybe (arg)
494 With no ARG, if `skeleton-pair' is non-nil, pairing can occur. If the region
495 is visible the pair is wrapped around it depending on `skeleton-autowrap'.
496 Else, if `skeleton-pair-on-word' is non-nil or we are not before or inside a
497 word, and if `skeleton-pair-filter-function' returns nil, pairing is performed.
501 If a match is found in `skeleton-pair-alist', that is inserted, else
505 (if (or arg (not skeleton-pair))
507 (let* ((mark (and skeleton-autowrap
510 (skeleton-end-hook)
512 (skeleton (or (assq char skeleton-pair-alist)
513 (assq char skeleton-pair-default-alist)
518 (if (not skeleton-pair-on-word) (looking-at "\\w"))
519 (funcall skeleton-pair-filter-function))))
521 (skeleton-insert (cons nil skeleton) (if mark -1))))))
532 ;; (make-local-variable 'skeleton-pair)
533 ;; (make-local-variable 'skeleton-pair-on-word)
534 ;; (make-local-variable 'skeleton-pair-filter-function)
535 ;; (make-local-variable 'skeleton-pair-alist)
538 ;; skeleton-pair-on-word t
540 ;; skeleton-pair-filter-function (lambda ()
549 ;; skeleton-pair-alist '((?) _ ?()
558 ;; skeleton-pair t)
559 ;; (let ((map (make-vector 256 'skeleton-pair-insert-maybe))
568 (provide 'skeleton)
571 ;;; skeleton.el ends here