protesilaos / denote

Simple notes for Emacs with an efficient file-naming scheme
https://protesilaos.com/emacs/denote
GNU General Public License v3.0
520 stars 55 forks source link

Allow users to custom `denote-org-dblock--get-file-contents`? #202

Open WeissP opened 10 months ago

WeissP commented 10 months ago

Regarding denote-org-dblock-insert-files, users can currently only control inserted file contents via option no-front-matter, could we change this option to something like extractor, which receives a function for extracting file contents?

More detaily, we could modify this part

(when no-front-matter
          (delete-region
           (if (natnump no-front-matter)
               (progn (forward-line no-front-matter) (line-beginning-position))
             (1+ (re-search-forward "^$" nil :no-error 1)))
           beginning-of-contents))

to something like

(when extractor (funcall extractor beginning-of-contents))

I havn't yet checked whether it is possible to pass functions via org dynamic block, it is just an idea.

My motivation is to extract only the contents before the first header, in my note system, this serves as a summary of the whole note. Here is what I have written for my extractor:

(defun weiss-denote-extract-summary (beginning-of-contents)
  (delete-region
   (1+ (re-search-forward "^$" nil :no-error 1))
   beginning-of-contents)
  (when (re-search-forward "^\\*+ " nil :no-error 1)      
    (delete-region (pos-bol) (point-max))
    )
  (delete-blank-lines)
  )

Now I have just used advice-add to override denote-org-dblock--get-file-contents to make my custom extractor work, which is of course not a good idea.

protesilaos commented 10 months ago

From: Weiss @.***> Date: Tue, 12 Dec 2023 21:09:51 -0800

[... 19 lines elided]

I havn't yet checked whether it is possible to pass functions via org dynamic block, it is just an idea.

I think this should work by passing the unquoted symbol of the function as the value of the parameter. Like:

:no-front-matter my-function

My motivation is to extract only the contents before the first header, in my note system, this serves as a summary of the whole note. Here is what I have written for my extractor:

[... 14 lines elided]

I think this is a good idea. Let's give it another week before working on it. I just need this extra time to be sure we catch any obvious bugs with the current stable version.

-- Protesilaos Stavrou https://protesilaos.com

protesilaos commented 7 months ago

Hello again @WeissP! It has been a while since we discussed the idea of passing a function to the Denote Org dynamic blocks. This is about how the :no-front-matter should be done. As I noted, I am happy to see this happen. If you have any concrete proposal, please send it.