Function: idlwave-complete-in-buffer

idlwave-complete-in-buffer is a byte-compiled function defined in idlwave.el.gz.

Signature

(idlwave-complete-in-buffer TYPE STYPE LIST SELECTOR PROMPT ISA &optional PREPARE-DISPLAY-FUNCTION SPECIAL-SELECTOR)

Documentation

Perform TYPE completion of word before point against LIST.

SELECTOR is the PREDICATE argument for the completion function. Show PROMPT in echo area. TYPE is one of the intern types, e.g., function, procedure, class-tag, keyword, sysvar. SPECIAL-SELECTOR is used only once, for all-completions, and can be used to, e.g., accumulate information on matching completions.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/idlwave.el.gz
(defun idlwave-complete-in-buffer (type stype list selector prompt isa
					&optional prepare-display-function
					special-selector)
  "Perform TYPE completion of word before point against LIST.
SELECTOR is the PREDICATE argument for the completion function.  Show
PROMPT in echo area.  TYPE is one of the intern types, e.g., `function',
`procedure', `class-tag', `keyword', `sysvar'.  SPECIAL-SELECTOR is
used only once, for `all-completions', and can be used to, e.g.,
accumulate information on matching completions."
  (let* ((completion-ignore-case t)
	 beg (end (point)) slash part spart completion all-completions
	 dpart dcompletion)

    (unless list
      (error (concat prompt ": No completions available")))

    ;; What is already in the buffer?
    (save-excursion
      (skip-chars-backward "a-zA-Z0-9_$")
      (setq slash (eq (preceding-char) ?/)
	    beg (point)
	    idlwave--complete-after-success-function
	    (lambda () (idlwave-after-successful-completion
		   type slash beg))
	    idlwave--complete-after-success-force-function
	    (lambda () (idlwave-after-successful-completion
		   type slash 'force))))

    ;; Try a completion
    (setq part (buffer-substring beg end)
	  dpart (downcase part)
	  spart (idlwave-sintern stype part)
	  completion (try-completion part list selector)
	  dcompletion (if (stringp completion) (downcase completion))
	  idlwave-completion-help-links nil)
    (cond
     ((null completion)
      ;; nothing available.
      (error (concat prompt ": no completion for \"%s\"") part))
     ((and (not (equal dpart dcompletion))
	   (not (eq t completion)))
      ;; We can add something
      (delete-region beg end)
      (insert (if (and (string= part dpart)
                       (or (not (string= part ""))
                           idlwave-complete-empty-string-as-lower-case)
                       (not idlwave-completion-force-default-case))
                  dcompletion
                completion))
      (if (eq t (try-completion completion list selector))
	  ;; Now this is a unique match
	  (idlwave-after-successful-completion type slash beg))
      t)
     ((or (eq completion t)
	  (and (= 1 (length (setq all-completions
				  (idlwave-uniquify
				   (all-completions part list
						    (or special-selector
							selector))))))
	       (equal dpart dcompletion)))
      ;; This is already complete
      (idlwave-after-successful-completion type slash beg)
      (message "%s is already the complete %s" part isa)
      nil)
     (t
      ;; We cannot add something - offer a list.
      (message "Making completion list...")

      (unless idlwave-completion-help-links ; already set somewhere?
	(mapc (lambda (x)  ; Pass link prop through to highlight-linked
		(let ((link (get-text-property 0 'link (car x))))
		  (if link
		      (push (cons (car x) link)
			    idlwave-completion-help-links))))
	      list))
      (let* ((list all-completions)
	     ;; "complete" means, this is already a valid completion
	     (complete (memq spart all-completions)))
	(setq list (sort list (lambda (a b)
				(string< (downcase a) (downcase b)))))
	(if prepare-display-function
	    (setq list (funcall prepare-display-function list)))
	(if (and (string= part dpart)
		 (or (not (string= part ""))
		     idlwave-complete-empty-string-as-lower-case)
		 (not idlwave-completion-force-default-case))
	    (setq list (mapcar (lambda (x)
				 (if (listp x)
				     (setcar x (downcase (car x)))
				   (setq x (downcase x)))
				 x)
			       list)))
	(idlwave-display-completion-list list prompt beg complete))
      t))))