6

Emacs 25.1 obsoletes a variable isearch-word and recommends to use the new isearch-regexp-function instead. Because Emacs 24 does not have the new variable, I can't just replace it like:

(if isearch-regexp-function

What's the best way to support both Emacs 24 and Emacs 25?

I don't want to just suppress the warning with with-no-warnings, which is already answered here: "How to avoid obsolete warning when defining a compatibility alias?"

1 Answer 1

3

Use boundp to test for the variable's existence:

(boundp SYMBOL)

Return t if SYMBOL's value is not void. Note that if lexical-binding is in effect, this refers to the global value outside of any lexical scope.

So:

(if (boundp 'isearch-regexp-function)
    (do-the-new-thing)
  (do-the-old-thing))
1
  • 1
    doesn't the bytecompiler warn you still if you have isearch-word in the else form? Feb 6, 2016 at 2:59

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.