I've been using zetteldeft to manage my notes for about six months now. Recently I've been wanting to reorganize my notes as some of them don't follow the zettelkasten principal of one idea per note.
Okay, most of them don't follow that principal if I'm honest about it.
I wanted to slice up my existing notes into smaller files and then link them all together. In my mind the process would go something like:
- Highlight the region to extract.
- Enter a title for the new note.
- Emacs would automatically move the text to the new note and insert a link where it used to be.
Emacs macros are handy for this kind of repeatable behaviour, so I started recording with an example note.
However, I quickly ran into a roadblock due to zetteldeft's behaviour when creating a new note. zetteldeft will create a file, insert the title, and save the file name to the Emacs kill ring. This meant any text I'd copied would be overwritten by the note title.
I decided to abandon the macro method and use a dedicated function instead. I
wrote a little function called sodaware/zd-extract-region-to-note
that
extracts a highlighted region to a new note:
(defun sodaware/zd-extract-region-to-note (title) "Extract the marked region to a new note with TITLE." (interactive (list (read-string "Note title: "))) (let* ((deft-use-filename-as-title t) (note-id (zetteldeft-generate-id title)) (note-filename (concat note-id zetteldeft-id-filename-separator title)) (note-text (kill-region (region-beginning) (region-end)))) (save-excursion (deft-new-file-named note-filename) (zetteldeft--insert-title title) (insert "\n\n") (yank) (save-buffer) (when (featurep 'evil) (evil-insert-state))) (sodaware/zd-insert-link note-filename title))) (defun sodaware/zd-insert-link (note title) "Insert a link to NOTE with TITLE as its link text." (interactive) (insert (format "[[zdlink:%s][%s]]" note title)))
I use the zdlink
protocol for my links, but the sodaware/zd-insert-link
function can be modified to use any kind of link. Eventually I'd like this to be
controlled via a variable.
I'd also like a function that returns focus to the original note after extraction, but for now I'm pretty happy with how things work.
2 Comments
Hi Phil
Yeah, that's a design choice stemming from the early days of Zetteldeft. I thought it would be convenient to insert the link in other notes when it was on the kill-ring. That's not really relevant anymore, and perhaps causes confusion now. Let me know if I should drop it (perhaps via an Issue on Github or something similar).
Also, this looks pretty convenient. Perhaps I should include it (or something similar) in the main codebase.
Cheers
Elias
Hi Elias,
Adding the note file name to the kill ring is not something that I use, but it might be useful to others. I'm always a little hesitant to change existing behaviour in case it breaks people's workflow.
I'm going to make the
sodaware/zd-insert-link
function configurable and then I'll open a pull request with this functionality.Cheers,
Phil