Function: hpath:shorten

hpath:shorten is a byte-compiled function defined in hpath.el.

Signature

(hpath:shorten PATH &optional RELATIVE-TO)

Documentation

Expand and then shorten and return a PATH optionally RELATIVE-TO other path.

Don't shorten if acting on a global button.

Ignore optional RELATIVE-TO if editing a message, i.e. (hmail:editor-p) => t. If RELATIVE-TO is omitted or nil, set it to default-directory. Replace Emacs Lisp variables and environment variables (format of ${var}) with their values in PATH. The first matching value for variables like ${PATH} is used. Then abbreviate any remaining path.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hpath.el
(defun hpath:shorten (path &optional relative-to)
  "Expand and then shorten and return a PATH optionally RELATIVE-TO other path.
Don't shorten if acting on a global button.

Ignore optional RELATIVE-TO if editing a message,
i.e. (hmail:editor-p) => t.  If RELATIVE-TO is omitted or nil,
set it to `default-directory'.  Replace Emacs Lisp variables and
environment variables (format of ${var}) with their values in
PATH.  The first matching value for variables like `${PATH}' is
used.  Then abbreviate any remaining path."
  (setq path (expand-file-name (hpath:substitute-value path)))
  (when (file-directory-p path)
    ;; Force path to have a final directory separator so comparisons
    ;; to `default-directory' work
    (setq path (file-name-as-directory path)))
  (if (hmail:editor-p)
      (hpath:substitute-var path)
    (unless relative-to
      (setq relative-to default-directory))
    (when (stringp relative-to)
      (setq relative-to (expand-file-name
			 (hpath:substitute-value relative-to))
	    path
	    (cond ((hyperb:stack-frame '(gbut:act))
		   path)
		  ((string-equal path relative-to)
		   "")
		  ((string-equal (file-name-directory path) relative-to)
		   (file-name-nondirectory path))
		  (t (hpath:relative-to path relative-to)))))
    (hpath:abbreviate-file-name (hpath:substitute-var path))))