protesilaos / denote

Simple notes for Emacs with an efficient file-naming scheme
https://protesilaos.com/emacs/denote
GNU General Public License v3.0
520 stars 55 forks source link

double `#+title ` when called through keybinding but not through `M-x` #149

Closed JonatanSahar closed 9 months ago

JonatanSahar commented 1 year ago

I started getting note names of the form #+title: #+title: note name, but only when calling denote functions through their keybindings(!).. when I call M-x denote I get the name rendered properly. Any idea how that might happen?

JonatanSahar commented 1 year ago

Ok, so it looks like a sporadic bug - not actually related to keybindings... I just tried again in a bunch of different ways, same filenames, called from same files, both calling denote and denote-link-or-create, but it didn't reproduce. very strange.

JonatanSahar commented 1 year ago

So it definitely happens when I use non english, RTL characters (hebrew in my case), but it happend before with simple, single, english words as well.

protesilaos commented 1 year ago

Hello @JonatanSahar!

Can you share your configuration? I normally use Denote commands via their key bindings and never encountered this issue.

In general, we need a way to reproduce this. Right now I have no guess as to what it could be.

JonatanSahar commented 1 year ago

sure! For the moment I only get this for notes with a hebrew title. you can try "בדיקה" (testing) as an example.

Below is my config, it's mostly copied from your (excellent) documentation:

(use-package! denote :config ;; Remember to check the doc strings of those variables. (setq denote-directory (expand-file-name "~/notes/")) (setq denote-known-keywords '("emacs" "thesis" "finance")) (setq denote-infer-keywords t) (setq denote-sort-keywords t) (setq denote-file-type nil) ; Org is the default, set others here (setq denote-prompts '(title keywords)) (setq denote-excluded-directories-regexp nil) (setq denote-excluded-keywords-regexp nil)

;; Pick dates, where relevant, with Org's advanced interface: (setq denote-date-prompt-use-org-read-date t)

;; Read this manual for how to specify `denote-templates'. We do not ;; include an example here to avoid potential confusion.

;; We allow multi-word keywords by default. The author's personal ;; preference is for single-word keywords for a more rigid workflow. (setq denote-allow-multi-word-keywords t)

(setq denote-date-format nil) ; read doc string

;; By default, we do not show the context of links. We just display ;; file names. This provides a more informative view. (setq denote-backlinks-show-context t)

;; Also see `denote-link-backlinks-display-buffer-action' which is a bit ;; advanced.

;; If you use Markdown or plain text files (Org renders links as buttons ;; right away) (add-hook 'find-file-hook #'denote-link-buttonize-buffer)

;; We use different ways to specify a path for demo purposes. (setq denote-dired-directories (list denote-directory (thread-last denote-directory (expand-file-name "attachments")) (expand-file-name "~/Documents/books")))

;; Generic (great if you rename files Denote-style in lots of places): ;; (add-hook 'dired-mode-hook #'denote-dired-mode) ;; ;; OR if only want it in `denote-dired-directories': (add-hook 'dired-mode-hook #'denote-dired-mode-in-directories)

;; Here is a custom, user-level command from one of the examples we ;; showed in this manual. We define it here and add it to a key binding ;; below. (defun my-denote-journal () "Create an entry tagged 'journal', while prompting for a title." (interactive) (denote (denote--title-prompt) '("journal")))

;; Denote DOES NOT define any key bindings. This is for the user to ;; decide. For example:

(with-eval-after-load 'org-capture (setq denote-org-capture-specifiers "%l\n%i\n%?") (add-to-list 'org-capture-templates '("n" "New note (with denote.el)" plain (file denote-last-path)

'denote-org-capture

               :no-save t
               :immediate-finish nil
               :kill-buffer t
               :jump-to-captured t)))

;; Also check the commands denote-link-after-creating', ;;denote-link-or-create'. You may want to bind them to keys as well )

protesilaos commented 1 year ago

I tried this with different file types. The #+title or equivalent is not duplicated here:

2023-03-31_19:11:00_565x1056

As for your config, I don't see anything there was would break this workflow.

JonatanSahar commented 1 year ago

thanks again for looking into it.. it's very strange.

JonatanSahar commented 1 year ago

I really don't understand what's going on - I've removed everything from my config other than some font and theme (setq ...)s (I'm on doom though, so there are stuff loading other than vanilla emacs) and I now get double #+title regardless of language..

protesilaos commented 1 year ago

Let's try to use a pristine Emacs environment to troubleshoot this.

  1. Find where your denote.el file is stored on your filesystem.

  2. One way to do this is to do M-x find-library and search for denote. Then M-x eval-expression which will bring up a minibuffer prompt. There evaluate:

    (kill-new (expand-file-name (buffer-file-name)))
  3. The above will save the path to your kill ring.

  4. In a terminal emulator or M-x shell do:

    emacs -Q
  5. This will open a new instance of Emacs in a pristine environment. No Doom and no other customisations.

  6. In the *scratch* buffer of emacs -Q, add your configurations like the following and try to reproduce the issue:

    (require 'denote "/full/path/to/what/you/got/denote.el")
    
    ;; Your configurations here
    
    ;; Then try to create a new note and see what happens
JonatanSahar commented 1 year ago

ok, I have a better understanding of it now, or possibly the problem changed.. the problem is not the language, the first note is always created well, but from the second note onwards I get the extra title. I'm not adding anything to org-mode-hook or to text-mode-hook.

I'm getting it with a "vanilla doom" - so doom without my config, but not with proper vanilla emacs.

this is the value of org-mode-hook, but maybe its something else that lazy loads?

(er/add-org-mode-expansions
 (closure
 ((hook . org-mode-hook)
  (--dolist-tail--)
  t)
 (&rest _)
 (add-hook 'before-save-hook 'org-encrypt-entries nil t))
 +lookup--init-org-mode-handlers-h
 (closure
 ((hook . org-mode-hook)
  (--dolist-tail--)
  t)
 (&rest _)
 (add-hook 'before-save-hook 'org-encrypt-entries nil t))
 #[0 "\300\301\302\303\304$\207"
    [add-hook change-major-mode-hook org-show-all append local]
    5]
 #[0 "\300\301\302\303\304$\207"
    [add-hook change-major-mode-hook org-babel-show-result-all append local]
    5]
 org-babel-result-hide-spec
 org-babel-hide-all-hashes
 #[0 "\301\211\207"
    [imenu-create-index-function org-imenu-get-tree]
    2]
 doom-disable-show-paren-mode-h
 doom-disable-show-trailing-whitespace-h
 +org-make-last-point-visible-h
 evil-org-mode
 toc-org-enable
 flyspell-mode
 embrace-org-mode-hook
 org-eldoc-load)

quite frustrating...

JonatanSahar commented 1 year ago

somehow with my own config in place the behavior changes, and it's again only for hebrew notes, regardless of first or second note. it also takes me into insert mode (evil) and marks the entire text of the front matter...

protesilaos commented 1 year ago

@JonatanSahar This must be related to the problem you reported in issue 150. I will label the issue accordingly. Maybe some other Doom user can help us.

protesilaos commented 1 year ago

Another user reported the duplicate #+title on Doom Emacs. It turns out this is a Doom module that can be disabled. It has nothing to do with the underlying language. Discussion on the mailing list: https://lists.sr.ht/~protesilaos/denote/%3Cm2a5t2skb3.fsf%40m4x.org%3E

protesilaos commented 9 months ago

As noted, this is a Doom Emacs behaviour. Closing now.