groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 18/18: tmac/an-old.tmac: Fix Savannah #43532.


From: G. Branden Robinson
Subject: [groff] 18/18: tmac/an-old.tmac: Fix Savannah #43532.
Date: Thu, 3 Jun 2021 11:03:26 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit b7f38e8a1d698e1078d7c215d08fde57d8e919b9
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Jun 4 00:41:20 2021 +1000

    tmac/an-old.tmac: Fix Savannah #43532.
    
    * tmac/an-old.tmac (an-abbreviate-title): Add new internal macro to
      reduce the length of a man page title (i.e., the "ls" in "ls(1)", if
      it is too wide to fit in the page header (and would overwrite the
      center header material, usually the title of the manual section).
      Since the beginning and end of the title might be important for
      disambiguation, truncation at either end would be unwise; replace the
      middle of the title with an ellipsis.  Define new an-pageref and
      an-title-abbv strings for use by other macros and user-defined PT and
      BT traps.
    
      (PT, an-footer): Use new an-pageref string for economy.
    
      (an-header): Call an-abbreviate-title after setting the title length.
    
    Fixes <https://savannah.gnu.org/bugs/index.php?43532>.
---
 ChangeLog        | 18 ++++++++++++++++--
 tmac/an-old.tmac | 51 ++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 64 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 540483a..f2a9a77 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,23 @@
 2021-06-03  G. Branden Robinson <g.branden.robinson@gmail.com>
 
-       * tmac/tests/an-old_title-abbreviation-works.sh: Add regression
-       test for Savannah #43532.
+       * tmac/an-old.tmac (an-abbreviate-title): Add new internal macro
+       to reduce the length of a man page title (i.e., the "ls" in
+       "ls(1)", if it is too wide to fit in the page header (and would
+       overwrite the center header material, usually the title of the
+       manual section).  Since the beginning and end of the title might
+       be important for disambiguation, truncation at either end would
+       be unwise; replace the middle of the title with an ellipsis.
+       Define new an-pageref and an-title-abbv strings for use by other
+       macros and user-defined PT and BT traps.
+       (PT, an-footer): Use new an-pageref string for economy.
+       (an-header): Call an-abbreviate-title after setting the title
+       length.
+
+       * tmac/tests/an-old_title-abbreviation-works.sh: Test it.
        * tmac/tmac.am (tmac_TESTS): Run test.
 
+       Fixes <https://savannah.gnu.org/bugs/index.php?43532>.
+
 2021-06-03  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * man/groff.7.man (Copy mode): Add new section.
diff --git a/tmac/an-old.tmac b/tmac/an-old.tmac
index 0eb568c..45a97a1 100644
--- a/tmac/an-old.tmac
+++ b/tmac/an-old.tmac
@@ -306,8 +306,7 @@
 .\" Redefine these to customize the header & footer
 .
 .de1 PT
-.  tl '\\*[an-title](\\*[an-section])'\\*[an-extra3]'\
-\\*[an-title](\\*[an-section])'
+.  tl '\\*[an-pageref]'\\*[an-extra3]'\\*[an-pageref]'
 ..
 .
 .de1 BT
@@ -321,11 +320,57 @@
 .    tl '\\*[an-extra2]'\\*[an-extra1]'\\*[an-outer-footer-text]'
 ..
 .
+.\" Abbreviate the page title if it's too long for the header.  Leaves
+.\" string an-pageref defined for use in .PT and .an-footer.  Also
+.\" leaves an-title-abbv for possible use by .PT and .BT re-definers.
+.de1 an-abbreviate-title
+.  ds an-title-abbv \\*[an-title]\"
+.  ds an-title-string \\*[an-title]\"
+.  ds an-ellipsis \|.\|.\|.\|\"
+.  ds an-pageref \\*[an-title-abbv](\\*[an-section])\"
+.  nr an-header-width \\w'\\*[an-pageref]\\*[an-extra3]\\*[an-pageref]'
+.  while (\\n[an-header-width] >= \\n[.lt]) \{\
+.    \" The page title is too long; trim some bits out of the middle.
+.    length an-title-length \\*[an-title-string]
+.    \" roff division rounds integers toward zero.  Remove an additional
+.    \" character on each side of the midpoint to account for the
+.    \" ellipsis we add later.
+.    nr an-mark1 (\\n[an-title-length] / 2 - 2)
+.    nr an-mark2 (\\n[an-title-length] / 2 + 2)
+.    ds an-prefix \\*[an-title-string]\"
+.    ds an-suffix \\*[an-title-string]\"
+.    \" Use extremum operators to ensure that the first and last
+.    \" characters of the title remain intact (in cases of pathological
+.    \" shortening).
+.    substring an-prefix 0 (\\n[an-mark1] >? 1)
+.    substring an-suffix (\\n[an-mark2] <? (\\n[an-title-length] - 1) -1
+.    ds an-title-string \\*[an-prefix]\\*[an-suffix]\"
+.    ds an-title-abbv \\*[an-prefix]\\*[an-ellipsis]\\*[an-suffix]\"
+.    \" Measure the string again and give up if we made no progress.
+.    length an-title-new-length \\*[an-title-string]
+.    ie (\\n[an-title-new-length] >= \\n[an-title-length]) \
+.      break
+.    ds an-pageref \\*[an-title-abbv](\\*[an-section])\"
+.    nr an-header-width \
+       \\w'\\*[an-pageref]\\*[an-extra3]\\*[an-pageref]'
+.  \}
+.  rr an-title-length-prev
+.  rr an-mark1
+.  rr an-mark2
+.  rm an-prefix
+.  rm an-suffix
+.  rm an-title-string
+.  rr an-title-length
+.  rr an-header-width
+.  rm an-ellipsis
+..
+.
 .de1 an-header
 .  ev an-env
 .  ps \\n[PS]u
 .  vs \\n[VS]u
 .  lt \\n[LT]u
+.  an-abbreviate-title
 .  if !\\n[an-is-output-html] \{\
 .    if !\\n[cR] \
 .      sp .5i
@@ -356,7 +401,7 @@
 .  lt \\n[LT]u
 .  if !\\n[an-is-output-html] \{\
 .    ie \\n[cR] \
-.      ds an-outer-footer-text "\\*[an-title](\\*[an-section])\"
+.      ds an-outer-footer-text "\\*[an-pageref]\"
 .    el \{\
 .      ds an-outer-footer-text \\n[%]\"
 .      if r X \{\



reply via email to

[Prev in Thread] Current Thread [Next in Thread]