Mercurial > emacs
comparison lisp/tutorial.el @ 74795:4404b91f3a72
(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.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Fri, 22 Dec 2006 15:17:24 +0000 |
parents | ecc3f98301f4 |
children | 90a64762539d |
comparison
equal
deleted
inserted
replaced
74794:4a9998346e6e | 74795:4404b91f3a72 |
---|---|
334 (tutorial--find-changed-keys | 334 (tutorial--find-changed-keys |
335 tutorial--default-keys))))) | 335 tutorial--default-keys))))) |
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) |
343 (let* ((def-fun (nth 1 tk)) | 343 (let* ((def-fun (nth 1 tk)) |
344 (key (nth 0 tk)) | 344 (key (nth 0 tk)) |
389 'follow-link t) | 389 'follow-link t) |
390 (insert "\n"))))) | 390 (insert "\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. | 400 |
409 | 401 '(KEY DEF-FUN DEF-FUN-TXT WHERE REMARK QUIET) |
410 Return a list with the keys that have been changed. The element | 402 |
411 of this list have the following format: | 403 where |
412 | 404 |
413 \(list KEY DEF-FUN DEF-FUN-TXT WHERE REMARK) | |
414 | |
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 |
419 WHERE is a text describing the key sequences to which DEF-FUN is | 408 WHERE is a text describing the key sequences to which DEF-FUN is |
420 bound now (or, if it is remapped, a key sequence | 409 bound now (or, if it is remapped, a key sequence |
427 | 416 |
428 Here TEXT is a link text to show to the user. The | 417 Here TEXT is a link text to show to the user. The |
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 |
436 ;; described in the doc string. | 427 ;; described in the doc string. |
437 (let* ((key (nth 1 kdf)) | 428 (let* ((key (nth 1 kdf)) |
467 (equal key [?\C-z]) | 458 (equal key [?\C-z]) |
468 (eq key-fun 'undo)))) | 459 (eq key-fun 'undo)))) |
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: |
495 ((and (boundp 'viper-mode-string) | 481 ((and (boundp 'viper-mode-string) |
496 (boundp 'viper-current-state) | 482 (boundp 'viper-current-state) |
516 (setq remark | 502 (setq remark |
517 (list "more info" 'current-binding | 503 (list "more info" 'current-binding |
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 | |
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 | 509 |
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>") |
535 ((string= "RET" desc) "<Return>") | 513 ((string= "RET" desc) "<Return>") |
547 ;; key-description of a changed key and CK is the | 525 ;; key-description of a changed key and CK is the |
548 ;; corresponding element in `changed-keys'. | 526 ;; corresponding element in `changed-keys'. |
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:]]"))) |
563 ;; Need the custom button face for viper buttons: | 541 ;; Need the custom button face for viper buttons: |
564 (if (boundp 'viper-mode-string) (require 'cus-edit)) | 542 (if (boundp 'viper-mode-string) (require 'cus-edit)) |
566 (if (or changed-keys (boundp 'viper-mode-string)) | 544 (if (or changed-keys (boundp 'viper-mode-string)) |
567 (let ((head (get-lang-string tutorial--lang 'tut-chgdhead)) | 545 (let ((head (get-lang-string tutorial--lang 'tut-chgdhead)) |
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." |
623 (expand-file-name "tutorial" | 609 (expand-file-name "tutorial" |
624 (if (eq system-type 'ms-dos) "~/_emacs.d/" "~/.emacs.d/"))) | 610 (if (eq system-type 'ms-dos) "~/_emacs.d/" "~/.emacs.d/"))) |
646 (setq prop-end (next-single-property-change prop-start 'tutorial-remark)) | 632 (setq prop-end (next-single-property-change prop-start 'tutorial-remark)) |
647 (setq prop-val (get-text-property prop-start 'tutorial-remark)) | 633 (setq prop-val (get-text-property prop-start 'tutorial-remark)) |
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. |
659 This saves the part of the tutorial before and after the area | 642 This saves the part of the tutorial before and after the area |
660 showing changed keys. It also saves the point position and the | 643 showing changed keys. It also saves the point position and the |
901 ;; Below is some attempt to handle language specific strings. These | 884 ;; Below is some attempt to handle language specific strings. These |
902 ;; are currently only used in the tutorial. | 885 ;; are currently only used in the 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 |
910 the most important standard Emacs commands (key bindings). | 893 the most important standard Emacs commands (key bindings). |
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 |
918 that can be returned by `read-language-name'. The elements in | 901 that can be returned by `read-language-name'. The elements in |
919 the list are themselves association lists with keys that are | 902 the list are themselves association lists with keys that are |