Function: hpath:substitute-var-name
hpath:substitute-var-name is a byte-compiled function defined in
hpath.el.
Signature
(hpath:substitute-var-name VAR-SYMBOL VAR-DIR-VAL PATH)
Documentation
Replace with VAR-SYMBOL any occurrences of VAR-DIR-VAL in PATH.
Replacement is done iff VAR-DIR-VAL is an absolute path.
If VAR-SYMBOL is 'load-path, remove the matching PATH part rather than replacing it with the variable since it can be resolved without attaching the variable name.
If PATH is modified, return PATH, otherwise return nil.
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260822.1645/hpath.el
(defun hpath:substitute-var-name (var-symbol var-dir-val path)
"Replace with VAR-SYMBOL any occurrences of VAR-DIR-VAL in PATH.
Replacement is done iff VAR-DIR-VAL is an absolute path.
If VAR-SYMBOL is \\='load-path, remove the matching PATH part
rather than replacing it with the variable since it can be
resolved without attaching the variable name.
If PATH is modified, return PATH, otherwise return nil."
(when (and (stringp var-dir-val) (file-name-absolute-p var-dir-val))
(let ((new-path (replace-regexp-in-string
(concat "^" (regexp-quote (file-name-as-directory var-dir-val)))
;; Remove matching path rather than adding the
;; variable to the path when the variable is one
;; for Elisp file paths and path is to an Elisp
;; file. These can be resolved without the
;; variable being included in the path.
(if (and (memq var-symbol '(load-path))
(delq nil (mapcar (lambda (suffix) (string-suffix-p suffix path))
(get-load-suffixes))))
""
(concat "$\{" (symbol-name var-symbol) "\}/"))
path t t)))
(if (equal new-path path) nil new-path))))