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
394 stars 42 forks source link

shouldn't zetteldeft--check return nonnil or nil rather than signalling an error? #139

Open maw opened 2 years ago

maw commented 2 years ago

Context: I want to have a menu of personal zetteldeft related functions that changes depending on whether I'm in zetteldeft territory or not.

I created my own version; it's just a rewrite of your version but it returns nil if we're outside of deft:

(defun mw::zetteldeft--check ()
  "this is copied from zetteldeft--check, but doesn't throw errors."
  (and (buffer-file-name)
       (string-match-p
        (regexp-quote (file-truename deft-directory))
        (file-truename (buffer-file-name)))))

Here is how I'm using it:

;; If I ever want these interleaved I could turn them into cons cells
;; or something and filter accordingly below
(setq mw::zetteldeft-ui-helper-functions-in-deft
      '(mw::zetteldeft-cleanup-tags
        mw::zetteldeft-add-tag 
        mw::zetteldeft-insert-template))
(setq mw::zetteldeft-ui-helper-functions-anywhere
      '(mw-zetteldeft-find-notes-tagged-with
        mw::zetteldeft-find-file))
;; I might someday want a list of functions -only-outside-deft, but so far I
;; haven't had a need.
(defun mw::zetteldeft-custom-function ()
  (interactive)
  (let* ((in-deft (mw::zetteldeft--check))
         (pool (-concat (if in-deft
                            mw::zetteldeft-ui-helper-functions-in-deft
                          nil)
                        mw::zetteldeft-ui-helper-functions-anywhere))
         (func (funcall #'helm-comp-read ;; zetteldeft-completing-read
                        "run: "
                        pool))
         (symbol (intern func)))
    (funcall symbol)))
maw commented 2 years ago

I'm aware that this might require seven functions in zetteldeft.org to be rewritten -- not to mention its impact on an unknown amount of third party code that depends on zetteldeft--check. So, I wouldn't change zetteldeft--check just yet.

There's probably a good way to keep zetteldeft--check's behavior, create an unexceptional function that does basically the same thing, and not duplicate much code, but I haven't worked it out yet.