From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Brian D. Carlstrom" Newsgroups: gmane.emacs.bugs Subject: Man-fontify-manpage does not handle man, version 1.5o1, ANSI escape sequences Date: 28 Nov 2004 21:49:55 -0000 Message-ID: <20041128214955.13825.qmail@electricrain.com> Reply-To: "Brian D. Carlstrom" NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1101678643 25381 80.91.229.6 (28 Nov 2004 21:50:43 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 28 Nov 2004 21:50:43 +0000 (UTC) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Nov 28 22:50:23 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CYWw3-0002FC-00 for ; Sun, 28 Nov 2004 22:50:23 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CYX5P-0001FD-6W for geb-bug-gnu-emacs@m.gmane.org; Sun, 28 Nov 2004 17:00:03 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CYX5N-0001F7-7I for bug-gnu-emacs@gnu.org; Sun, 28 Nov 2004 17:00:01 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CYX5M-0001Ev-NZ for bug-gnu-emacs@gnu.org; Sun, 28 Nov 2004 17:00:01 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CYX5M-0001Eq-EI for bug-gnu-emacs@gnu.org; Sun, 28 Nov 2004 17:00:00 -0500 Original-Received: from [64.71.143.226] (helo=electricrain.com) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1CYWvg-0000Oo-8q for bug-gnu-emacs@gnu.org; Sun, 28 Nov 2004 16:50:00 -0500 Original-Received: (qmail 13826 invoked by uid 525); 28 Nov 2004 21:49:55 -0000 Original-To: bug-gnu-emacs@gnu.org X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.bugs:9856 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:9856 In GNU Emacs 21.3.1 (i686-pc-linux-gnu) of 2003-11-02 on zot.electricrain.com configured using `configure --prefix=/pkg/emacs-21.3 --without-x --without-jpeg --without-png' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: nil value of $LC_CTYPE: nil value of $LC_MESSAGES: nil value of $LC_MONETARY: nil value of $LC_NUMERIC: nil value of $LC_TIME: nil value of $LANG: nil locale-coding-system: nil default-enable-multibyte-characters: t Please describe exactly what actions triggered the bug and the precise symptoms of the bug: My GNU/Linux system recently had several upgrades: kernel upgraded to 2.6.9 glibc upgraded to 2.3.3 man upgraded to 1.5o1 (other unknown upgrades, I'd have to ask administrator) Since then my M-x man output has been full of ANSI escape sequences that weren't previously there. I traced this to the fact that Man-fontify-manpage assumes that the ANSI sequences will be terminated by "\e[0m". However, the new "man" output uses more specific attribute termination sequences. For example: bold "\e[22m" underline "\e[24m" reverse "\e[27m" I append a fix below. Basically I pull out the code that previously only handled ANSI bold sequences and replace it with a new function Man-fontify-manpage-ANSI that I call from Man-fontify-manpage to handle bold, underlining, and reverse video. Previously I reported another Man-fontify-manpage bug that remains unfixed at CVS head: Man-fontify-manpage does not handle MKS man ANSI escape sequences http://lists.gnu.org/archive/html/bug-gnu-emacs/2003-06/msg00147.html This fix supercedes that bug. -bri (defcustom Man-reverse-face 'secondary-selection "*Face to use when fontifying reverse video." :type 'face :group 'man) (defun Man-fontify-manpage () "Convert overstriking and underlining to the correct fonts. Same for the ANSI bold and normal escape sequences." (interactive) (message "Please wait: making up the %s man page..." Man-arguments) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; BEGIN CHANGES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (Man-fontify-manpage-ANSI "\e[1m" "\e[22m" Man-overstrike-face) (Man-fontify-manpage-ANSI "\e[4m" "\e[24m" Man-underline-face) (Man-fontify-manpage-ANSI "\e[7m" "\e[27m" Man-reverse-face) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; END CHANGES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (if (< (buffer-size) (position-bytes (point-max))) ;; Multibyte characters exist. (progn (goto-char (point-min)) (while (search-forward "__\b\b" nil t) (backward-delete-char 4) (put-text-property (point) (1+ (point)) 'face Man-underline-face)) (goto-char (point-min)) (while (search-forward "\b\b__" nil t) (backward-delete-char 4) (put-text-property (1- (point)) (point) 'face Man-underline-face)))) (goto-char (point-min)) (while (search-forward "_\b" nil t) (backward-delete-char 2) (put-text-property (point) (1+ (point)) 'face Man-underline-face)) (goto-char (point-min)) (while (search-forward "\b_" nil t) (backward-delete-char 2) (put-text-property (1- (point)) (point) 'face Man-underline-face)) (goto-char (point-min)) (while (re-search-forward "\\(.\\)\\(\b+\\1\\)+" nil t) (replace-match "\\1") (put-text-property (1- (point)) (point) 'face Man-overstrike-face)) (goto-char (point-min)) (while (re-search-forward "o\b\\+\\|\\+\bo" nil t) (replace-match "o") (put-text-property (1- (point)) (point) 'face 'bold)) (goto-char (point-min)) (while (re-search-forward "[-|]\\(\b[-|]\\)+" nil t) (replace-match "+") (put-text-property (1- (point)) (point) 'face 'bold)) (Man-softhyphen-to-minus) (message "%s man page made up" Man-arguments)) (defun Man-fontify-manpage-ANSI (start-escape end-escape face) (goto-char (point-min)) (while (search-forward start-escape nil t) (delete-backward-char (length start-escape)) (let* ((start (point)) (end) ;; calculated cend of escape sequence (delete-count) ;; number of characters to delete ;; generic reset escape (reset-escape "\e[0m") ;; find if the end or reset escape is closer (reset-point (search-forward reset-escape nil t)) (dummy (goto-char start)) (end-point (search-forward end-escape nil t))) (cond ((and reset-point end-point) ;; if we find both escapes, select the closer one to start point (if (< reset-point end-point) (setq end reset-point delete-count (length reset-escape)) (setq end end-point delete-count (length end-escape)))) (reset-point ;; if we didn't find both escapes, see if we found reset-escape (setq end reset-point delete-count (length reset-escape))) (end-point ;; if we didn't find both escapes, see if we found end-escape (setq end end-point delete-count (length end-escape))) (t ;; if we didn't find either, do nothing (setq end start delete-count 0))) (goto-char end) (delete-backward-char delete-count) (setq end (- end delete-count)) (put-text-property start end 'face face))))