- (cond (;--Within a declaration or parameterlist
- (or (eq state 'declaration) (eq state 'paramlist)
- (and (eq state 'defun)
- (save-excursion
- (re-search-backward ")[ \t]*:"
- (pascal-get-beg-of-line) t))))
- (if (or (eq state 'paramlist) (eq state 'defun))
- (pascal-beg-of-defun))
- (pascal-type-completion)
- (pascal-keyword-completion pascal-type-keywords))
- (;--Starting a new statement
- (and (not (eq state 'contexp))
- (save-excursion
- (skip-chars-backward "a-zA-Z0-9_.")
- (backward-sexp 1)
- (or (looking-at pascal-nosemi-re)
- (progn
- (forward-sexp 1)
- (looking-at "\\s *\\(;\\|:[^=]\\)")))))
- (save-excursion (pascal-var-completion))
- (pascal-func-completion 'procedure)
- (pascal-keyword-completion pascal-start-keywords))
- (t;--Anywhere else
- (save-excursion (pascal-var-completion))
- (pascal-func-completion 'function)
- (pascal-keyword-completion pascal-separator-keywords))))
-
- ;; Now we have built a list of all matches. Give response to caller
- (pascal-completion-response))))
-
-(defun pascal-completion-response ()
- (cond ((or (equal pascal-flag 'lambda) (null pascal-flag))
- ;; This was not called by all-completions
- (if (null pascal-all)
- ;; Return nil if there was no matching label
- nil
- ;; Get longest string common in the labels
- (let* ((elm (cdr pascal-all))
- (match (car pascal-all))
- (min (length match))
- tmp)
- (if (string= match pascal-str)
- ;; Return t if first match was an exact match
- (setq match t)
- (while (not (null elm))
- ;; Find longest common string
- (if (< (setq tmp (pascal-string-diff match (car elm))) min)
- (progn
- (setq min tmp)
- (setq match (substring match 0 min))))
- ;; Terminate with match=t if this is an exact match
- (if (string= (car elm) pascal-str)
- (progn
- (setq match t)
- (setq elm nil))
- (setq elm (cdr elm)))))
- ;; If this is a test just for exact match, return nil ot t
- (if (and (equal pascal-flag 'lambda) (not (equal match 't)))
- nil
- match))))
- ;; If flag is t, this was called by all-completions. Return
- ;; list of all possible completions
- (pascal-flag
- pascal-all)))
+ (setq all
+ ;; Determine what should be completed
+ (cond
+ ( ;--Within a declaration or parameterlist
+ (or (eq state 'declaration) (eq state 'paramlist)
+ (and (eq state 'defun)
+ (save-excursion
+ (re-search-backward ")[ \t]*:"
+ (pascal-get-beg-of-line) t))))
+ (if (or (eq state 'paramlist) (eq state 'defun))
+ (pascal-beg-of-defun))
+ (nconc
+ (pascal-type-completion pascal-str)
+ (pascal-keyword-completion pascal-type-keywords pascal-str)))
+ ( ;--Starting a new statement
+ (and (not (eq state 'contexp))
+ (save-excursion
+ (skip-chars-backward "a-zA-Z0-9_.")
+ (backward-sexp 1)
+ (or (looking-at pascal-nosemi-re)
+ (progn
+ (forward-sexp 1)
+ (looking-at "\\s *\\(;\\|:[^=]\\)")))))
+ (nconc
+ (pascal-var-completion pascal-str)
+ (pascal-func-completion 'procedure pascal-str)
+ (pascal-keyword-completion pascal-start-keywords pascal-str)))
+ (t ;--Anywhere else
+ (nconc
+ (pascal-var-completion pascal-str)
+ (pascal-func-completion 'function pascal-str)
+ (pascal-keyword-completion pascal-separator-keywords
+ pascal-str)))))
+
+ (setq pascal-completion-cache
+ (list all pascal-str (current-buffer) (field-beginning)))))
+
+ ;; Now we have built a list of all matches. Give response to caller
+ (complete-with-action pascal-flag all pascal-str pascal-pred)))