Function: pascal-completion

pascal-completion is a byte-compiled function defined in pascal.el.gz.

Signature

(pascal-completion PASCAL-STR PASCAL-PRED PASCAL-FLAG)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/pascal.el.gz
(defun pascal-completion (pascal-str pascal-pred pascal-flag)
  (let ((all (car pascal-completion-cache)))
    ;; Check the cache's freshness.
    (unless (and pascal-completion-cache
                 (string-prefix-p (nth 1 pascal-completion-cache) pascal-str)
                 (eq (current-buffer) (nth 2 pascal-completion-cache))
                 (eq (field-beginning) (nth 3 pascal-completion-cache)))
      (let ((state (car (pascal-calculate-indent))))
        (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]*:" (line-beginning-position) t))))
                (save-excursion
                  (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)))