0

This works in emacs 25:

(setq custom-keymap (copy-keymap global-map))

(defun custom-def (keys func &optional file &optional global-p)
  (define-key custom-keymap keys func)
  (if global-p (global-set-key keys func))
  (if file (autoload func file "[custom autoload]" t)))

(custom-def [delete] 'delete-char)

But when I call custom-def in emacs 26 I get an invalid-function error. I isolated it to the &optional parameters. I removed those two args and custom-def works.

So what changed between 25 and 26? What am I missing here? I want the flexible ARGLIST that works in emacs 25.

Drew
  • 29,895
  • 7
  • 74
  • 104
tbc0
  • 1,563
  • 1
  • 17
  • 21

1 Answers1

3

Use optional just once in the parameter list- the following parameters will all be optional [other keywords can follow as well - see info(elisp) Functions].

(defun custom-def (keys func &optional file global-p)
  ;; ...
  )

[I'm not sure what the change was - perhaps duplicated parameter checking was added?]

Rorschach
  • 31,301
  • 5
  • 78
  • 129
  • 1
    D'oh. I had never tried compiling that function. Emacs 25 allows it, but Emacs 26 tells me exactly what I did: `Error: Duplicate &optional` – tbc0 Jun 29 '20 at 14:56