Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
maw opened this issue Aug 17, 2022 · 1 comment

Comments

@maw
Copy link
Contributor

maw commented Aug 17, 2022

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
Copy link
Contributor Author

maw commented Aug 17, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant