Function: actypes::link-to-denote

actypes::link-to-denote is an interactive and byte-compiled function defined in hsys-denote.el.

Signature

(actypes::link-to-denote ID-AND-SECTION &optional FILE)

Documentation

Display a denote entry given by ID-AND-SECTION and optional FILE.

ID-AND-SECTION optionally may be prefixed with "denote:" and may be suffixed with:

  1. #section or ::*section, where section is any exact match to a denote
     in-file heading;
or
  2. ::#section-id, where section-id is an Org id linking to a section.

Optional FILE is the denote file to display. If given, the file is displayed ignoring any information in ID-AND-SECTION.

This does nothing if denote has not been installed. If installed and ID-AND-SECTION or FILE is not found, trigger an error.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260822.1645/hsys-denote.el
(defact link-to-denote (id-and-section &optional file)
  "Display a denote entry given by ID-AND-SECTION and optional FILE.
ID-AND-SECTION optionally may be prefixed with \"denote:\" and may be
suffixed with:

  1. #section or ::*section, where section is any exact match to a denote
     in-file heading;
or
  2. ::#section-id, where section-id is an Org id linking to a section.

Optional FILE is the denote file to display.  If given, the file is
displayed ignoring any information in ID-AND-SECTION.

This does nothing if denote has not been installed.  If installed
and ID-AND-SECTION or FILE is not found, trigger an error."
  (interactive
   (if (require 'denote nil t)
       (let ((file (denote-file-prompt
		    nil ;; for default: (denote-get-identifier-at-point)
		    "Get denote entry id" nil t)))
	 (if (stringp file)
	     (list (denote-extract-id-from-string file) file)
	   '(nil nil)))
     '(nil nil)))
  (when (require 'denote nil t)
    (if (and (stringp file) (not (string-empty-p file)))
        (if (file-readable-p file)
	    (hpath:find file)
	  (hypb:error "(link-to-denote): File is unreadable: \"%s\""
		      file))
      (if (stringp id-and-section)
	  ;; Remove any "denote:" prefix
	  (let ((file-id (denote-extract-id-from-string id-and-section))
                (section (when (and (string-match (hys-denote-get-link-regexp)
                                                  id-and-section)
                                    ;; section start, if any
                                    (match-beginning 5))
                           ;; Don't use `match-string-no-properties' here
                           ;; because it doesn't allow spaces in the section
                           ;; name
                           (substring-no-properties id-and-section
                                                    (match-beginning 5))))
                (section-prefix (match-string-no-properties 4 id-and-section)))
            (if (and section-prefix
                     ;; An Org section/heading id
                     (or (string-equal "::#" section-prefix)
                         (hsys-org-uuid-is-p section)))
                (hact 'link-to-org-id section)
	      (setq file (denote-get-path-by-id file-id))
              (if (and file (file-readable-p file))
                  ;; Change the section prefix to # since `hpath:find'
                  ;; only understands the # syntax
		  (hpath:find (if section (concat file "#" section) file))
                (hypb:error "(link-to-denote): File from ID \"%s\" is unreadable: \"%s\""
			    id-and-section file))))
        (hypb:error "(link-to-denote): Invalid file ID and optional section: \"%s\""
                    id-and-section)))))