Function: hywiki-word-at
hywiki-word-at is a byte-compiled function defined in hywiki.el.
Signature
(hywiki-word-at &optional RANGE-FLAG HASH-SIGN-ONLY-FLAG)
Documentation
Return potential HyWikiWord and optional #section:Lnum:Cnum at point or nil.
hywiki-mode(var)/hywiki-mode(fun) must be enabled or this will return nil.
If the HyWikiWord is delimited, point must be within the delimiters. This works regardless of whether the HyWikiWord has been highlighted or not.
With optional RANGE-FLAG, return a list of (HyWikiWord start-position end-position); the positions include the entire HyWikiWord#section:Lnum:Cnum string but exclude any delimiters.
This does not test whether a referent exists for the HyWikiWord; call
hywiki-referent-exists-p without an argument for that. Nor does it
test whether the HyWikiWord reference is within a valid context; call
hywiki-non-hook-context-p for that.
A call to hywiki-active-in-current-buffer-p at point must return
non-nil or this will return nil.
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hywiki.el
(defun hywiki-word-at (&optional range-flag hash-sign-only-flag)
"Return potential HyWikiWord and optional #section:Lnum:Cnum at point or nil.
`hywiki-mode' must be enabled or this will return nil.
If the HyWikiWord is delimited, point must be within the delimiters.
This works regardless of whether the HyWikiWord has been highlighted
or not.
With optional RANGE-FLAG, return a list of (HyWikiWord start-position
end-position); the positions include the entire
HyWikiWord#section:Lnum:Cnum string but exclude any delimiters.
This does not test whether a referent exists for the HyWikiWord; call
`hywiki-referent-exists-p' without an argument for that. Nor does it
test whether the HyWikiWord reference is within a valid context; call
`hywiki-non-hook-context-p' for that.
A call to `hywiki-active-in-current-buffer-p' at point must return
non-nil or this will return nil."
(if (hywiki-active-in-current-buffer-p)
(save-excursion
;; First look for an Org-type [[hy:WikiWord]] reference.
;; Don't use `cl-destructuring-bind' here since the `hargs:delimited' call
;; can return nil rather than the 3 arg list that would be required
(let* ((start-regexp (concat "\\[\\[\\(" hywiki-org-link-type ":\\)?"))
(opoint (point))
(hywiki-org-link-type-flag)
(wikiword-start-end
(save-excursion
(skip-chars-backward (concat hywiki-org-link-type ":["))
(when (looking-at start-regexp)
(setq hywiki-org-link-type-flag (match-string 1))
(goto-char opoint)
;; This next line drops any `hywiki-org-link-type': from the
;; start of the WikiWord since it is part of the delimiter used.
(hargs:delimited (concat "\\[\\[\\(" hywiki-org-link-type ":\\)?")
"\\(\\]\\[\\|\\]\\]\\)" t t t))))
(wikiword (nth 0 wikiword-start-end))
(start (nth 1 wikiword-start-end))
(end (nth 2 wikiword-start-end)))
(with-syntax-table hywiki--org-mode-syntax-table
(if (and (cond (wikiword
;; Enforce `hywiki-org-link-type-required' setting
(unless (and hywiki-org-link-type-required
(not hywiki-org-link-type-flag))
;; Handle an Org link [[HyWikiWord]] [[hy:HyWikiWord]]
;; or [[HyWikiWord#section][Description Text]].
;; Get the HyWikiWord link reference, ignoring any
;; description given in the link.
;;
;; Don't use next line so don't have to load all of Org
;; mode just to check for HyWikiWords; however,
;; ignoring this disables support for Org mode aliases.
;; (setq wikiword (org-link-expand-abbrev (org-link-unescape (string-trim wikiword))))
(setq wikiword (hywiki-strip-org-link wikiword))
(when (and wikiword end)
;; Update start and end to newly stripped
;; string positions
(save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
(when (search-forward wikiword nil t)
(setq start (match-beginning 0)
end (match-end 0))))))
(hywiki-word-is-p wikiword)))
;; Handle a delimited HyWikiWord reference with
;; multiple, possibly whitespace-separated words in
;; its section, e.g. (MyWikiWord#one two three).
;; Whitespace between section words is allowed only
;; if the delimiters are immediately before and
;; after a single HyWikiWord reference.
((let ((case-fold-search nil)
(bol (line-beginning-position))
opoint)
;; May be a non-delimiter but HyWikiWord ending
;; punctuation to skip past
(skip-chars-backward (hywiki-get-buttonize-characters) bol)
(setq opoint (point))
(when (setq wikiword-start-end (hywiki-delimited-p)) ;; limited to 2 lines
(setq start (nth 1 wikiword-start-end)
end (nth 2 wikiword-start-end))
(goto-char start)
(if (and (save-restriction
(narrow-to-region (point) end)
(looking-at hywiki-word-with-optional-suffix-exact-regexp))
;; WikiWord ref is the entirety of the string
(= end (match-end 0))
;; Can't be followed by a # character
(/= (or (char-after (match-end 0)) 0)
?#))
(setq wikiword (match-string-no-properties 0)
start (match-beginning 0)
end (match-end 0))
(goto-char opoint)
(unless (or (progn
(skip-chars-backward "-_*#:[:alnum:]" bol)
(hywiki-maybe-at-wikiword-beginning))
(progn
;; Skip past HyWikiWord or section with
;; possible whitespace
(skip-syntax-backward "^$()<>._\"\'" bol)
(unless (= (or (char-before) 0) ?#)
(goto-char opoint)
(skip-syntax-backward "^-$()<>._\"\'" bol))
;; Move to start of wikiword reference
(skip-chars-backward "-_*#:[:alnum:]" bol)
(skip-syntax-backward "-" bol)
;; Preceding char must now be the
;; opening delimiter or else there may
;; be multiple non-section words within
;; the delimiters, so reprocess and do
;; not allow spaces in the #section part
(memq (char-syntax (or (char-before) 0))
'(?\( ?\< ?\"))))
(goto-char opoint)
(skip-syntax-backward "^-$()<>._\"\'" bol)
;; Move to start of wikiword reference
(skip-chars-backward "-_*#:[:alnum:]" bol)
(skip-syntax-backward "-" bol))
(when (and
;; (or (bolp)
;; (string-match (regexp-quote
;; (char-to-string (char-before)))
;; "\[\(\{\<\""))
(progn
(skip-chars-forward " \t")
(hywiki-maybe-at-wikiword-beginning))
(looking-at (concat
hywiki-word-regexp
"\\(#[^][#()<>{}\" \t\n\r\f]*\\)?"
hywiki-word-line-and-column-numbers-regexp "?"))
;; Can't be followed by a # character
(/= (or (char-after (match-end 0)) 0)
?#)
(progn (goto-char (match-end 0))
(skip-syntax-forward "-")))
(setq start (match-beginning 0)
end (match-end 0)
;; No following char
wikiword (string-trim
(buffer-substring-no-properties start end))))))))
;; Handle a non-delimited HyWikiWord reference
;; with multiple dash-separated words in its section,
;; e.g. WikiWord#one-two-three.
((let ((case-fold-search nil)
(bol (line-beginning-position))
opoint)
;; May be a non-delimiter but HyWikiWord ending
;; punctuation to skip past
(skip-chars-backward (hywiki-get-buttonize-characters) bol)
(setq opoint (point))
(goto-char opoint)
(skip-syntax-backward "^-$()<>._\"\'" bol)
;; Move to start of wikiword reference
(skip-chars-backward "-_*#:[:alnum:]" bol)
(skip-syntax-backward "-" bol)
(when (and (or (bolp)
(string-match (regexp-quote
(char-to-string (char-before)))
"\[\(\{\<\""))
(progn
(skip-chars-forward " \t")
(hywiki-maybe-at-wikiword-beginning))
(looking-at (concat
hywiki-word-regexp
"\\(#[^][#()<>{}\" \t\n\r\f]+\\)?"
hywiki-word-line-and-column-numbers-regexp "?"))
;; Can't be followed by a # character
(/= (or (char-after (match-end 0)) 0)
?#)
(goto-char (match-end 0)))
(setq start (match-beginning 0)
end (match-end 0)
;; No following char
wikiword (string-trim (match-string-no-properties 0))))))
;; Handle a non-delimited HyWikiWord reference with
;; optional #section:Lnum:Cnum; if it is an Org
;; link, it may optionally have a hy: link-type
;; prefix. #section may not contain spaces. Ignore
;; wikiwords preceded by any non-whitespace
;; character, except any of these: "([\"'`'"
(t (let ((case-fold-search nil))
(skip-chars-forward " \t")
(when (hywiki-maybe-at-wikiword-beginning)
(when (looking-at (concat hywiki-org-link-type ":"))
(goto-char (match-end 0)))
(cond ((looking-at hywiki--word-and-buttonize-character-regexp)
(setq start (match-beginning 1)
end (match-end 1)
wikiword (string-trim (match-string-no-properties 1))))
((or (and (looking-at hywiki-word-with-optional-suffix-regexp)
;; Can't be followed by a # character
(/= (or (char-after (match-end 0)) 0)
?#))
(and hash-sign-only-flag
(looking-at (concat hywiki-word-regexp "#"))))
(setq start (match-beginning 0)
end (match-end 0)
;; No following char
wikiword (string-trim (match-string-no-properties 0)))))))))
;; If `wikiword' reference has a #section, ensure
;; it stops when there are any disallowed characters
;; and reset the value of 'end' to match any reduction.
;; One set of \n\r characters is allowed but no
;; whitespace at the end of the reference.
(if (and (stringp wikiword) (string-match "#" wikiword))
(let ((section-regexp "#[^][#()<>{}\"\f]*[^][#()<>{}\"\f\t\n\r ]"))
(when (string-match
(if hash-sign-only-flag
(concat "#\\'\\|" section-regexp)
section-regexp)
wikiword)
(setq end (- end (- (length wikiword)
(match-end 0)))
wikiword (substring wikiword 0 (match-end 0)))))
t))
(if range-flag
(list wikiword start end)
wikiword)
(when range-flag
'(nil nil nil))))))
(when range-flag
'(nil nil nil))))