From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Man-fontify-manpage does not handle man, version 1.5o1, ANSI escape sequences Date: Mon, 29 Nov 2004 18:56:51 -0500 Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1101773215 25117 80.91.229.6 (30 Nov 2004 00:06:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 30 Nov 2004 00:06:55 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Nov 30 01:06:49 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 1CYvRf-0002XJ-00 for ; Tue, 30 Nov 2004 01:00:40 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CYvb5-0006dy-Bs for ged-emacs-devel@m.gmane.org; Mon, 29 Nov 2004 19:10:23 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CYvXr-0005zb-2T for emacs-devel@gnu.org; Mon, 29 Nov 2004 19:07:03 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CYvXp-0005zF-LC for emacs-devel@gnu.org; Mon, 29 Nov 2004 19:07:02 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CYvXp-0005yt-35 for emacs-devel@gnu.org; Mon, 29 Nov 2004 19:07:01 -0500 Original-Received: from [132.204.24.67] (helo=mercure.iro.umontreal.ca) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CYvO9-0005ep-Nq for emacs-devel@gnu.org; Mon, 29 Nov 2004 18:57:01 -0500 Original-Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id 9781D8282C5; Mon, 29 Nov 2004 18:57:00 -0500 (EST) Original-Received: from asado.iro.umontreal.ca (asado.iro.umontreal.ca [132.204.24.84]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id 0F2664AC598; Mon, 29 Nov 2004 18:56:52 -0500 (EST) Original-Received: by asado.iro.umontreal.ca (Postfix, from userid 20848) id CD65A8CA69; Mon, 29 Nov 2004 18:56:51 -0500 (EST) Original-To: "Brian D. Carlstrom" In-Reply-To: (Brian D. Carlstrom's message of "28 Nov 2004 21:49:55 -0000") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux) X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=0, requis 5) X-MailScanner-From: monnier@iro.umontreal.ca X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:30507 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:30507 > 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. Can you try the patch below instead? It tries to handle the case where the code does \e[1m...\e[4m....\e[0m where the 0 turns off both bold and underline. BTW, is it right that bold is turned on with \e[1m and turned off with \e[22m? It seems odd that it isn't \e[21m to turn it off or \e[2m to turn it on, seeing how the other fit the \e[Nm and \e[2Nm rule. Stefan --- man.el 03 nov 2004 00:44:39 -0500 1.138 +++ man.el 29 nov 2004 18:53:50 -0500 @@ -1,6 +1,7 @@ ;;; man.el --- browse UNIX manual pages -*- coding: iso-8859-1 -*- -;; Copyright (C) 1993, 1994, 1996, 1997, 2001, 2003, 2004 Free Software Foundation, Inc. +;; Copyright (C) 1993, 1994, 1996, 1997, 2001, 2003, 2004 +;; Free Software Foundation, Inc. ;; Author: Barry A. Warsaw ;; Maintainer: FSF @@ -94,6 +95,7 @@ ;;; Code: +(eval-when-compile (require 'cl)) (require 'assoc) (require 'button) @@ -153,6 +155,11 @@ :type 'face :group 'man) +(defcustom Man-reverse-face 'secondary-selection + "*Face to use when fontifying reverse video." + :type 'face + :group 'man) + ;; Use the value of the obsolete user option Man-notify, if set. (defcustom Man-notify-method (if (boundp 'Man-notify) Man-notify 'friendly) "*Selects the behavior when manpage is ready. @@ -813,13 +820,27 @@ (interactive) (message "Please wait: formatting the %s man page..." Man-arguments) (goto-char (point-min)) - (while (search-forward "\e[1m" nil t) - (delete-backward-char 4) - (put-text-property (point) - (progn (if (search-forward "\e[0m" nil 'move) - (delete-backward-char 4)) - (point)) - 'face Man-overstrike-face)) + ;; Fontify ANSI escapes. + (let ((faces nil) + (start (point)) + code) + (while (re-search-forward "\\e[\\([1470]\\|2\\([247]\\)\\)m" nil t) + (if faces (put-text-property start (match-beginning 0) 'face faces)) + (setq faces + (if (match-beginning 2) + (delq (case (char-after (match-beginning 2)) + (2 Man-overstrike-face) + (4 Man-underline-face) + (7 Man-reverse-face)) + faces) + (cons (case (char-after (match-beginning 1)) + (1 Man-overstrike-face) + (4 Man-underline-face) + (7 Man-reverse-face) + (t nil)) + faces))) + (delete-region (match-beginning 0) (match-end 0)))) + ;; Other highlighting. (if (< (buffer-size) (position-bytes (point-max))) ;; Multibyte characters exist. (progn @@ -1372,5 +1393,5 @@ (provide 'man) -;;; arch-tag: 587cda76-8e23-4594-b1f3-89b6b09a0d47 +;; arch-tag: 587cda76-8e23-4594-b1f3-89b6b09a0d47 ;;; man.el ends here