Function: hywiki-maybe-highlight-references
hywiki-maybe-highlight-references is an interactive and byte-compiled
function defined in hywiki.el.
Signature
(hywiki-maybe-highlight-references &optional REGION-START REGION-END SKIP-LOOKUPS-UPDATE-FLAG)
Documentation
Highlight each non-Org link HyWiki page#section in the current buffer/region.
With optional REGION-START and REGION-END positions or markers (active region interactively), limit highlight adjustment to the region. With optional SKIP-LOOKUPS-UPDATE-FLAG non-nil, HyWiki lookup tables should have already been updated and this is skipped.
Use hywiki-word-face to highlight. Do not highlight references
to the current page unless they have sections attached.
HyWiki mode must be active in the current buffer for highlighting
to occur; otherwise, highlighting is removed and disabled in the
current buffer. Highlight/dehighlight HyWiki page buffers
whenever hywiki-mode(var)/hywiki-mode(fun) is enabled/disabled.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hywiki.el
(defun hywiki-maybe-highlight-references (&optional region-start region-end skip-lookups-update-flag)
"Highlight each non-Org link HyWiki page#section in the current buffer/region.
With optional REGION-START and REGION-END positions or markers (active
region interactively), limit highlight adjustment to the region. With
optional SKIP-LOOKUPS-UPDATE-FLAG non-nil, HyWiki lookup tables
should have already been updated and this is skipped.
Use `hywiki-word-face' to highlight. Do not highlight references
to the current page unless they have sections attached.
HyWiki mode must be active in the current buffer for highlighting
to occur; otherwise, highlighting is removed and disabled in the
current buffer. Highlight/dehighlight HyWiki page buffers
whenever `hywiki-mode' is enabled/disabled."
(interactive (when (use-region-p) (list (region-beginning) (region-end))))
;; Avoid doing many lets for efficiency.
;; Highlight HyWikiWords throughout buffers where `hywiki-mode' is enabled
;; or HyWiki pages below `hywiki-directory' whenever displayed in a window.
(if (hywiki-active-in-current-buffer-p)
(progn
(unless skip-lookups-update-flag
;; Rebuild lookup tables if any HyWiki page name has changed
(hywiki-get-referent-hasht))
(unwind-protect
(save-excursion
(save-restriction
(setq hywiki--save-case-fold-search case-fold-search
case-fold-search nil
hywiki--save-org-link-type-required hywiki-org-link-type-required
hywiki-org-link-type-required t
hywiki--current-page (hywiki-get-buffer-page-name))
(cond ((and (markerp region-start) (markerp region-end))
(when (and (marker-position region-start)
(marker-position region-end))
(narrow-to-region region-start region-end)))
((and region-start region-end)
(narrow-to-region region-start region-end)))
;; Enable dehighlighting in HyWiki pages only when
;; whole buffer is being processed; this prevents an
;; error when called from `hywiki-maybe-highlight-sexp'.
(unless (and region-start region-end)
(let ((hywiki-mode))
(hywiki-maybe-dehighlight-references)))
(let ((highlight-in-comments-and-strings-only
(and (derived-mode-p 'prog-mode)
(not (apply #'derived-mode-p hywiki-highlight-all-in-prog-modes))))
hywiki--start
hywiki--end)
(dolist (hywiki-words-regexp hywiki--any-wikiword-regexp-list)
(goto-char (point-min))
(while (re-search-forward hywiki-words-regexp nil t)
(setq hywiki--start (match-beginning 1)
hywiki--end (match-end 1))
(save-excursion
(goto-char hywiki--start)
(when (save-match-data
(if highlight-in-comments-and-strings-only
;; Non-nil if match is inside a comment or a string
(or (nth 4 (syntax-ppss)) (hypb:in-string-p))
t))
;; Otherwise, highlight any HyWikiWord found, including
;; any #section:Lnum:Cnum.
(when (hywiki-maybe-at-wikiword-beginning)
(or (unless (hyperb:stack-frame '(hywiki-maybe-highlight-balanced-pairs))
(hywiki-maybe-highlight-balanced-pairs))
(progn (with-syntax-table hbut:syntax-table
(skip-syntax-forward "^-\)$\>._\"\'"))
(skip-chars-forward "-_*[:alnum:]")
(unless (zerop (skip-chars-forward "#:"))
(skip-chars-forward
(if (save-restriction
(widen)
(and (hywiki-delimited-p)
;; Only if delimiter is
;; the char preceding
;; the start of the
;; WikiWord do we skip
;; over spaces to find
;; the #section.
(hash-get
(char-to-string
(or (char-before (or hywiki--start 0))
0))
hywiki--open-close-hasht)))
"-_*: \t[:alnum:]"
"-_*:[:alnum:]")))
(setq hywiki--end (point))
;; Don't highlight current-page matches unless they
;; include a #section.
(unless (string-equal hywiki--current-page
(buffer-substring-no-properties hywiki--start hywiki--end))
(hywiki-maybe-highlight-region-reference hywiki--start hywiki--end))))))))))
;; Disable dehighlighting of HyWikiWords between [] and <>.
;;
;; (let (str-start-end)
;; (goto-char (point-min))
;; (while (search-forward "[" nil t)
;; (when (setq str-start-end (hargs:delimited-p "[" "]" nil nil t))
;; (setq hywiki--start (nth 1 str-start-end)
;; hywiki--end (nth 2 str-start-end))
;; ;; Clear any HyWikiWord highlighting that may
;; ;; just be a part of a larger square brackets
;; ;; delimited text with multiple words.
;; (hproperty:but-clear-all-in-list
;; (hproperty:but-get-all-in-region hywiki--start hywiki--end
;; 'face hywiki-word-face))
;; (goto-char (min (1+ hywiki--end) (point-max)))))
;; (goto-char (point-min))
;; (while (search-forward "<" nil t)
;; (when (setq str-start-end (hargs:delimited-p "<" ">" nil nil t))
;; (setq hywiki--start (nth 1 str-start-end)
;; hywiki--end (nth 2 str-start-end))
;; ;; Clear any HyWikiWord highlighting that may
;; ;; just be a part of a larger angle brackets
;; ;; delimited text with multiple words.
;; (hproperty:but-clear-all-in-list
;; (hproperty:but-get-all-in-region hywiki--start hywiki--end
;; 'face hywiki-word-face))
;; (goto-char (min (1+ hywiki--end) (point-max))))))
(unless (and region-start region-end
(or (/= region-start (point-min))
(/= region-end (point-max))))
(setq hywiki-buffer-highlighted-state 'h))))
(setq case-fold-search hywiki--save-case-fold-search
hywiki-org-link-type-required hywiki--save-org-link-type-required)))
;; Otherwise, dehighlight HyWikiWords in this buffer when
;; 'hywiki-mode' is disabled or set to ':pages' and this is not a
;; HyWiki page buffer. If this is a HyWiki page buffer, then
;; dehighlight when `hywiki-mode' is disabled.
(hywiki-maybe-dehighlight-references region-start region-end))
(unless (hyperb:stack-frame '(hywiki-maybe-highlight-wikiwords-in-frame))
(hywiki-maybe-directory-updated))
nil)