From: Manuel Giraud Date: Thu, 19 Jun 2025 14:42:57 +0000 (+0200) Subject: Fix bold or underline of underscores (bug#78839) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=bc27c3525be0c57ce4dad3f3944ba2d2381cc78f;p=emacs.git Fix bold or underline of underscores (bug#78839) * lisp/man.el (Man-fontify-manpage): Fix the "_\b_" case. (cherry picked from commit 00b8d11ac8682749f15ac7125f54f357b8825d86) --- diff --git a/lisp/man.el b/lisp/man.el index d1b3b5b0ffd..d914e7d9f4a 100644 --- a/lisp/man.el +++ b/lisp/man.el @@ -1364,17 +1364,24 @@ Same for the ANSI bold and normal escape sequences." (put-text-property (1- (point)) (point) 'font-lock-face 'Man-underline)))) (goto-char (point-min)) - (while (and (search-forward "_\b" nil t) (not (eobp))) - (delete-char -2) - (put-text-property (point) (1+ (point)) 'font-lock-face 'Man-underline)) + (while (and (re-search-forward "_\b\\([^_]\\)" nil t) (not (eobp))) + (replace-match "\\1") + (put-text-property (1- (point)) (point) 'font-lock-face 'Man-underline)) (goto-char (point-min)) - (while (search-forward "\b_" nil t) - (delete-char -2) + (while (re-search-forward "\\([^_]\\)\b_" nil t) + (replace-match "\\1") (put-text-property (1- (point)) (point) 'font-lock-face 'Man-underline)) (goto-char (point-min)) - (while (re-search-forward "\\(.\\)\\(\b+\\1\\)+" nil t) + (while (re-search-forward "\\([^_]\\)\\(\b+\\1\\)+" nil t) (replace-match "\\1") (put-text-property (1- (point)) (point) 'font-lock-face 'Man-overstrike)) + ;; Special case for "__": is it an underlined underscore or a bold + ;; underscore? Look at the face after it to know. + (goto-char (point-min)) + (while (search-forward "_\b_" nil t) + (delete-char -2) + (let ((face (get-text-property (point) 'font-lock-face))) + (put-text-property (1- (point)) (point) 'font-lock-face face))) (goto-char (point-min)) (while (re-search-forward "o\b\\+\\|\\+\bo" nil t) (replace-match "o")