[Top][All Lists]

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

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

From: Brian D. Carlstrom
Subject: Man-fontify-manpage does not handle man, version 1.5o1, ANSI escape sequences
Date: 28 Nov 2004 21:49:55 -0000

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

This fix supercedes that bug.


(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."
  (message "Please wait: making up the %s man page..." Man-arguments)
  (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)
  (if (< (buffer-size) (position-bytes (point-max)))
      ;; Multibyte characters exist.
        (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))
  (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))))
             ;; if we didn't find both escapes, see if we found reset-escape
             (setq end reset-point delete-count (length reset-escape)))
             ;; if we didn't find both escapes, see if we found end-escape
             (setq end end-point delete-count (length end-escape)))
             ;; 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))))

reply via email to

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