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

Lines Matching defs:tempo

0 ;;; tempo.el --- Flexible template insertion
45 ;; jump between with the commands `tempo-backward-mark' and
46 ;; `tempo-forward-mark'. If the template definer provides a prompt for
47 ;; the point, and the variable `tempo-interactive' is non-nil, the
59 ;; See the documentation for tempo-define-template for the different
60 ;; items that can be used to define a tempo template.
62 ;; One of the more powerful features of tempo templates are automatic
64 ;; should be recognized by `tempo-complete-tag' and expanded to the
73 ;; `tempo-template-foo' will be created whose value as a variable will
77 ;; The latest tempo.el distribution can be fetched from
102 ;; tempo.el. Thanks.
113 (defgroup tempo nil
115 :prefix "tempo-"
118 (defcustom tempo-interactive nil
120 If this variable is non-nil, `tempo-insert' prompts the
123 :group 'tempo)
125 (defcustom tempo-insert-region nil
133 :group 'tempo)
135 (defcustom tempo-show-completion-buffer t
139 :group 'tempo)
141 (defcustom tempo-leave-completion-buffer nil
142 "*If nil, a completion buffer generated by \\[tempo-complete-tag]
145 :group 'tempo)
149 (defvar tempo-insert-string-functions nil
155 (defvar tempo-tags nil
158 (defvar tempo-local-tags '((tempo-tags . nil))
163 documentation for the function `tempo-complete-tag' for more info.
165 `tempo-tags' is always in the last position in this list.")
167 (defvar tempo-collection nil
170 (defvar tempo-dirty-collection t
173 (defvar tempo-marks nil
174 "A list of marks to jump to with `\\[tempo-forward-mark]' and `\\[tempo-backward-mark]'.")
176 (defvar tempo-match-finder "\\b\\([[:word:]]+\\)\\="
179 If `tempo-match-finder' is a string, it should contain a regular
181 `tempo-complete-tag' calls `re-search-backward' with this string, and
190 If `tempo-match-finder' is a symbol, it should be a function that
195 (defvar tempo-user-elements nil
198 This function should return something to be sent to `tempo-insert' if
201 (defvar tempo-named-insertions nil
204 (defvar tempo-region-start (make-marker)
207 (defvar tempo-region-stop (make-marker)
212 (make-variable-buffer-local 'tempo-marks)
213 (make-variable-buffer-local 'tempo-local-tags)
214 (make-variable-buffer-local 'tempo-match-finder)
215 (make-variable-buffer-local 'tempo-collection)
216 (make-variable-buffer-local 'tempo-dirty-collection)
221 ;; tempo-define-template
223 (defun tempo-define-template (name elements &optional tag documentation taglist)
225 This function creates a template variable `tempo-template-NAME' and an
226 interactive function `tempo-template-NAME' that inserts the template
234 added to `tempo-tags'.
238 - A string: It is sent to the hooks in `tempo-insert-string-functions',
240 - The symbol `p': This position is saved in `tempo-marks'.
241 - The symbol `r': If `tempo-insert' is called with ON-REGION non-nil
243 - (p PROMPT <NAME> <NOINSERT>): If `tempo-interactive' is non-nil, the
252 forces `tempo-interactive' to be true.
254 `tempo-interactive' is nil and `tempo-insert' is called with
259 if tempo-interactive is nil.
279 (let* ((template-name (intern (concat "tempo-template-"
287 (list 'tempo-insert-template (list 'quote
289 (list 'if 'tempo-insert-region
292 (tempo-add-tag tag template-name taglist))
296 ;;; tempo-insert-template
298 (defun tempo-insert-template (template on-region)
312 (set-marker tempo-region-start (min (mark) (point)))
313 (set-marker tempo-region-stop (max (mark) (point))))
315 (goto-char tempo-region-start))
317 (tempo-insert-mark (point-marker))
319 (tempo-insert elt on-region)))
321 (tempo-insert-mark (point-marker)))
322 (tempo-forward-mark))
323 (tempo-forget-insertions)
330 ;;; tempo-insert
332 (defun tempo-insert (element on-region)
337 See documentation for `tempo-define-template' for the kind of elements
339 (cond ((stringp element) (tempo-process-and-insert-string element))
341 (eq (car element) 'p)) (tempo-insert-prompt-compat
344 (eq (car element) 'P)) (let ((tempo-interactive t))
345 (tempo-insert-prompt-compat
348 ;;; (eq (car element) 'v)) (tempo-save-named
354 (goto-char tempo-region-stop)
355 (tempo-insert-prompt-compat
360 (goto-char tempo-region-stop)
362 (tempo-insert-prompt-compat
365 (eq (car element) 's)) (tempo-insert-named (car (cdr element))))
369 (tempo-insert elt on-region)))
371 ((eq element 'p) (tempo-insert-mark (point-marker)))
373 (goto-char tempo-region-stop)
374 (tempo-insert-mark (point-marker))))
377 (goto-char tempo-region-stop)
379 (tempo-insert-mark (point-marker))))
403 (t (tempo-insert (or (tempo-is-user-element element)
408 ;;; tempo-insert-prompt
410 (defun tempo-insert-prompt-compat (prompt)
411 "Compatibility hack for `tempo-insert-prompt'.
413 `tempo-insert-prompt', or nil."
415 (apply 'tempo-insert-prompt prompt)
416 (tempo-insert-prompt prompt)))
418 (defun tempo-insert-prompt (prompt &optional save-name no-insert)
420 If the variable `tempo-interactive' is non-nil the user is prompted
422 buffer. If `tempo-interactive' is nil, the current point is placed on
423 `tempo-mark'.
433 (tempo-lookup-named save-name))))
438 (tempo-insert-named save-name)) ; A double lookup here, but who
445 (tempo-interactive
447 (error "tempo: The prompt (%s) is not a string" prompt))
452 (tempo-save-named save-name insertion)))
454 (tempo-insert-mark (point-marker))))))
457 ;;; tempo-is-user-element
459 (defun tempo-is-user-element (element)
460 "Tries all the user-defined element handlers in `tempo-user-elements'."
466 tempo-user-elements)
470 ;;; tempo-forget-insertions
472 (defun tempo-forget-insertions ()
474 (setq tempo-named-insertions nil))
477 ;;; tempo-save-named
479 (defun tempo-save-named (name data) ; Had an optional prompt for 'v
483 The data can later be retrieved with `tempo-lookup-named'.
487 (setq tempo-named-insertions
489 tempo-named-insertions))
493 ;;; tempo-lookup-named
495 (defun tempo-lookup-named (name)
498 (cdr (assq name tempo-named-insertions)))
501 ;;; tempo-insert-named
503 (defun tempo-insert-named (name)
505 If there is no such name saved, a tempo mark is inserted.
509 (let* ((insertion (tempo-lookup-named name)))
511 (tempo-insert-mark (point-marker)))
515 (tempo-insert insertion nil)))))
519 ;;; tempo-process-and-insert-string
521 (defun tempo-process-and-insert-string (string)
523 Run a string through the preprocessors in `tempo-insert-string-functions'
525 (cond ((null tempo-insert-string-functions)
527 ((symbolp tempo-insert-string-functions)
529 (funcall tempo-insert-string-functions string)))
530 ((listp tempo-insert-string-functions)
531 (dolist (fn tempo-insert-string-functions)
534 (error "Bogus value in tempo-insert-string-functions: %s"
535 tempo-insert-string-functions)))
539 ;;; tempo-insert-mark
541 (defun tempo-insert-mark (mark)
542 "Insert a mark `tempo-marks' while keeping it sorted."
543 (cond ((null tempo-marks) (setq tempo-marks (list mark)))
544 ((< mark (car tempo-marks)) (setq tempo-marks (cons mark tempo-marks)))
545 (t (let ((lp tempo-marks))
553 ;;; tempo-forward-mark
555 (defun tempo-forward-mark ()
556 "Jump to the next mark in `tempo-forward-mark-list'."
564 tempo-marks)
571 ;;; tempo-backward-mark
573 (defun tempo-backward-mark ()
574 "Jump to the previous mark in `tempo-back-mark-list'."
584 tempo-marks)
590 ;;; tempo-add-tag
592 (defun tempo-add-tag (tag template &optional tag-list)
595 or to `tempo-tags' if TAG-LIST is nil."
599 (setq tag-list 'tempo-tags))
602 (tempo-invalidate-collection))
605 ;;; tempo-use-tag-list
607 (defun tempo-use-tag-list (tag-list &optional completion-function)
610 `tempo-add-tag'.
613 function or string that is used by `\\[tempo-complete-tag]' to find a
615 variable `tempo-match-finder'. In this version, supplying a
616 COMPLETION-FUNCTION just sets `tempo-match-finder' locally."
617 (let ((old (assq tag-list tempo-local-tags)))
620 (setq tempo-local-tags (cons (cons tag-list completion-function)
621 tempo-local-tags))))
623 (setq tempo-match-finder completion-function))
624 (tempo-invalidate-collection))
627 ;;; tempo-invalidate-collection
629 (defun tempo-invalidate-collection ()
632 (setq tempo-dirty-collection t))
635 ;;; tempo-build-collection
637 (defun tempo-build-collection ()
639 If `tempo-dirty-collection' is nil, the old collection is reused."
641 (or (and (not tempo-dirty-collection)
642 tempo-collection)
643 (setq tempo-collection
647 ; tempo-local-tags changes,
650 tempo-local-tags))))
651 (setq tempo-dirty-collection nil)))
654 ;;; tempo-find-match-string
656 (defun tempo-find-match-string (finder)
675 ;;; tempo-complete-tag
677 (defun tempo-complete-tag (&optional silent)
679 All the tags in the tag lists in `tempo-local-tags'
680 \(this includes `tempo-tags') are searched for a match for the text
682 be altered with the variable `tempo-match-finder'. If
683 `tempo-match-finder' returns nil, then the results are the same as
692 If a partial completion is found and `tempo-show-completion-buffer' is
698 (let* ((collection (tempo-build-collection))
699 (match-info (tempo-find-match-string tempo-match-finder))
708 ((eq compl t) (tempo-insert-template
713 (tempo-insert-template (cdr exact) nil)
716 (if tempo-show-completion-buffer
717 (tempo-display-completions match-string
722 ;;; tempo-display-completions
724 (defun tempo-display-completions (string tag-list)
726 (if tempo-leave-completion-buffer
739 ;;; tempo-expand-if-complete
741 (defun tempo-expand-if-complete ()
748 \(defun tempo-space ()
750 (or (tempo-expand-if-complete)
754 (let* ((collection (tempo-build-collection))
755 (match-info (tempo-find-match-string tempo-match-finder))
762 (tempo-insert-template (cdr exact) nil)
766 (provide 'tempo)
769 ;;; tempo.el ends here