Function: hywiki-completion-at-point
hywiki-completion-at-point is a byte-compiled function defined in
hywiki.el.
Signature
(hywiki-completion-at-point)
Documentation
Complete a HyWiki reference at point.
Each candidate is an alist with keys: file, line, text, and display.
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20261018.1143/hywiki.el
(defun hywiki-completion-at-point ()
"Complete a HyWiki reference at point.
Each candidate is an alist with keys: file, line, text, and display."
(setq hywiki--start-pos nil
hywiki--end-pos nil)
(let* ((ref-start-end (and (hywiki-active-in-current-buffer-p)
(not (hywiki-non-hook-context-p))
(hywiki-word-at t t)))
(ref (nth 0 ref-start-end))
(start (nth 1 ref-start-end))
(end (nth 2 ref-start-end))
(prefix (and start end (buffer-substring-no-properties start end)))
(existing-wikiword-prefix (when ref (hywiki-word-strip-suffix ref))))
(when prefix
(let* ((default-directory hywiki-directory)
;; set +f ensures globbing is on, so file wildcards are
;; expanded but only within the subshell created by the outer
;; parens
(cmd (format "(set +f && grep -nEH '^([ \t]*\\*+|#\\+TITLE:) +' ./%s*%s)"
existing-wikiword-prefix
hywiki-file-extension))
(output (with-temp-buffer
;; Check exist status and if any error (non-zero),
;; that means there were no HyWiki #section completions,
;; so `output' will be nil. Still need to allow for
;; HyWiki page completions further down.
(when (zerop (call-process-shell-command
cmd nil (current-buffer)))
(buffer-string))))
(lines (when output (split-string output "[\n\r]" t)))
(candidates
(delq nil
(nconc
;; Return only candidates that start with 'existing-wikiword-prefix'
(seq-filter (lambda (str)
(string-prefix-p existing-wikiword-prefix str))
(hywiki-get-referent-list))
(mapcar #'hywiki-format-grep-to-reference lines)))))
(when candidates
(setq hywiki--char-before (char-before start)
hywiki--start-pos start
hywiki--end-pos end)
(list start end candidates
:exclusive 'no
;; For company, allow any non-delim chars in prefix
;; :company-prefix-length t
;; :company-prefix-dirty t
;; Returning the prefix as (string . t) tells Company:
;; 'This is the prefix, and yes, it is currently valid (dirty).'
;; :company-prefix-snapshot (cons ref t)
;; This prevents the minibuffer/Corfu/Company from
;; re-parsing the # as a 'function quote' trigger.
:company-kind (lambda (_) 'keyword)
:annotation-function (lambda (_) " [HyWiki]")
;; Corfu uses this
:exit-function #'hywiki-completion-exit-function))))))