]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix bold or underline of underscores (bug#78839)
authorManuel Giraud <manuel@ledu-giraud.fr>
Thu, 19 Jun 2025 14:42:57 +0000 (16:42 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 22 Jun 2025 08:09:26 +0000 (10:09 +0200)
* lisp/man.el (Man-fontify-manpage): Fix the "_\b_" case.

(cherry picked from commit 00b8d11ac8682749f15ac7125f54f357b8825d86)

lisp/man.el

index d1b3b5b0ffd2ef3227812c93e3ee8c3ca47ce504..d914e7d9f4a634c712daf553314adbba78e79f14 100644 (file)
@@ -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 "_\b_": 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")