Function: hpath:to-markup-anchor
hpath:to-markup-anchor is a byte-compiled function defined in
hpath.el.
Signature
(hpath:to-markup-anchor HASH ANCHOR &optional INSTANCE-NUM)
Documentation
Ignore HASH when ANCHOR is non-null and move point to ANCHOR string if found.
Move point to beginning of buffer if HASH is non-nil and ANCHOR is null. With optional INSTANCE-NUM, go to that instance of ANCHOR from the start of the buffer.
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hpath.el
(defun hpath:to-markup-anchor (hash anchor &optional instance-num)
"Ignore HASH when ANCHOR is non-null and move point to ANCHOR string if found.
Move point to beginning of buffer if HASH is non-nil and ANCHOR is null.
With optional INSTANCE-NUM, go to that instance of ANCHOR from the start
of the buffer."
(let ((omin (point-min))
(omax (point-max)))
(unwind-protect
(progn (widen)
(cond ((and (stringp anchor) (not (equal anchor "")))
(cond ((memq major-mode hui-select-markup-modes)
;; In HTML-like mode where link ids are case-sensitive.
(let ((opoint (point))
(case-fold-search))
(goto-char (point-min))
(if (re-search-forward (format hpath:html-anchor-id-pattern (regexp-quote anchor)) nil t instance-num)
(progn (goto-char (match-beginning 0))
(when (eq (current-buffer) (window-buffer))
(recenter 0)))
(goto-char opoint)
(error "(hpath:to-markup-anchor): %s - Anchor `%s' not found in the visible buffer portion"
(buffer-name)
anchor))))
(t
(let* ((opoint (point))
(prog-mode (derived-mode-p 'prog-mode))
;; Markdown or outline link ids are case insensitive.
(case-fold-search (not prog-mode))
(anchor-name (hpath:dashes-to-spaces-markup-anchor anchor))
(referent-regexp (format
(cond ((or (derived-mode-p 'outline-mode) ;; Includes Org mode
;; Treat all caps filenames without suffix like outlines,
;; e.g. README, INSTALL, HY-NEWS, ...
(and (hypb:buffer-file-name)
(string-match-p "\\`[A-Z0-9][A-Z0-9_-]*\\'"
(file-name-nondirectory (hypb:buffer-file-name)))))
hpath:outline-section-pattern)
((or (and (hypb:buffer-file-name)
(string-match-p hpath:markdown-suffix-regexp (hypb:buffer-file-name)))
(apply #'derived-mode-p hpath:shell-modes))
hpath:markdown-section-pattern)
((derived-mode-p 'texinfo-mode)
hpath:texinfo-section-pattern)
((or prog-mode (null (hypb:buffer-file-name))
(apply #'derived-mode-p '(fundamental-mode text-mode)))
"%s")
(t hpath:outline-section-pattern))
(regexp-quote anchor-name)))
(referent-leading-spaces-regexp
(when (and (not (string-empty-p referent-regexp))
(= (aref referent-regexp 0) ?^))
(concat "^[ \t]*" (substring referent-regexp 1)))))
(goto-char (point-min))
(cond ((and (derived-mode-p 'org-mode)
(hywiki-org-to-heading-instance
anchor-name instance-num))
(when (eq (current-buffer) (window-buffer))
(recenter 0)))
((or (re-search-forward referent-regexp nil t instance-num)
(and referent-leading-spaces-regexp
(re-search-forward referent-leading-spaces-regexp nil t instance-num)))
(goto-char (match-beginning 0))
(when (eq (current-buffer) (window-buffer))
(recenter 0)))
(t
(goto-char opoint)
(error "(hpath:to-markup-anchor): %s - Section `%s' not found in the visible buffer portion"
(buffer-name) anchor-name)))))))
(hash (goto-char omin))))
(when (and (<= omin (point)) (>= omax (point)))
(narrow-to-region omin omax)))))