5

I'm using this code on Xubuntu (emacs 24.5.1) but it throw error on windows (emacs 25.0.50.1 64bit)

(defun ignore-error-wrapper (fn)
  "Funtion return new function that ignore errors.
   The function wraps a function with `ignore-errors' macro."
  (lexical-let ((fn fn))
    (lambda ()
      (interactive)
      (ignore-errors
        (funcall fn)))))

(global-set-key [s-left] (ignore-error-wrapper 'windmove-left))
(global-set-key [s-right] (ignore-error-wrapper 'windmove-right))
(global-set-key [s-up] (ignore-error-wrapper 'windmove-up))
(global-set-key [s-down] (ignore-error-wrapper 'windmove-down))
2
  • Please include some description of the error that is signaled. My crystal ball says that the problem is that you use lexical-let without first requiring cl (which is the package that exports lexical-let).
    – Stefan
    Dec 9, 2015 at 13:12
  • @Stefan FWIW the error (void-function lexical-let) was mentioned in the title of the question. (But I do think it is very confusing.)
    – YoungFrog
    Dec 10, 2015 at 10:31

1 Answer 1

5

lexical-let is defined in cl.el. You can (eval-when-compile (require 'cl)) to fix the problem. This is mostly equivalent to (require 'cl) but is more efficient when you byte-compile your code (see Drew's comment below).

4
  • 2
    cl-lib is preferred to cl. To quote the CL manual: "New code should use cl-lib rather than cl." Ref: gnu.org/software/emacs/manual/html_node/cl/…
    – bmag
    Dec 9, 2015 at 11:37
  • 3
    But cl-lib doesn't define lexical-let, so it's a bit less interesting for the problem at hand. I think the preferred way would be to rewrite the code with lexical-binding turned on.
    – YoungFrog
    Dec 9, 2015 at 11:40
  • You are correct. I assumed that cl-lib provided lexical-let, but I was wrong.
    – bmag
    Dec 9, 2015 at 11:46
  • 3
    Nope. You do not need to (and should not, since you do not need to), require cl.el at runtime. lexical-let is a macro (defined in cl.el), so what you should do is (eval-when-compile (require 'cl)).
    – Drew
    Dec 9, 2015 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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