Function: hywiki-reference-to-referent

hywiki-reference-to-referent is a byte-compiled function defined in hywiki.el.

Signature

(hywiki-reference-to-referent REFERENCE &optional FULL-DATA)

Documentation

Resolve HyWikiWord REFERENCE to its referent file or other type of referent.

If the referent is not a file type, return (referent-type . referent-value).

Otherwise: Reference may end with optional suffix of the form: (#|::)section:Lnum:Cnum. With optional FULL-DATA non-nil, return a list in the form of (pathname hywikiword suffix); otherwise:
  - with a section, return pathname::section;
  - with just line and optionally column numbers, return pathname:Lnum:Cnum
  - and without any suffix, return just the pathname.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hywiki.el
(defun hywiki-reference-to-referent (reference &optional full-data)
  "Resolve HyWikiWord REFERENCE to its referent file or other type of referent.
If the referent is not a file type, return (referent-type . referent-value).

Otherwise:
Reference may end with optional suffix of the form: (#|::)section:Lnum:Cnum.
With optional FULL-DATA non-nil, return a list in the form of (pathname
hywikiword suffix); otherwise:
  - with a section, return pathname::section;
  - with just line and optionally column numbers, return pathname:Lnum:Cnum
  - and without any suffix, return just the pathname."
  (when (stringp reference)
    (when (string-match (concat "\\`" hywiki-org-link-type ":") reference)
      ;; Remove hy: reference prefix
      (setq reference (substring reference (match-end 0))))
    (let* ((suffix-type (and (string-match hywiki-word-suffix-regexp reference)
			     (match-string 1 reference)))
	   (suffix (and suffix-type (match-string 2 reference)))
           (word (if (and suffix (not (string-empty-p suffix)))
                     (substring reference 0 (match-beginning 0))
		   reference))
           (referent (and word (hywiki-get-referent word)))
	   (referent-type (car referent))
           (pathname (when (memq referent-type '(page path-link))
		       (expand-file-name (or (cdr referent) "")
					 hywiki-directory))))
      (if (stringp pathname)
	  (cond
	   (full-data
	    (list pathname word (concat suffix-type suffix)))
	   ((and suffix (not (string-empty-p suffix)))
	    (if (equal suffix-type ":L")
		(concat pathname suffix-type suffix)
	      (concat pathname "::" suffix)))
	   (t pathname))
	referent))))