Currently, I have this code:

(defalias 'hydra-set-transient-map
    (if (fboundp 'set-transient-map)
      (lambda (map keep-pred &optional on-exit)
        (set-temporary-overlay-map map (hydra--pred on-exit)))))

It uses the newer set-transient-map that obsoletes set-temporary-overlay-map when it's available, however I still want the package to work for Emacs versions that don't have set-transient-map. And I'm getting this warning when byte compiling:

set-temporary-overlay-map is an obsolete function (as of 24.4); use set-transient-map instead.

What's the proper procedure to avoid the warning in this case, without ignoring a whole class of warnings?

1 Answer 1


Wrap your obsolete code with a with-no-warnings form.

(defalias 'hydra-set-transient-map
  (if (fboundp 'set-transient-map)
      (lambda (map keep-pred &optional on-exit)
        (set-temporary-overlay-map map (hydra--pred on-exit))))))

From the docstring:

(with-no-warnings &rest BODY)
Like progn, but prevents compiler warnings in the body.

  • That's not bad. I was thinking of something along the lines that the branch with set-temporary-overlay-map never gets called in appropriate Emacs. So with something like eval-when-compile maybe it could be possible to avoid the warning.
    – abo-abo
    Mar 4, 2015 at 10:13
  • 1
    @abo-abo I think just wrapping the entire if inside an eval-when-compile should also work here, but with-no-warnings is equally effective. It is also more expressive about your intentions and will work in more situations.
    – Malabarba
    Mar 4, 2015 at 10:46

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.