comparison lisp/descr-text.el @ 67814:cc79e7966f97

2005-12-27 Nick Roberts <nickrob@snap.net.nz> * descr-text.el (describe-char): Add optional argument for buffer. Set buffer appropriately. Call help-setup-xref. Suggested by Stefan Monnier. 2005-12-27 Juri Linkov <juri@jurta.org> * descr-text.el (help-fns): Require. Don't require button for byte compilation. (describe-text-widget): Add help echo for first button. Use 'help-info for second. (describe-property-list): Use 'help-argument-name instead of 'italic. (describe-text-category): Prompt in minibuffer. Call help-setup-xref. (describe-char): Use 'help-character-set. Add help echo. Use 'help-input-method. Remove superfluous insert.
author Nick Roberts <nickrob@snap.net.nz>
date Mon, 26 Dec 2005 11:41:22 +0000
parents dd459879f1e7
children 3af6058f9f07
comparison
equal deleted inserted replaced
67813:7ead07735f77 67814:cc79e7966f97
28 28
29 ;;; Describe-Text Mode. 29 ;;; Describe-Text Mode.
30 30
31 ;;; Code: 31 ;;; Code:
32 32
33 (eval-when-compile (require 'button) (require 'quail)) 33 (eval-when-compile (require 'quail))
34 (require 'help-fns)
34 35
35 ;;; Describe-Text Utilities. 36 ;;; Describe-Text Utilities.
36 37
37 (defun describe-text-widget (widget) 38 (defun describe-text-widget (widget)
38 "Insert text to describe WIDGET in the current buffer." 39 "Insert text to describe WIDGET in the current buffer."
39 (insert-text-button 40 (insert-text-button
40 (symbol-name (if (symbolp widget) widget (car widget))) 41 (symbol-name (if (symbolp widget) widget (car widget)))
41 'action `(lambda (&rest ignore) 42 'action `(lambda (&rest ignore)
42 (widget-browse ',widget))) 43 (widget-browse ',widget))
44 'help-echo "mouse-2, RET: browse this widget")
43 (insert " ") 45 (insert " ")
44 (insert-text-button "(widget)Top" 46 (insert-text-button
45 'action (lambda (&rest ignore) (info "(widget)Top")) 47 "(widget)Top" 'type 'help-info 'help-args '("(widget)Top")))
46 'help-echo "mouse-2, RET: read this Info node"))
47 48
48 (defun describe-text-sexp (sexp) 49 (defun describe-text-sexp (sexp)
49 "Insert a short description of SEXP in the current buffer." 50 "Insert a short description of SEXP in the current buffer."
50 (let ((pp (condition-case signal 51 (let ((pp (condition-case signal
51 (pp-to-string sexp) 52 (pp-to-string sexp)
79 (lambda (a b) (string< (prin1-to-string (nth 0 a) t) 80 (lambda (a b) (string< (prin1-to-string (nth 0 a) t)
80 (prin1-to-string (nth 0 b) t))))) 81 (prin1-to-string (nth 0 b) t)))))
81 (let ((key (nth 0 elt)) 82 (let ((key (nth 0 elt))
82 (value (nth 1 elt))) 83 (value (nth 1 elt)))
83 (insert (propertize (format " %-20s " key) 84 (insert (propertize (format " %-20s " key)
84 'face 'italic)) 85 'face 'help-argument-name))
85 (cond ((eq key 'category) 86 (cond ((eq key 'category)
86 (insert-text-button (symbol-name value) 87 (insert-text-button
87 'action `(lambda (&rest ignore) 88 (symbol-name value)
88 (describe-text-category ',value)) 89 'action `(lambda (&rest ignore)
89 'help-echo 90 (describe-text-category ',value))
90 "mouse-2, RET: describe this category")) 91 'help-echo "mouse-2, RET: describe this category"))
91 ((memq key '(face font-lock-face mouse-face)) 92 ((memq key '(face font-lock-face mouse-face))
92 (insert (concat "`" (format "%S" value) "'"))) 93 (insert (concat "`" (format "%S" value) "'")))
93 ((widgetp value) 94 ((widgetp value)
94 (describe-text-widget value)) 95 (describe-text-widget value))
95 (t 96 (t
98 99
99 ;;; Describe-Text Commands. 100 ;;; Describe-Text Commands.
100 101
101 (defun describe-text-category (category) 102 (defun describe-text-category (category)
102 "Describe a text property category." 103 "Describe a text property category."
103 (interactive "S") 104 (interactive "SCategory: ")
105 (help-setup-xref (list #'describe-text-category category) (interactive-p))
104 (save-excursion 106 (save-excursion
105 (with-output-to-temp-buffer "*Help*" 107 (with-output-to-temp-buffer "*Help*"
106 (set-buffer standard-output) 108 (set-buffer standard-output)
107 (insert "Category " (format "%S" category) ":\n\n") 109 (insert "Category " (format "%S" category) ":\n\n")
108 (describe-property-list (symbol-plist category)) 110 (describe-property-list (symbol-plist category))
400 (if encoded 402 (if encoded
401 (encoded-string-description encoded coding))))) 403 (encoded-string-description encoded coding)))))
402 404
403 405
404 ;;;###autoload 406 ;;;###autoload
405 (defun describe-char (pos) 407 (defun describe-char (pos &optional buf)
406 "Describe the character after POS (interactively, the character after point). 408 "Describe the character after POS (interactively, the character after point).
407 The information includes character code, charset and code points in it, 409 The information includes character code, charset and code points in it,
408 syntax, category, how the character is encoded in a file, 410 syntax, category, how the character is encoded in a file,
409 character composition information (if relevant), 411 character composition information (if relevant),
410 as well as widgets, buttons, overlays, and text properties." 412 as well as widgets, buttons, overlays, and text properties."
411 (interactive "d") 413 (interactive "d")
414 (let ((help-buffer (help-buffer)))
415 (with-current-buffer (if buf buf (current-buffer))
412 (if (>= pos (point-max)) 416 (if (>= pos (point-max))
413 (error "No character follows specified position")) 417 (error "No character follows specified position"))
414 (let* ((char (char-after pos)) 418 (let* ((char (char-after pos))
415 (charset (char-charset char)) 419 (charset (char-charset char))
416 (composition (find-composition pos nil nil t)) 420 (composition (find-composition pos nil nil t))
426 (single-key-description char) 430 (single-key-description char)
427 (if (< char 128) 431 (if (< char 128)
428 (single-key-description char) 432 (single-key-description char)
429 (string-to-multibyte 433 (string-to-multibyte
430 (char-to-string char))))) 434 (char-to-string char)))))
431 (text-props-desc 435 (text-props-desc
432 (let ((tmp-buf (generate-new-buffer " *text-props*"))) 436 (let ((tmp-buf (generate-new-buffer " *text-props*")))
433 (unwind-protect 437 (unwind-protect
434 (progn 438 (progn
435 (describe-text-properties pos tmp-buf) 439 (describe-text-properties pos tmp-buf)
436 (with-current-buffer tmp-buf (buffer-string))) 440 (with-current-buffer tmp-buf (buffer-string)))
437 (kill-buffer tmp-buf)))) 441 (kill-buffer tmp-buf))))
438 item-list max-width unicode) 442 item-list max-width unicode)
439 443
440 (if (or (< char 256) 444 (if (or (< char 256)
441 (memq 'mule-utf-8 (find-coding-systems-region pos (1+ pos))) 445 (memq 'mule-utf-8 (find-coding-systems-region pos (1+ pos)))
442 (get-char-property pos 'untranslated-utf-8)) 446 (get-char-property pos 'untranslated-utf-8))
443 (setq unicode (or (get-char-property pos 'untranslated-utf-8) 447 (setq unicode (or (get-char-property pos 'untranslated-utf-8)
444 (encode-char char 'ucs)))) 448 (encode-char char 'ucs))))
445 (setq item-list 449 (setq item-list
446 `(("character" 450 `(("character"
447 ,(format "%s (%d, #o%o, #x%x%s)" 451 ,(format "%s (%d, #o%o, #x%x%s)"
448 (apply 'propertize char-description 452 (apply 'propertize char-description
449 (text-properties-at pos)) 453 (text-properties-at pos))
450 char char char 454 char char char
451 (if unicode 455 (if unicode
452 (format ", U+%04X" unicode) 456 (format ", U+%04X" unicode)
453 ""))) 457 "")))
454 ("charset" 458 ("charset"
455 ,`(insert-text-button 459 ,`(insert-text-button
456 (symbol-name charset) 460 ,(symbol-name charset)
457 'action `(lambda (&rest ignore) 461 'type 'help-character-set 'help-args '(,charset))
458 (describe-character-set ',charset))
459 'help-echo
460 "mouse-2, RET: describe this character set")
461 ,(format "(%s)" (charset-description charset))) 462 ,(format "(%s)" (charset-description charset)))
462 ("code point" 463 ("code point"
463 ,(let ((split (split-char char))) 464 ,(let ((split (split-char char)))
464 `(insert-text-button ,(if (= (charset-dimension charset) 1) 465 `(insert-text-button
465 (format "%d" (nth 1 split)) 466 ,(if (= (charset-dimension charset) 1)
466 (format "%d %d" (nth 1 split) 467 (format "%d" (nth 1 split))
467 (nth 2 split))) 468 (format "%d %d" (nth 1 split)
468 'action (lambda (&rest ignore) 469 (nth 2 split)))
469 (list-charset-chars ',charset) 470 'action (lambda (&rest ignore)
470 (with-selected-window 471 (list-charset-chars ',charset)
471 (get-buffer-window "*Character List*" 0) 472 (with-selected-window
472 (goto-char (point-min)) 473 (get-buffer-window "*Character List*" 0)
473 (forward-line 2) ;Skip the header. 474 (goto-char (point-min))
474 (let ((case-fold-search nil)) 475 (forward-line 2) ;Skip the header.
475 (search-forward ,(char-to-string char) 476 (let ((case-fold-search nil))
476 nil t))))))) 477 (search-forward ,(char-to-string char)
478 nil t))))
479 'help-echo
480 "mouse-2, RET: show this character in its character set")))
477 ("syntax" 481 ("syntax"
478 ,(let ((syntax (syntax-after pos))) 482 ,(let ((syntax (syntax-after pos)))
479 (with-temp-buffer 483 (with-temp-buffer
480 (internal-describe-syntax-value syntax) 484 (internal-describe-syntax-value syntax)
481 (buffer-string)))) 485 (buffer-string))))
501 (list "type" 505 (list "type"
502 (mapconcat #'(lambda (x) (concat "\"" x "\"")) 506 (mapconcat #'(lambda (x) (concat "\"" x "\""))
503 key-list " or ") 507 key-list " or ")
504 "with" 508 "with"
505 `(insert-text-button 509 `(insert-text-button
506 (symbol-name current-input-method) 510 ,(symbol-name current-input-method)
507 'action (lambda (&rest ignore) 511 'type 'help-input-method
508 (describe-input-method 512 'help-args '(,current-input-method))))))
509 ',current-input-method)))))))
510 ("buffer code" 513 ("buffer code"
511 ,(encoded-string-description 514 ,(encoded-string-description
512 (string-as-unibyte (char-to-string char)) nil)) 515 (string-as-unibyte (char-to-string char)) nil))
513 ("file code" 516 ("file code"
514 ,@(let* ((coding buffer-file-coding-system) 517 ,@(let* ((coding buffer-file-coding-system)
573 ((and nobreak-char-display unicode (eq unicode '#xad)) 576 ((and nobreak-char-display unicode (eq unicode '#xad))
574 'escape-glyph) 577 'escape-glyph)
575 ((and (< char 32) (not (memq char '(9 10)))) 578 ((and (< char 32) (not (memq char '(9 10))))
576 'escape-glyph))))) 579 'escape-glyph)))))
577 (if face (list (list "hardcoded face" 580 (if face (list (list "hardcoded face"
578 '(insert 581 (concat "`" (symbol-name face) "'")))))
579 (concat "`" (symbol-name face) "'"))))))
580 ,@(let ((unicodedata (and unicode 582 ,@(let ((unicodedata (and unicode
581 (describe-char-unicode-data unicode)))) 583 (describe-char-unicode-data unicode))))
582 (if unicodedata 584 (if unicodedata
583 (cons (list "Unicode data" " ") unicodedata))))) 585 (cons (list "Unicode data" " ") unicodedata)))))
584 (setq max-width (apply #'max (mapcar #'(lambda (x) 586 (setq max-width (apply #'max (mapcar #'(lambda (x)
585 (if (cadr x) (length (car x)) 0)) 587 (if (cadr x) (length (car x)) 0))
586 item-list))) 588 item-list)))
587 (help-setup-xref nil (interactive-p)) 589 (help-setup-xref
588 (with-output-to-temp-buffer (help-buffer) 590 (list #'describe-char pos (if buf buf (current-buffer)))
591 (interactive-p))
592 (with-output-to-temp-buffer help-buffer
589 (with-current-buffer standard-output 593 (with-current-buffer standard-output
590 (set-buffer-multibyte multibyte-p) 594 (set-buffer-multibyte multibyte-p)
591 (let ((formatter (format "%%%ds:" max-width))) 595 (let ((formatter (format "%%%ds:" max-width)))
592 (dolist (elt item-list) 596 (dolist (elt item-list)
593 (when (cadr elt) 597 (when (cadr elt)
686 (insert "\nSee the variable `reference-point-alist' for " 690 (insert "\nSee the variable `reference-point-alist' for "
687 "the meaning of the rule.\n")) 691 "the meaning of the rule.\n"))
688 692
689 (if text-props-desc (insert text-props-desc)) 693 (if text-props-desc (insert text-props-desc))
690 (toggle-read-only 1) 694 (toggle-read-only 1)
691 (print-help-return-message))))) 695 (print-help-return-message)))))))
692 696
693 (defalias 'describe-char-after 'describe-char) 697 (defalias 'describe-char-after 'describe-char)
694 (make-obsolete 'describe-char-after 'describe-char "22.1") 698 (make-obsolete 'describe-char-after 'describe-char "22.1")
695 699
696 (provide 'descr-text) 700 (provide 'descr-text)