diff options
| author | Stefan Monnier | 2004-11-30 22:26:26 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2004-11-30 22:26:26 +0000 |
| commit | 079c2d0047f34e36febcf3883b9ff034133250ec (patch) | |
| tree | 117b1d9f76ba083c39c202b1bcffabf58c422f5d | |
| parent | 83a2a07a8e52cc308de3d238fa3ea5ce576eb54f (diff) | |
| download | emacs-079c2d0047f34e36febcf3883b9ff034133250ec.tar.gz emacs-079c2d0047f34e36febcf3883b9ff034133250ec.zip | |
(Man-fontify-manpage): Improve handling of ANSI escapes.
| -rw-r--r-- | lisp/man.el | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/lisp/man.el b/lisp/man.el index e4573748fcb..5ff380baca0 100644 --- a/lisp/man.el +++ b/lisp/man.el | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | ;;; man.el --- browse UNIX manual pages -*- coding: iso-8859-1 -*- | 1 | ;;; man.el --- browse UNIX manual pages -*- coding: iso-8859-1 -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1993, 1994, 1996, 1997, 2001, 2003, 2004 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1993, 1994, 1996, 1997, 2001, 2003, 2004 |
| 4 | ;; Free Software Foundation, Inc. | ||
| 4 | 5 | ||
| 5 | ;; Author: Barry A. Warsaw <bwarsaw@cen.com> | 6 | ;; Author: Barry A. Warsaw <bwarsaw@cen.com> |
| 6 | ;; Maintainer: FSF | 7 | ;; Maintainer: FSF |
| @@ -94,6 +95,7 @@ | |||
| 94 | 95 | ||
| 95 | ;;; Code: | 96 | ;;; Code: |
| 96 | 97 | ||
| 98 | (eval-when-compile (require 'cl)) | ||
| 97 | (require 'assoc) | 99 | (require 'assoc) |
| 98 | (require 'button) | 100 | (require 'button) |
| 99 | 101 | ||
| @@ -153,6 +155,11 @@ the manpage buffer." | |||
| 153 | :type 'face | 155 | :type 'face |
| 154 | :group 'man) | 156 | :group 'man) |
| 155 | 157 | ||
| 158 | (defcustom Man-reverse-face 'secondary-selection | ||
| 159 | "*Face to use when fontifying reverse video." | ||
| 160 | :type 'face | ||
| 161 | :group 'man) | ||
| 162 | |||
| 156 | ;; Use the value of the obsolete user option Man-notify, if set. | 163 | ;; Use the value of the obsolete user option Man-notify, if set. |
| 157 | (defcustom Man-notify-method (if (boundp 'Man-notify) Man-notify 'friendly) | 164 | (defcustom Man-notify-method (if (boundp 'Man-notify) Man-notify 'friendly) |
| 158 | "*Selects the behavior when manpage is ready. | 165 | "*Selects the behavior when manpage is ready. |
| @@ -813,13 +820,39 @@ Same for the ANSI bold and normal escape sequences." | |||
| 813 | (interactive) | 820 | (interactive) |
| 814 | (message "Please wait: formatting the %s man page..." Man-arguments) | 821 | (message "Please wait: formatting the %s man page..." Man-arguments) |
| 815 | (goto-char (point-min)) | 822 | (goto-char (point-min)) |
| 816 | (while (search-forward "\e[1m" nil t) | 823 | ;; Fontify ANSI escapes. |
| 817 | (delete-backward-char 4) | 824 | (let ((faces nil) |
| 818 | (put-text-property (point) | 825 | (start (point))) |
| 819 | (progn (if (search-forward "\e[0m" nil 'move) | 826 | ;; http://www.isthe.com/chongo/tech/comp/ansi_escapes.html |
| 820 | (delete-backward-char 4)) | 827 | ;; suggests many codes, but we only handle: |
| 821 | (point)) | 828 | ;; ESC [ 00 m reset to normal display |
| 822 | 'face Man-overstrike-face)) | 829 | ;; ESC [ 01 m bold |
| 830 | ;; ESC [ 04 m underline | ||
| 831 | ;; ESC [ 07 m reverse-video | ||
| 832 | ;; ESC [ 22 m no-bold | ||
| 833 | ;; ESC [ 24 m no-underline | ||
| 834 | ;; ESC [ 27 m no-reverse-video | ||
| 835 | (while (re-search-forward "\e\\[0?\\([1470]\\|2\\([247]\\)\\)m" nil t) | ||
| 836 | (if faces (put-text-property start (match-beginning 0) 'face | ||
| 837 | (if (cdr faces) faces (car faces)))) | ||
| 838 | (setq faces | ||
| 839 | (cond | ||
| 840 | ((match-beginning 2) | ||
| 841 | (delq (case (char-after (match-beginning 2)) | ||
| 842 | (?2 Man-overstrike-face) | ||
| 843 | (?4 Man-underline-face) | ||
| 844 | (?7 Man-reverse-face)) | ||
| 845 | faces)) | ||
| 846 | ((eq (char-after (match-beginning 1)) ?0) nil) | ||
| 847 | (t | ||
| 848 | (cons (case (char-after (match-beginning 1)) | ||
| 849 | (?1 Man-overstrike-face) | ||
| 850 | (?4 Man-underline-face) | ||
| 851 | (?7 Man-reverse-face)) | ||
| 852 | faces)))) | ||
| 853 | (delete-region (match-beginning 0) (match-end 0)) | ||
| 854 | (setq start (point)))) | ||
| 855 | ;; Other highlighting. | ||
| 823 | (if (< (buffer-size) (position-bytes (point-max))) | 856 | (if (< (buffer-size) (position-bytes (point-max))) |
| 824 | ;; Multibyte characters exist. | 857 | ;; Multibyte characters exist. |
| 825 | (progn | 858 | (progn |
| @@ -1372,5 +1405,5 @@ Specify which REFERENCE to use; default is based on word at point." | |||
| 1372 | 1405 | ||
| 1373 | (provide 'man) | 1406 | (provide 'man) |
| 1374 | 1407 | ||
| 1375 | ;;; arch-tag: 587cda76-8e23-4594-b1f3-89b6b09a0d47 | 1408 | ;; arch-tag: 587cda76-8e23-4594-b1f3-89b6b09a0d47 |
| 1376 | ;;; man.el ends here | 1409 | ;;; man.el ends here |