0

I have been having the following issue for a whilst now. I try to add a deadline to a headline and I receive the following error:
Wrong number of arguments: (1 . 2), 0. Here is the corresponding backtrace:

Debugger entered--Lisp error: (wrong-number-of-arguments (1 . 2) 0)
  #f(compiled-function (arg &optional time) "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.\nWith one universal prefix argument, remove any deadline from the item.\nWith two universal prefix arguments, prompt for a warning delay.\nWith argument TIME, set the deadline at the corresponding date.  TIME\ncan either be an Org date like \"2011-07-24\" or a delta like \"+2d\"." (interactive "P") #<bytecode 0x1e5d005>)()
  apply(#f(compiled-function (arg &optional time) "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.\nWith one universal prefix argument, remove any deadline from the item.\nWith two universal prefix arguments, prompt for a warning delay.\nWith argument TIME, set the deadline at the corresponding date.  TIME\ncan either be an Org date like \"2011-07-24\" or a delta like \"+2d\"." (interactive "P") #<bytecode 0x1e5d005>) nil)
  org-deadline()
  funcall-interactively(org-deadline)
  call-interactively(org-deadline record nil)
  command-execute(org-deadline record)
  helm-M-x(nil #("org-deadline" 0 12 (match-part "org-deadline")))
  funcall-interactively(helm-M-x nil #("org-deadline" 0 12 (match-part "org-deadline")))
  call-interactively(helm-M-x nil nil)
  command-execute(helm-M-x)

I receive this error before I am given the option to select a date from the calendar for the deadline.

I also receive a similar error (Wrong number of arguments (0 . 0), 2) when trying to set a deadline in the agenda view, however I am able to select a date from the calendar and weirdly the deadline actually gets created. toggle-debug-on-error doesn't present a backtrace upon doing this, yet the error message above is displayed nonetheless. I provide this agenda issue in case it contains useful information, but the issue at hand is that I cannot add deadlines to headlines.

I have tried updating org-mode and the problem persists.
I am using Emacs 26.2, Spacemacs v.0.200.13 and Org Mode 9.2.6.
Please let me know if I am missing any other key information and thank you for your help.

Additional information:
Result of calling C-h f org-deadline:

org-deadline is an interactive compiled Lisp function in ‘org.el’.

It is bound to M-RET d, M-m m d, C-c C-d, and many ordinary text characters.

(org-deadline ARG &optional TIME)

:after advice: ‘org-save-all-org-buffers’

Insert the "DEADLINE:" string with a timestamp to make a deadline.
With one universal prefix argument, remove any deadline from the item.
With two universal prefix arguments, prompt for a warning delay.
With argument TIME, set the deadline at the corresponding date.  TIME
can either be an Org date like "2011-07-24" or a delta like "+2d".

[back]
  • 1
    Do you see the same problem if you use ordinary M-x (execute-extended-command) instead of helm-M-x? Just a thought. Otherwise, maybe try removing any byte-compiled Org libraries. It looks like call-interactively is not picking up a value (should be nil) for the required arg (prefix arg). – Drew Sep 24 at 14:16
  • Hi, thanks for the reply. Yes the issue remains. Could you elaborate on byte-compiled Org libraries? All libraries I have installed AFAIK have been through MELPA. Forgive my ignorance I'm fairly new to (spac)emacs. – quantum285 Sep 24 at 19:20
  • 1
    When you use the package system source files (*.el) are automatically compiled (to *.elc files). You can remove or rename a *.elc file, so the *.el file gets picked up instead. If you see the problem with the *.elc file but not with the *.el file then there may be a byte-compiler problem. Just a thought. – Drew Sep 24 at 21:38
  • 1
    Use the command spacemacs/recompile-elpa to avoid problems caused by packages byte-compiled under different emacs versions. (That can take a while depending on the number of packages you have installed.) – Tobias Sep 27 at 4:35
  • 1
    @quantum285 Okay now we know why call-interactively calls org-deadline without args. (interactive nil) is a wrong interactive-form for org-deadline. You see that if you scan the line beginning with apply(#f(compiled-function up to (interactive "P") which gives org-deadline the prefix argument as single argument. Our task is now to determine why interactive-form returns the wrong interactive form for org-deadline. Call C-h f org-deadline and copy the full help buffer and paste it to the question. Alternatively, you can also scan that help buffer yourself for oddities. – Tobias Sep 29 at 18:44
1
+50

You added org-save-all-org-buffers as :after advice of org-deadline. The documentation of org-save-all-org-buffers says that it is an interactive function without arguments. But org-deadline has one obligatory argument which is deduced from the prefix-arg in interactive calls.

So you advise an interactive function with an interactive function.

The documentation of add-function, which is also valid for advice-add, says:

If one of FUNCTION or OLDFUN is interactive, then the resulting function is also interactive. There are 3 cases:

  • FUNCTION is not interactive: the interactive spec of OLDFUN is used.
  • The interactive spec of FUNCTION is itself a function: it should take one argument (the interactive spec of OLDFUN, which it can pass to ‘advice-eval-interactive-spec’) and return the list of arguments to use.
  • Else, use the interactive spec of FUNCTION and ignore the one of OLDFUN.

The third case is relevant for you. The interactive spec of the advising function org-save-all-org-buffers is used for org-deadline which is wrong since it does not supply the required argument.

If you want an :after-advice working for all interactive functions you can use the &rest keyword in the definition of the advising function to ignore all arguments:

(defun my-org-save-all-org-buffers (&rest _ignore)
  "Apply `org-save-all-org-buffers' ignoring all arguments."
  (org-save-all-org-buffers))

(advice-add 'org-deadline :after #'my-org-save-all-org-buffers)

User quantum285 found the error himself after some help from me.

The following comment from me was a full hit:

call-interactively uses interactive-form to determine how the user should be queried for the arguments of the command. That fails in the above backtrace. funcall-interactively is called with the command name as its only argument. Please, call M-: (interactive-form 'org-deadline) and report the result. It should be (interactive "P") but I assume that it is just (interactive) in your case which is wrong.

When quantum285 acknowledged that, I asked him to add the full help string of org-deadline to his question since I knew that the advice system adds advice information to that doc string.

After reading the doc string of org-deadline user quantum285 identified the advice with org-save-all-org-buffers as the culprit.

He asked me add an answer with the root cause of the problem. There we are...

  • Great, thanks a lot for this. There's a lot of transferable knowledge here. – quantum285 Sep 29 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.