gbranden pushed a commit to branch master
in repository groff.
commit c678299b3bb45c7c3446015cc9b3d157b217330a
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Apr 3 17:44:31 2026 -0500
[troff]: Implement new `rhw` request.
* src/roff/troff/env.cpp: Implement `rhw` request removing user-defined
hyphenation exception words.
(remove_hyphenation_exception_words_request): New function empties the
current language's hyphenation exception word dictionary of all
entries populated by the user. (We retain those supplied by files
like "tmac/hyphenex.{cs,en,pl}".)
(init_hyphenation_pattern_requests): Wire up `rhw` request name to
`remove_hyphenation_exception_words_request()`.
* src/roff/groff/tests/rhw-request-works.sh: Test it.
* src/roff/groff/groff.am (groff_TESTS): Run test.
* doc/groff.texi.in (Manipulating Hyphenation):
* man/groff.7.man (Request short reference):
* man/groff_diff.7.man (New requests):
* NEWS: Document it.
Begins fixing <https://savannah.gnu.org/bugs/?64478>.
---
ChangeLog | 21 ++++++++++++
NEWS | 4 +++
doc/groff.texi.in | 18 ++++++++---
man/groff.7.man | 5 +++
man/groff_diff.7.man | 6 ++++
src/roff/groff/groff.am | 1 +
src/roff/groff/tests/rhw-request-works.sh | 53 +++++++++++++++++++++++++++++++
src/roff/troff/env.cpp | 31 ++++++++++++++++++
8 files changed, 135 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f38c4c385..04b4978eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2026-04-03 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/env.cpp: Implement `rhw` request removing
+ user-defined hyphenation exception words.
+ (remove_hyphenation_exception_words_request): New function
+ empties the current language's hyphenation exception word
+ dictionary of all entries populated by the input. (We retain
+ those supplied by files like "tmac/hyphenex.{cs,en,pl}".)
+ (init_hyphenation_pattern_requests): Wire up `rhw` request name
+ to `remove_hyphenation_exception_words_request()`.
+
+ * src/roff/groff/tests/rhw-request-works.sh: Test it.
+ * src/roff/groff/groff.am (groff_TESTS): Run test.
+
+ * doc/groff.texi.in (Manipulating Hyphenation):
+ * man/groff.7.man (Request short reference):
+ * man/groff_diff.7.man (New requests):
+ * NEWS: Document it.
+
+ Begins fixing <https://savannah.gnu.org/bugs/?64478>.
+
2026-04-03 G. Branden Robinson <[email protected]>
* src/roff/troff/dictionary.cpp (dictionary_iterator::get):
diff --git a/NEWS b/NEWS
index 7afe3a63c..1ab709182 100644
--- a/NEWS
+++ b/NEWS
@@ -43,6 +43,10 @@ troff
the request (and issues a warning in category "range"), leaving the
operand (first request argument) unchanged instead of emptying it.
+* A new request, `rhw`, clears the current hyphenation language's list
+ of user-defined hyphenation exception words. Those supplied by files
+ like "tmac/hyphenex.{cs,en,pl}" are retained.
+
Macro packages
--------------
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index 2f80aa332..f7aebded7 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -10086,8 +10086,7 @@ even possible is an unsolved problem in computer
science:@:
unusual words found in technical literature. We can instruct GNU
@code{troff} how to hyphenate specific words if the need arises.
-@c TODO: Add request `rhw`; see Savannah #64478.
-@cindex hyphenation exception words
+@cindex hyphenation exception words, adding
@Defreq {hw, word @dots{}}
Define each argument @var{word}
(comprising ordinary,
@@ -10147,6 +10146,15 @@ that would normally apply to a word
matching a hyphenation exception word defined with
@code{hw}.
+@cindex hyphenation exception words, removing
+@Defreq {rhw}
+Empty the current hyphenation language's exception word list
+of all entries populated by the input.@footnote{GNU
+@command{troff} @c GNU
+retains those supplied by hyphenation pattern exception files;
+see below.}
+@endDefreq
+
Situations also arise when only a specific occurrence of a word needs
its hyphenation altered or suppressed, or when a URL or similar
specialized text needs to be breakable in sensible places without
@@ -10346,8 +10354,10 @@ non-zero even mode.
@pindex hyphenex.cs
@pindex hyphenex.en
@pindex hyphenex.pl
-@cindex hyphenation pattern files
-@cindex pattern files, for hyphenation
+@cindex hyphenation pattern and exception files
+@cindex pattern and exception files, hyphenation
+@cindex exception file, hyphenation pattern
+@cindex file, hyphenation pattern or exception
The automatic placement of hyphens in words is determined by
@dfn{pattern files}, which are derived from @TeX{} and available for
several languages. These files are named @file{hyphen.@var{xx}} (for
diff --git a/man/groff.7.man b/man/groff.7.man
index 7b8ebb494..356bfa214 100644
--- a/man/groff.7.man
+++ b/man/groff.7.man
@@ -4884,6 +4884,11 @@ See
.BR fschar .
.
.TPx
+.REQ .rhw
+Empty the current hyphenation language's exception word list
+of all entries populated by the input.
+.
+.TPx
.REQ .rj
Break,
right-align the output of the next productive input line without
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index ffe2647a0..b8ed37317 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -4193,6 +4193,12 @@ See
.
.
.TP
+.B .rhw
+Empty the current hyphenation language's exception word list
+of all entries populated by the input.
+.
+.
+.TP
.BR .rj\~ [\c
.IR n ]
Break,
diff --git a/src/roff/groff/groff.am b/src/roff/groff/groff.am
index a41a556ec..a93571aac 100644
--- a/src/roff/groff/groff.am
+++ b/src/roff/groff/groff.am
@@ -118,6 +118,7 @@ groff_TESTS = \
src/roff/groff/tests/regression_savannah_58162.sh \
src/roff/groff/tests/regression_savannah_58337.sh \
src/roff/groff/tests/regression_savannah_59202.sh \
+ src/roff/groff/tests/rhw-request-works.sh \
src/roff/groff/tests/safer-mode-works.sh \
src/roff/groff/tests/set-stroke-thickness.sh \
src/roff/groff/tests/sizes-request-works.sh \
diff --git a/src/roff/groff/tests/rhw-request-works.sh
b/src/roff/groff/tests/rhw-request-works.sh
new file mode 100755
index 000000000..9d70c13d4
--- /dev/null
+++ b/src/roff/groff/tests/rhw-request-works.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+#
+# Copyright 2026 G. Branden Robinson
+#
+# This file is part of groff, the GNU roff typesetting system.
+#
+# groff is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# groff is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+groff="${abs_top_builddir:-.}/test-groff"
+
+fail=
+
+wail () {
+ echo "...FAILED"
+ fail=yes
+}
+
+input='.
+.hw baz-qux kwy-ji-bo sa-hu-agin
+.rhw
+.phw
+.'
+
+echo "checking operation of 'rhw' request without arguments"
+output=$(printf '%s\n' "$input" | "$groff" 2>&1)
+echo "$output"
+echo "$output" | grep -Eqx "(baz-qux|kwy-ji-bo|sa-hu-agin)" && wail
+
+#input='.
+#.hw baz-qux kwy-ji-bo sa-hu-agin
+#.rhw kwyjibo
+#.phw
+#.'
+#
+#echo "checking operation of 'rhw' request without arguments"
+#output=$(printf '%s\n' "$input" | "$groff" 2>&1)
+#echo "$output"
+#echo "$output" | grep -qx "kwyjibo" || wail
+
+test -z "$fail"
+
+# vim:set autoindent expandtab shiftwidth=4 tabstop=4 textwidth=72:
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index bc2cb3cc0..f0b7e497c 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -3955,6 +3955,33 @@ static void add_hyphenation_exception_words_request() //
.hw
skip_line();
}
+static void remove_hyphenation_exception_words_request() // .rhw
+{
+ if (0 /* nullptr */ == current_language) {
+ error("cannot remove hyphenation exception words when no"
+ " hyphenation language is selected");
+ skip_line();
+ return;
+ }
+ dictionary_iterator iter(current_language->exceptions);
+ symbol entry;
+ if (!has_arg()) {
+ while (iter.get(&entry, 0 /* nullptr */)) {
+ assert(!entry.is_null());
+ // The exception word symbol's contents contains a space if it's
+ // _not_ user-defined. Kind of kludgy, but possibly not worth
+ // fixing without also migrating to an STL unordered_map or
+ // similar, and using a `struct` with a string and a `bool` in it
+ // as the values.
+ if (strchr(entry.contents(), ' ') == 0 /* nullptr */)
+ current_language->exceptions.remove(entry.contents());
+ }
+ }
+ // TODO: Else read each argument as a word, normalize any hyphens
+ // (dashes) out of it, and remove it from the exceptions dictionary.
+ skip_line();
+}
+
static void print_hyphenation_exceptions_request() // .phw
{
if (0 /* nullptr */ == current_language) {
@@ -3983,6 +4010,9 @@ static void print_hyphenation_exceptions_request() // .phw
wordbuf[j++] = '-';
hypoint++;
}
+ // The exception word symbol's contents contains a space if it's
+ // _not_ user-defined. See
+ // `remove_hyphenation_exception_words_request()` above.
if (word[i] == ' ') {
assert(i == (len - 1));
is_mode_dependent = true;
@@ -4697,6 +4727,7 @@ void init_hyphenation_pattern_requests()
init_request("hpfa", append_hyphenation_patterns_from_file_request);
init_request("hw", add_hyphenation_exception_words_request);
init_request("phw", print_hyphenation_exceptions_request);
+ init_request("rhw", remove_hyphenation_exception_words_request);
}
// Local Variables:
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit