From 7e4cec049ba8fcd5f8d329dbbd3c97f872c14089 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 16 Jan 2025 12:24:48 -0800 Subject: Map dash-like unicode characters to ASCII dash.k - Look for the following characters in the input: - U+2010 (Hyphen), - U+2013 (En Dash) - U+2014 (Em Dash) - U+2212 (Minus) and convert them to: - U+002D (ASCII Hyphen-Minus) - This is not just for appearance. I use an old version of Screen which somehow reacts badly to the U+2010 hyphen; the terminal becomes seriously corrupt, making the portions of a man page adjacent to hyphenated lines unreadable. --- README.md | 5 +++++ mnpgr.tl | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 47b8a24..b2184c2 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,11 @@ syntax coloring, like what you see `less`. Because `mngpr` itself resolves the overstrikes, the resulting rendering in Vim is searchable. +Another benefit of `mnpgr` is that it replaces with a plain ASCII dash +(U+002D) all the nonsense Unicode dashes output by GNU groff. +This is not just esthetics. In some systems, the U+2010 hyphen +seriously corrupts the terminal display, rendering man pages unreadable. + ## Installation The `mnpgr.vim` file goes into your `~/.vim/syntax` directory, which diff --git a/mnpgr.tl b/mnpgr.tl index 46619c9..3256815 100755 --- a/mnpgr.tl +++ b/mnpgr.tl @@ -97,7 +97,8 @@ (with-resources ((rendered-file (path-cat mnpgr-dir `@page.@section.@cols`) (remove-path rendered-file))) (with-stream (s (open-file rendered-file "w")) - (let ((ofilt (make-overstrike-filter (lambda (str) (put-string str s))))) + (let ((hfilt (op regsub #/[\x2010\x2013\x2014\x2212]/ "-")) + (ofilt (make-overstrike-filter (lambda (str) (put-string str s))))) (whilet ((line (get-line))) - [ofilt line]))) + (flow line hfilt ofilt)))) (sh `vim +'@{vim-commands}' '@{rendered-file}' < /dev/tty`)))) -- cgit v1.2.3