summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1994-05-08 21:11:37 +0000
committerRichard M. Stallman <rms@gnu.org>1994-05-08 21:11:37 +0000
commite7c01a8723bcfedef1a4d3c3d5a7025c15c915e4 (patch)
treee936576414176afb6404d73e5e39bf9a5f5c5495
parent1a9932914f4feb22edb902d6a7fd6bae608441ad (diff)
downloademacs-e7c01a8723bcfedef1a4d3c3d5a7025c15c915e4.tar.gz
(tempo-insert-region, tempo-show-completion-buffer,
tempo-leave-completion-buffer): New variables. (tempo-complete-tag): Added a completion buffer mechanism. (tempo-display-completions): New function. (tempo-insert-template): An extension to the (p ...) tag enables named insertion for later insertion using a (s ...) tag.
-rw-r--r--lisp/tempo.el127
1 files changed, 107 insertions, 20 deletions
diff --git a/lisp/tempo.el b/lisp/tempo.el
index 57037173c60..9f809097dc3 100644
--- a/lisp/tempo.el
+++ b/lisp/tempo.el
@@ -3,7 +3,7 @@
;; Author: David K}gedal <davidk@lysator.liu.se >
;; Created: 16 Feb 1994
-;; Version: 1.0
+;; Version: 1.1.1
;; Keywords: extensions, languages, tools
;; This file is part of GNU Emacs.
@@ -89,6 +89,20 @@
If this variable is non-nil, `tempo-insert' prompts the
user for text to insert in the templates")
+(defvar tempo-insert-region nil
+ "*Automatically insert current region when there is a `r' in the template
+If this variable is NIL, `r' elements will be treated just like `p'
+elements, unless the template function is given a prefix (or a non-nil
+argument). If this variable is non-NIL, the behaviour is reversed.")
+
+(defvar tempo-show-completion-buffer t
+ "*If non-NIL, show a buffer with possible completions, when only
+a partial completion can be found")
+
+(defvar tempo-leave-completion-buffer nil
+ "*If NIL, a completion buffer generated by \\[tempo-complete-tag]
+disappears at the next keypress; otherwise, it remains forever.")
+
(defvar tempo-insert-string-functions nil
"List of functions to run when inserting a string.
Each function is called with a single arg, STRING." )
@@ -112,6 +126,9 @@ documentation for the function `tempo-complete-tag' for more info.
(defvar tempo-default-match-finder "\\b\\([^\\b]*\\)\\="
"The default regexp used to find the string to match against the tags.")
+(defvar tempo-named-insertions nil
+ "Temporary storage for named insertions")
+
;; Make some variables local to every buffer
(make-variable-buffer-local 'tempo-marks)
@@ -142,12 +159,17 @@ The elements in ELEMENTS can be of several types:
- The symbol 'p. This position is saved in `tempo-marks'.
- The symbol 'r. If `tempo-insert' is called with ON-REGION non-nil
the current region is placed here. Otherwise it works like 'p.
- - (p . PROMPT) If `tempo-interactive' is non-nil, the user is
+ - (p PROMPT <NAME>) If `tempo-interactive' is non-nil, the user is
prompted in the minbuffer with PROMPT for a string to be inserted.
+ If the optional parameter NAME is non-nil, the text is saved for
+ later insertion with the `s' tag.
If `tempo-interactive is nil, it works like 'p.
- - (r . PROMPT) like the previou, but if `tempo-interactive' is nil
+ - (r PROMPT) like the previous, but if `tempo-interactive' is nil
and `tempo-insert' is called with ON-REGION non-nil, the current
region is placed here.
+ - (s NAME) Inserts text previously read with the (p ..) construct.
+ Finds the insertion saved under NAME and inserts it. Acts like 'p
+ if tempo-interactive is nil.
- '& If there is only whitespace between the line start and point,
nothing happens. Otherwise a newline is inserted.
- '% If there is only whitespace between point and end-of-line
@@ -169,8 +191,9 @@ The elements in ELEMENTS can be of several types:
(concat "Insert a " name "."))
(list 'interactive "*P")
(list 'tempo-insert-template (list 'quote
- template-name)
- 'arg)))
+ template-name)
+ (list 'if 'tempo-insert-region
+ (list 'not 'arg) 'arg))))
(and tag
(tempo-add-tag tag template-name taglist))
command-name))
@@ -190,7 +213,8 @@ TEMPLATE is the template to be inserted. If ON-REGION is non-nil the
(mapcar 'tempo-insert
(symbol-value template))
(tempo-insert-mark (point-marker)))
- (tempo-forward-mark))
+ (tempo-forward-mark)
+ (tempo-forget-insertions))
;;;
;;; tempo-insert
@@ -206,6 +230,10 @@ Insert one element from a template. See documentation for
(if on-region
(exchange-point-and-mark)
(tempo-insert-prompt (cdr element))))
+ ((and (consp element) (eq (car element) 's))
+ (if tempo-interactive
+ (tempo-insert-named (cdr element))
+ (tempo-insert-mark (point-marker))))
((eq element 'p) (tempo-insert-mark (point-marker)))
((eq element 'r) (if on-region
(exchange-point-and-mark)
@@ -234,21 +262,58 @@ Insert one element from a template. See documentation for
If the variable `tempo-interactive' is non-nil the user is prompted
for a string in the minibuffer, which is then inserted in the current
buffer. If `tempo-interactive' is nil, the current point is placed on
-`tempo-forward-mark-list'.
+`tempo-mark'.
-PROMPT is the prompt string."
+PROMPT is the prompt string or a list containing the prompt string and
+a name to save the inserted text under."
(if tempo-interactive
- (insert (read-string prompt))
+ (let ((prompt-string (if (listp prompt)
+ (car prompt)
+ prompt))
+ (save-name (and (listp prompt) (nth 1 prompt)))
+ inserted-text)
+
+ (progn
+ (setq inserted-text (read-string prompt-string))
+ (insert inserted-text)
+ (if save-name
+ (tempo-remember-insertion save-name inserted-text))))
(tempo-insert-mark (point-marker))))
;;;
+;;; tempo-remember-insertion
+
+(defun tempo-remember-insertion (save-name string)
+ "Save the text in STRING under the name SAVE-NAME for later retrieval."
+ (setq tempo-named-insertions (cons (cons save-name string)
+ tempo-named-insertions)))
+
+;;;
+;;; tempo-forget-insertions
+
+(defun tempo-forget-insertions ()
+ "Forget all the saved named insertions."
+ (setq tempo-named-insertions nil))
+
+;;;
+;;; tempo-insert-named
+
+(defun tempo-insert-named (elt)
+ "Insert the previous insertion saved under a named specified in ELT.
+The name is in the car of ELT."
+ (let* ((name (car elt))
+ (insertion (cdr (assq name tempo-named-insertions))))
+ (if insertion
+ (insert insertion)
+ (error "Named insertion not found"))))
+
+;;;
;;; tempo-process-and-insert-string
(defun tempo-process-and-insert-string (string)
"Insert a string from a template.
Run a string through the preprocessors in `tempo-insert-string-functions'
and insert the results."
-
(cond ((null tempo-insert-string-functions)
nil)
((symbolp tempo-insert-string-functions)
@@ -381,7 +446,7 @@ FINDER is a function or a string. Returns (STRING . POS)."
;;; tempo-complete-tag
(defun tempo-complete-tag (&optional silent)
- "Look for a tag and expand it..
+ "Look for a tag and expand it.
It goes through the tag lists in `tempo-local-tags' (this includes
`tempo-tags') and for each list it uses the corresponding match-finder
@@ -397,8 +462,12 @@ list are considered, so if you provide similar tags in different lists
in `tempo-local-tags', the result may not be desirable.
If no match is found or a partial match is found, and SILENT is
-non-nil, the function will give a signal."
+non-nil, the function will give a signal.
+
+If tempo-show-completion-buffer is non-NIL, a buffer containing
+possible completions is displayed when a partial completion is found."
+ ;; This function is really messy. Some cleaning up is necessary.
(interactive)
(if (catch 'completed
(mapcar
@@ -411,30 +480,33 @@ non-nil, the function will give a signal."
(match-string (car match-info))
(match-start (cdr match-info))
(compl (or (cdr (assoc match-string tag-list))
- (try-completion (car match-info)
+ (try-completion match-string
tag-list))))
(if compl ;any match
(delete-region match-start (point)))
(cond
- ((null compl)
+ ((null compl) ; No match
nil)
- ((symbolp compl)
+ ((symbolp compl) ; ??
(tempo-insert-template compl nil)
(throw 'completed t))
- ((eq compl t)
+ ((eq compl t) ; Exact, sole match
(tempo-insert-template (cdr (assoc match-string tag-list))
nil)
(throw 'completed t))
- ((stringp compl)
+ ((stringp compl) ; (partial) completion found
(let ((compl2 (assoc compl tag-list)))
(if compl2
(tempo-insert-template (cdr compl2) nil)
(insert compl)
- (if (string= match-string compl)
- (if (not silent)
- (ding)))))
+ (if t ;(string= match-string compl)
+ (if tempo-show-completion-buffer
+ (tempo-display-completions match-string
+ tag-list)
+ (if (not silent)
+ (ding))))))
(throw 'completed t))))))
tempo-local-tags)
;; No completion found. Return nil
@@ -446,4 +518,19 @@ non-nil, the function will give a signal."
(ding))
nil))
+;;;
+;;; 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
+ (all-completions string tag-list)))
+ (save-window-excursion
+ (with-output-to-temp-buffer "*Completions*"
+ (display-completion-list
+ (all-completions string tag-list)))
+ (sit-for 32767))))
+
;;; tempo.el ends here