about summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/+lisp.el2
-rw-r--r--lisp/+org.el3
-rw-r--r--lisp/+vterm.el2
-rw-r--r--lisp/acdw.el13
-rw-r--r--lisp/system.el240
5 files changed, 142 insertions, 118 deletions
diff --git a/lisp/+lisp.el b/lisp/+lisp.el index c45fdf6..a78e40e 100644 --- a/lisp/+lisp.el +++ b/lisp/+lisp.el
@@ -157,6 +157,8 @@ With a prefix argument N, (un)comment that many sexps."
157 (+lisp-comment-sexp--raw)))) 157 (+lisp-comment-sexp--raw))))
158 158
159;;; Sort `setq' constructs 159;;; Sort `setq' constructs
160;;https://emacs.stackexchange.com/questions/33039/
161
160(defun +lisp-sort-setq () 162(defun +lisp-sort-setq ()
161 (interactive) 163 (interactive)
162 (save-excursion 164 (save-excursion
diff --git a/lisp/+org.el b/lisp/+org.el index 95a3da2..348ba6e 100644 --- a/lisp/+org.el +++ b/lisp/+org.el
@@ -420,8 +420,7 @@ the deletion might narrow the column."
420 "Open thing at point, or if there isn't something, list things." 420 "Open thing at point, or if there isn't something, list things."
421 (interactive "P") 421 (interactive "P")
422 (save-excursion 422 (save-excursion
423 (let* ((browse-url-browser-function #'browse-url-default-browser) 423 (let* ((this-char-type (org-element-type (org-element-context)))
424 (this-char-type (org-element-type (org-element-context)))
425 (prev-char-type (ignore-errors 424 (prev-char-type (ignore-errors
426 (save-excursion 425 (save-excursion
427 (backward-char) 426 (backward-char)
diff --git a/lisp/+vterm.el b/lisp/+vterm.el index 66e226b..06c0028 100644 --- a/lisp/+vterm.el +++ b/lisp/+vterm.el
@@ -4,7 +4,7 @@
4 4
5;;; Code: 5;;; Code:
6 6
7(require +vterm) 7(require 'vterm)
8 8
9(defun +vterm-counsel-yank-pop-action (orig-fun &rest args) 9(defun +vterm-counsel-yank-pop-action (orig-fun &rest args)
10 (if (equal major-mode 'vterm-mode) 10 (if (equal major-mode 'vterm-mode)
diff --git a/lisp/acdw.el b/lisp/acdw.el index 7cad67c..17741ab 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el
@@ -114,13 +114,19 @@ If Emacs is already started, run FUNCTION. Otherwise, add it to
114 (funcall function) 114 (funcall function)
115 (add-hook 'after-init-hook function))) 115 (add-hook 'after-init-hook function)))
116 116
117(defmacro +with-ensure-after-init (&rest body)
118 "Ensure BODY forms run after init.
119Convenience macro wrapper around `+ensure-after-init'."
120 (declare (indent 0) (debug (def-body)))
121 `(+ensure-after-init (lambda () ,@body)))
122
117(defun +remember-prefix-arg (p-arg P-arg) 123(defun +remember-prefix-arg (p-arg P-arg)
118 "Display prefix ARG, in \"p\" and \"P\" `interactive' types. 124 "Display prefix ARG, in \"p\" and \"P\" `interactive' types.
119I keep forgetting how they differ." 125I keep forgetting how they differ."
120 (interactive "p\nP") 126 (interactive "p\nP")
121 (message "p: %S P: %S" p-arg P-arg)) 127 (message "p: %S P: %S" p-arg P-arg))
122 128
123(defmacro +defvar (var value &optional _) 129(defmacro +defvar (var value &rest _)
124 "Quick way to `setq' a variable from a `defvar' form." 130 "Quick way to `setq' a variable from a `defvar' form."
125 (declare (doc-string 3)) 131 (declare (doc-string 3))
126 `(setq ,var ,value)) 132 `(setq ,var ,value))
@@ -133,7 +139,7 @@ If body executes without errors, MESSAGE...Done will be displayed."
133 `(let ((,msg ,message)) 139 `(let ((,msg ,message))
134 (unwind-protect (progn (message "%s..." ,msg) 140 (unwind-protect (progn (message "%s..." ,msg)
135 ,@body) 141 ,@body)
136 (message "%s... Done." ,msg))))) 142 (message "%s...done" ,msg)))))
137 143
138(defun +mapc-some-buffers (func &optional predicate) 144(defun +mapc-some-buffers (func &optional predicate)
139 "Perform FUNC on all buffers satisfied by PREDICATE. 145 "Perform FUNC on all buffers satisfied by PREDICATE.
@@ -171,7 +177,8 @@ active, or else the entire buffer."
171 (replace-match "\n\n")) 177 (replace-match "\n\n"))
172 ;; Insert a newline at the end. 178 ;; Insert a newline at the end.
173 (goto-char (point-max)) 179 (goto-char (point-max))
174 (unless (= (line-beginning-position) (line-end-position)) 180 (unless (or (buffer-narrowed-p)
181 (= (line-beginning-position) (line-end-position)))
175 (insert "\n"))))) 182 (insert "\n")))))
176 183
177(defun +open-paragraph () 184(defun +open-paragraph ()
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