Function: hywiki-get-definition

hywiki-get-definition is an autoloaded, interactive and byte-compiled function defined in hywiki.el.

Signature

(hywiki-get-definition TERM &optional DISPLAY-FLAG FILE)

Documentation

Return or display the HyWiki glossary definition string for TERM.

Return nil if TERM is not a string, if TERM is the empty string or no match is found.

If called interactively or with optional DISPLAY-FLAG non-nil, display a buffer with TERM's definition but don't return it. Get definition from HyWiki's Glossary.org or optional FILE. If the file is not readable or no matching TERM entry is found, return nil; othewise, return t.

If the consult package is installed, interactively select and complete the entry to be inserted.

Below is a table of how the inputs determine the lookup performed. Only top-level headlines are searched.
|------------------+------+---------------+----------------------------------|
| TERM | FILE | Entry to Find | Entry Target |
|------------------+------+---------------+----------------------------------|
| phrase | file | phrase | HyWiki file specified |
| phrase | nil | phrase | Glossary.org in hywiki-directory |
| WikiWord#section | nil | section | WikiWord.org in hywiki-directory |
| WikiWord | nil | WikiWord | Glossary.org in hywiki-directory |
| #section | nil | section | current buffer |
|------------------+------+---------------+----------------------------------|

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260822.1645/hywiki.el
;;;###autoload
(defun hywiki-get-definition (term &optional display-flag file)
  "Return or display the HyWiki glossary definition string for TERM.
Return nil if TERM is not a string, if TERM is the empty string or no match
is found.

If called interactively or with optional DISPLAY-FLAG non-nil, display a
buffer with TERM's definition but don't return it.  Get definition from
HyWiki's Glossary.org or optional FILE.  If the file is not readable or no
matching TERM entry is found, return nil; othewise, return t.

If the `consult' package is installed, interactively select and complete
the entry to be inserted.

Below is a table of how the inputs determine the lookup performed.  Only
top-level headlines are searched.
|------------------+------+---------------+----------------------------------|
| TERM             | FILE | Entry to Find | Entry Target                     |
|------------------+------+---------------+----------------------------------|
| phrase           | file | phrase        | HyWiki file specified            |
| phrase           | nil  | phrase        | Glossary.org in hywiki-directory |
| WikiWord#section | nil  | section       | WikiWord.org in hywiki-directory |
| WikiWord         | nil  | WikiWord      | Glossary.org in hywiki-directory |
| #section         | nil  | section       | current buffer                   |
|------------------+------+---------------+----------------------------------|"
  ;; Add completing-read here after gathering terms from the Glossary.org file
  (interactive (list (hywiki-completing-read-glossary-term
                      "HyWiki glossary definition of: ")
                     nil t))
  (when (and (stringp term) (not (string-empty-p term)))
    (let ((glossary (hywiki-get-glossary-file file))
          entry
          index
          term-regexp
          wikiword)
      (cond ((setq index (seq-position term ?#))
             ;; WikiWord#section or #section
             (setq wikiword (substring term 0 index)
                   term (substring term (1+ index))
                   term-regexp (hywiki-get-term-variant-regexp term)
                   file (if (zerop index)
                            buffer-file-name
                          (hywiki-get-page-file wikiword))))
            ((or (hywiki-word-is-p term t) (null file))
             ;; Is a WikiWord or phrase only; match to any of several
             ;; forms: WikiWord, wikiword, Wiki Word, wiki word -- in
             ;; file when given or the Glossary file when not
             (when (file-readable-p glossary)
               (setq term-regexp (hywiki-get-term-variant-regexp term))
               (unless (and (stringp file) (not (string-empty-p file)))
                 (setq file glossary))))
            (t
             ;; `file' is non-null so try to use that or trigger an error
             (when (or (not (stringp file)) (string-empty-p file)
                       (not (file-readable-p file)))
               (error "(hywiki-get-definition): \"%s\" is invalid" file))
             (setq term-regexp (hywiki-get-term-variant-regexp term))))

      ;; Return and possibly display matching definition
      (setq entry (hywiki-get-entry term-regexp display-flag file t))

      (when (stringp entry)
        ;; Remove * or # prefix from def entry before returning, so can be
        ;; embedded in other doc
        (setq entry (substring entry (if (string-match "\\`[*#]+[ \t\n\f]*"
                                                       entry)
                                         (match-end 0)
                                       0))))
      entry)))