all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Brian D. Carlstrom" <bdc@carlstrom.com>
Subject: Man-fontify-manpage does not handle man, version 1.5o1, ANSI escape sequences
Date: 28 Nov 2004 21:49:55 -0000	[thread overview]
Message-ID: <20041128214955.13825.qmail@electricrain.com> (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))))

             reply	other threads:[~2004-11-28 21:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-28 21:49 Brian D. Carlstrom [this message]
     [not found] <mailman.2045.1101679203.27204.bug-gnu-emacs@gnu.org>
2004-11-29 23:56 ` Man-fontify-manpage does not handle man, version 1.5o1, ANSI escape sequences Stefan Monnier
2004-11-30  8:40   ` Brian D. Carlstrom
2004-11-30 13:16     ` Stefan
2004-11-30 15:18   ` Werner LEMBERG
2004-12-01  2:56   ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041128214955.13825.qmail@electricrain.com \
    --to=bdc@carlstrom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.