8

Emacs 24.4 made an incompatible change to interpreter-mode-alist, treating its members now as regular expressions and no longer as simple strings (http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=1af4c2203ce7954c089133234ba80e6272ce9458). I want to replace:

(add-to-list 'interpreter-mode-alist
             ;; Match php, php-3, php5, php7, php5.5, php-7.0.1, etc.
             (cons "php\\(?:-?[3457]\\(?:\\.[0-9]+\\)*\\)?" 'php-mode))

(which works fine with Emacs 24.4 and newer) with compatibility code that, depending on the version of Emacs, adds either a regular expression or strings.

What is the preferred way to test if the Emacs version in use is 24.4 or newer? (if (version< emacs-version "24.4") …)?

5
  • Using emacs-version with the version* functions is sane, yes.
    – phils
    Sep 7, 2017 at 2:33
  • You may also be interested in playing with version-list-... and version-to-list; e.g., (unless (version-list-<= (version-to-list emacs-version) '(25 2 50 1)) ...)
    – lawlist
    Sep 7, 2017 at 5:51
  • @phils: Could you please post your answer as an answer? You can use my code at github.com/scfc/php-mode/commit/… to mirror the code in the question. Sep 8, 2017 at 4:17
  • @lawlist: Thanks, that's interesting. For my use (simple) case, I'll stick with version<. Sep 8, 2017 at 4:18
  • @TimLandscheidt, sure; done.
    – phils
    Sep 9, 2017 at 4:02

1 Answer 1

12

Using emacs-version with the various version* functions is sane, yes.

  • version=
  • version<
  • version<=

(These are convenience wrappers which use the version-list functionality behind the scenes.)

By way of example, the following is the code Tim ended up using:

(if (version< emacs-version "24.4")
    (dolist (i '("php" "php3" "php5" "php7" "php-5" "php-5.5" "php7.0.1"))
      (add-to-list 'interpreter-mode-alist (cons i 'php-mode)))
  (add-to-list 'interpreter-mode-alist
               ;; Match php, php-3, php5, php7, php5.5, php-7.0.1, etc.
               (cons "php\\(?:-?[3457]\\(?:\\.[0-9]+\\)*\\)?" 'php-mode)))
1
  • 1
    n.b. The variables emacs-major-version and emacs-minor-version were also mentioned in another answer (which has unfortunately been deleted), and these might be useful alternatives in some situations.
    – phils
    Sep 9, 2017 at 4:07

Your Answer

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

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