Mercurial > emacs
comparison lisp/descr-text.el @ 67752:dd459879f1e7
Add FSF as maintainer.
(describe-text-mode, describe-text-mode-map)
(describe-text-mode-hook, describe-text-done): Delete. Use normal
help-mode.
(describe-text-widget, describe-text-sexp)
(describe-property-list, describe-text-category)
(describe-text-properties, describe-text-properties-1)
(describe-char): Use help buttons instead of widgets.
(describe-char-unicodedata-file): Make URL link in doc string.
author | Nick Roberts <nickrob@snap.net.nz> |
---|---|
date | Fri, 23 Dec 2005 01:51:44 +0000 |
parents | da1c54077c04 |
children | cc79e7966f97 |
comparison
equal
deleted
inserted
replaced
67751:5b235259a476 | 67752:dd459879f1e7 |
---|---|
2 | 2 |
3 ;; Copyright (C) 1994, 1995, 1996, 2001, 2002, 2003, 2004, | 3 ;; Copyright (C) 1994, 1995, 1996, 2001, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | 4 ;; 2005 Free Software Foundation, Inc. |
5 | 5 |
6 ;; Author: Boris Goldowsky <boris@gnu.org> | 6 ;; Author: Boris Goldowsky <boris@gnu.org> |
7 ;; Maintainer: FSF | |
7 ;; Keywords: faces, i18n, Unicode, multilingual | 8 ;; Keywords: faces, i18n, Unicode, multilingual |
8 | 9 |
9 ;; This file is part of GNU Emacs. | 10 ;; This file is part of GNU Emacs. |
10 | 11 |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | 12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
29 | 30 |
30 ;;; Code: | 31 ;;; Code: |
31 | 32 |
32 (eval-when-compile (require 'button) (require 'quail)) | 33 (eval-when-compile (require 'button) (require 'quail)) |
33 | 34 |
34 (defun describe-text-done () | |
35 "Delete the current window or bury the current buffer." | |
36 (interactive) | |
37 (if (> (count-windows) 1) | |
38 (delete-window) | |
39 (bury-buffer))) | |
40 | |
41 (defvar describe-text-mode-map | |
42 (let ((map (make-sparse-keymap))) | |
43 (set-keymap-parent map widget-keymap) | |
44 map) | |
45 "Keymap for `describe-text-mode'.") | |
46 | |
47 (defcustom describe-text-mode-hook nil | |
48 "List of hook functions ran by `describe-text-mode'." | |
49 :type 'hook | |
50 :group 'facemenu) | |
51 | |
52 (defun describe-text-mode () | |
53 "Major mode for buffers created by `describe-char'. | |
54 | |
55 \\{describe-text-mode-map} | |
56 Entry to this mode calls the value of `describe-text-mode-hook' | |
57 if that value is non-nil." | |
58 (kill-all-local-variables) | |
59 (setq major-mode 'describe-text-mode | |
60 mode-name "Describe-Text") | |
61 (use-local-map describe-text-mode-map) | |
62 (widget-setup) | |
63 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t) | |
64 (run-mode-hooks 'describe-text-mode-hook)) | |
65 | |
66 ;;; Describe-Text Utilities. | 35 ;;; Describe-Text Utilities. |
67 | 36 |
68 (defun describe-text-widget (widget) | 37 (defun describe-text-widget (widget) |
69 "Insert text to describe WIDGET in the current buffer." | 38 "Insert text to describe WIDGET in the current buffer." |
70 (widget-create 'link | 39 (insert-text-button |
71 :notify `(lambda (&rest ignore) | 40 (symbol-name (if (symbolp widget) widget (car widget))) |
72 (widget-browse ',widget)) | 41 'action `(lambda (&rest ignore) |
73 (format "%S" (if (symbolp widget) | 42 (widget-browse ',widget))) |
74 widget | 43 (insert " ") |
75 (car widget)))) | 44 (insert-text-button "(widget)Top" |
76 (widget-insert " ") | 45 'action (lambda (&rest ignore) (info "(widget)Top")) |
77 (widget-create 'info-link :tag "widget" "(widget)Top")) | 46 'help-echo "mouse-2, RET: read this Info node")) |
78 | 47 |
79 (defun describe-text-sexp (sexp) | 48 (defun describe-text-sexp (sexp) |
80 "Insert a short description of SEXP in the current buffer." | 49 "Insert a short description of SEXP in the current buffer." |
81 (let ((pp (condition-case signal | 50 (let ((pp (condition-case signal |
82 (pp-to-string sexp) | 51 (pp-to-string sexp) |
86 (if (cond ((string-match "\n" pp) | 55 (if (cond ((string-match "\n" pp) |
87 nil) | 56 nil) |
88 ((> (length pp) (- (window-width) (current-column))) | 57 ((> (length pp) (- (window-width) (current-column))) |
89 nil) | 58 nil) |
90 (t t)) | 59 (t t)) |
91 (widget-insert pp) | 60 (insert pp) |
92 (widget-create 'push-button | 61 (insert-text-button |
93 :tag "show" | 62 "show" 'action `(lambda (&rest ignore) |
94 :action (lambda (widget &optional event) | 63 (with-output-to-temp-buffer |
95 (with-output-to-temp-buffer | 64 "*Pp Eval Output*" |
96 "*Pp Eval Output*" | 65 (princ ',pp))) |
97 (princ (widget-get widget :value)))) | 66 'help-echo "mouse-2, RET: pretty print value in another buffer")))) |
98 pp)))) | |
99 | 67 |
100 (defun describe-property-list (properties) | 68 (defun describe-property-list (properties) |
101 "Insert a description of PROPERTIES in the current buffer. | 69 "Insert a description of PROPERTIES in the current buffer. |
102 PROPERTIES should be a list of overlay or text properties. | 70 PROPERTIES should be a list of overlay or text properties. |
103 The `category', `face' and `font-lock-face' properties are made | 71 The `category', `face' and `font-lock-face' properties are made |
104 into widget buttons that call `describe-text-category' or | 72 into help buttons that call `describe-text-category' or |
105 `describe-face' when pushed." | 73 `describe-face' when pushed." |
106 ;; Sort the properties by the size of their value. | 74 ;; Sort the properties by the size of their value. |
107 (dolist (elt (sort (let (ret) | 75 (dolist (elt (sort (let (ret) |
108 (while properties | 76 (while properties |
109 (push (list (pop properties) (pop properties)) ret)) | 77 (push (list (pop properties) (pop properties)) ret)) |
110 ret) | 78 ret) |
111 (lambda (a b) (string< (prin1-to-string (nth 0 a) t) | 79 (lambda (a b) (string< (prin1-to-string (nth 0 a) t) |
112 (prin1-to-string (nth 0 b) t))))) | 80 (prin1-to-string (nth 0 b) t))))) |
113 (let ((key (nth 0 elt)) | 81 (let ((key (nth 0 elt)) |
114 (value (nth 1 elt))) | 82 (value (nth 1 elt))) |
115 (widget-insert (propertize (format " %-20s " key) | 83 (insert (propertize (format " %-20s " key) |
116 'font-lock-face 'italic)) | 84 'face 'italic)) |
117 (cond ((eq key 'category) | 85 (cond ((eq key 'category) |
118 (widget-create 'link | 86 (insert-text-button (symbol-name value) |
119 :notify `(lambda (&rest ignore) | 87 'action `(lambda (&rest ignore) |
120 (describe-text-category ',value)) | 88 (describe-text-category ',value)) |
121 (format "%S" value))) | 89 'help-echo |
90 "mouse-2, RET: describe this category")) | |
122 ((memq key '(face font-lock-face mouse-face)) | 91 ((memq key '(face font-lock-face mouse-face)) |
123 (widget-create 'link | 92 (insert (concat "`" (format "%S" value) "'"))) |
124 :notify `(lambda (&rest ignore) | |
125 (describe-face ',value)) | |
126 (format "%S" value))) | |
127 ((widgetp value) | 93 ((widgetp value) |
128 (describe-text-widget value)) | 94 (describe-text-widget value)) |
129 (t | 95 (t |
130 (describe-text-sexp value)))) | 96 (describe-text-sexp value)))) |
131 (widget-insert "\n"))) | 97 (insert "\n"))) |
132 | 98 |
133 ;;; Describe-Text Commands. | 99 ;;; Describe-Text Commands. |
134 | 100 |
135 (defun describe-text-category (category) | 101 (defun describe-text-category (category) |
136 "Describe a text property category." | 102 "Describe a text property category." |
137 (interactive "S") | 103 (interactive "S") |
138 (save-excursion | 104 (save-excursion |
139 (with-output-to-temp-buffer "*Help*" | 105 (with-output-to-temp-buffer "*Help*" |
140 (set-buffer standard-output) | 106 (set-buffer standard-output) |
141 (widget-insert "Category " (format "%S" category) ":\n\n") | 107 (insert "Category " (format "%S" category) ":\n\n") |
142 (describe-property-list (symbol-plist category)) | 108 (describe-property-list (symbol-plist category)) |
143 (describe-text-mode) | |
144 (goto-char (point-min))))) | 109 (goto-char (point-min))))) |
145 | 110 |
146 ;;;###autoload | 111 ;;;###autoload |
147 (defun describe-text-properties (pos &optional output-buffer) | 112 (defun describe-text-properties (pos &optional output-buffer) |
148 "Describe widgets, buttons, overlays and text properties at POS. | 113 "Describe widgets, buttons, overlays and text properties at POS. |
163 (setq target-buffer "*Help*<2>")) | 128 (setq target-buffer "*Help*<2>")) |
164 (save-excursion | 129 (save-excursion |
165 (with-output-to-temp-buffer target-buffer | 130 (with-output-to-temp-buffer target-buffer |
166 (set-buffer standard-output) | 131 (set-buffer standard-output) |
167 (setq output-buffer (current-buffer)) | 132 (setq output-buffer (current-buffer)) |
168 (widget-insert "Text content at position " (format "%d" pos) ":\n\n") | 133 (insert "Text content at position " (format "%d" pos) ":\n\n") |
169 (with-current-buffer buffer | 134 (with-current-buffer buffer |
170 (describe-text-properties-1 pos output-buffer)) | 135 (describe-text-properties-1 pos output-buffer)) |
171 (describe-text-mode) | |
172 (goto-char (point-min)))))))) | 136 (goto-char (point-min)))))))) |
173 | 137 |
174 (defun describe-text-properties-1 (pos output-buffer) | 138 (defun describe-text-properties-1 (pos output-buffer) |
175 (let* ((properties (text-properties-at pos)) | 139 (let* ((properties (text-properties-at pos)) |
176 (overlays (overlays-at pos)) | 140 (overlays (overlays-at pos)) |
184 (widget (or wid-field wid-button wid-doc))) | 148 (widget (or wid-field wid-button wid-doc))) |
185 (with-current-buffer output-buffer | 149 (with-current-buffer output-buffer |
186 ;; Widgets | 150 ;; Widgets |
187 (when (widgetp widget) | 151 (when (widgetp widget) |
188 (newline) | 152 (newline) |
189 (widget-insert (cond (wid-field "This is an editable text area") | 153 (insert (cond (wid-field "This is an editable text area") |
190 (wid-button "This is an active area") | 154 (wid-button "This is an active area") |
191 (wid-doc "This is documentation text"))) | 155 (wid-doc "This is documentation text"))) |
192 (widget-insert " of a ") | 156 (insert " of a ") |
193 (describe-text-widget widget) | 157 (describe-text-widget widget) |
194 (widget-insert ".\n\n")) | 158 (insert ".\n\n")) |
195 ;; Buttons | 159 ;; Buttons |
196 (when (and button (not (widgetp wid-button))) | 160 (when (and button (not (widgetp wid-button))) |
197 (newline) | 161 (newline) |
198 (widget-insert "Here is a " (format "%S" button-type) | 162 (insert "Here is a " (format "%S" button-type) |
199 " button labeled `" button-label "'.\n\n")) | 163 " button labeled `" button-label "'.\n\n")) |
200 ;; Overlays | 164 ;; Overlays |
201 (when overlays | 165 (when overlays |
202 (newline) | 166 (newline) |
203 (if (eq (length overlays) 1) | 167 (if (eq (length overlays) 1) |
204 (widget-insert "There is an overlay here:\n") | 168 (insert "There is an overlay here:\n") |
205 (widget-insert "There are " (format "%d" (length overlays)) | 169 (insert "There are " (format "%d" (length overlays)) |
206 " overlays here:\n")) | 170 " overlays here:\n")) |
207 (dolist (overlay overlays) | 171 (dolist (overlay overlays) |
208 (widget-insert " From " (format "%d" (overlay-start overlay)) | 172 (insert " From " (format "%d" (overlay-start overlay)) |
209 " to " (format "%d" (overlay-end overlay)) "\n") | 173 " to " (format "%d" (overlay-end overlay)) "\n") |
210 (describe-property-list (overlay-properties overlay))) | 174 (describe-property-list (overlay-properties overlay))) |
211 (widget-insert "\n")) | 175 (insert "\n")) |
212 ;; Text properties | 176 ;; Text properties |
213 (when properties | 177 (when properties |
214 (newline) | 178 (newline) |
215 (widget-insert "There are text properties here:\n") | 179 (insert "There are text properties here:\n") |
216 (describe-property-list properties))))) | 180 (describe-property-list properties))))) |
217 | 181 |
218 (defcustom describe-char-unicodedata-file nil | 182 (defcustom describe-char-unicodedata-file nil |
219 "Location of Unicode data file. | 183 "Location of Unicode data file. |
220 This is the UnicodeData.txt file from the Unicode consortium, used for | 184 This is the UnicodeData.txt file from the Unicode consortium, used for |
221 diagnostics. If it is non-nil `describe-char' will print data | 185 diagnostics. If it is non-nil `describe-char' will print data |
222 looked up from it. This facility is mostly of use to people doing | 186 looked up from it. This facility is mostly of use to people doing |
223 multilingual development. | 187 multilingual development. |
224 | 188 |
225 This is a fairly large file, not typically present on GNU systems. At | 189 This is a fairly large file, not typically present on GNU systems. At |
226 the time of writing it is at | 190 the time of writing it is at the URL |
227 <URL:http://www.unicode.org/Public/UNIDATA/UnicodeData.txt>." | 191 `http://www.unicode.org/Public/UNIDATA/UnicodeData.txt'." |
228 :group 'mule | 192 :group 'mule |
229 :version "22.1" | 193 :version "22.1" |
230 :type '(choice (const :tag "None" nil) | 194 :type '(choice (const :tag "None" nil) |
231 file)) | 195 file)) |
232 | 196 |
486 char char char | 450 char char char |
487 (if unicode | 451 (if unicode |
488 (format ", U+%04X" unicode) | 452 (format ", U+%04X" unicode) |
489 ""))) | 453 ""))) |
490 ("charset" | 454 ("charset" |
491 ,`(widget-create 'link | 455 ,`(insert-text-button |
492 :notify (lambda (&rest ignore) | 456 (symbol-name charset) |
493 (describe-character-set ',charset)) | 457 'action `(lambda (&rest ignore) |
494 ,(symbol-name charset)) | 458 (describe-character-set ',charset)) |
459 'help-echo | |
460 "mouse-2, RET: describe this character set") | |
495 ,(format "(%s)" (charset-description charset))) | 461 ,(format "(%s)" (charset-description charset))) |
496 ("code point" | 462 ("code point" |
497 ,(let ((split (split-char char))) | 463 ,(let ((split (split-char char))) |
498 `(widget-create | 464 `(insert-text-button ,(if (= (charset-dimension charset) 1) |
499 'link | 465 (format "%d" (nth 1 split)) |
500 :notify (lambda (&rest ignore) | 466 (format "%d %d" (nth 1 split) |
501 (list-charset-chars ',charset) | 467 (nth 2 split))) |
502 (with-selected-window | 468 'action (lambda (&rest ignore) |
503 (get-buffer-window "*Character List*" 0) | 469 (list-charset-chars ',charset) |
504 (goto-char (point-min)) | 470 (with-selected-window |
471 (get-buffer-window "*Character List*" 0) | |
472 (goto-char (point-min)) | |
505 (forward-line 2) ;Skip the header. | 473 (forward-line 2) ;Skip the header. |
506 (let ((case-fold-search nil)) | 474 (let ((case-fold-search nil)) |
507 (search-forward ,(char-to-string char) | 475 (search-forward ,(char-to-string char) |
508 nil t)))) | 476 nil t))))))) |
509 ,(if (= (charset-dimension charset) 1) | |
510 (format "%d" (nth 1 split)) | |
511 (format "%d %d" (nth 1 split) (nth 2 split)))))) | |
512 ("syntax" | 477 ("syntax" |
513 ,(let ((syntax (syntax-after pos))) | 478 ,(let ((syntax (syntax-after pos))) |
514 (with-temp-buffer | 479 (with-temp-buffer |
515 (internal-describe-syntax-value syntax) | 480 (internal-describe-syntax-value syntax) |
516 (buffer-string)))) | 481 (buffer-string)))) |
535 (if (consp key-list) | 500 (if (consp key-list) |
536 (list "type" | 501 (list "type" |
537 (mapconcat #'(lambda (x) (concat "\"" x "\"")) | 502 (mapconcat #'(lambda (x) (concat "\"" x "\"")) |
538 key-list " or ") | 503 key-list " or ") |
539 "with" | 504 "with" |
540 `(widget-create | 505 `(insert-text-button |
541 'link | 506 (symbol-name current-input-method) |
542 :notify (lambda (&rest ignore) | 507 'action (lambda (&rest ignore) |
543 (describe-input-method | 508 (describe-input-method |
544 ',current-input-method)) | 509 ',current-input-method))))))) |
545 ,(format "%s" current-input-method)))))) | |
546 ("buffer code" | 510 ("buffer code" |
547 ,(encoded-string-description | 511 ,(encoded-string-description |
548 (string-as-unibyte (char-to-string char)) nil)) | 512 (string-as-unibyte (char-to-string char)) nil)) |
549 ("file code" | 513 ("file code" |
550 ,@(let* ((coding buffer-file-coding-system) | 514 ,@(let* ((coding buffer-file-coding-system) |
609 ((and nobreak-char-display unicode (eq unicode '#xad)) | 573 ((and nobreak-char-display unicode (eq unicode '#xad)) |
610 'escape-glyph) | 574 'escape-glyph) |
611 ((and (< char 32) (not (memq char '(9 10)))) | 575 ((and (< char 32) (not (memq char '(9 10)))) |
612 'escape-glyph))))) | 576 'escape-glyph))))) |
613 (if face (list (list "hardcoded face" | 577 (if face (list (list "hardcoded face" |
614 `(widget-create | 578 '(insert |
615 'link | 579 (concat "`" (symbol-name face) "'")))))) |
616 :notify (lambda (&rest ignore) | |
617 (describe-face ',face)) | |
618 ,(format "%s" face)))))) | |
619 ,@(let ((unicodedata (and unicode | 580 ,@(let ((unicodedata (and unicode |
620 (describe-char-unicode-data unicode)))) | 581 (describe-char-unicode-data unicode)))) |
621 (if unicodedata | 582 (if unicodedata |
622 (cons (list "Unicode data" " ") unicodedata))))) | 583 (cons (list "Unicode data" " ") unicodedata))))) |
623 (setq max-width (apply #'max (mapcar #'(lambda (x) | 584 (setq max-width (apply #'max (mapcar #'(lambda (x) |
624 (if (cadr x) (length (car x)) 0)) | 585 (if (cadr x) (length (car x)) 0)) |
625 item-list))) | 586 item-list))) |
626 (with-output-to-temp-buffer "*Help*" | 587 (help-setup-xref nil (interactive-p)) |
588 (with-output-to-temp-buffer (help-buffer) | |
627 (with-current-buffer standard-output | 589 (with-current-buffer standard-output |
628 (let ((help-xref-following t)) | |
629 (help-setup-xref nil nil)) | |
630 (set-buffer-multibyte multibyte-p) | 590 (set-buffer-multibyte multibyte-p) |
631 (let ((formatter (format "%%%ds:" max-width))) | 591 (let ((formatter (format "%%%ds:" max-width))) |
632 (dolist (elt item-list) | 592 (dolist (elt item-list) |
633 (when (cadr elt) | 593 (when (cadr elt) |
634 (insert (format formatter (car elt))) | 594 (insert (format formatter (car elt))) |
635 (dolist (clm (cdr elt)) | 595 (dolist (clm (cdr elt)) |
636 (if (eq (car-safe clm) 'widget-create) | 596 (if (eq (car-safe clm) 'insert-text-button) |
637 (progn (insert " ") (eval clm)) | 597 (progn (insert " ") (eval clm)) |
638 (when (>= (+ (current-column) | 598 (when (>= (+ (current-column) |
639 (or (string-match "\n" clm) | 599 (or (string-match "\n" clm) |
640 (string-width clm)) | 600 (string-width clm)) |
641 1) | 601 1) |
671 (cddr (aref disp-vector i))) | 631 (cddr (aref disp-vector i))) |
672 "-- no font --") | 632 "-- no font --") |
673 "\n") | 633 "\n") |
674 (when (> (car (aref disp-vector i)) #x7ffff) | 634 (when (> (car (aref disp-vector i)) #x7ffff) |
675 (let* ((face-id (lsh (car (aref disp-vector i)) -19)) | 635 (let* ((face-id (lsh (car (aref disp-vector i)) -19)) |
676 (face (car (delq nil (mapcar (lambda (face) | 636 (face (car (delq nil (mapcar |
677 (and (eq (face-id face) | 637 (lambda (face) |
678 face-id) face)) | 638 (and (eq (face-id face) |
679 (face-list)))))) | 639 face-id) face)) |
640 (face-list)))))) | |
680 (when face | 641 (when face |
681 (insert (propertize " " 'display '(space :align-to 5)) | 642 (insert (propertize " " 'display '(space :align-to 5)) |
682 "face: ") | 643 "face: ") |
683 (widget-create 'link | 644 (insert (concat "`" (symbol-name face) "'")) |
684 :notify `(lambda (&rest ignore) | |
685 (describe-face ',face)) | |
686 (format "%S" face)) | |
687 (insert "\n")))))) | 645 (insert "\n")))))) |
688 (insert "these terminal codes:\n") | 646 (insert "these terminal codes:\n") |
689 (dotimes (i (length disp-vector)) | 647 (dotimes (i (length disp-vector)) |
690 (insert (car (aref disp-vector i)) | 648 (insert (car (aref disp-vector i)) |
691 (propertize " " 'display '(space :align-to 5)) | 649 (propertize " " 'display '(space :align-to 5)) |
727 (or (cdr elt) "-- not encodable --")))) | 685 (or (cdr elt) "-- not encodable --")))) |
728 (insert "\nSee the variable `reference-point-alist' for " | 686 (insert "\nSee the variable `reference-point-alist' for " |
729 "the meaning of the rule.\n")) | 687 "the meaning of the rule.\n")) |
730 | 688 |
731 (if text-props-desc (insert text-props-desc)) | 689 (if text-props-desc (insert text-props-desc)) |
732 (describe-text-mode) | |
733 (toggle-read-only 1) | 690 (toggle-read-only 1) |
734 (help-make-xrefs (current-buffer)) | |
735 (print-help-return-message))))) | 691 (print-help-return-message))))) |
736 | 692 |
737 (defalias 'describe-char-after 'describe-char) | 693 (defalias 'describe-char-after 'describe-char) |
738 (make-obsolete 'describe-char-after 'describe-char "22.1") | 694 (make-obsolete 'describe-char-after 'describe-char "22.1") |
739 | 695 |