Org-capture error's MSWindows

I am having issues configuring org-capture templates on a work machine running windows 10.

I am currently using the standalone emacs 29.1-no-deps.
I have this for capture config in init.el:

(setq org-default-notes-file (expand-file-name "redacted"))

(setq org-capture-templates
      '(("t" "Todo" entry (file+headline "redacted/capture.org" "Tasks")
         "* TODO %?\n  %i\n  %a")
        ;; ("j" "Journal" entry (file+datetree "~/org/journal.org")
        ;;  "* %?\nEntered on %U\n  %i\n  %a")
	))


(defun my-org-capture-debug ()
  (interactive)
  (message "org-capture-templates: %s" org-capture-templates)
  (org-capture))

(global-set-key (kbd "C-c c") 'my-org-capture-debug)

Y’all will have to trust me on the file names. Redacting the paths is maybe excessive but -shrug-.

Anyhow, if I C-c c this is what I get in *Messages*:

org-capture-templates: ((t Todo entry (file+headline redacted/capture.org Tasks) * TODO %?
  %i
  %a))
(New file)
File mode specification error: (wrong-number-of-arguments (0 . 0) 1)
org-capture: Capture abort: Wrong number of arguments: (0 . 0), 1
Quit

This is what I see in the debugger:

Debugger entered--Lisp error: (error "Capture abort: Wrong number of arguments: (0 . 0),...")
  error("Capture abort: %s" "Wrong number of arguments: (0 . 0), 1")
  org-capture()
  my-org-capture-debug()
  funcall-interactively(my-org-capture-debug)
  command-execute(my-org-capture-debug)

That brings me to line 717 in org-capture where I find the string "Capture abort: "

;; ...
	(org-capture-set-target-location (and (equal goto 0) 'here))
	(condition-case error
	    (org-capture-put :template (org-capture-fill-template))
	  ((error quit)
	   (if (get-buffer "*Capture*") (kill-buffer "*Capture*"))
	   (error "Capture abort: %s" (error-message-string error))))
;; ...

I’m really not sure what the problem is. I copied the example from the Capture Templates docs page and changed the path.

My little own little debug function shows the correct path.
I have also tried:

  • windows style paths
  • unix style paths
  • UNC style paths - some parts of emacs seem fine with these others choke on them (also note technically my files are on a network drive)
  • creating a shortcut to my notes directory inside of ~/org

All result in the same error.

You might need to use call-interactively around org-capture. I don’t see anything wrong with your template, so I’m guessing it has to do with how you are calling org-capture. You could also try using edebug and stepping through org-capture.

So running org-capture under edebug yields some observations:

When I get to line 679

(entry (or org-capture-entry (org-capture-select-template-keys)))

I can see the template being retrieve and it looks fine?

Result: ("t" "Todo" entry (file+headline "~/redacted/capt..." "Tasks") "* TODO %?\n  %i\n  %a")

But then at line 681:

      (setq initial (or org-capture-initial
			(and (org-region-active-p)
			     (buffer-substring (point) (mark)))))

This error pops up repeatedly

redisplay--pre-redisplay-functions: (cl-assertion-failed (mark)) [376 times]

Which eventually trips the error handling further down on line 712

	(condition-case error
	    (org-capture-put :template (org-capture-fill-template))
	  ((error quit)
	   (if (get-buffer "*Capture*") (kill-buffer "*Capture*"))
	   (error "Capture abort: %s" (error-message-string error))))

I’m not any clearer on what is going wrong.
This has been an interesting exercise in learning how to use edebug but I’m not sure I know enough lisp or the inner workings of emacs to actually understand what is happening.

Hello @Splendorous_Triangle

Have you try to add (require 'org-capture) at the top of your init.el file ?

I have just download the release you mention and test it on windows 11 with emacs -q from the scratch buffer.
From my side, it’s fully working.

Well it also seems to work on my end with emacs -q which means the problem is somewhere in my init.el.

Unfortunately adding (require 'org-capture) did not fix it.
I do appreciate the sanity check, thank you.

Do you have your complete init.el somewhere online?

init.el (15.8 KB)

I don’t have a public repo for my dotfiles or anything no. I don’t trust myself to not put something important in there by accident :upside_down_face:

I have attached my work init.el here.
It’s a bit of a mess I apologize, all the commented out chunks are things I had setup on my personal machine and figured I wouldn’t need at work or could wait to get setup later.

I redacted a few paths but the placeholder I swapped in with preserves the structure of the path.

Also I’ve only really actively been using emacs for like eight months? So I’m probably doing some silly things in there.
More than happy to hear about how it could be structured better.

Also I realize I should go through and unify the style of file path I am using.

Hello,

It’s just a quick overview on my end but taking a look at the signature of add-hook function, I think line 262 is not right.

(add-hook HOOK FUNCTION &optional DEPTH LOCAL)

I suggest to replace it by something like this:

(add-hook 'org-mode-hook 'dired-mode-hook)
(add-hook 'org-mode-hook (lambda ()
 			               (org-indent-mode 1)
 			               (org-download-enable)))

So this is the change I made.

;; (add-hook 'org-mode-hook 'org-indent-mode 'dired-mode-hook 'org-download-enable) 
(add-hook 'org-mode-hook 'dired-mode-hook)
(add-hook 'org-mode-hook (lambda ()
 			               (org-indent-mode 1)
  			               (org-download-enable)))

Interestingly this changes the error message I get when I try to call org-capture to:
org-capture: Capture abort: Symbol’s function definition is void: dired-mode-hook

Also to be clear, in both instances I don’t get the error until I give org-capture the template key.

If I just do this:
So this is the change I made.

;; (add-hook 'org-mode-hook 'org-indent-mode 'dired-mode-hook 'org-download-enable) 
;;(add-hook 'org-mode-hook 'dired-mode-hook)
(add-hook 'org-mode-hook (lambda ()
 			               (org-indent-mode 1)
  			               (org-download-enable)))

I get the same old org-capture: Capture abort: Wrong number of arguments: (0 . 0), 1.

You don’t add a hook to a hook. If you want to start dired-mode during org-mode, then you’d hook into dired-mode. But you usually never, ever want to run another major mode within another -hook. Never.

That being said, maybe you can try to cut it down to a more minimal init.el that still shows the same behavior. Also, which Emacs version do you use?

I apologize for this mistake and thank you for this explanation.

No worries, you just refactored the original line :sweat_smile:

1 Like

Let’s say the original idea was to enable org-download with dired major mode.

(with-eval-after-load 'org
  (require 'org-download)
  (add-hook 'dired-mode 'org-download-enable))

That makes sense :sweat_smile:
I imagine I was just trying to get things working and not thinking too hard about what I was doing. Not great practice.

This being said, I don’t think these lines in question are related to my issue with the capture templates (although I don’t doubt that they could be causing other problems). I’ve tried commenting them out and the capture problem persists. Also the capture problem predates the addition of org-download to init.el.

As for version: GNU Emacs 29.1 (build 2, x86_64-w64-mingw32) of 2023-07-30

I’ve just find this one in line 233
org-toggle-pretty-entities doesn’t need arguments.

If you want to activate the feature each time you open an org-mode buffer, you need to set the default behavior for ‘org-pretty-entities’ to t. You can replace your code with:

(setq org-pretty-entities t)
(add-hook 'org-mode-hook 'org-toggle-pretty-entities)
1 Like

Ah! That’s the one that did it!
Thank you!

That should be

(setopt org-pretty-entities t)

only within init.el. Otherwise, the (setq org-pretty-entities t) will set the pretty entities enabled, but opening any .org file will automatically toggle the pretty entities to disabled again.

1 Like

I recommend you to change your configuration into a use-package-based one then. That will make it easier to group some of the options. It also eases the hook setup IMHO.

Hey @ashraz,

I wasn’t aware of setopt before. Thanks to let me know. I will dig a bit into the manual and experiment on my end.
BTW, after looking at the code can you confirm that it’s not necessary to set org-pretty-entities to enable it if the function is hooked to org-mode ?

(

defun org-toggle-pretty-entities ()
  "Toggle the composition display of entities as UTF8 characters."
  (interactive)
  (setq-local org-pretty-entities (not org-pretty-entities))
  (org-restart-font-lock)
  (if org-pretty-entities
      (message "Entities are now displayed as UTF8 characters")
    (save-restriction
      (widen)
      (decompose-region (point-min) (point-max))
      (message "Entities are now displayed as plain text"))))

Eh, it’s a bit more complicated. Usually, all toggle functions are user-facing. At least from my understanding, they should not be called within Lisp, but only via M-x (or via a keybinding). The issue with those toggle functions is that they’re not idempotent: calling them again will change the state of the buffer.

Let’s see that in action with a minimal example:

(define-derived-mode example-mode fundamental-mode "Example")

(defun toggle-example ()
    (message "toggled!"))

(add-hook 'example-mode-hook #'toggle-example)

Now go ahead and use M-x example-mode multiple times within the same buffer. You will see that the hook gets called every time. With that, you would toggle the prettification whenever you happen to run org-mode within your current buffer. This can easily happen if you accidentally run another -mode command first and then change back to org-mode, e.g.

(progn
   (org-mode)
   (fundamental-mode) ; do some editing without syntax highligthing to fix a broken org file
   (org-mode))

And suddenly, the prettifications are all off.