Function: consult--left-truncate-file

consult--left-truncate-file is a byte-compiled function defined in consult.el.

Signature

(consult--left-truncate-file FILE)

Documentation

Return abbreviated file name of FILE for use in completing-read prompt.

Source Code

;; Defined in ~/.emacs.d/elpa/consult-20260805.1130/consult.el
(defun consult--left-truncate-file (file)
  "Return abbreviated file name of FILE for use in `completing-read' prompt."
  (save-match-data
    (let* ((file-name-handler-alist) ;; No Tramp interference please.
           (file (directory-file-name (abbreviate-file-name file)))
           (prefix nil))
      (when (string-match "\\`/\\([^/|:]+:[^/|:]*:\\)" file)
        (setq prefix (propertize (match-string 1 file) 'face 'error)
              file (if (= (match-end 0) (length file)) "/" (substring file (match-end 0)))))
      (when (string-match "/\\([^/]+\\)/\\([^/]+\\)\\'" file)
        (let* ((fst (truncate-string-to-width (match-string 1 file) 20 nil nil "…"))
               (snd (truncate-string-to-width (match-string 2 file) 20 nil nil "…"))
               (trunc (format "…/%s/%s" fst snd)))
          (setq file (if (< (length trunc) (length file)) trunc file))))
      (concat prefix file))))