Function: hpath:symlink-expand
hpath:symlink-expand is a byte-compiled function defined in hpath.el.
Signature
(hpath:symlink-expand REFERENT DIRNAME)
Documentation
Return expanded file or directory REFERENT relative to DIRNAME.
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hpath.el
(defun hpath:symlink-expand (referent dirname)
"Return expanded file or directory REFERENT relative to DIRNAME."
(let ((var-link)
(dir dirname))
(while (string-match "\\$(\\([^\)]*\\))" referent)
(setq var-link (getenv (substring referent (match-beginning 1)
(match-end 1)))
referent (concat (substring referent 0 (match-beginning 0))
var-link
(substring referent (match-end 0)))))
;; If referent is not an absolute path
(let ((nd-abbrev (string-match "`node_data" referent)))
(if (and nd-abbrev (= nd-abbrev 0))
(setq referent (concat
;; Prepend node name given in dirname, if any
(and (string-match "^//[^/]+" dirname)
(substring dirname 0 (match-end 0)))
"/sys/" (substring referent 1)))))
(while (string-match "\\(^\\|/\\)\\.\\.\\(/\\|$\\)" referent)
;; Match to "//.." or "/.." at the start of link referent
(while (string-match "^\\(//\\.\\.\\|/\\.\\.\\)\\(/\\|$\\)" referent)
(setq referent (substring referent (match-end 1))))
;; Match to "../" or ".." at the start of link referent
(while (string-match "^\\.\\.\\(/\\|$\\)" referent)
(setq dir (file-name-directory (directory-file-name dir))
referent (concat dir (substring referent (match-end 0)))))
;; Match to rest of "../" in link referent
(while (string-match "[^/]+/\\.\\./" referent)
(setq referent (concat (substring referent 0 (match-beginning 0))
(substring referent (match-end 0))))))
(and (not (eq (aref referent 0) ?~))
(not (eq (aref referent 0) ?/))
(setq referent (expand-file-name referent dirname))))
referent)