diff options
author | Case Duckworth | 2022-01-17 13:45:32 -0600 |
---|---|---|
committer | Case Duckworth | 2022-01-17 13:45:32 -0600 |
commit | 1394b10658f5059aeb5fa45a2985f4cac97f833d (patch) | |
tree | 9a448cbcd0e6d94d337893f764f28fe1f833e77d /lisp | |
parent | Add sort-setq (diff) | |
download | emacs-1394b10658f5059aeb5fa45a2985f4cac97f833d.tar.gz emacs-1394b10658f5059aeb5fa45a2985f4cac97f833d.zip |
So! Many! Changes!!
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/+lisp.el | 2 | ||||
-rw-r--r-- | lisp/+org.el | 3 | ||||
-rw-r--r-- | lisp/+vterm.el | 2 | ||||
-rw-r--r-- | lisp/acdw.el | 13 | ||||
-rw-r--r-- | lisp/system.el | 240 |
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. | ||
119 | Convenience 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. |
119 | I keep forgetting how they differ." | 125 | I 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. | ||
23 | Each cell is of the form (PREDICATE . SYSTEM), where PREDICATE is | ||
24 | a function of no arguments and SYSTEM is a string or symbol that | ||
25 | will be passed to `system-settings-load'. | ||
26 | 19 | ||
27 | This list need not be exhaustive; see `system-settings-load' for | 20 | (defcustom system-load-directory (locate-user-emacs-file "systems" |
28 | more 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. |
32 | Set 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. |
37 | Set 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. |
45 | Set 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. |
57 | A floating-point number is recommended, since that makes it | 50 | A floating-point number is recommended, since that makes it |
58 | relative to the `default' face height." | 51 | relative to the `default' face height. |
52 | |||
53 | Set 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. | ||
58 | The 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. |
63 | Do not edit this by hand. Instead, call `system-get-system'.") | 68 | The 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' |
67 | Do not edit this by hand. Instead, call `system-get-system-file'.") | 72 | - :user - `user-login-name' |
68 | 73 | ||
69 | ;;; Functions | 74 | Each value is made safe to be a file name by passing through |
75 | `system--safe'. | ||
76 | |||
77 | Do 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." | 81 | Do 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. |
82 | This function is like `warn', except it uses the `system' type." | 88 | This 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 () |
94 | The 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 | 101 | This system updates `system-system', which see." |
96 | this function and SET-SYSTEM-FILE-P is nil. If both SYSTEM and | 102 | ;; Add system-name |
97 | SET-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 | |
100 | If SYSTEM is not passed, and `system-file' is set, simply return | 106 | (setf (plist-get system-system :type) |
101 | its 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 |
103 | appropriate system by testing the car of each cell there. When | 109 | (setf (plist-get system-system :user) |
104 | one matches, use the cdr of that cell as SYSTEM. If none | 110 | ;; Use `user-real-login-name' in case Emacs gets called under su. |
105 | matches, return nil. | 111 | (intern (system--safe (user-real-login-name)))) |
106 | 112 | system-system) | |
107 | This 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)) | 116 | The system load-files should live in `system-load-directory', and |
111 | (system-get-system))) | 117 | named 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)) | 121 | The second form of file-name is to work around name collisions, |
116 | file)) | 122 | e.g. if a there's a user named \"bob\" and a system named |
123 | \"bob\". | ||
124 | |||
125 | This 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'. |
121 | Load settings from `system-file', or the `system-file' as | 143 | Each list in `system-files' will be considered item-by-item; the |
122 | determined by SYSTEM, if passed. See `system-get-system-file' for | 144 | first found file in each will be loaded. |
123 | details on how the `system-file' is determined. | ||
124 | 145 | ||
125 | ERROR determines how to deal with errors: if nil, warn the user | 146 | ERROR determines how to deal with errors: if nil, warn the user |
126 | when `system-file' can't be found or when the system being used | 147 | when no system-files can be found or when the system being used |
127 | can't be determined. If t, those are elevated to errors. If any | 148 | cannot be determined. If t, these warnings are elevated to |
128 | other value, the errors are completely ignored. | 149 | errors. Any other value ignores the warnings completely. |
129 | 150 | ||
130 | NOMESSAGE is passed directly to `load'." | 151 | NOMESSAGE 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 | |||