olivuser · 2022-09-29 06:44
Hej fellows,
in a way this is a follow-up to my post before where paredit hindered `ORG-HTML-EXPORT-TO-HTML`.
**EDIT:** Solved the first problem myself, now I've got another one, see EDIT below.
I realized that not using `PROG-MODE-HOOK` for the activation of my `PROGRAMMING-SETTINGS` is detrimental to my programming workflow. So I wanted to keep the prog-mode stuff as it is and instead hook into the machinery behind org export. However, it seems to work differently, because when I use my "normal" workflow to work with hooks, it errors out, saying "wrong number of arguments".
My normal workflow consists of defining a function that activates or de-activates stuff, and I call the function via `ADD-HOOK`. So far, I've not had problems with this workflow.
(defun my/programming-settings ()
(paredit-mode 1)
(rainbow-delimiters-mode 1)
(column-number-mode 1)
(line-number-mode 1)
(hl-line-mode 1)
(show-paren-mode 1)
(display-line-numbers-mode 1)
(org-indent-mode -1))
(add-hook 'prog-mode-hook 'my/programming-settings)
However, when I try to do the same with the `ORG-EXPORT-BEFORE-PROCESSING-HOOK`, I run into the aforementioned "wrong number of arguments".
(defun my/org-export-settings ()
(paredit-mode -1))
(add-hook 'org-export-before-processing-hook 'my/org-export-settings)
[ ... me trying to export an org file to html via org-html-export-to-html ... ]
org-export-as: Wrong number of arguments: (lambda nil (paredit-mode -1)), 1
Can anyone help me understand what is problematic in my approach or idiomatic about the way `ORG-EXPORT-PROCESSING-HOOK` works?
Have a good day, fellows :)
**EDIT:** I found the solution to the first part of my problem myself. It seems to be necessary to wrap the function to be called into a lambda with the export backend as its argument. If I understand [this stackoverflow post](https://emacs.stackexchange.com/questions/40708/trouble-with-org-export-before-processing-hook-in-emacs) correctly, the correct way of doing what I want in OP is this:
(defun my/org-export-settings ()
(paredit-mode -1))
(add-hook 'org-export-before-processing-hook #'(lambda (html) (my/org-export-settings)))
However, I run into another problem. While I would expect that, after enabling the hook, `PAREDIT-MODE` is disabled while exporting (to html), I run into the "old" error: `paredit-mode: Unmatched bracket or quote`. Any ideas?
7890yuiop · 2022-09-29 07:24
Quoting the hook's documentation:
"Every function in this hook will be called with one argument: the back-end currently used, as a symbol."
Hooks which are called with arguments are known as "abnormal hooks", so your subject line is apt; this is literally not a "normal" hook. Often, but not always, such hooks actually have a name ending with `-functions` rather than `-hook`. Don't assume that'll be the case though, and always check the documentation.
> (lambda (html) (my/org-export-settings))
Why "html" ??
I suggest `_backend` (with the underscore telling the byte-compiler that it's intentionally unused).
olivuser · 2022-09-29 08:24
Thanks for your suggestion!
However, replacing `(html)` by `(_backend)` doesn't solve the issue, I still get the error `paredit-mode: unmatched bracket or quote`. Or is it `(lambda _backend (my/org/export-settings))`?
7890yuiop · 2022-09-29 08:55
I'm not trying to solve your `paredit-mode` error (I don't know anything about paredit-mode). I was only responding to your question about `org-export-processing-hook`.
7890yuiop · 2022-09-29 09:45
Furthermore, rather than changing your original (no lambda) code to this:
(defun my/org-export-settings ()
(paredit-mode -1))
(add-hook 'org-export-before-processing-hook #'(lambda (_backend) (my/org-export-settings)))
Instead make this simpler change:
(defun my/org-export-settings (_backend)
(paredit-mode -1))
(add-hook 'org-export-before-processing-hook #'my/org-export-settings)
Aside from no longer calling two functions where one would suffice, there are good reasons not to add lambda forms to hook variables. You started out doing it right (using a named function), so there's no need to complicate matters by introducing a lamba.
7890yuiop · 2022-09-30 00:28
> I run into the "old" error: `paredit-mode: Unmatched bracket or quote`. Any ideas?
In the (thus far) absence of paredit users offering suggestions...
Is that an actual error? If you `M-x toggle-debug-on-error` do you get a backtrace? If so, add it to the question text.
Otherwise, you've called `(paredit-mode -1)` and yet you're getting that error/message, so I suspect either:
1. The buffer you've disabled `paredit-mode` in is not the buffer in which the problem is occurring.
2. After you've disabled `paredit-mode`, something is enabling it.
You can try to catch (2) with `M-x debug-on-entry` for `paredit-mode` (note also `M-x cancel-debug-on-entry`).
(1) would be more easily identified if the "error" is a real error we can get a backtrace for. If `toggle-debug-on-error` doesn't help, then try using this:
-- Variable: debug-on-message
If you set ‘debug-on-message’ to a regular expression, Emacs will
enter the debugger if it displays a matching message in the echo
area. For example, this can be useful when trying to find the
cause of a particular message.
In all cases, see `C-h i g (elisp)Debugger Commands` for driving the debugger.