aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/tutorial.el
diff options
context:
space:
mode:
authorMattias EngdegÄrd2026-01-29 11:41:19 +0100
committerMattias EngdegÄrd2026-01-29 13:53:53 +0100
commit495f6b412de244a87cc82a46bab26a86b83e8b15 (patch)
tree52ddf3ad79975b2d72a37f628cb1dcad316d39c6 /lisp/tutorial.el
parentc07ffa21884edae0bf241eb68c44114639a2a1a0 (diff)
downloademacs-495f6b412de244a87cc82a46bab26a86b83e8b15.tar.gz
emacs-495f6b412de244a87cc82a46bab26a86b83e8b15.zip
tutorial.el: don't mutate quoted list
* lisp/tutorial.el (tutorial--default-keys): Don't sort quoted list in-place. Sort at compile time, not load time. Uniform key representation (vectors) so that the default comparison can be used. Eliminate unnecessary backquote. (tutorial--sort-keys): Remove.
Diffstat (limited to 'lisp/tutorial.el')
-rw-r--r--lisp/tutorial.el57
1 files changed, 7 insertions, 50 deletions
diff --git a/lisp/tutorial.el b/lisp/tutorial.el
index f98a13b8a4a..c071c1ff1d8 100644
--- a/lisp/tutorial.el
+++ b/lisp/tutorial.el
@@ -159,54 +159,11 @@ options:
159 (fill-region (point-min) (point))))) 159 (fill-region (point-min) (point)))))
160 (help-print-return-message)))) 160 (help-print-return-message))))
161 161
162(defun tutorial--sort-keys (left right)
163 "Sort predicate for use with `tutorial--default-keys'.
164This is a predicate function to `sort'.
165
166The sorting is for presentation purpose only and is done on the
167key sequence.
168
169LEFT and RIGHT are the elements to compare."
170 (let ((x (append (cadr left) nil))
171 (y (append (cadr right) nil)))
172 ;; Skip the front part of the key sequences if they are equal:
173 (while (and x y
174 (listp x) (listp y)
175 (equal (car x) (car y)))
176 (setq x (cdr x))
177 (setq y (cdr y)))
178 ;; Try to make a comparison that is useful for presentation (this
179 ;; could be made nicer perhaps):
180 (let ((cx (car x))
181 (cy (car y)))
182 ;;(message "x=%s, y=%s;;;; cx=%s, cy=%s" x y cx cy)
183 (cond
184 ;; Lists? Then call this again
185 ((and cx cy
186 (listp cx)
187 (listp cy))
188 (tutorial--sort-keys cx cy))
189 ;; Are both numbers? Then just compare them
190 ((and (wholenump cx)
191 (wholenump cy))
192 (> cx cy))
193 ;; Is one of them a number? Let that be bigger then.
194 ((wholenump cx)
195 t)
196 ((wholenump cy)
197 nil)
198 ;; Are both symbols? Compare the names then.
199 ((and (symbolp cx)
200 (symbolp cy))
201 (string< (symbol-name cy)
202 (symbol-name cx)))))))
203
204(defconst tutorial--default-keys 162(defconst tutorial--default-keys
205 ;; On window system, `suspend-emacs' is replaced in the default keymap. 163 (eval-when-compile
206 (let* ((suspend-emacs 'suspend-frame) 164 (let ((default-keys
207 (default-keys
208 ;; The first few are not mentioned but are basic: 165 ;; The first few are not mentioned but are basic:
209 `((ESC-prefix [27]) 166 '((ESC-prefix [27])
210 (Control-X-prefix [?\C-x]) 167 (Control-X-prefix [?\C-x])
211 (mode-specific-command-prefix [?\C-c]) 168 (mode-specific-command-prefix [?\C-c])
212 (save-buffers-kill-terminal [?\C-x ?\C-c]) 169 (save-buffers-kill-terminal [?\C-x ?\C-c])
@@ -227,7 +184,7 @@ LEFT and RIGHT are the elements to compare."
227 (move-end-of-line [?\C-e]) 184 (move-end-of-line [?\C-e])
228 (backward-sentence [?\M-a]) 185 (backward-sentence [?\M-a])
229 (forward-sentence [?\M-e]) 186 (forward-sentence [?\M-e])
230 (newline "\r") 187 (newline [?\C-m])
231 (beginning-of-buffer [?\M-<]) 188 (beginning-of-buffer [?\M-<])
232 (end-of-buffer [?\M->]) 189 (end-of-buffer [?\M->])
233 (universal-argument [?\C-u]) 190 (universal-argument [?\C-u])
@@ -245,7 +202,7 @@ LEFT and RIGHT are the elements to compare."
245 202
246 ;; * INSERTING AND DELETING 203 ;; * INSERTING AND DELETING
247 ;; C-u 8 * to insert ********. 204 ;; C-u 8 * to insert ********.
248 (delete-backward-char "\d") 205 (delete-backward-char [?\C-?])
249 (delete-char [?\C-d]) 206 (delete-char [?\C-d])
250 (backward-kill-word [?\M-\d]) 207 (backward-kill-word [?\M-\d])
251 (kill-word [?\M-d]) 208 (kill-word [?\M-d])
@@ -309,8 +266,8 @@ LEFT and RIGHT are the elements to compare."
309 266
310 ;; * CONCLUSION 267 ;; * CONCLUSION
311 ;;(iconify-or-deiconify-frame [?\C-z]) 268 ;;(iconify-or-deiconify-frame [?\C-z])
312 (,suspend-emacs [?\C-z])))) 269 (suspend-frame [?\C-z]))))
313 (sort default-keys 'tutorial--sort-keys)) 270 (sort default-keys :key #'cadr)))
314 "Default Emacs key bindings that the tutorial depends on.") 271 "Default Emacs key bindings that the tutorial depends on.")
315 272
316(defun tutorial--detailed-help (button) 273(defun tutorial--detailed-help (button)