"RET, \\<minibuffer-local-map>\\[abort-recursive-edit] or \\[help-command]")
"Replacement for %s in prompts of recursive subskeletons.")
-
-(defvar skeleton-debug nil
- "If non-nil `define-skeleton' will override previous definition.")
-
(defvar skeleton-positions nil
"List of positions marked with @, after skeleton insertion.
The list describes the most recent skeleton insertion, and its elements
SKELETON is as defined under `skeleton-insert'."
(declare (doc-string 2) (debug (&define name stringp skeleton-edebug-spec))
(indent defun))
- (if skeleton-debug
- (set command skeleton))
`(progn
;; Tell self-insert-command that this function, if called by an
;; abbrev, should cause the self-insert to be skipped.
(setq literal (cdr literal)))))
((null element))
(t (skeleton-internal-1 (eval element) t recursive))))
-\f
-;; Maybe belongs into simple.el or elsewhere
-;; ;;;###autoload
-;; (define-skeleton local-variables-section
-;; "Insert a local variables section. Use current comment syntax if any."
-;; (completing-read "Mode: " obarray
-;; (lambda (symbol)
-;; (if (commandp symbol)
-;; (string-match "-mode$" (symbol-name symbol))))
-;; t)
-;; '(save-excursion
-;; (if (re-search-forward page-delimiter nil t)
-;; (error "Not on last page")))
-;; comment-start "Local Variables:" comment-end \n
-;; comment-start "mode: " str
-;; & -5 | '(kill-line 0) & -1 | comment-end \n
-;; ( (completing-read (format "Variable, %s: " skeleton-subprompt)
-;; obarray
-;; (lambda (symbol)
-;; (or (eq symbol 'eval)
-;; (custom-variable-p symbol)))
-;; t)
-;; comment-start str ": "
-;; (read-from-minibuffer "Expression: " nil read-expression-map nil
-;; 'read-expression-history) | _
-;; comment-end \n)
-;; resume:
-;; comment-start "End:" comment-end \n)
-\f
-;; Variables and command for automatically inserting pairs like () or "".
-
-(defvar skeleton-pair nil
- "If this is nil pairing is turned off, no matter what else is set.
-Otherwise modes with `skeleton-pair-insert-maybe' on some keys
-will attempt to insert pairs of matching characters.")
-
-
-(defvar skeleton-pair-on-word nil
- "If this is nil, paired insertion is inhibited before or inside a word.")
-
-
-(defvar skeleton-pair-filter-function (lambda () nil)
- "Attempt paired insertion if this function returns nil, before inserting.
-This allows for context-sensitive checking whether pairing is appropriate.")
-
-
-(defvar skeleton-pair-alist ()
- "An override alist of pairing partners matched against `last-command-event'.
-Each alist element, which looks like (ELEMENT ...), is passed to
-`skeleton-insert' with no interactor. Variable `str' does nothing.
-
-Elements might be (?\\=` ?\\=` _ \"\\='\\='\"), (?\\( ? _ \" )\") or (?{ \\n > _ \\n ?} >).")
-
-(defvar skeleton-pair-default-alist '((?\( _ ?\)) (?\))
- (?\[ _ ?\]) (?\])
- (?{ _ ?}) (?\})
- (?< _ ?>) (?\>)
- (?« _ ?») (?\»)
- (?` _ ?')))
-
-;;;###autoload
-(defun skeleton-pair-insert-maybe (arg)
- "Insert the character you type ARG times.
-
-With no ARG, if `skeleton-pair' is non-nil, pairing can occur. If the region
-is visible the pair is wrapped around it depending on `skeleton-autowrap'.
-Else, if `skeleton-pair-on-word' is non-nil or we are not before or inside a
-word, and if `skeleton-pair-filter-function' returns nil, pairing is performed.
-Pairing is also prohibited if we are right after a quoting character
-such as backslash.
-
-If a match is found in `skeleton-pair-alist', that is inserted, else
-the defaults are used. These are (), [], {}, <> and (grave
-accent, apostrophe) for the paired ones, and the same character
-twice for the others."
- (interactive "*P")
- (if (or arg (not skeleton-pair))
- (self-insert-command (prefix-numeric-value arg))
- (let* ((mark (and skeleton-autowrap
- (or (eq last-command 'mouse-drag-region)
- (and transient-mark-mode mark-active))))
- (char last-command-event)
- (skeleton (or (assq char skeleton-pair-alist)
- (assq char skeleton-pair-default-alist)
- `(,char _ ,char))))
- (if (or (memq (char-syntax (preceding-char)) '(?\\ ?/))
- (and (not mark)
- (or overwrite-mode
- (if (not skeleton-pair-on-word) (looking-at "\\w"))
- (funcall skeleton-pair-filter-function))))
- (self-insert-command (prefix-numeric-value arg))
- ;; Newlines not desirable for inserting pairs. See bug#16138.
- (let ((skeleton-end-newline nil))
- (skeleton-insert (cons nil skeleton) (if mark -1)))))))
-
-\f
-;; A more serious example can be found in sh-script.el
-;; (defun mirror-mode ()
-;; "This major mode is an amusing little example of paired insertion.
-;;All printable characters do a paired self insert, while the other commands
-;;work normally."
-;; (interactive)
-;; (kill-all-local-variables)
-;; (make-local-variable 'skeleton-pair)
-;; (make-local-variable 'skeleton-pair-on-word)
-;; (make-local-variable 'skeleton-pair-filter-function)
-;; (make-local-variable 'skeleton-pair-alist)
-;; (setq major-mode 'mirror-mode
-;; mode-name "Mirror"
-;; skeleton-pair-on-word t
-;; ;; in the middle column insert one or none if odd window-width
-;; skeleton-pair-filter-function (lambda ()
-;; (if (>= (current-column)
-;; (/ (window-width) 2))
-;; ;; insert both on next line
-;; (next-line 1)
-;; ;; insert one or both?
-;; (= (* 2 (1+ (current-column)))
-;; (window-width))))
-;; ;; mirror these the other way round as well
-;; skeleton-pair-alist '((?) _ ?()
-;; (?] _ ?[)
-;; (?} _ ?{)
-;; (?> _ ?<)
-;; (?/ _ ?\\)
-;; (?\\ _ ?/)
-;; (?` ?` _ "''")
-;; (?' ?' _ "``"))
-;; ;; in this mode we exceptionally ignore the user, else it's no fun
-;; skeleton-pair t)
-;; (let ((map (make-vector 256 'skeleton-pair-insert-maybe))
-;; (i 0))
-;; (use-local-map `(keymap ,map))
-;; (while (< i ? )
-;; (aset map i nil)
-;; (aset map (+ i 128) nil)
-;; (setq i (1+ i))))
-;; (run-mode-hooks 'mirror-mode-hook))
(provide 'skeleton)
a partial completion can be found."
:type 'boolean)
-(defcustom tempo-leave-completion-buffer nil
- "If nil, a completion buffer generated by \\[tempo-complete-tag]
-disappears at the next keypress; otherwise, it remains forever."
- :type 'boolean)
-
;;; Internal variables
(defvar tempo-insert-string-functions nil
;;;
;;; tempo-insert-template
-(defun tempo-insert-template (template on-region)
+(defun tempo-insert-template (template &optional on-region)
"Insert a template.
TEMPLATE is the template to be inserted. If ON-REGION is non-nil the
`r' elements are replaced with the current region. In Transient Mark
(tempo-insert-mark (point-marker))
(mapc (lambda (elt)
(tempo-insert elt on-region))
- (symbol-value template))
+ (if (symbolp template) (symbol-value template) template))
(tempo-insert-mark (point-marker)))
(tempo-forward-mark))
(tempo-forget-insertions)
;;;
;;; tempo-complete-tag
-(defun tempo-complete-tag (&optional silent)
+(defun tempo-complete-tag (&optional _)
"Look for a tag and expand it.
All the tags in the tag lists in `tempo-local-tags'
\(this includes `tempo-tags') are searched for a match for the text
no match at all.
If a single match is found, the corresponding template is expanded in
-place of the matching string.
-
-If a partial completion or no match at all is found, and SILENT is
-non-nil, the function will give a signal.
-
-If a partial completion is found and `tempo-show-completion-buffer' is
-non-nil, a buffer containing possible completions is displayed."
-
- ;; This function may look like a hack, but this is how I want it to
- ;; work.
+place of the matching string."
(interactive "*")
(let* ((collection (tempo-build-collection))
(match-info (tempo-find-match-string tempo-match-finder))
(compl (or (car exact)
(and match-info (try-completion match-string collection)))))
(if compl (delete-region match-start (point)))
- (cond ((null match-info) (or silent (ding)))
- ((null compl) (or silent (ding)))
+ (cond ((null match-info))
+ ((null compl))
((eq compl t) (tempo-insert-template
(cdr (assoc match-string
collection))
nil))
(t (if (setq exact (assoc compl collection))
(tempo-insert-template (cdr exact) nil)
- (insert compl)
- (or silent (ding))
- (if tempo-show-completion-buffer
- (tempo-display-completions match-string
- collection)))))))
-
-
-;;;
-;;; tempo-display-completions
-
-(defun tempo-display-completions (string tag-list)
- "Show a buffer containing possible completions for STRING."
- (if tempo-leave-completion-buffer
- (with-output-to-temp-buffer "*Completions*"
- (display-completion-list
- (completion-hilit-commonality (all-completions string tag-list)
- (length string))))
- (save-window-excursion
- (with-output-to-temp-buffer "*Completions*"
- (display-completion-list
- (completion-hilit-commonality (all-completions string tag-list)
- (length string))))
- (sit-for 32767))))
+ (insert compl))))))
;;;
;;; tempo-expand-if-complete