# Org-capture error's MSWindows

**URL:** https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848
**Category:** Emacs
**Created:** [July 9, 2024, 5:21pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848 "2024-07-09T17:21:31Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Splendorous\_Triangle](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@Splendorous\_Triangle](https://forum.systemcrafters.net/u/Splendorous_Triangle)
#### Post date: [July 9, 2024, 5:21pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/1 "2024-07-09T17:21:31Z")

</div>

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`:

```lisp
(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*`:

```lisp
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:

```auto
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: "

```lisp
;; ...
	(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](https://orgmode.org/manual/Capture-templates.html) 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.

---

<div class="post-metadata">

### Author: ![wolfjb](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/wolfjb/32/428_2.png) [@wolfjb](https://forum.systemcrafters.net/u/wolfjb)
#### Post date: [July 10, 2024, 5:27pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/2 "2024-07-10T17:27:07Z")

</div>

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`.

---

<div class="post-metadata">

### Author: ![Splendorous\_Triangle](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@Splendorous\_Triangle](https://forum.systemcrafters.net/u/Splendorous_Triangle)
#### Post date: [July 12, 2024, 4:29pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/3 "2024-07-12T16:29:51Z")

</div>

So running `org-capture` under `edebug` yields some observations:

When I get to line 679

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

```

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

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

```

But then at line 681:

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

```

This error pops up repeatedly

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

```

Which eventually trips the error handling further down on line 712

```lisp
	(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.

---

<div class="post-metadata">

### Author: ![altomcat](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/altomcat/32/583_2.png) [@altomcat](https://forum.systemcrafters.net/u/altomcat)
#### Post date: [July 14, 2024, 1:48pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/4 "2024-07-14T13:48:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Splendorous\_Triangle](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@Splendorous\_Triangle](https://forum.systemcrafters.net/u/Splendorous_Triangle)
#### Post date: [July 15, 2024, 4:16pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/5 "2024-07-15T16:16:01Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ashraz](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ashraz/32/509_2.png) [@ashraz](https://forum.systemcrafters.net/u/ashraz)
#### Post date: [July 16, 2024, 6:22pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/7 "2024-07-16T18:22:48Z")

</div>

Do you have your complete `init.el` somewhere online?

---

<div class="post-metadata">

### Author: ![Splendorous\_Triangle](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@Splendorous\_Triangle](https://forum.systemcrafters.net/u/Splendorous_Triangle)
#### Post date: [July 18, 2024, 2:26am UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/8 "2024-07-18T02:26:28Z")

</div>

[init.el](https://forum.systemcrafters.net/uploads/short-url/zyhOwFlvA8tLGtnSVCWh8dXzBka.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 🙃

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.

---

<div class="post-metadata">

### Author: ![altomcat](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/altomcat/32/583_2.png) [@altomcat](https://forum.systemcrafters.net/u/altomcat)
#### Post date: [July 18, 2024, 7:43am UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/9 "2024-07-18T07:43:02Z")

</div>

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:

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

```

---

<div class="post-metadata">

### Author: ![Splendorous\_Triangle](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@Splendorous\_Triangle](https://forum.systemcrafters.net/u/Splendorous_Triangle)
#### Post date: [July 18, 2024, 10:53pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/10 "2024-07-18T22:53:45Z")

</div>

So this is the change I made.

```lisp
;; (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.

```lisp
;; (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`.

---

<div class="post-metadata">

### Author: ![ashraz](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ashraz/32/509_2.png) [@ashraz](https://forum.systemcrafters.net/u/ashraz)
#### Post date: [July 19, 2024, 1:29pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/11 "2024-07-19T13:29:16Z")

</div>

> [@altomcat](#):
>
> `(add-hook 'org-mode-hook 'dired-mode-hook)`

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?

---

<div class="post-metadata">

### Author: ![altomcat](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/altomcat/32/583_2.png) [@altomcat](https://forum.systemcrafters.net/u/altomcat)
#### Post date: [July 19, 2024, 2:25pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/12 "2024-07-19T14:25:04Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ashraz](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ashraz/32/509_2.png) [@ashraz](https://forum.systemcrafters.net/u/ashraz)
#### Post date: [July 19, 2024, 2:45pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/13 "2024-07-19T14:45:54Z")

</div>

No worries, you just refactored the original line 😅

---

<div class="post-metadata">

### Author: ![altomcat](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/altomcat/32/583_2.png) [@altomcat](https://forum.systemcrafters.net/u/altomcat)
#### Post date: [July 19, 2024, 3:00pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/14 "2024-07-19T15:00:49Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![Splendorous\_Triangle](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@Splendorous\_Triangle](https://forum.systemcrafters.net/u/Splendorous_Triangle)
#### Post date: [July 19, 2024, 4:32pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/15 "2024-07-19T16:32:59Z")

</div>

That makes sense 😅  
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

---

<div class="post-metadata">

### Author: ![altomcat](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/altomcat/32/583_2.png) [@altomcat](https://forum.systemcrafters.net/u/altomcat)
#### Post date: [July 19, 2024, 4:40pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/16 "2024-07-19T16:40:52Z")

</div>

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:

```auto
(setq org-pretty-entities t)
(add-hook 'org-mode-hook 'org-toggle-pretty-entities)

```

---

<div class="post-metadata">

### Author: ![Splendorous\_Triangle](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@Splendorous\_Triangle](https://forum.systemcrafters.net/u/Splendorous_Triangle)
#### Post date: [July 19, 2024, 11:54pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/17 "2024-07-19T23:54:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ashraz](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ashraz/32/509_2.png) [@ashraz](https://forum.systemcrafters.net/u/ashraz)
#### Post date: [July 20, 2024, 3:12pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/18 "2024-07-20T15:12:55Z")

</div>

> [@altomcat](#):
>
> ```auto
> (setq org-pretty-entities t)
> (add-hook 'org-mode-hook 'org-toggle-pretty-entities)
> 
> ```

That should be

```auto
(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.

---

<div class="post-metadata">

### Author: ![ashraz](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ashraz/32/509_2.png) [@ashraz](https://forum.systemcrafters.net/u/ashraz)
#### Post date: [July 20, 2024, 3:14pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/19 "2024-07-20T15:14:00Z")

</div>

> [@Splendorous\_Triangle](#):
>
> As for version: GNU Emacs 29.1 (build 2, x86\_64-w64-mingw32) of 2023-07-30

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.

---

<div class="post-metadata">

### Author: ![altomcat](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/altomcat/32/583_2.png) [@altomcat](https://forum.systemcrafters.net/u/altomcat)
#### Post date: [July 20, 2024, 5:13pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/20 "2024-07-20T17:13:33Z")

</div>

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 ?

(

```auto
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"))))

```

---

<div class="post-metadata">

### Author: ![ashraz](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ashraz/32/509_2.png) [@ashraz](https://forum.systemcrafters.net/u/ashraz)
#### Post date: [July 20, 2024, 5:54pm UTC](https://forum.systemcrafters.net/t/org-capture-errors-mswindows/848/21 "2024-07-20T17:54:32Z")

</div>

> [@altomcat](#):
>
> 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 ?

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:

```auto
(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.

```auto
(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.
