gbranden pushed a commit to branch master
in repository groff.

commit 63369f239ea1f596a0dbcc966cff3c8e455e5f64
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Nov 1 22:35:44 2026 -0600

    [troff]: Add `.sv` register.
    
    * src/roff/troff/div.cpp: New file-local class handles dynamically
      computed `saved_space` amount.  (The class `readonly_reg` is not
      appropriate because its constructor requires a parameter of type
      `int`.  `saved_space` is of type `vunits`.)
    
      (saved_vertical_space_reg::get_string): Retrieve the amount.
    
      (init_div_requests): Wire up `.sv` register name to object of this new
      class.
    
    * doc/groff.texi.in (Page Control):
    * man/groff.7.man.in (Read-only registers):
    * man/groff_diff.7.man.in (New registers): Document it.
    
    * src/roff/groff/tests/sv-and-os-requests-work.sh: Test it.
    
    Fixes <https://savannah.gnu.org/bugs/?68865>.
    
    NEWS: Add item.
---
 ChangeLog                                       | 21 +++++++++++++++++++++
 NEWS                                            |  4 ++++
 doc/groff.texi.in                               | 10 +++++++++-
 man/groff.7.man.in                              |  8 ++++++++
 man/groff_diff.7.man                            |  9 +++++++++
 src/roff/groff/tests/sv-and-os-requests-work.sh | 18 ++++++++++++++++++
 src/roff/troff/div.cpp                          | 11 +++++++++++
 7 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index dc606844c..b06bb1bf3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2026-11-01  G. Branden Robinson <[email protected]>
+
+       [troff]: Implement new `.sv` read-only register.
+
+       * src/roff/troff/div.cpp (class saved_vertical_space_reg): New
+       file-local class handles dynamically computed `saved_space`
+       amount.  (The class `readonly_reg` is not appropriate because
+       its constructor requires a parameter of type `int`.
+       `saved_space` is of type `vunits`.)
+       (saved_vertical_space_reg::get_string): Retrieve the amount.
+       (init_div_requests): Wire up `.sv` register name to object of
+       this new class.
+
+       * doc/groff.texi.in (Page Control):
+       * man/groff.7.man.in (Read-only registers):
+       * man/groff_diff.7.man.in (New registers): Document it.
+
+       * src/roff/groff/tests/sv-and-os-requests-work.sh: Test it.
+
+       Fixes <https://savannah.gnu.org/bugs/?68865>.
+
 2026-11-01  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp (token::next): Throw warning in
diff --git a/NEWS b/NEWS
index a9491a41a..7603411ce 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,10 @@ troff
 *  The `shift` request no longer performs an operation if it is given an
    invalid argument.
 
+*  A new read-only register `.sv` reports the amount of vertical space
+   saved by the most recent `sv` request, if it has not yet been output
+   with the `os` request.
+
 *  The formatter now emits a warning in category "style" if -crementing
    interpolation (such as `\n+[myreg]` or `\n-[count]`) is (uselessly)
    applied to a non-auto-crementing register.
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index 4c6c15ec8..614d28a36 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -13006,7 +13006,8 @@ request outputs the saved vertical space as if with the
 request.
 
 @DefreqList {sv, [@Var{space}]}
-@DefreqListEndx {os, }
+@DefreqItem {os, }
+@DefregListEndx {.sv}
 @cindex @code{ne} request, comparison with @code{sv}
 @code{sv}
 requires vertical space as
@@ -13036,6 +13037,13 @@ If
 @var{space}
 is not specified,
 the formatter assumes @samp{1v}.
+
+The read-only register
+@code{.sv}
+contains the amount of vertical space demanded by the most recent
+@code{sv}
+request if it has not yet been output with
+@code{os}.
 There is only one,
 global,
 saved space amount.
diff --git a/man/groff.7.man.in b/man/groff.7.man.in
index ceaa17488..f000bdc4a 100644
--- a/man/groff.7.man.in
+++ b/man/groff.7.man.in
@@ -8119,6 +8119,14 @@ and
 .esc f .
 .
 .TP
+.REG .sv
+Amount of vertical space saved by the most recent
+.request sv
+request if it has not yet been output by the
+.request os
+request.
+.
+.TP
 .REG .t
 Distance to next vertical position trap;
 see
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index 17f2ff84d..b0e64d8cb 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -5494,6 +5494,15 @@ This is a string-valued register.
 .
 .
 .TP
+.B \[rs]n[.sv]
+Interpolate the amount of vertical space saved by the most recent
+.B sv
+request if it has not yet been output by the
+.B os
+request.
+.
+.
+.TP
 .B \[rs]n[.tabs]
 Interpolate the environment's tab stop settings
 (if any)
diff --git a/src/roff/groff/tests/sv-and-os-requests-work.sh 
b/src/roff/groff/tests/sv-and-os-requests-work.sh
index 2442d5975..48b9ed840 100755
--- a/src/roff/groff/tests/sv-and-os-requests-work.sh
+++ b/src/roff/groff/tests/sv-and-os-requests-work.sh
@@ -29,6 +29,7 @@ wail () {
 # Unit-test `sv` and `os` requests.
 
 input='.
+.ec @
 .nf
 1
 2
@@ -40,6 +41,7 @@ input='.
 8
 9
 .sv 1i/2u
+.tm T1=@n[.sv]
 13
 14
 15
@@ -89,6 +91,7 @@ input='.
 59
 60
 .sv 1i
+.tm T2=@n[.sv]
 A
 B
 C
@@ -96,6 +99,7 @@ D
 E
 F
 .os
+.tm T3=@n[.sv]
 G
 H
 I
@@ -118,6 +122,20 @@ echo "$output" \
 echo "checking that 'os' works" >&2
 echo "$output" | grep -q "72 73 G 74 H 75 I 76 DONE 77 78" || wail
 
+error=$(printf '%s\n' "$input" | "$groff" -z -T ascii 2>&1)
+echo "$error"
+
+echo "checking that 'sv' far from a trap" \
+    "does not populate .sv register" >&2
+echo "$error" | grep -qx 'T1=0'
+
+echo "checking that 'sv' close to a trap" \
+    "populates .sv register" >&2
+echo "$error" | grep -qx 'T2=240'
+
+echo "checking that 'os' zeroes the .sv register" >&2
+echo "$error" | grep -qx 'T3=0'
+
 test -z "$fail"
 
 # vim:set autoindent expandtab shiftwidth=4 tabstop=4 textwidth=72:
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index 473d2791e..5785a0792 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -1297,6 +1297,16 @@ const char *no_space_mode_reg::get_string()
   return curdiv->is_in_no_space_mode ? "1" : "0";
 }
 
+class saved_vertical_space_reg : public reg {
+public:
+  const char *get_string();
+};
+
+const char *saved_vertical_space_reg::get_string()
+{
+  return i_to_a(saved_space.to_units());
+}
+
 void init_div_requests()
 {
   init_request("box", box);
@@ -1332,6 +1342,7 @@ void init_div_requests()
   register_dictionary.define(".p", new page_length_reg);
   register_dictionary.define(".pe", new page_ejecting_reg);
   register_dictionary.define(".pn", new next_page_number_reg);
+  register_dictionary.define(".sv", new saved_vertical_space_reg);
   register_dictionary.define(".t", new distance_to_next_trap_reg);
   register_dictionary.define(".trap", new next_trap_name_reg);
   register_dictionary.define(".trunc",

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to