Function: try-complete-file-name

try-complete-file-name is a byte-compiled function defined in hippie-exp.el.gz.

Signature

(try-complete-file-name OLD)

Documentation

Try to complete text as a file name.

The argument OLD has to be nil the first call of this function, and t for subsequent calls (for further possible completions of the same string). It returns t if a new completion is found, nil otherwise.

Source Code

;; Defined in /usr/src/emacs/lisp/hippie-exp.el.gz
;;;  Here follows the try-functions and their requisites:


(defun try-complete-file-name (old)
  "Try to complete text as a file name.
The argument OLD has to be nil the first call of this function, and t
for subsequent calls (for further possible completions of the same
string).  It returns t if a new completion is found, nil otherwise."
  (if (not old)
      (progn
	(he-init-string (he-file-name-beg) (point))
	(let ((name-part (file-name-nondirectory he-search-string))
	      (dir-part (expand-file-name (or (file-name-directory
					       he-search-string)
					      ""))))
	  (if (not (he-string-member name-part he-tried-table))
	      (setq he-tried-table (cons name-part he-tried-table)))
	  (if (and (not (equal he-search-string ""))
		   (file-directory-p dir-part))
	      (setq he-expand-list (sort (file-name-all-completions
					  name-part
					  dir-part)
					 #'string-lessp))
	      (setq he-expand-list ())))))

  (while (and he-expand-list
	      (he-string-member (car he-expand-list) he-tried-table))
    (setq he-expand-list (cdr he-expand-list)))
  (if (null he-expand-list)
      (progn
	(if old (he-reset-string))
	())
      (let ((filename (he-concat-directory-file-name
		       (file-name-directory he-search-string)
		       (car he-expand-list))))
	(he-substitute-string filename)
	(setq he-tried-table (cons (car he-expand-list) (cdr he-tried-table)))
	(setq he-expand-list (cdr he-expand-list))
	t)))