Function: hywiki-get-entry

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

Signature

(hywiki-get-entry REFERENCE &optional DISPLAY-FLAG FILE REGEXP-FLAG)

Documentation

Return a string of the first HyWiki entry headline containing REFERENCE.

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

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

Get definition from HyWiki's Glossary.org, optional FILE, or the current buffer for #in-file references. Trigger an error if an invalid non-nil FILE argument is sent.

With optional prefix arg, REGEXP-FLAG, treat REFERENCE as a regular expression instead of a string.

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.
|------------------+------+---------------+----------------------------------|
| REFERENCE | 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-entry (reference &optional display-flag file regexp-flag)
  "Return a string of the first HyWiki entry headline containing REFERENCE.
Return nil if REFERENCE is not a string, if REFERENCE is the empty string or
no match is found.

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

Get definition from HyWiki's Glossary.org, optional FILE, or the current
buffer for #in-file references.  Trigger an error if an invalid non-nil FILE
argument is sent.

With optional prefix arg, REGEXP-FLAG, treat REFERENCE as a regular
expression instead of a string.

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.
|------------------+------+---------------+----------------------------------|
| REFERENCE        | 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                   |
|------------------+------+---------------+----------------------------------|"
  (interactive (list (hywiki-read-headline-regexp "Return")
		     current-prefix-arg))
  (when (and (stringp reference) (not (string-empty-p reference)))
    (let ((hyrolo-display-buffer hywiki-glossary-display-buffer)
          (buf-file buffer-file-name)
          (found 0)
          (word-end (hywiki-word-is-p reference t))
          (consult-flag (and (called-interactively-p 'interactive) (hsys-consult-active-p)))
          (phrase "")
          entry-to-match
          path-list)
      (save-window-excursion
        (with-current-buffer (get-buffer-create hywiki-glossary-display-buffer)
          (setq hyrolo-display-buffer hywiki-glossary-display-buffer)
          ;; (hyrolo--cache-initialize)
	  (cond ((or consult-flag
                     (not (string-match-p "#" reference))
                     (not word-end))
                 (setq phrase ""
                       entry-to-match reference))
                (word-end
                 (setq phrase (string-trim (substring reference 0 word-end))
                       entry-to-match (unless (= word-end (length reference))
                                        (string-trim (substring reference (1+ word-end)))))))
          ;; If path-list remains nil, then search will be across the whole wiki
          (cond ((stringp file)
                 ;; explicit `file' given
                 (setq path-list (list (expand-file-name file hywiki-directory))))
                ((and (not consult-flag) (string-match-p "\\`#" reference))
                 ;; in-file reference
                 (setq entry-to-match (substring reference 1)
                       path-list (if buf-file
                                     (list buf-file)
                                   (user-error "(hywiki-get-entry): #section not allowed in non-file buffer: reference = %s; buffer = %S"
                                               reference (get-buffer buf-file)))))
                ((not (string-empty-p phrase))
                 ;; The phrase is a WikiWord; use this as the file to search
                 (setq path-list (list (expand-file-name
                                        (concat phrase
                                                (unless (string-suffix-p hywiki-file-extension phrase)
                                                  hywiki-file-extension))
                                        hywiki-directory)))))

          (unless entry-to-match
            (error "(hywiki-get-entry): No `entry-to-match' derivable from \"%s\""
                   reference))

          (save-excursion
            (setq found
                  (if (and consult-flag
                           (or path-list
                               ;; Extract `name' from the line-numbered
                               ;; `consult-grep' match results
                               (string-match "\\([^ \t\n\r\"'`]*[^ \t\n\r:\"'`0-9]\\): ?\\([1-9][0-9]*\\)[ :]"
                                             reference)))
		      (hyrolo-grep-file (if path-list (car path-list) (match-string-no-properties 1 reference))
                                        (funcall (if regexp-flag #'identity #'regexp-quote)
                                                 (if path-list
                                                     entry-to-match
                                                   (substring reference (match-end 0))))
                                        -1 nil t)
                    (hyrolo-grep (if regexp-flag entry-to-match (regexp-quote entry-to-match))
                                 -1
                                 (hyrolo-expand-path-list (or path-list (list hywiki-directory)))
                                 nil t (not display-flag)))))))
      (if display-flag
          (if (zerop found)
              (progn (beep)
                     (message "(hywiki-get-entry): No match for `%s' found in `%s'"
                              reference
                              (or path-list hywiki-directory))
                     nil)
            ;; Display even if no entries are found
            (hyrolo-display-matches)
            ;; skip past header to the entry
            (hyrolo-to-next-entry)
            t)
        (unless (zerop found)
          (with-current-buffer hyrolo-display-buffer
            (save-excursion
              (goto-char (point-min))
              ;; skip past header to the entry
              (hyrolo-to-next-entry)
              (buffer-substring (point) (point-max)))))))))