about summary refs log tree commit diff stats
path: root/lisp/system.el
diff options
context:
space:
mode:
authorCase Duckworth2022-01-17 13:45:32 -0600
committerCase Duckworth2022-01-17 13:45:32 -0600
commit1394b10658f5059aeb5fa45a2985f4cac97f833d (patch)
tree9a448cbcd0e6d94d337893f764f28fe1f833e77d /lisp/system.el
parentAdd sort-setq (diff)
downloademacs-1394b10658f5059aeb5fa45a2985f4cac97f833d.tar.gz
emacs-1394b10658f5059aeb5fa45a2985f4cac97f833d.zip
So! Many! Changes!!
Diffstat (limited to 'lisp/system.el')
-rw-r--r--lisp/system.el240
1 files changed, 128 insertions, 112 deletions
diff --git a/lisp/system.el b/lisp/system.el index 7fe39f1..0c1e457 100644 --- a/lisp/system.el +++ b/lisp/system.el
@@ -1,9 +1,9 @@
1;;; system.el --- System-specific configuration -*- lexical-binding: t; -*- 1;;; system.el --- Load system-dependendant settings -*- lexical-binding: t; -*-
2 2
3;;; Commentary: 3;;; Commentary:
4 4
5;; When using Emacs on separate computers, some variables need different 5;; When using Emacs on multiple computers, some variables and functions need
6;; settings. This library contains functions and variables to work with 6;; different definitions. This library is built to assist in working with
7;; different system configurations for Emacs. 7;; different system configurations for Emacs.
8 8
9;;; Code: 9;;; Code:
@@ -15,145 +15,161 @@
15 :group 'emacs 15 :group 'emacs
16 :prefix "system-") 16 :prefix "system-")
17 17
18;;; Variables 18;;; Settings
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 19
27This list need not be exhaustive; see `system-settings-load' for 20(defcustom system-load-directory (locate-user-emacs-file "systems"
28more details on what happens if this alist is exhausted." 21 "~/.emacs-systems")
29 :type '(alist :key-type function :value-type (choice string symbol))) 22 "The directory where system-specific configurations live."
30
31(defcustom system-load-directory (locate-user-emacs-file "systems")
32 "The directory from which to load system-specific configurations."
33 :type 'file) 23 :type 'file)
34 24
35;; `defcustoms' defined here are best-guess defaults. 25;; These `defcustom's are best-guess defaults.
36 26
37(defcustom system-default-font (pcase system-type 27(defcustom system-default-font (cond
38 ((or 'ms-dos 'windows-nt) 28 ((memq system-type '(ms-dos windows-nt))
39 "Consolas") 29 "Consolas")
40 (_ "monospace")) 30 (t "monospace"))
41 "The font used for the `default' face." 31 "The font used for the `default' face.
32Set this in your system files."
42 :type 'string) 33 :type 'string)
43 34
44(defcustom system-default-height 100 35(defcustom system-default-height 100
45 "The height used for the `default' face." 36 "The height used for the `default' face.
37Set this in your system files."
46 :type 'number) 38 :type 'number)
47 39
48(defcustom system-variable-pitch-font (pcase system-type 40(defcustom system-variable-pitch-font (cond
49 ((or 'ms-dos 'windows-nt) 41 ((memq system-type '(ms-dos windows-nt))
50 "Arial") 42 "Arial")
51 (_ "sans-serif")) 43 (t "sans-serif"))
52 "The font used for the `variable-pitch' face." 44 "The font used for the `variable-pitch' face.
45Set this in your system files."
53 :type 'string) 46 :type 'string)
54 47
55(defcustom system-variable-pitch-height 1.0 48(defcustom system-variable-pitch-height 1.0
56 "The height used for the `variable-pitch' face. 49 "The height used for the `variable-pitch' face.
57A floating-point number is recommended, since that makes it 50A floating-point number is recommended, since that makes it
58relative to the `default' face height." 51relative to the `default' face height.
52
53Set this in your system files."
59 :type 'number) 54 :type 'number)
60 55
56(defcustom system-files-order '(:type :name :user)
57 "The order to load `system-files' in.
58The elements of this list correspond to the keys in
59`system-system'."
60 :type '(list (const :tag "System type" :type)
61 (const :tag "System name" :name)
62 (const :tag "Current user" :user)))
63
64;;; Variables
65
61(defvar system-system nil 66(defvar system-system nil
62 "The current system's symbol. 67 "Plist of systems that Emacs is in.
63Do not edit this by hand. Instead, call `system-get-system'.") 68The keys are as follows:
64 69
65(defvar system-file nil 70- :name - `system-name'
66 "The current system's file for system-specific configuration. 71- :type - `system-type'
67Do not edit this by hand. Instead, call `system-get-system-file'.") 72- :user - `user-login-name'
68 73
69;;; Functions 74Each value is made safe to be a file name by passing through
75`system--safe'.
76
77Do not edit this by hand. Instead, call `system-get-systems'.")
70 78
71;; Convenience functions for systems 79(defvar system-files nil
72(defun system-microsoft-p () 80 "List of files to load for system-specific configuration.
73 "Return non-nil if running in a Microsoft system." 81Do not edit this by hand. Instead, call `system-get-system-files'.")
74 (memq system-type '(ms-dos windows-nt)))
75 82
76(defun system-linux-p () 83
77 "Return non-nil if running on a Linux system." 84;;; Functions
78 (memq system-type '(gnu/linux)))
79 85
80(defun system-warn (message &rest args) 86(defun system--warn (message &rest args)
81 "Display a wraning message made from (format-message MESSAGE ARGS...). 87 "Display a system-file warning message.
82This function is like `warn', except it uses the `system' type." 88This function is like `warn', except it uses a `system' type."
83 (display-warning 'system (apply #'format-message message args))) 89 (display-warning 'system (apply #'format-message message args)))
84 90
85(defun system-get-system () 91(defun system--safe (str)
86 "Determine the current system." 92 "Make STR safe for a file name."
87 (cl-loop for (p . s) in system-load-alist 93 (let ((bad-char-regexp ))
88 if (with-demoted-errors (format "Problem running function `%s'" p) 94 (downcase (string-trim
89 (funcall p)) 95 (replace-regexp-in-string "[#%&{}\$!'\":@<>*?/ \r\n\t+`|=]+"
90 return (setq system-system s))) 96 "-" str)
91 97 "-" "-"))))
92(defun system-get-system-file (&optional system refresh-cache set-system-file-p) 98
93 "Determine the current system's system-specific file. 99(defun system-get-systems ()
94The current system's file will be returned. The value of 100 "Determine the current system(s).
95`system-file' is set, /unless/ the parameter SYSTEM was passed to 101This system updates `system-system', which see."
96this function and SET-SYSTEM-FILE-P is nil. If both SYSTEM and 102 ;; Add system-name
97SET-SYSTEM-FILE-P are non-nil, this function will still set 103 (setf (plist-get system-system :name)
98`system-file'. 104 (intern (system--safe (system-name))))
99 105 ;; Add system-type
100If SYSTEM is not passed, and `system-file' is set, simply return 106 (setf (plist-get system-system :type)
101its value /unless/ REFRESH-CACHE is non-nil, in which case 107 (intern (system--safe (symbol-name system-type))))
102`system-load-alist' will be looped through to find the 108 ;; Add current user
103appropriate system by testing the car of each cell there. When 109 (setf (plist-get system-system :user)
104one matches, use the cdr of that cell as SYSTEM. If none 110 ;; Use `user-real-login-name' in case Emacs gets called under su.
105matches, return nil. 111 (intern (system--safe (user-real-login-name))))
106 112 system-system)
107This function will only look for system-specific files in 113
108`system-load-directory'." 114(defun system-get-files ()
109 (let* ((system* (or system 115 "Determine the current systems' load-files.
110 (and system-file (not refresh-cache)) 116The system load-files should live in `system-load-directory', and
111 (system-get-system))) 117named using either the raw name given by the values of
112 (file (expand-file-name (format "%s" system*) system-load-directory))) 118`system-system', or that name prepended with the type, e.g.,
113 (when (or (not system) 119\"name-bob.el\", for a system named \"bob\".
114 (and system set-system-file-p)) 120
115 (setq system-file file)) 121The second form of file-name is to work around name collisions,
116 file)) 122e.g. if a there's a user named \"bob\" and a system named
123\"bob\".
124
125This function updates `system-files'."
126 ;; Get systems
127 (system-get-systems)
128 ;; Re-set `system-files'
129 (setq system-files nil)
130
131 (let (ret)
132 (dolist (key (reverse system-files-order))
133 (let* ((val (plist-get system-system key))
134 (key-val (intern (system--safe (format "%s-%s" key val)))))
135 (push (list key-val val) ret)))
136
137 ;; Update `system-files'.
138 (setq system-files ret)))
117 139
118;;;###autoload 140;;;###autoload
119(defun system-settings-load (&optional system error nomessage) 141(defun system-settings-load (&optional error nomessage)
120 "Load system settings. 142 "Load system settings from `system-files'.
121Load settings from `system-file', or the `system-file' as 143Each list in `system-files' will be considered item-by-item; the
122determined by SYSTEM, if passed. See `system-get-system-file' for 144first found file in each will be loaded.
123details on how the `system-file' is determined.
124 145
125ERROR determines how to deal with errors: if nil, warn the user 146ERROR determines how to deal with errors: if nil, warn the user
126when `system-file' can't be found or when the system being used 147when no system-files can be found or when the system being used
127can't be determined. If t, those are elevated to errors. If any 148cannot be determined. If t, these warnings are elevated to
128other value, the errors are completely ignored. 149errors. Any other value ignores the warnings completely.
129 150
130NOMESSAGE is passed directly to `load'." 151NOMESSAGE is passed directly to `load'."
131 (let ((file (system-get-system-file system))) 152 (system-get-files)
132 (if file 153 (if system-files
133 (condition-case e 154 (let (files-loaded)
134 (load file nil nomessage) 155 (dolist (ss system-files)
135 (t (cond ((eq error t) (signal (car e) (cdr e))) 156 (catch :done
136 ((null error) (system-warn "Couldn't find file `%s'." 157 (dolist (s ss)
137 file))))) 158 (let ((fn (expand-file-name (format "%s" s)
138 (funcall (cond ((eq error t) #'error) 159 system-load-directory)))
139 ((null error) #'system-warn) 160 (when (load fn t nomessage)
140 (t #'ignore)) 161 (push fn files-loaded)
141 "Could not determine the system being used.")))) 162 (throw :done nil))))))
142 163 (unless files-loaded
143;;;###autoload 164 (cond ((eq error t) (error "Error loading system-files.")
144(defun system-find-system-file (&optional system) 165 (null error) (system--warn "Couldn't load system-files."))))
145 "Find the current system's system-file." 166 files-loaded)
146 (interactive (list (completing-read "System file: " 167 (funcall (cond ((eq error t) #'error)
147 (mapcar (lambda (a) (format "%s" (cdr a))) 168 ((null error) #'system--warn)
148 system-load-alist) 169 (t #'ignore))
149 nil t nil nil 170 "Couldn't determine the system being used.")))
150 (format "%s" (system-get-system)))))
151 (find-file (cl-loop with file = (system-get-system-file system)
152 for cand in (list file
153 (concat file ".el"))
154 if (file-exists-p cand)
155 return cand
156 finally return cand)))
157 171
158(provide 'system) 172(provide 'system)
159;;; system.el ends here 173;;; system.el ends here
174
175