Function: iswitchb-completions

iswitchb-completions is a byte-compiled function defined in iswitchb.el.gz.

Signature

(iswitchb-completions NAME)

Documentation

Return the string that is displayed after the user's text.

Modified from icomplete-completions.

Source Code

;; Defined in /usr/src/emacs/lisp/obsolete/iswitchb.el.gz
(defun iswitchb-completions (name)
  "Return the string that is displayed after the user's text.
Modified from `icomplete-completions'."

  (let ((comps iswitchb-matches)
                                        ; "-determined" - only one candidate
        (open-bracket-determined "[")
        (close-bracket-determined "]")
                                        ;"-prospects" - more than one candidate
        (open-bracket-prospects "{")
        (close-bracket-prospects "}")
	first)

    (if (and iswitchb-use-faces comps)
	(progn
	  (setq first (copy-sequence (car comps)))
	  (setq first (format "%s" first))
	  (put-text-property 0 (length first) 'face
			     (if (= (length comps) 1)
                                 (if iswitchb-invalid-regexp
                                     'iswitchb-invalid-regexp
                                   'iswitchb-single-match)
			       'iswitchb-current-match)
			     first)
	  (setq comps  (cons first (cdr comps)))))

    ;; If no buffers matched, and virtual buffers are being used, then
    ;; consult the list of past visited files, to see if we can find
    ;; the file which the user might thought was still open.
    (when (and iswitchb-use-virtual-buffers (null comps)
	       recentf-list)
      (setq iswitchb-virtual-buffers nil)
      (let ((head recentf-list) name)
	(while head
	  (if (and (setq name (file-name-nondirectory (car head)))
		   (string-match (if iswitchb-regexp
				     iswitchb-text
				   (regexp-quote iswitchb-text)) name)
		   (null (get-file-buffer (car head)))
		   (not (assoc name iswitchb-virtual-buffers))
		   (not (iswitchb-ignore-buffername-p name))
		   (file-exists-p (car head)))
	      (setq iswitchb-virtual-buffers
		    (cons (cons name (car head))
			  iswitchb-virtual-buffers)))
	  (setq head (cdr head)))
	(setq iswitchb-virtual-buffers (nreverse iswitchb-virtual-buffers)
	      comps (mapcar #'car iswitchb-virtual-buffers))
	(let ((comp comps))
	  (while comp
	    (put-text-property 0 (length (car comp))
			       'face 'iswitchb-virtual-matches
			       (car comp))
	    (setq comp (cdr comp))))))

    (cond ((null comps) (format " %sNo match%s"
				open-bracket-determined
				close-bracket-determined))

	  (iswitchb-invalid-regexp
           (concat " " (car comps)))
          ((null (cdr comps))		;one match
	   (concat
            (if (if (not iswitchb-regexp)
                    (= (length name)
                       (length (car comps)))
                  (string-match name (car comps))
                  (string-equal (match-string 0 (car comps))
                                (car comps)))
                ""
              (concat open-bracket-determined
			       ;; when there is one match, show the
			       ;; matching buffer name in full
			       (car comps)
			       close-bracket-determined))
		   (if (not iswitchb-use-faces) " [Matched]")))
	  (t				;multiple matches
	   (if (and iswitchb-max-to-show
		    (> (length comps) iswitchb-max-to-show))
	       (setq comps
		     (append
		      (let ((res nil)
			    (comp comps)
			    (end (/ iswitchb-max-to-show 2)))
			(while (>= (setq end (1- end)) 0)
			  (setq res (cons (car comp) res)
				comp (cdr comp)))
			(nreverse res))
		      (list "...")
		      (nthcdr (- (length comps)
				 (/ iswitchb-max-to-show 2))
			      comps))))
	   (let* (
		  (alternatives
		   (mapconcat #'identity comps iswitchb-delim)))

	     (concat

	      ;; put in common completion item -- what you get by
	      ;; pressing tab
	      (if (and (stringp iswitchb-common-match-string)
		       (> (length iswitchb-common-match-string) (length name)))
		  (concat open-bracket-determined
			  (substring iswitchb-common-match-string
				     (length name))
			  close-bracket-determined))
	      ;; end of partial matches...

	      ;; list all alternatives
	      open-bracket-prospects
	      alternatives
	      close-bracket-prospects))))))