PROJECTS NOTES HOME

attempt to modify denote links to suite ox-publish

NOTE: still in progress

This - https://github.com/protesilaos/denote/issues/369

First time doing such debugging.

Elisp code examples:

;; only journal
(let ((table (denote-retrieve-filename-title "~/GIT/devnotes/20240217T103305--journal__personal.org")))
  (message "Title: %s" table))

;; full name
(let ((table (ag-denote-retrieve-filename-identifier "~/GIT/devnotes/20240217T103305--journal__personal.org")))
  (message "Title: %s" table))

;; full name
(let ((table (denote--link-get-description "~/GIT/devnotes/20240217T103305--journal__personal.org")))
  (message "Title: %s" table))

;; ----------------------------------------------------------------

(defun ag-denote-link (file file-type description &optional id-only)
  "Create link to FILE note in variable `denote-directory' with DESCRIPTION.

When called interactively, prompt for FILE using completion.  In
this case, derive FILE-TYPE from the current buffer.

The DESCRIPTION is returned by the function specified in variable
`denote-link-description-function'.  If the region is active, its
content is deleted and can be used as the description of the
link.  The default value of `denote-link-description-function'
returns the content of the active region, if any, else the title
of the linked file is used as the description.  The title comes
either from the front matter or the file name.  Note that if you
change the default value of `denote-link-description-function',
make sure to use the `region-text' parameter.  Regardless of the
value of this user option, `denote-link' will always replace the
content of the active region.

With optional ID-ONLY as a non-nil argument, such as with a
universal prefix (\\[universal-argument]), insert links with just
the identifier and no further description.  In this case, the
link format is always [[denote:IDENTIFIER]].  If the DESCRIPTION
is empty, the link is also as if ID-ONLY were non-nil.  The
default value of `denote-link-description-function' returns an
empty string when the region is empty.  Thus, the link will have
no description in this case.

When called from Lisp, FILE is a string representing a full file
system path.  FILE-TYPE is a symbol as described in
`denote-file-type'.  DESCRIPTION is a string.  Whether the caller
treats the active region specially, is up to it."
  (interactive
   (let* ((file (denote-file-prompt nil "Link to FILE"))
          (file-type (denote-filetype-heuristics buffer-file-name))
          (description (when (file-exists-p file)
                         (denote--link-get-description file))))
       (list file file-type description current-prefix-arg)))
  (unless (or (denote--file-type-org-capture-p)
              (and buffer-file-name (denote-file-has-supported-extension-p buffer-file-name)))
    (user-error "The current file type is not recognized by Denote"))
  (unless (file-exists-p file)
    (user-error "The linked file does not exist"))
  (let* ((beg (point)))
    (denote--delete-active-region-content)
    (insert (ag-denote-format-link file description file-type id-only))
    (unless (derived-mode-p 'org-mode)
      (make-button beg (point) 'type 'denote-link-button))))


(defun ag-denote-format-link (file description file-type id-only)
  "Prepare link to FILE using DESCRIPTION.

FILE-TYPE and ID-ONLY are used to get the format of the link.
See the `:link' property of `denote-file-types'."
  ;; Print the arguments to the message buffer
  (message "File: %s" file)
  (message "Description: %s" description)
  (message "File type: %s" file-type)
  (message "ID only: %s" id-only)
  (format
   (if
       (or id-only (null description) (string-empty-p description)) ;; If any of these 3 conditions are true, the overall condition will be true
       denote-id-only-link-format ;; if true do this
     (denote--link-format file-type) ;; if false do this
     )
   (denote-retrieve-filename-identifier file) ;cia yra tai, kas matosi pirmuose skliaustuose po denote

   description                          ;cia yra tai, kas matosi antruose skliaustuose

   ))


(defun test ()
  (let* ((file "~/GIT/devnotes/20240217T103305--journal__personal.org")
         ;; (file-type (denote-filetype-heuristics file))
         (file-type 'org)
         (description nil)
         (id-only nil))
    ;; (message "File type: %s" file-type)
    (message (denote-format-link file description file-type id-only))
    ))

(test)


(defun my-test-insert-denote-link ()
  "Test inserting a Denote link with specific arguments."
  (let* ((file "~/GIT/devnotes/20240217T103305--journal__personal.org")
         ;; (file-type (denote-filetype-heuristics file))
         (file-type 'org)
         (description nil)
         (id-only nil))
    ;; (message "File type: %s" file-type)
    (message (denote-format-link file description file-type id-only))
    ))

(my-test-insert-denote-link)

(global-set-key (kbd "C-c n a") 'ag-denote-link)