about summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/system.el113
1 files changed, 113 insertions, 0 deletions
diff --git a/lisp/system.el b/lisp/system.el new file mode 100644 index 0000000..9bb057c --- /dev/null +++ b/lisp/system.el
@@ -0,0 +1,113 @@
1;;; system.el --- System-specific configuration -*- lexical-binding: t; -*-
2
3;;; Commentary:
4
5;; When using Emacs on separate computers, some variables need different
6;; settings. This library contains functions and variables to work with
7;; different system configurations for Emacs.
8
9;;; Code:
10
11(require 'cl-lib)
12
13(defgroup system nil
14 "System-specific configurations."
15 :group 'emacs
16 :prefix "system-")
17
18;;; Variables
19
20(defcustom system-load-alist '((system-microsoft-p . windows)
21 (system-linux-p . linux))
22 "Alist describing which system Emacs is on.
23Each cell is of the form (PREDICATE . SYSTEM), where PREDICATE is
24a function of no arguments and SYSTEM is a string or symbol that
25will be passed to `system-settings-load'.
26
27This list need not be exhaustive; see `system-settings-load' for
28more details on what happens if this alist is exhausted."
29 :type '(alist :key-type function :value-type (choice string symbol)))
30
31(defcustom system-load-directory (locate-user-emacs-file "systems")
32 "The directory from which to load system-specific configurations."
33 :type 'file)
34
35;; `defcustoms' defined here are best-guess defaults.
36
37(defcustom system-default-font (pcase system-type
38 ((or 'ms-dos 'windows-nt)
39 "Consolas")
40 (_ "monospace"))
41 "The font used for the `default' face."
42 :type 'string)
43
44(defcustom system-default-height 100
45 "The height used for the `default' face."
46 :type 'number)
47
48(defcustom system-variable-pitch-font (pcase system-type
49 ((or 'ms-dos 'windows-nt)
50 "Arial")
51 (_ "sans-serif"))
52 "The font used for the `variable-pitch' face."
53 :type 'string)
54
55(defcustom system-variable-pitch-height 1.0
56 "The height used for the `variable-pitch' face.
57A floating-point number is recommended, since that makes it
58relative to the `default' face height."
59 :type 'number)
60
61;;; Functions
62
63;; Convenience functions for systems
64(defun system-microsoft-p ()
65 "Return non-nil if running in a Microsoft system."
66 (memq system-type '(ms-dos windows-nt)))
67
68(defun system-linux-p ()
69 "Return non-nil if running on a Linux system."
70 (memq system-type '(gnu/linux)))
71
72(defun system-warn (message &rest args)
73 "Display a wraning message made from (format-message MESSAGE ARGS...).
74This function is like `warn', except it uses the `system' type."
75 (display-warning 'system (apply #'format-message message args)))
76
77;;;###autoload
78(defun system-settings-load (&optional system error nomessage)
79 "Load system settings.
80If optional SYSTEM (a symbol or a string) is not provided, loop
81through `system-load-alist', testing the car of each cell there.
82When one matches, use the cdr of that cell as SYSTEM. Either
83way, look in `system-load-directory' for the files to load.
84
85If none match, warn the user.
86
87Optional argument ERROR is similar to in `load', but negated: if
88t, it will generate an error; if nil, it will warn the user;
89otherwise, if ERROR is anything else, it will be completely
90silent.
91
92NOMESSAGE is passed as-is to `load'."
93 (let ((system (or system
94 (cl-loop for (p . s) in system-load-alist
95 if (funcall p)
96 return s))))
97 (if system
98 (condition-case e
99 (load (expand-file-name (format "%s" system) system-load-directory)
100 nil nomessage)
101 (t (cond ((eq error t) (signal (car e) (cdr e)))
102 ((null error) (system-warn
103 (concat
104 "Couldn't find file `%s' to load"
105 " (Looked in %s).")
106 system system-load-directory)))))
107 (funcall (cond ((eq error t) #'error)
108 ((null error) #'system-warn)
109 (t #'ignore))
110 "Could not determine the system being used."))))
111
112(provide 'system)
113;;; system.el ends here