protesilaos / denote

Simple notes for Emacs with an efficient file-naming scheme

Home Page:https://protesilaos.com/emacs/denote

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option to ask `y` or `n` just once from `denote-rename-file`

mentalisttraceur opened this issue · comments

One of the things I immediately monkey-patched in Denote once I started using it was to disable just the frontmatter rewrite confirmation (but not the file rename confirmation) in my calls to denote-rename-file.

I didn't want to disable all confirmation in interactive calls. It's very useful to be asked so that I can double-check/abort if I made a mistake.

I just didn't want two confirmations, nor to have the number of confirmations depend on the type and location of the file (I like my UX uniform so that the same muscle memory applies to all uses of the same operation, and I can already start executing movements for the next operation without having to make my movements conditional on more specific information - a confirmation that's only asked for file renames when that file can have Denote frontmatter complects one more thing into my thinking+movements).

If I take the time to check that my inputs were correct and I'm operating on the right file, questions to which the sluggified file name confirmation is an almost-complete and concise answer, then as a user of Denote's stable releases, I trust that the front matter rewrite code is going to do the right thing.


The way I currently do it basically looks like this (except my actual wrapper does more than this):

(defun hack-denote-rewrite-front-matter
        (denote-rewrite-front-matter path &rest arguments)
    (with-advice ('y-or-n-p :override 'always)
        (apply denote-rewrite-front-matter path arguments)))

(defun my-denote-rename-file-wrapper (...)
    (with-advice ('denote-rename-file :around 'hack-denote-rename-file)
        (denote-rename-file ...)))

A more complete version would have to also advise denote--add-front-matter:

(defun suppress-denote-front-matter-y-or-n-p (function path &rest arguments)
    (with-advice ('y-or-n-p :override 'always)
        (apply function path arguments)))

(defun my-denote-rename-file-wrapper (...)
    (with-advice ('denote-rewrite-front-matter
                      :around 'suppress-denote-front-matter-y-or-n-p
                  'denote--add-front-matter
                      :around 'suppress-denote-front-matter-y-or-n-p)
        (denote-rename-file ...)))

I'd appreciate support in-package for this.

The lisp advice to do it externally has to be coupled to implementation details, and has to be more complicated than support in-package would be - note, in particular, that with-advice doesn't ship with Emacs, so you must either hand-roll that with unwind-protect, or use some other way if you want to limit the behavior change to just these calls - the only way to make it simpler from the outside is to suppress confirmation in more cases.

Since you already have denote-rename-no-confirm, where t disables both prompts, you could extend it to use a symbol for more granularity. For example, 'front-matter could mean the "no confirm" applies to just the frontmatter update/insert (and if you want symmetry, 'file-name could apply it to just the rename).

One possibly useful additional enhancement is to allow narrowing confirm suppression to just frontmatter rewrite (but still ask to confirm in frontmatter add). Suggested denote-rename-no-confirm value: 'front-matter-rewrite.

This would make sense because changing front matter is basically the default use case, but adding front matter is a more irregular situation which you might want to be notified about.

This should be fixed around May (or June). See my comment in #299.

May or June arrived earlier than usual ;) I just merged the contribution of @jeanphilippegg which should fix this issue. Please check.

Yep, the design of that change looks good to me. Thank you!