改进Elisp条件表达式

时间:2011-08-09 10:50:46

标签: elisp

以下伪代码的elisp代码

if "the emacs version is less than 23.1.x"
do
  something
else
  something-else

写成

(if (or (< emacs-major-version 23)
        (and (= emacs-major-version 23)
             (<= emacs-minor-version 1)))
    (setq color-theme-is-global t)
  (color-theme-initialize))

如何优化上述代码,以便“emacs-major-version”不会被引用两次。

1 个答案:

答案 0 :(得分:11)

不需要,version<=emacs-version

(if (version<= emacs-version "23.1")
    (setq color-theme-is-global t)
  (color-theme-initialize))