diff options
| author | Chong Yidong | 2006-12-22 15:17:24 +0000 |
|---|---|---|
| committer | Chong Yidong | 2006-12-22 15:17:24 +0000 |
| commit | 87fe23eef1e0414119a12d38dfdb754bcac88dd0 (patch) | |
| tree | aaee4ce69e15bf10685d1f3305e325e7760f8f54 | |
| parent | d7e39ca971657f2dc5486d677a43c15d9972967e (diff) | |
| download | emacs-87fe23eef1e0414119a12d38dfdb754bcac88dd0.tar.gz emacs-87fe23eef1e0414119a12d38dfdb754bcac88dd0.zip | |
(tutorial--detailed-help): Remove unnecessary link
to the Emacs Lisp reference manual.
(tutorial--tab-map): Remove. All callers changed.
(tutorial--find-changed-keys): New elt QUIET, used to...
(tutorial--display-changes): ...ensure that warning messages are
only issued once per changed key.
(tutorial--remove-remarks): Delete unused code-path.
(lang-strings): Remove extraneous formatting.
| -rw-r--r-- | lisp/tutorial.el | 157 |
1 files changed, 70 insertions, 87 deletions
diff --git a/lisp/tutorial.el b/lisp/tutorial.el index a711e766221..1f37687d7e4 100644 --- a/lisp/tutorial.el +++ b/lisp/tutorial.el | |||
| @@ -336,7 +336,7 @@ LEFT and RIGHT are the elements to compare." | |||
| 336 | (when changed-keys | 336 | (when changed-keys |
| 337 | (insert | 337 | (insert |
| 338 | "The following key bindings used in the tutorial had been changed | 338 | "The following key bindings used in the tutorial had been changed |
| 339 | from Emacs default in the " (buffer-name tutorial-buffer) " buffer:\n\n" ) | 339 | from the Emacs default in the " (buffer-name tutorial-buffer) " buffer:\n\n" ) |
| 340 | (let ((frm " %-9s %-27s %-11s %s\n")) | 340 | (let ((frm " %-9s %-27s %-11s %s\n")) |
| 341 | (insert (format frm "Key" "Standard Binding" "Is Now On" "Remark"))) | 341 | (insert (format frm "Key" "Standard Binding" "Is Now On" "Remark"))) |
| 342 | (dolist (tk changed-keys) | 342 | (dolist (tk changed-keys) |
| @@ -391,28 +391,17 @@ from Emacs default in the " (buffer-name tutorial-buffer) " buffer:\n\n" ) | |||
| 391 | 391 | ||
| 392 | (insert " | 392 | (insert " |
| 393 | It is OK to change key bindings, but changed bindings do not | 393 | It is OK to change key bindings, but changed bindings do not |
| 394 | correspond to what the tutorial says. (See also ") | 394 | correspond to what the tutorial says.\n\n") |
| 395 | (insert-button "Key Binding Conventions" | ||
| 396 | 'action | ||
| 397 | (lambda(button) (interactive) | ||
| 398 | (info | ||
| 399 | "(elisp) Key Binding Conventions") | ||
| 400 | (message "Type C-x 0 to close the new window")) | ||
| 401 | 'follow-link t) | ||
| 402 | (insert ".)\n\n") | ||
| 403 | (print-help-return-message))))) | 395 | (print-help-return-message))))) |
| 404 | 396 | ||
| 405 | (defun tutorial--find-changed-keys (default-keys) | 397 | (defun tutorial--find-changed-keys (default-keys) |
| 406 | "Find the key bindings that have changed. | 398 | "Find the key bindings used in the tutorial that have changed. |
| 407 | Check if the default Emacs key bindings that the tutorial depends | 399 | Return a list with elements of the form |
| 408 | on have been changed. | ||
| 409 | 400 | ||
| 410 | Return a list with the keys that have been changed. The element | 401 | '(KEY DEF-FUN DEF-FUN-TXT WHERE REMARK QUIET) |
| 411 | of this list have the following format: | ||
| 412 | 402 | ||
| 413 | \(list KEY DEF-FUN DEF-FUN-TXT WHERE REMARK) | 403 | where |
| 414 | 404 | ||
| 415 | Where | ||
| 416 | KEY is a key sequence whose standard binding has been changed | 405 | KEY is a key sequence whose standard binding has been changed |
| 417 | DEF-FUN is the standard binding of KEY | 406 | DEF-FUN is the standard binding of KEY |
| 418 | DEF-FUN-TXT is a short descriptive text for DEF-FUN | 407 | DEF-FUN-TXT is a short descriptive text for DEF-FUN |
| @@ -429,7 +418,9 @@ Where | |||
| 429 | rest of the list is used to show information when | 418 | rest of the list is used to show information when |
| 430 | the user clicks the link. | 419 | the user clicks the link. |
| 431 | 420 | ||
| 432 | KEY-FUN is the actual binding for KEY." | 421 | KEY-FUN is the actual binding for KEY. |
| 422 | QUIET is t if this changed keybinding should be handled quietly. | ||
| 423 | This is used by `tutorial--display-changes'." | ||
| 433 | (let (changed-keys remark) | 424 | (let (changed-keys remark) |
| 434 | (dolist (kdf default-keys) | 425 | (dolist (kdf default-keys) |
| 435 | ;; The variables below corresponds to those with the same names | 426 | ;; The variables below corresponds to those with the same names |
| @@ -469,26 +460,21 @@ Where | |||
| 469 | (setq remark (list "cua-mode, more info" 'cua-mode)) | 460 | (setq remark (list "cua-mode, more info" 'cua-mode)) |
| 470 | nil) | 461 | nil) |
| 471 | ((and cua-mode | 462 | ((and cua-mode |
| 472 | (or | 463 | (or (and (eq def-fun 'ESC-prefix) |
| 473 | (and (eq def-fun 'ESC-prefix) | 464 | (equal key-fun |
| 474 | (equal key-fun | ||
| 475 | `(keymap | 465 | `(keymap |
| 476 | (118 . cua-repeat-replace-region)))) | 466 | (118 . cua-repeat-replace-region))) |
| 477 | (and (eq def-fun 'mode-specific-command-prefix) | 467 | (setq def-fun-txt "\"ESC prefix\"")) |
| 478 | (equal key-fun | 468 | (and (eq def-fun 'mode-specific-command-prefix) |
| 479 | '(keymap | 469 | (equal key-fun |
| 480 | (timeout . copy-region-as-kill)))) | 470 | '(keymap |
| 481 | (and (eq def-fun 'Control-X-prefix) | 471 | (timeout . copy-region-as-kill))) |
| 482 | (equal key-fun | 472 | (setq def-fun-txt "\"C-c prefix\"")) |
| 483 | '(keymap (timeout . kill-region)))))) | 473 | (and (eq def-fun 'Control-X-prefix) |
| 474 | (equal key-fun | ||
| 475 | '(keymap (timeout . kill-region))) | ||
| 476 | (setq def-fun-txt "\"C-x prefix\"")))) | ||
| 484 | (setq remark (list "cua-mode replacement" 'cua-mode)) | 477 | (setq remark (list "cua-mode replacement" 'cua-mode)) |
| 485 | (cond | ||
| 486 | ((eq def-fun 'mode-specific-command-prefix) | ||
| 487 | (setq def-fun-txt "\"C-c prefix\"")) | ||
| 488 | ((eq def-fun 'Control-X-prefix) | ||
| 489 | (setq def-fun-txt "\"C-x prefix\"")) | ||
| 490 | ((eq def-fun 'ESC-prefix) | ||
| 491 | (setq def-fun-txt "\"ESC prefix\""))) | ||
| 492 | (setq where "Same key") | 478 | (setq where "Same key") |
| 493 | nil) | 479 | nil) |
| 494 | ;; viper-mode specials: | 480 | ;; viper-mode specials: |
| @@ -518,17 +504,9 @@ Where | |||
| 518 | key-fun def-fun key where)) | 504 | key-fun def-fun key where)) |
| 519 | nil)) | 505 | nil)) |
| 520 | (add-to-list 'changed-keys | 506 | (add-to-list 'changed-keys |
| 521 | (list key def-fun def-fun-txt where remark))))) | 507 | (list key def-fun def-fun-txt where remark nil))))) |
| 522 | changed-keys)) | 508 | changed-keys)) |
| 523 | 509 | ||
| 524 | (defvar tutorial--tab-map | ||
| 525 | (let ((map (make-sparse-keymap))) | ||
| 526 | (define-key map [tab] 'forward-button) | ||
| 527 | (define-key map [(shift tab)] 'backward-button) | ||
| 528 | (define-key map [(meta tab)] 'backward-button) | ||
| 529 | map) | ||
| 530 | "Keymap that allows tabbing between buttons.") | ||
| 531 | |||
| 532 | (defun tutorial--key-description (key) | 510 | (defun tutorial--key-description (key) |
| 533 | (let ((desc (key-description key))) | 511 | (let ((desc (key-description key))) |
| 534 | (cond ((string= "ESC" desc) "<ESC>") | 512 | (cond ((string= "ESC" desc) "<ESC>") |
| @@ -549,14 +527,14 @@ with some explanatory links." | |||
| 549 | (changed-keys-alist | 527 | (changed-keys-alist |
| 550 | (mapcar (lambda (ck) (cons (tutorial--key-description (car ck)) ck)) | 528 | (mapcar (lambda (ck) (cons (tutorial--key-description (car ck)) ck)) |
| 551 | changed-keys)) | 529 | changed-keys)) |
| 530 | changed-key | ||
| 552 | (start (point)) | 531 | (start (point)) |
| 553 | (case-fold-search nil) | 532 | (case-fold-search nil) |
| 554 | (keybindings-regexp | 533 | (keybindings-regexp |
| 555 | (concat "[[:space:]]\\(" | 534 | (concat "[[:space:]]\\(" |
| 556 | (mapconcat (lambda (kdf) | 535 | (mapconcat (lambda (kdf) (regexp-quote |
| 557 | (regexp-quote | 536 | (tutorial--key-description |
| 558 | (tutorial--key-description | 537 | (nth 1 kdf)))) |
| 559 | (nth 1 kdf)))) | ||
| 560 | tutorial--default-keys | 538 | tutorial--default-keys |
| 561 | "\\|") | 539 | "\\|") |
| 562 | "\\)[[:punct:][:space:]]"))) | 540 | "\\)[[:punct:][:space:]]"))) |
| @@ -568,55 +546,63 @@ with some explanatory links." | |||
| 568 | (head2 (get-lang-string tutorial--lang 'tut-chgdhead2))) | 546 | (head2 (get-lang-string tutorial--lang 'tut-chgdhead2))) |
| 569 | (when (and head head2) | 547 | (when (and head head2) |
| 570 | (goto-char tutorial--point-before-chkeys) | 548 | (goto-char tutorial--point-before-chkeys) |
| 571 | (insert head) | 549 | (insert head " [") |
| 572 | (insert-button head2 'tutorial-buffer (current-buffer) | 550 | (insert-button head2 'tutorial-buffer (current-buffer) |
| 573 | 'action 'tutorial--detailed-help | 551 | 'action 'tutorial--detailed-help |
| 574 | 'follow-link t 'face 'link) | 552 | 'follow-link t 'face 'link) |
| 575 | (insert "]\n\n") | 553 | (insert "]\n\n") |
| 576 | (add-text-properties tutorial--point-before-chkeys (point) | 554 | (add-text-properties tutorial--point-before-chkeys (point) |
| 577 | '(local-map tutorial--tab-map | 555 | '(tutorial-remark remark |
| 578 | tutorial-remark t | 556 | face tutorial-warning-face |
| 579 | face tutorial-warning-face | 557 | read-only t))))) |
| 580 | read-only t))))) | ||
| 581 | 558 | ||
| 582 | ;; Scan the tutorial for all key sequences. | 559 | ;; Scan the tutorial for all key sequences. |
| 583 | (goto-char (point-min)) | 560 | (goto-char (point-min)) |
| 584 | (while (re-search-forward keybindings-regexp (point-max) t) | 561 | (while (re-search-forward keybindings-regexp (point-max) t) |
| 585 | ;; Then highlight each rebound key sequence. | 562 | ;; Then highlight each rebound key sequence. |
| 586 | ;; This avoids issuing a warning for, e.g., C-x C-b if C-b is rebound. | 563 | ;; This avoids issuing a warning for, e.g., C-x C-b if C-b is rebound. |
| 587 | (let ((changed-key (assoc (match-string 1) changed-keys-alist))) | 564 | (setq changed-key (assoc (match-string 1) changed-keys-alist)) |
| 588 | (and changed-key | 565 | (and changed-key |
| 589 | (not (get-text-property (match-beginning 1) 'tutorial-remark)) | 566 | (not (get-text-property (match-beginning 1) 'tutorial-remark)) |
| 590 | (let* ((desc (car changed-key)) | 567 | (let* ((desc (car changed-key)) |
| 591 | (ck (cdr changed-key)) | 568 | (ck (cdr changed-key)) |
| 592 | (key (nth 0 ck)) | 569 | (key (nth 0 ck)) |
| 593 | (def-fun (nth 1 ck)) | 570 | (def-fun (nth 1 ck)) |
| 594 | (where (nth 3 ck))) | 571 | (where (nth 3 ck)) |
| 595 | (unless (string= where "Same key") | 572 | s1 s2 help-string) |
| 596 | (setq tutorial--point-after-chkeys (point-marker)) | 573 | (unless (string= where "Same key") |
| 597 | (put-text-property (match-beginning 1) | 574 | (setq tutorial--point-after-chkeys (point-marker) |
| 598 | (match-end 1) | 575 | s1 (get-lang-string tutorial--lang 'tut-chgdkey) |
| 599 | 'face 'tutorial-warning-face) | 576 | s2 (get-lang-string tutorial--lang 'tut-chgdkey2) |
| 600 | (put-text-property (match-beginning 1) | 577 | help-string (and s1 s2 (format s1 desc where))) |
| 601 | (match-end 1) | 578 | (add-text-properties (match-beginning 1) (match-end 1) |
| 602 | 'tutorial-remark t) | 579 | '(face tutorial-warning-face |
| 603 | (save-excursion | 580 | tutorial-remark key-sequence)) |
| 604 | (forward-line) | 581 | (if help-string |
| 605 | (let ((s (get-lang-string tutorial--lang 'tut-chgdkey)) | 582 | (if (nth 5 ck) |
| 606 | (s2 (get-lang-string tutorial--lang 'tut-chgdkey2)) | 583 | ;; Put help string in the tooltip. |
| 607 | (start (point))) | 584 | (put-text-property (match-beginning 1) (match-end 1) |
| 608 | (when (and s s2) | 585 | 'help-echo help-string) |
| 609 | (insert (format s desc where s2)) | 586 | ;; Put help string in the buffer. |
| 587 | (save-excursion | ||
| 588 | (setcar (nthcdr 5 ck) t) | ||
| 589 | (forward-line) | ||
| 590 | ;; Two or more changed keys were on the same line. | ||
| 591 | (while (eq (get-text-property (point) 'tutorial-remark) | ||
| 592 | 'remark) | ||
| 593 | (forward-line)) | ||
| 594 | (setq start (point)) | ||
| 595 | (insert "** " help-string " [") | ||
| 610 | (insert-button s2 'tutorial-buffer (current-buffer) | 596 | (insert-button s2 'tutorial-buffer (current-buffer) |
| 611 | 'action 'tutorial--detailed-help | 597 | 'action 'tutorial--detailed-help |
| 612 | 'explain-key-desc desc 'follow-link t | 598 | 'explain-key-desc desc 'follow-link t |
| 613 | 'face 'link) | 599 | 'face 'link) |
| 614 | (insert "] **\n") | 600 | (insert "] **\n") |
| 615 | (add-text-properties start (point) | 601 | (add-text-properties start (point) |
| 616 | '(local-map tutorial--tab-map | 602 | '(tutorial-remark remark |
| 617 | tutorial-remark t | 603 | rear-nonsticky t |
| 618 | face tutorial-warning-face | 604 | face tutorial-warning-face |
| 619 | read-only t)))))))))))) | 605 | read-only t))))))))))) |
| 620 | 606 | ||
| 621 | (defun tutorial--saved-dir () | 607 | (defun tutorial--saved-dir () |
| 622 | "Directory to which tutorials are saved." | 608 | "Directory to which tutorials are saved." |
| @@ -648,11 +634,8 @@ with some explanatory links." | |||
| 648 | (unless prop-end | 634 | (unless prop-end |
| 649 | (setq prop-end (point-max))) | 635 | (setq prop-end (point-max))) |
| 650 | (goto-char prop-end) | 636 | (goto-char prop-end) |
| 651 | (if (eq prop-val 'only-colored) | 637 | (unless (eq prop-val 'key-sequence) |
| 652 | (put-text-property prop-start prop-end 'face '(:background nil)) | 638 | (delete-region prop-start prop-end)))))) |
| 653 | (let ((orig-text (get-text-property prop-start 'tutorial-orig))) | ||
| 654 | (delete-region prop-start prop-end) | ||
| 655 | (when orig-text (insert orig-text)))))))) | ||
| 656 | 639 | ||
| 657 | (defun tutorial--save-tutorial () | 640 | (defun tutorial--save-tutorial () |
| 658 | "Save the tutorial buffer. | 641 | "Save the tutorial buffer. |
| @@ -903,7 +886,7 @@ Run the Viper tutorial? ")) | |||
| 903 | 886 | ||
| 904 | (defconst lang-strings | 887 | (defconst lang-strings |
| 905 | '(("English" . | 888 | '(("English" . |
| 906 | ((tut-chgdkey . "** %s has been rebound, but you can use %s instead [") | 889 | ((tut-chgdkey . "%s has been rebound, but you can use %s instead") |
| 907 | (tut-chgdkey2 . "More") | 890 | (tut-chgdkey2 . "More") |
| 908 | (tut-chgdhead . " | 891 | (tut-chgdhead . " |
| 909 | NOTICE: The main purpose of the Emacs tutorial is to teach you | 892 | NOTICE: The main purpose of the Emacs tutorial is to teach you |
| @@ -911,7 +894,7 @@ Run the Viper tutorial? ")) | |||
| 911 | However, your Emacs has been customized by changing some of | 894 | However, your Emacs has been customized by changing some of |
| 912 | these basic editing commands, so it doesn't correspond to the | 895 | these basic editing commands, so it doesn't correspond to the |
| 913 | tutorial. We have inserted colored notices where the altered | 896 | tutorial. We have inserted colored notices where the altered |
| 914 | commands have been introduced. [") | 897 | commands have been introduced.") |
| 915 | (tut-chgdhead2 . "More")))) | 898 | (tut-chgdhead2 . "More")))) |
| 916 | "Language specific strings for Emacs. | 899 | "Language specific strings for Emacs. |
| 917 | This is an association list with the keys equal to the strings | 900 | This is an association list with the keys equal to the strings |