emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Man-fontify-manpage does not handle man, version 1.5o1, ANSI escape


From: Stefan Monnier
Subject: Re: Man-fontify-manpage does not handle man, version 1.5o1, ANSI escape sequences
Date: Mon, 29 Nov 2004 18:56:51 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux)

> 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 <address@hidden>
 ;; 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]