Presently, I'm testing for windows like this in my startup for Emacs v23.1.1:

(if (eq system-type 'windows-nt) (load-library "visual-basic-mode"))

However, this is true for both Windows 7 and Windows XP and I do not have visual-basic-mode on my windows XP machine.

Is there a way to add a condition to detect that it is XP and not load the file? Alternatively, can I pass arguments to load-library so that it is not an error if not found?

Update: I tried adding t as the second argument to load-library and get this error:

byte-code: Wrong number of arguments:
  #[(library) "Á!" [library load] 2 729706
        (list (completing-read "Load library: "
                               (apply-partially (quote locate-file-completion-table)
                                                load-path (get-load-suffixes))))], 2

Update: Trying to use the system version does not eval:

Debugger entered--Lisp error: (void-function pcase)
  (pcase (and (eq system-type ...) (w32-version))
     (\` (5 0 \,_) (quote windows-2k))
     (\` (5 \, ... \,_) (quote windows-xp))
     (\` (6 0 \,_) (quote windows-vista))
     (\` (6 1 \,_) (load-library "visual-basic-mode") (quote windows-7))
     (\` (6 2 \,_) (quote windows-8))
     (\` (6 3 \,_) (quote windows-8\.1)))
  eval-region(42066 42335 t (lambda (ignore) (goto-char 42335)
                              (quote (pcase ... ... ... ... ... ...
                                            ...))))  ; Reading at buffer position 42223
  apply(eval-region (42066 42335 t (lambda (ignore) (goto-char 42335) (quote ...))))
  call-interactively(eval-defun t nil)
  call-interactively(execute-extended-command nil nil)
  byte-code("Æ  @Ç=!

Nor compile:

Error: Wrong number of arguments: #[(structure) "\301!A\207"
            [structure backquote-process] 2 1716431], 2

I note that the value of (w32-version) on Windows XP for me is: (5 1 2600)

  • You should use load instead of load-library. load-library is only intended for interactive use.
    – npostavs
    Aug 4, 2015 at 19:51

2 Answers 2


Since this seems like a configuration based not on OS version so much as a particular machine's program installation, I think it would be better to conditionalize based on the system-name variable.

For the record, you can pass t as the 2nd argument to load, which will not signal an error if the listed file or library is not found.

  • Would like to use the second argument, but see update question for how that fails.
    – WilliamKF
    Aug 4, 2015 at 16:23

For your particular case, I think @InHarmsWay's answer is the best. But for the general case, you can use w32-version:

(pcase (and (eq system-type 'windows-nt)
  (`(5 0 ,_) 'windows-2k)
  (`(5 ,(or 1 2) ,_) 'windows-xp)
  (`(6 0 ,_) 'windows-vista)
  (`(6 1 ,_) 'windows-7)
  (`(6 2 ,_) 'windows-8)
  (`(6 3 ,_) 'windows-8.1))

More complete mappings from internal version numbers to Windows editions are at https://msdn.microsoft.com/en-ca/library/windows/desktop/ms724832%28v=vs.85%29.aspx (only goes back to 2k) and https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions.

pcase was introduced in 24.1, for older Emacs:

(let ((version (and (eq system-type 'windows-nt)
   ((and (version-list-<= '(5 1) version)
         (version-list-< version '(5 3)))
   ((and (version-list-<= '(6 1) version)
         (version-list-< version '(6 2)))
   ((and (version-list-<= '(6 3) version)
         (version-list-< version '(6 4)))

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.