Zettelkasten Forum


Making Zetteldeft work like The Archive

After spending the whole day trying to make Zetteldeft work on markdown and with the conventions I use on The Archive, I finally made it work and wanted to share it with you all. If youre a noob like me and you are using Doom Emacs, I guess you can copy and paste the following into your config.el file and try.

The naming convention I use for The Archive is: 12 digits as UID as generated when pressing CMD U-some-words-for-reference.md- They look like: 202101240843-note-about-something.md.

Links are also The Archive standard: [[UID]] and looks like: [[202101240444]].

I'm not using tags so I'm not sure if there's more configuration needed.

The part of config.el refered to Deft and Zetteldeft is:

(use-package deft
  :ensure t
  :init
   (setq deft-extensions '("md")
         deft-default-extension "md"
         deft-directory "~/notes" ;; Change accordingly
         deft-use-filename-as-title t
         deft-recursive t))

(use-package zetteldeft
  :ensure t
  :after deft
  :config (zetteldeft-set-classic-keybindings)
  :init
       (setq zetteldeft-link-indicator "[["
             zetteldeft-link-suffix "]]"
             zetteldeft-title-prefix "# "
             zetteldeft-list-prefix "* "
             zetteldeft-id-format "%Y%m%d%H%M"
             zetteldeft-id-regex "[0-9]\\{12\\}"))

(font-lock-add-keywords 'markdown-mode
   `((,zetteldeft-id-regex
      . font-lock-warning-face)))

(font-lock-add-keywords 'markdown-mode
   `((,(concat "\\[\\["
               zetteldeft-id-regex
               "\\]\\]")
      . font-lock-warning-face)))

I am far from being able to contribute to the code but I hope the complete example helps absolute newcomers to Emacs to use @EFLS amazing work.

I leave part from my system information in case is needed to compare (obtained through M-x doom/info)

EMACS   dir        ~/.emacs.d/
        version    27.1
        build      Nov 14, 2020
DOOM    dir        ~/.doom.d/
        version    2.0.9
        elc-files  0
        modules    (:completion company ivy :ui deft doom doom-dashboard doom-quit hl-todo modeline ophints (popup +defaults) vc-gutter vi-tilde-fringe workspaces zen :editor (evil +everywhere) file-templates fold snippets :emacs dired electric undo vc :checkers syntax :tools (eval +overlay) lookup magit :os macos :lang emacs-lisp markdown (org +journal +pretty) sh :config (default +bindings +smartparens))
        packages   ((eww) (zetteldeft))
        unpin      (n/a)
        elpa       (n/a)

Comments

  • Oh this is great! Happy to see that you got Zetteldeft to mimic The Archive so closely. I've never used The Archive so I haven't been able to attempt this myself.

    If it works satisfactorily, I should add your setup to the zd-tutorial

  • I know Deft can open the current file in another pane using C-o. Does it have a follow mode that will automatically display the contents of the file under the cursor in another pane? That's one thing I miss from The Archive - being able to quickly scroll through my notes and see their contents.

  • If using deft, a ripgrep wrapper with consult could speed up your query. Not test by myself, but it might be useful to someone.

  • edited January 2021

    @d503
    Awesome. Works pretty well for me. Thanks for posting.

    I switched a while back to a different link convention by using [[UID title of note]]. I had doubts. Now I regret it. So it goes.

    Point of information, there's no need to put :ensure t in your config if you're on Doom. Per the maintainer: ":ensure t does nothing in Doom unless you've set up package.el, which you shouldn't do."
    https://discord.com/channels/406534637242810369/406554085794381833/798915035442315294

    @pat said:
    I know Deft can open the current file in another pane using C-o. Does it have a follow mode that will automatically display the contents of the file under the cursor in another pane? That's one thing I miss from The Archive - being able to quickly scroll through my notes and see their contents.

    C-c d F achieves this.
    https://www.eliasstorms.net/zd-tutorial/2020-02-15-1626 Zetteldeft basic commands.html

  • That's not what I mean.

    When the list of notes is open in Deft, I would like pressing the up/down arrow to automatically display the currently selected note in another pane. It's like when you select a note in The Archive, it displays the note content automatically.

    org-mode has a follow mode, but I haven't figured out something similar for Deft. I always have to manually open each file, whereas I'd prefer to have the current note automatically displayed.

  • @pat said:
    That's not what I mean.

    When the list of notes is open in Deft, I would like pressing the up/down arrow to automatically display the currently selected note in another pane.

    There's always deft-open-file-other-window. I've got it bound to <tab> which is convenient enough.
    As this is Emacs, there's probably a way to automate that, if one keypress is too much (but I wouldn't know what's the most convenient approach to achieve something like that).

  • @pat said:
    That's not what I mean.

    When the list of notes is open in Deft, I would like pressing the up/down arrow to automatically display the currently selected note in another pane. It's like when you select a note in The Archive, it displays the note content automatically.

    org-mode has a follow mode, but I haven't figured out something similar for Deft. I always have to manually open each file, whereas I'd prefer to have the current note automatically displayed.

    Hi @pat

    It is quite easy. Copy the folllowing lines to your Emacs config:

    (defun my-deft-next-line ()
      "Move cursor to the next line.
    When the point is at a widget, open the file in the other window."
      (interactive)
      (call-interactively #'next-line) (deft-open-file-other-window))
    
    (defun my-deft-previous-line ()
      "Move cursor to the previous line.
    When the point is at a widget, open the file in the other window."
      (interactive)
      (call-interactively #'previous-line) (deft-open-file-other-window))
    
    (define-key deft-mode-map (kbd "<down>") 'my-deft-next-line)
    (define-key deft-mode-map (kbd   "<up>") 'my-deft-previous-line)
    

    Enjoy :p

  • @kohled said:

    I switched a while back to a different link convention by using [[UID title of note]]. I had doubts. Now I regret it. So it goes.

    >

    I just figured out some code for generating a link in zetteldeft with the full filename, a la obsidian. This might be helpful for you:

    (defun my-zetteldeft-find-file-filename-insert (file)
      "Find deft file FILE and insert a link with title."
      (interactive (list
                    (completing-read "File to insert full title from: "
                                     (deft-find-all-files-no-prefix))))
      (let ((deft-use-filename-as-title t))
      (insert zetteldeft-link-indicator
              (substring (file-name-sans-extension file) 1 nil)
              zetteldeft-link-suffix
              )))
    

    I don't know how to make the zetteldeft link following work with those yet, but I'm using zetteldeft-search-at-point and it works great.

  • @mediapathic said:

    I just figured out some code for generating a link in zetteldeft with the full filename, a la obsidian. This might be helpful for you:

    I don't know how to make the zetteldeft link following work with those yet, but I'm using zetteldeft-search-at-point and it works great.

    Nice! Thanks so much. Very cool. Looking forward to experimenting with it. My elisp skills are coming surely but slowly.

    This thread got me configuring zetteldeft and whilst through the looking glass, org-roam started calling again. Just incredible software. And since it's built on org-mode... oh man. Seems I've crossed the emacs event horizon.

    Thanks for sharing the code. Much for me to learn. Wishing you well.

Sign In or Register to comment.