unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* Man-fontify-manpage does not handle man, version 1.5o1, ANSI escape sequences
@ 2004-11-28 21:49 Brian D. Carlstrom
  0 siblings, 0 replies; only message in thread
From: Brian D. Carlstrom @ 2004-11-28 21:49 UTC (permalink / raw)


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))))

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-11-28 21:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-28 21:49 Man-fontify-manpage does not handle man, version 1.5o1, ANSI escape sequences Brian D. Carlstrom

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).