diff options
| author | Chong Yidong | 2006-10-30 14:56:44 +0000 |
|---|---|---|
| committer | Chong Yidong | 2006-10-30 14:56:44 +0000 |
| commit | b3fcf4f50e208f5504c2ffc24f76bcf934d62dd9 (patch) | |
| tree | 7c62523d19f06ccd78d46266a6067ae2791d69cb | |
| parent | cb753f52412f6054296b1d3cf8d396ca3f1cbcae (diff) | |
| download | emacs-b3fcf4f50e208f5504c2ffc24f76bcf934d62dd9.tar.gz emacs-b3fcf4f50e208f5504c2ffc24f76bcf934d62dd9.zip | |
Fix last fix.
| -rw-r--r-- | lisp/tutorial.el | 310 |
1 files changed, 155 insertions, 155 deletions
diff --git a/lisp/tutorial.el b/lisp/tutorial.el index 90e44d47e0d..194f939951c 100644 --- a/lisp/tutorial.el +++ b/lisp/tutorial.el | |||
| @@ -47,6 +47,161 @@ | |||
| 47 | "Tutorial language.") | 47 | "Tutorial language.") |
| 48 | (make-variable-buffer-local 'tutorial--lang) | 48 | (make-variable-buffer-local 'tutorial--lang) |
| 49 | 49 | ||
| 50 | (defun tutorial--describe-nonstandard-key (value) | ||
| 51 | "Give more information about a changed key binding. | ||
| 52 | This is used in `help-with-tutorial'. The information includes | ||
| 53 | the key sequence that no longer has a default binding, the | ||
| 54 | default binding and the current binding. It also tells in what | ||
| 55 | keymap the new binding has been done and how to access the | ||
| 56 | function in the default binding from the keyboard. | ||
| 57 | |||
| 58 | For `cua-mode' key bindings that try to combine CUA key bindings | ||
| 59 | with default Emacs bindings information about this is shown. | ||
| 60 | |||
| 61 | VALUE should have either of these formats: | ||
| 62 | |||
| 63 | \(cua-mode) | ||
| 64 | \(current-binding KEY-FUN DEF-FUN KEY WHERE) | ||
| 65 | |||
| 66 | Where | ||
| 67 | KEY is a key sequence whose standard binding has been changed | ||
| 68 | KEY-FUN is the actual binding for KEY | ||
| 69 | DEF-FUN is the standard binding of KEY | ||
| 70 | WHERE is a text describing the key sequences to which DEF-FUN is | ||
| 71 | bound now (or, if it is remapped, a key sequence | ||
| 72 | for the function it is remapped to)" | ||
| 73 | (with-output-to-temp-buffer (help-buffer) | ||
| 74 | (help-setup-xref (list #'tutorial--describe-nonstandard-key value) | ||
| 75 | (interactive-p)) | ||
| 76 | (with-current-buffer (help-buffer) | ||
| 77 | (insert | ||
| 78 | "Your Emacs customizations override the default binding for this key:" | ||
| 79 | "\n\n") | ||
| 80 | (let ((inhibit-read-only t)) | ||
| 81 | (cond | ||
| 82 | ((eq (car value) 'cua-mode) | ||
| 83 | (insert | ||
| 84 | "CUA mode is enabled. | ||
| 85 | |||
| 86 | When CUA mode is enabled, you can use C-z, C-x, C-c, and C-v to | ||
| 87 | undo, cut, copy, and paste in addition to the normal Emacs | ||
| 88 | bindings. The C-x and C-c keys only do cut and copy when the | ||
| 89 | region is active, so in most cases, they do not conflict with the | ||
| 90 | normal function of these prefix keys. | ||
| 91 | |||
| 92 | If you really need to perform a command which starts with one of | ||
| 93 | the prefix keys even when the region is active, you have three | ||
| 94 | options: | ||
| 95 | - press the prefix key twice very quickly (within 0.2 seconds), | ||
| 96 | - press the prefix key and the following key within 0.2 seconds, or | ||
| 97 | - use the SHIFT key with the prefix key, i.e. C-S-x or C-S-c.")) | ||
| 98 | ((eq (car value) 'current-binding) | ||
| 99 | (let ((cb (nth 1 value)) | ||
| 100 | (db (nth 2 value)) | ||
| 101 | (key (nth 3 value)) | ||
| 102 | (where (nth 4 value)) | ||
| 103 | map | ||
| 104 | (maps (current-active-maps)) | ||
| 105 | mapsym) | ||
| 106 | ;; Look at the currently active keymaps and try to find | ||
| 107 | ;; first the keymap where the current binding occurs: | ||
| 108 | (while maps | ||
| 109 | (let* ((m (car maps)) | ||
| 110 | (mb (lookup-key m key t))) | ||
| 111 | (setq maps (cdr maps)) | ||
| 112 | (when (eq mb cb) | ||
| 113 | (setq map m) | ||
| 114 | (setq maps nil)))) | ||
| 115 | ;; Now, if a keymap was found we must found the symbol | ||
| 116 | ;; name for it to display to the user. This can not | ||
| 117 | ;; always be found since all keymaps does not have a | ||
| 118 | ;; symbol pointing to them, but here they should have | ||
| 119 | ;; that: | ||
| 120 | (when map | ||
| 121 | (mapatoms (lambda (s) | ||
| 122 | (and | ||
| 123 | ;; If not already found | ||
| 124 | (not mapsym) | ||
| 125 | ;; and if s is a keymap | ||
| 126 | (and (boundp s) | ||
| 127 | (keymapp (symbol-value s))) | ||
| 128 | ;; and not the local symbol map | ||
| 129 | (not (eq s 'map)) | ||
| 130 | ;; and the value of s is map | ||
| 131 | (eq map (symbol-value s)) | ||
| 132 | ;; then save this value in mapsym | ||
| 133 | (setq mapsym s))))) | ||
| 134 | (insert "The default Emacs binding for the key " | ||
| 135 | (key-description key) | ||
| 136 | " is the command `") | ||
| 137 | (insert (format "%s" db)) | ||
| 138 | (insert "'. " | ||
| 139 | "However, your customizations have rebound it to the command `") | ||
| 140 | (insert (format "%s" cb)) | ||
| 141 | (insert "'.") | ||
| 142 | (when mapsym | ||
| 143 | (insert " (For the more advanced user:" | ||
| 144 | " This binding is in the keymap `" | ||
| 145 | (format "%s" mapsym) | ||
| 146 | "'.)")) | ||
| 147 | (if (string= where "") | ||
| 148 | (unless (keymapp db) | ||
| 149 | (insert "\n\nYou can use M-x " | ||
| 150 | (format "%s" db) | ||
| 151 | " RET instead.")) | ||
| 152 | (insert "\n\nWith you current key bindings" | ||
| 153 | " you can use the key " | ||
| 154 | where | ||
| 155 | " to get the function `" | ||
| 156 | (format "%s" db) | ||
| 157 | "'.")) | ||
| 158 | ) | ||
| 159 | (fill-region (point-min) (point))))) | ||
| 160 | (print-help-return-message)))) | ||
| 161 | |||
| 162 | (defun tutorial--sort-keys (left right) | ||
| 163 | "Sort predicate for use with `tutorial--default-keys'. | ||
| 164 | This is a predicate function to `sort'. | ||
| 165 | |||
| 166 | The sorting is for presentation purpose only and is done on the | ||
| 167 | key sequence. | ||
| 168 | |||
| 169 | LEFT 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 comparision 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 | |||
| 50 | (defconst tutorial--default-keys | 205 | (defconst tutorial--default-keys |
| 51 | (let* ( | 206 | (let* ( |
| 52 | ;; On window system suspend Emacs is replaced in the | 207 | ;; On window system suspend Emacs is replaced in the |
| @@ -272,161 +427,6 @@ correspond to what the tutorial says. (See also " ) | |||
| 272 | (insert ".)\n\n") | 427 | (insert ".)\n\n") |
| 273 | (print-help-return-message))))) | 428 | (print-help-return-message))))) |
| 274 | 429 | ||
| 275 | (defun tutorial--describe-nonstandard-key (value) | ||
| 276 | "Give more information about a changed key binding. | ||
| 277 | This is used in `help-with-tutorial'. The information includes | ||
| 278 | the key sequence that no longer has a default binding, the | ||
| 279 | default binding and the current binding. It also tells in what | ||
| 280 | keymap the new binding has been done and how to access the | ||
| 281 | function in the default binding from the keyboard. | ||
| 282 | |||
| 283 | For `cua-mode' key bindings that try to combine CUA key bindings | ||
| 284 | with default Emacs bindings information about this is shown. | ||
| 285 | |||
| 286 | VALUE should have either of these formats: | ||
| 287 | |||
| 288 | \(cua-mode) | ||
| 289 | \(current-binding KEY-FUN DEF-FUN KEY WHERE) | ||
| 290 | |||
| 291 | Where | ||
| 292 | KEY is a key sequence whose standard binding has been changed | ||
| 293 | KEY-FUN is the actual binding for KEY | ||
| 294 | DEF-FUN is the standard binding of KEY | ||
| 295 | WHERE is a text describing the key sequences to which DEF-FUN is | ||
| 296 | bound now (or, if it is remapped, a key sequence | ||
| 297 | for the function it is remapped to)" | ||
| 298 | (with-output-to-temp-buffer (help-buffer) | ||
| 299 | (help-setup-xref (list #'tutorial--describe-nonstandard-key value) | ||
| 300 | (interactive-p)) | ||
| 301 | (with-current-buffer (help-buffer) | ||
| 302 | (insert | ||
| 303 | "Your Emacs customizations override the default binding for this key:" | ||
| 304 | "\n\n") | ||
| 305 | (let ((inhibit-read-only t)) | ||
| 306 | (cond | ||
| 307 | ((eq (car value) 'cua-mode) | ||
| 308 | (insert | ||
| 309 | "CUA mode is enabled. | ||
| 310 | |||
| 311 | When CUA mode is enabled, you can use C-z, C-x, C-c, and C-v to | ||
| 312 | undo, cut, copy, and paste in addition to the normal Emacs | ||
| 313 | bindings. The C-x and C-c keys only do cut and copy when the | ||
| 314 | region is active, so in most cases, they do not conflict with the | ||
| 315 | normal function of these prefix keys. | ||
| 316 | |||
| 317 | If you really need to perform a command which starts with one of | ||
| 318 | the prefix keys even when the region is active, you have three | ||
| 319 | options: | ||
| 320 | - press the prefix key twice very quickly (within 0.2 seconds), | ||
| 321 | - press the prefix key and the following key within 0.2 seconds, or | ||
| 322 | - use the SHIFT key with the prefix key, i.e. C-S-x or C-S-c.")) | ||
| 323 | ((eq (car value) 'current-binding) | ||
| 324 | (let ((cb (nth 1 value)) | ||
| 325 | (db (nth 2 value)) | ||
| 326 | (key (nth 3 value)) | ||
| 327 | (where (nth 4 value)) | ||
| 328 | map | ||
| 329 | (maps (current-active-maps)) | ||
| 330 | mapsym) | ||
| 331 | ;; Look at the currently active keymaps and try to find | ||
| 332 | ;; first the keymap where the current binding occurs: | ||
| 333 | (while maps | ||
| 334 | (let* ((m (car maps)) | ||
| 335 | (mb (lookup-key m key t))) | ||
| 336 | (setq maps (cdr maps)) | ||
| 337 | (when (eq mb cb) | ||
| 338 | (setq map m) | ||
| 339 | (setq maps nil)))) | ||
| 340 | ;; Now, if a keymap was found we must found the symbol | ||
| 341 | ;; name for it to display to the user. This can not | ||
| 342 | ;; always be found since all keymaps does not have a | ||
| 343 | ;; symbol pointing to them, but here they should have | ||
| 344 | ;; that: | ||
| 345 | (when map | ||
| 346 | (mapatoms (lambda (s) | ||
| 347 | (and | ||
| 348 | ;; If not already found | ||
| 349 | (not mapsym) | ||
| 350 | ;; and if s is a keymap | ||
| 351 | (and (boundp s) | ||
| 352 | (keymapp (symbol-value s))) | ||
| 353 | ;; and not the local symbol map | ||
| 354 | (not (eq s 'map)) | ||
| 355 | ;; and the value of s is map | ||
| 356 | (eq map (symbol-value s)) | ||
| 357 | ;; then save this value in mapsym | ||
| 358 | (setq mapsym s))))) | ||
| 359 | (insert "The default Emacs binding for the key " | ||
| 360 | (key-description key) | ||
| 361 | " is the command `") | ||
| 362 | (insert (format "%s" db)) | ||
| 363 | (insert "'. " | ||
| 364 | "However, your customizations have rebound it to the command `") | ||
| 365 | (insert (format "%s" cb)) | ||
| 366 | (insert "'.") | ||
| 367 | (when mapsym | ||
| 368 | (insert " (For the more advanced user:" | ||
| 369 | " This binding is in the keymap `" | ||
| 370 | (format "%s" mapsym) | ||
| 371 | "'.)")) | ||
| 372 | (if (string= where "") | ||
| 373 | (unless (keymapp db) | ||
| 374 | (insert "\n\nYou can use M-x " | ||
| 375 | (format "%s" db) | ||
| 376 | " RET instead.")) | ||
| 377 | (insert "\n\nWith you current key bindings" | ||
| 378 | " you can use the key " | ||
| 379 | where | ||
| 380 | " to get the function `" | ||
| 381 | (format "%s" db) | ||
| 382 | "'.")) | ||
| 383 | ) | ||
| 384 | (fill-region (point-min) (point))))) | ||
| 385 | (print-help-return-message)))) | ||
| 386 | |||
| 387 | (defun tutorial--sort-keys (left right) | ||
| 388 | "Sort predicate for use with `tutorial--default-keys'. | ||
| 389 | This is a predicate function to `sort'. | ||
| 390 | |||
| 391 | The sorting is for presentation purpose only and is done on the | ||
| 392 | key sequence. | ||
| 393 | |||
| 394 | LEFT and RIGHT are the elements to compare." | ||
| 395 | (let ((x (append (cadr left) nil)) | ||
| 396 | (y (append (cadr right) nil))) | ||
| 397 | ;; Skip the front part of the key sequences if they are equal: | ||
| 398 | (while (and x y | ||
| 399 | (listp x) (listp y) | ||
| 400 | (equal (car x) (car y))) | ||
| 401 | (setq x (cdr x)) | ||
| 402 | (setq y (cdr y))) | ||
| 403 | ;; Try to make a comparision that is useful for presentation (this | ||
| 404 | ;; could be made nicer perhaps): | ||
| 405 | (let ((cx (car x)) | ||
| 406 | (cy (car y))) | ||
| 407 | ;;(message "x=%s, y=%s;;;; cx=%s, cy=%s" x y cx cy) | ||
| 408 | (cond | ||
| 409 | ;; Lists? Then call this again | ||
| 410 | ((and cx cy | ||
| 411 | (listp cx) | ||
| 412 | (listp cy)) | ||
| 413 | (tutorial--sort-keys cx cy)) | ||
| 414 | ;; Are both numbers? Then just compare them | ||
| 415 | ((and (wholenump cx) | ||
| 416 | (wholenump cy)) | ||
| 417 | (> cx cy)) | ||
| 418 | ;; Is one of them a number? Let that be bigger then. | ||
| 419 | ((wholenump cx) | ||
| 420 | t) | ||
| 421 | ((wholenump cy) | ||
| 422 | nil) | ||
| 423 | ;; Are both symbols? Compare the names then. | ||
| 424 | ((and (symbolp cx) | ||
| 425 | (symbolp cy)) | ||
| 426 | (string< (symbol-name cy) | ||
| 427 | (symbol-name cx))) | ||
| 428 | )))) | ||
| 429 | |||
| 430 | (defun tutorial--find-changed-keys (default-keys) | 430 | (defun tutorial--find-changed-keys (default-keys) |
| 431 | "Find the key bindings that have changed. | 431 | "Find the key bindings that have changed. |
| 432 | Check if the default Emacs key bindings that the tutorial depends | 432 | Check if the default Emacs key bindings that the tutorial depends |