3

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 ...))))
  eval-defun-2()
  eval-defun(nil)
  call-interactively(eval-defun t nil)
  execute-extended-command(nil)
  call-interactively(execute-extended-command nil nil)
  recursive-edit()
  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)

WilliamKF
  • 363
  • 5
  • 15
  • You should use `load` instead of `load-library`. `load-library` is only intended for interactive use. – npostavs Aug 04 '15 at 19:51

2 Answers2

4

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.

InHarmsWay
  • 1,309
  • 7
  • 8
4

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)
            (w32-version))
  (`(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)
                    (w32-version))))
  (cond
   ((and (version-list-<= '(5 1) version)
         (version-list-< version '(5 3)))
    'windows-xp)
   ((and (version-list-<= '(6 1) version)
         (version-list-< version '(6 2)))
    'windows-7)
   ((and (version-list-<= '(6 3) version)
         (version-list-< version '(6 4)))
    'windows-8.1)))
npostavs
  • 9,033
  • 1
  • 21
  • 53