aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/tutorial.el
diff options
context:
space:
mode:
authorDmitry Gutov2026-02-03 05:12:49 +0200
committerDmitry Gutov2026-02-03 05:14:59 +0200
commit083f89f85859add3d1ebfa41a4d77afd7692ae3b (patch)
treebfcf8d812c17c0aee726903e28ae48b21649399f /lisp/tutorial.el
parent53bc4a2cb6578c53f9ca4bf00fd7480d7c3fe5ba (diff)
downloademacs-083f89f85859add3d1ebfa41a4d77afd7692ae3b.tar.gz
emacs-083f89f85859add3d1ebfa41a4d77afd7692ae3b.zip
Fix [More] buttons in tutorial and other buttons in Semantic
* lisp/help-mode.el (help-setup-xref): Update docstring (bug#80276). * etc/NEWS: Add description for the earlier change in help-setup-xref. * lisp/tutorial.el (tutorial--describe-nonstandard-key) (tutorial--detailed-help): Use 'with-help-window', call it after. * lisp/cedet/semantic/util.el (semantic-describe-buffer): Same. * lisp/cedet/semantic/decorate/include.el (semantic-decoration-include-describe) (semantic-decoration-unknown-include-describe) (semantic-decoration-fileless-include-describe) (semantic-decoration-unparsed-include-describe) (semantic-decoration-all-include-summary): Same.
Diffstat (limited to 'lisp/tutorial.el')
-rw-r--r--lisp/tutorial.el274
1 files changed, 136 insertions, 138 deletions
diff --git a/lisp/tutorial.el b/lisp/tutorial.el
index c071c1ff1d8..6ade473c975 100644
--- a/lisp/tutorial.el
+++ b/lisp/tutorial.el
@@ -69,18 +69,17 @@ Where
69 WHERE is a text describing the key sequences to which DEF-FUN is 69 WHERE is a text describing the key sequences to which DEF-FUN is
70 bound now (or, if it is remapped, a key sequence 70 bound now (or, if it is remapped, a key sequence
71 for the function it is remapped to)" 71 for the function it is remapped to)"
72 (with-output-to-temp-buffer (help-buffer) 72 (help-setup-xref (list #'tutorial--describe-nonstandard-key value)
73 (help-setup-xref (list #'tutorial--describe-nonstandard-key value) 73 (called-interactively-p 'interactive))
74 (called-interactively-p 'interactive)) 74 (with-help-window (help-buffer)
75 (with-current-buffer (help-buffer) 75 (insert
76 (insert 76 "Your Emacs customizations override the default binding for this key:"
77 "Your Emacs customizations override the default binding for this key:" 77 "\n\n")
78 "\n\n") 78 (let ((inhibit-read-only t))
79 (let ((inhibit-read-only t)) 79 (cond
80 (cond 80 ((eq (car value) 'cua-mode)
81 ((eq (car value) 'cua-mode) 81 (insert
82 (insert 82 "CUA mode is enabled.
83 "CUA mode is enabled.
84 83
85When CUA mode is enabled, you can use C-z, C-x, C-c, and C-v to 84When CUA mode is enabled, you can use C-z, C-x, C-c, and C-v to
86undo, cut, copy, and paste in addition to the normal Emacs 85undo, cut, copy, and paste in addition to the normal Emacs
@@ -94,70 +93,70 @@ options:
94- press the prefix key twice very quickly (within 0.2 seconds), 93- press the prefix key twice very quickly (within 0.2 seconds),
95- press the prefix key and the following key within 0.2 seconds, or 94- press the prefix key and the following key within 0.2 seconds, or
96- use the SHIFT key with the prefix key, i.e. C-S-x or C-S-c.")) 95- use the SHIFT key with the prefix key, i.e. C-S-x or C-S-c."))
97 ((eq (car value) 'current-binding) 96 ((eq (car value) 'current-binding)
98 (let ((cb (nth 1 value)) 97 (let ((cb (nth 1 value))
99 (db (nth 2 value)) 98 (db (nth 2 value))
100 (key (nth 3 value)) 99 (key (nth 3 value))
101 (where (nth 4 value)) 100 (where (nth 4 value))
102 map 101 map
103 (maps (current-active-maps)) 102 (maps (current-active-maps))
104 mapsym) 103 mapsym)
105 ;; Look at the currently active keymaps and try to find 104 ;; Look at the currently active keymaps and try to find
106 ;; first the keymap where the current binding occurs: 105 ;; first the keymap where the current binding occurs:
107 (while maps 106 (while maps
108 (let* ((m (car maps)) 107 (let* ((m (car maps))
109 (mb (lookup-key m key t))) 108 (mb (lookup-key m key t)))
110 (setq maps (cdr maps)) 109 (setq maps (cdr maps))
111 (when (eq mb cb) 110 (when (eq mb cb)
112 (setq map m) 111 (setq map m)
113 (setq maps nil)))) 112 (setq maps nil))))
114 ;; Now, if a keymap was found we must found the symbol 113 ;; Now, if a keymap was found we must found the symbol
115 ;; name for it to display to the user. This can not 114 ;; name for it to display to the user. This can not
116 ;; always be found since all keymaps does not have a 115 ;; always be found since all keymaps does not have a
117 ;; symbol pointing to them, but here they should have 116 ;; symbol pointing to them, but here they should have
118 ;; that: 117 ;; that:
119 (when map 118 (when map
120 (mapatoms (lambda (s) 119 (mapatoms (lambda (s)
121 (and 120 (and
122 ;; If not already found 121 ;; If not already found
123 (not mapsym) 122 (not mapsym)
124 ;; and if s is a keymap 123 ;; and if s is a keymap
125 (and (boundp s) 124 (and (boundp s)
126 (keymapp (symbol-value s))) 125 (keymapp (symbol-value s)))
127 ;; and not the local symbol map 126 ;; and not the local symbol map
128 (not (eq s 'map)) 127 (not (eq s 'map))
129 ;; and the value of s is map 128 ;; and the value of s is map
130 (eq map (symbol-value s)) 129 (eq map (symbol-value s))
131 ;; then save this value in mapsym 130 ;; then save this value in mapsym
132 (setq mapsym s))))) 131 (setq mapsym s)))))
133 (insert 132 (insert
134 (format-message 133 (format-message
135 "The default Emacs binding for the key %s is the command `%s'. " 134 "The default Emacs binding for the key %s is the command `%s'. "
136 (key-description key) 135 (key-description key)
137 db)) 136 db))
138 (insert "However, your customizations have " 137 (insert "However, your customizations have "
139 (if cb 138 (if cb
140 (format-message "rebound it to the command `%s'" cb) 139 (format-message "rebound it to the command `%s'" cb)
141 "unbound it")) 140 "unbound it"))
142 (insert ".") 141 (insert ".")
143 (when mapsym 142 (when mapsym
144 (insert " (For the more advanced user:" 143 (insert " (For the more advanced user:"
145 (format-message 144 (format-message
146 " This binding is in the keymap `%s'.)" mapsym))) 145 " This binding is in the keymap `%s'.)" mapsym)))
147 (if (string= where "") 146 (if (string= where "")
148 (unless (keymapp db) 147 (unless (keymapp db)
149 (insert "\n\nYou can use M-x " 148 (insert "\n\nYou can use M-x "
150 (format "%s" db) 149 (format "%s" db)
151 " RET instead.")) 150 " RET instead."))
152 (insert "\n\nWith your current key bindings" 151 (insert "\n\nWith your current key bindings"
153 " you can use " 152 " you can use "
154 (if (string-match-p "^the .*menus?$" where) 153 (if (string-match-p "^the .*menus?$" where)
155 "" 154 ""
156 "the key ") 155 "the key ")
157 where 156 where
158 (format-message " to get the function `%s'." db)))) 157 (format-message " to get the function `%s'." db))))
159 (fill-region (point-min) (point))))) 158 (fill-region (point-min) (point)))))
160 (help-print-return-message)))) 159 (help-print-return-message)))
161 160
162(defconst tutorial--default-keys 161(defconst tutorial--default-keys
163 (eval-when-compile 162 (eval-when-compile
@@ -272,71 +271,70 @@ options:
272 271
273(defun tutorial--detailed-help (button) 272(defun tutorial--detailed-help (button)
274 "Give detailed help about changed keys." 273 "Give detailed help about changed keys."
275 (with-output-to-temp-buffer (help-buffer) 274 (help-setup-xref (list #'tutorial--detailed-help button)
276 (help-setup-xref (list #'tutorial--detailed-help button) 275 (called-interactively-p 'interactive))
277 (called-interactively-p 'interactive)) 276 (with-help-window (help-buffer)
278 (with-current-buffer (help-buffer) 277 (let* ((tutorial-buffer (button-get button 'tutorial-buffer))
279 (let* ((tutorial-buffer (button-get button 'tutorial-buffer)) 278 (explain-key-desc (button-get button 'explain-key-desc))
280 (explain-key-desc (button-get button 'explain-key-desc)) 279 (changed-keys (with-current-buffer tutorial-buffer
281 (changed-keys (with-current-buffer tutorial-buffer 280 (save-excursion
282 (save-excursion 281 (goto-char (point-min))
283 (goto-char (point-min)) 282 (tutorial--find-changed-keys
284 (tutorial--find-changed-keys 283 tutorial--default-keys)))))
285 tutorial--default-keys))))) 284 (when changed-keys
286 (when changed-keys 285 (insert
287 (insert 286 "The following key bindings used in the tutorial have been changed
288 "The following key bindings used in the tutorial have been changed
289from the Emacs default:\n\n" ) 287from the Emacs default:\n\n" )
290 (let ((frm " %-14s %-27s %-16s\n")) 288 (let ((frm " %-14s %-27s %-16s\n"))
291 (insert (format frm 289 (insert (format frm
292 "Standard Key" "Command" "In Your Emacs"))) 290 "Standard Key" "Command" "In Your Emacs")))
293 (dolist (tk changed-keys) 291 (dolist (tk changed-keys)
294 (let* ((def-fun (nth 1 tk)) 292 (let* ((def-fun (nth 1 tk))
295 (key (nth 0 tk)) 293 (key (nth 0 tk))
296 (def-fun-txt (nth 2 tk)) 294 (def-fun-txt (nth 2 tk))
297 (where (nth 3 tk)) 295 (where (nth 3 tk))
298 (remark (nth 4 tk)) 296 (remark (nth 4 tk))
299 (key-txt (key-description key)) 297 (key-txt (key-description key))
300 (key-fun (with-current-buffer tutorial-buffer (key-binding key)))) 298 (key-fun (with-current-buffer tutorial-buffer (key-binding key))))
301 (unless (eq def-fun key-fun) 299 (unless (eq def-fun key-fun)
302 ;; Insert key binding description: 300 ;; Insert key binding description:
303 (when (string= key-txt explain-key-desc) 301 (when (string= key-txt explain-key-desc)
304 (put-text-property 0 (length key-txt) 302 (put-text-property 0 (length key-txt)
305 'face 'tutorial-warning-face key-txt)) 303 'face 'tutorial-warning-face key-txt))
306 (insert " " key-txt " ") 304 (insert " " key-txt " ")
307 (indent-to 18) 305 (indent-to 18)
308 ;; Insert a link describing the old binding: 306 ;; Insert a link describing the old binding:
309 (insert-button def-fun-txt 307 (insert-button def-fun-txt
310 'value def-fun 308 'value def-fun
311 'action 309 'action
312 (lambda (button) (interactive) 310 (lambda (button) (interactive)
313 (describe-function 311 (describe-function
314 (button-get button 'value))) 312 (button-get button 'value)))
315 'follow-link t) 313 'follow-link t)
316 (indent-to 45) 314 (indent-to 45)
317 (when (listp where) 315 (when (listp where)
318 (setq where "list")) 316 (setq where "list"))
319 ;; Tell where the old binding is now: 317 ;; Tell where the old binding is now:
320 (insert (format " %-16s " 318 (insert (format " %-16s "
321 (if (string= "" where) 319 (if (string= "" where)
322 (format "M-x %s" def-fun-txt) 320 (format "M-x %s" def-fun-txt)
323 where))) 321 where)))
324 ;; Insert a link with more information, for example 322 ;; Insert a link with more information, for example
325 ;; current binding and keymap or information about 323 ;; current binding and keymap or information about
326 ;; cua-mode replacements: 324 ;; cua-mode replacements:
327 (insert-button (car remark) 325 (insert-button (car remark)
328 'action 326 'action
329 (lambda (b) (interactive) 327 (lambda (b) (interactive)
330 (let ((value (button-get b 'value))) 328 (let ((value (button-get b 'value)))
331 (tutorial--describe-nonstandard-key value))) 329 (tutorial--describe-nonstandard-key value)))
332 'value (cdr remark) 330 'value (cdr remark)
333 'follow-link t) 331 'follow-link t)
334 (insert "\n"))))) 332 (insert "\n")))))
335 333
336 (insert " 334 (insert "
337It is OK to change key bindings, but changed bindings do not 335It is OK to change key bindings, but changed bindings do not
338correspond to what the tutorial says.\n\n") 336correspond to what the tutorial says.\n\n")
339 (help-print-return-message))))) 337 (help-print-return-message))))
340 338
341(defun tutorial--find-changed-keys (default-keys) 339(defun tutorial--find-changed-keys (default-keys)
342 "Find the key bindings used in the tutorial that have changed. 340 "Find the key bindings used in the tutorial that have changed.