0

setting different config options depending on OS. When checking if gnu/linux I get a "wrong type argument char-or-string-p, gnu/linux"

Tried so far:

(string-equal (upcase system-type) "GNU/LINUX") 

(string-equal (format "%S" system-type) "gnu/linux") 

(string-prefix-p "gnu" system-type)

(string-equal system-type "gnu/linux")

if(eq system-type 'gnu/linux)

if(eq string= (system-type) 'gnu/linux)

None of them worked.

  • 1
    I use (if (eq window-system 'x)) – bertfred Aug 17 '18 at 10:08
  • You can use (symbol-name system-type) to get a string. – InHarmsWay Aug 17 '18 at 10:18
1

The version you were closest to is that one with if:

(if (eq system-type 'gnu/linux)
    (progn
      (message "... stuff you want to do under gnu/linux ...")
      (message "1st statement for the then-branch")
      (message "2nd statement for the then-branch")
    )
  (message "... 1st statement of the stuff you want to do otherwise ...")
  (message "... 2nd statement of the stuff you want to do otherwise ...")
)

If you want to configure several systems you can use cl-case. Example:

(cl-case system-type
  (gnu/linux
    (message "... stuff you want to do under gnu/linux ...")
  )
  (windows-nt
    (message "... stuff you need under windows-nt ...")
  )
  (t
    (message "Config for unknown system type.")
  )
)

That version uses the cl library. cl-case is autoloaded. So it should work without further configuration.

If you don't want to draw cl in you can also use cond. Example:

(cond
  ((eq system-type 'gnu/linux)
    (message "... stuff you want to do under gnu/linux ...")
  )
  ((eq system-type 'windows-nt)
    (message "... stuff you need under windows-nt ...")
  )
  (t
    (message "Config for unknown system type.")
  )
)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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