Function: url-dav-file-name-completion

url-dav-file-name-completion is a byte-compiled function defined in url-dav.el.gz.

Signature

(url-dav-file-name-completion FILE URL)

Documentation

Complete file name FILE in URL.

Returns the longest string common to all file names in URL that start with FILE. If there is only one and FILE matches it exactly, returns t. Returns nil if URL contains no name starting with FILE.

Source Code

;; Defined in /usr/src/emacs/lisp/url/url-dav.el.gz
(defun url-dav-file-name-completion (file url)
  "Complete file name FILE in URL.
Returns the longest string common to all file names in URL
that start with FILE.
If there is only one and FILE matches it exactly, returns t.
Returns nil if URL contains no name starting with FILE."
  (let ((matches (url-dav-file-name-all-completions file url))
	;; (result nil)
	)
    ;; FIXME: Use `try-completion'!
    (cond
     ((null matches)
      ;; No matches
      nil)
     ((and (= (length matches) 1)
	   (string= file (car matches)))
      ;; Only one file and FILE matches it exactly...
      t)
     (t
      ;; Need to figure out the longest string that they have in common
      (setq matches (sort matches (lambda (a b) (> (length a) (length b)))))
      (let ((n (length file))
	    (searching t)
	    (regexp nil)
	    (failed nil))
	(while (and searching
		    (< n (length (car matches))))
	  (setq regexp (concat "^" (substring (car matches) 0 (1+ n)))
		failed nil)
	  (dolist (potential matches)
	    (if (not (string-match regexp potential))
		(setq failed t)))
	  (if failed
	      (setq searching nil)
            (incf n)))
	(substring (car matches) 0 n))))))