EFLS / zetteldeft

A Zettelkasten system! Or rather, some functions on top of the emacs deft package.
https://efls.github.io/zetteldeft
GNU General Public License v3.0
393 stars 42 forks source link

Add `zetteldeft-extract-region-to-note` function #111

Closed Sodaware closed 3 years ago

Sodaware commented 3 years ago

This function extracts a highlighted region into a new note, and replaces the old text with a link to the new note. This is an updated version of the code I wrote about in "Extracting zetteldeft notes" and is more customizable.

By default it inserts a standard zetteldeft link (like § 2021-05-06-1127 Example link), but this can be customized through the zetteldeft-insert-note-link-function variable.

EFLS commented 3 years ago

Thanks Phil! I'll look at the PR over the coming days.

EFLS commented 3 years ago

I think it's a but too much to introduce a new customizable zetteldeft-insert-note-link-function just for this new function.

Could you explain the rationale behind this customization? Is it because you prefer to have links shown differently? (Perhaps Org-mode style?)

I think there are two options:

Sodaware commented 3 years ago

The main reason is because I use zdlink: style links instead of the default § ones. I agree that adding zetteldeft-insert-note-link-function is a little much if it's just used when extracting notes. It could be used in other functions that insert links (like zetteldeft-find-file-id-insert) without too much work.

However, I'm a little hesitant to make that change as I'm not sure it's useful for anyone except me :)

So there's a third option: remove the zetteldeft-insert-note-link-function customization and have zetteldeft-extract-region-to-note insert the default link style. I'm happy to modify this pull request with that change if you think it's better.

EFLS commented 3 years ago

It could be used in other functions that insert links (like zetteldeft-find-file-id-insert) without too much work.

Yeah, and it would allow for greater customization (and even better integration with Org-links for those who prefer that).

There is at least one challenge, though: the default links are either just the link-indicator and identifier (e.g. §2021-05-13-1923) or that plus a title (§2021-05-13-1923 A title). So the zetteldeft-insert-note-link-function should take as arguments an ID and an optional title or description.

This means that for zdlink: type links, which are Org-links, there should be a 'short' version as well

EFLS commented 3 years ago

I made an attempt at implementing a new function called zetteldeft--insert-link with a customizable variable zetteldeft-insert-link-function in #114. @Sodaware, can you take a look to see whether it makes sense like this?

Sodaware commented 3 years ago

Looks good! I think having the option to choose between both link styles makes it clearer as to why the option is there.

EFLS commented 3 years ago

I think having the option to choose between both link styles makes it clearer as to why the option is there.

Yeah, unfortunately I can't seem to get the :options of the defcustom to work properly (or rather, my understanding of the defcustom is a bit limited). In any case, the documentation is there.

EFLS commented 3 years ago

I have now merged the branch with the new zetteldeft--insert-link function and the zetteldeft-insert-link-function variable. Could you rewrite your PR to use these changes?

Also, I think it makes more sense to put your new function under *** New file creation in the .org file, right below the new file and backlink header.

Sodaware commented 3 years ago

I've updated the extract function to use zetteldeft--insert-link. I tested with regular and org-style links and both work great.

I also moved the function to be under the New file creation heading.

EFLS commented 3 years ago

Thanks. I've replaced some of the code so that it makes use of zetteldeft-new-file. I've also included a check to ensure region is active.

Ideally, I'd like to make it so that with a prefix, a backlink is included in the new file, but that would mean the function could only be called from an existing Zetteldeft note (and not from, for example, a general org-agenda file). I'll leave it as it is for now.