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.

(post deleted by author)

Do you have your complete init.el somewhere online?