$OpenBSD: patch-tmac_doc_tmac,v 1.7 2017/04/14 19:49:06 schwarze Exp $
chunks 1,2,4-6,8-14: Simplify .Bl -tag without -width (merged upstream).
chunk 3: Trailing -width/-offset must not pick up old args (merged upstream).
chunk 7: Always format .Pa the same way, as requested by jmc@ (local change).
chunk 15: Use typographic quotes for .%T (merged upstream).
chunk 16: Improve .Lk with more than two arguments (merged upstream).
--- tmac/doc.tmac.orig	Tue Nov  4 09:38:35 2014
+++ tmac/doc.tmac	Fri Apr 14 21:02:49 2017
@@ -2990,6 +2990,7 @@
 .  \}
 .  el \{ .ie "\$1"-tag" \{\
 .    ds doc-list-type-stack\n[doc-list-depth] tag-list
+.    nr doc-list-indent-stack\n[doc-list-depth] 6n
 .    nr doc-list-have-indent-stack\n[doc-list-depth] 1
 .  \}
 .  el \{ .ie "\$1"-item" \{\
@@ -3105,7 +3106,6 @@
 .\" NS   doc-list-offset-stackXXX
 .\" NS   doc-num-columns
 .\" NS   doc-tag-prefix-stackXXX
-.\" NS   doc-tag-width-stackXXX
 .\" NS
 .\" NS local variables:
 .\" NS   doc-box-dBla
@@ -3126,7 +3126,7 @@
 .
 .  \" avoid a warning message in case e.g. `-offset' has no parameter
 .  nr doc-reg-dBla (\n[doc-arg-ptr] + 1)
-.  if !d doc-arg\n[doc-reg-dBla] \
+.  if (\n[doc-arg-limit] < \n[doc-reg-dBla]) \
 .    ds doc-arg\n[doc-reg-dBla]
 .
 .  nr doc-reg-dBla 1
@@ -3148,8 +3148,6 @@
 .
 .  el \{ .ie "\*[doc-arg\n[doc-arg-ptr]]"-width" \{\
 .    nr doc-arg-ptr +1
-.    ds doc-tag-width-stack\n[doc-list-depth] TagwidtH
-.
 .    ds doc-str-dBla "\*[doc-arg\n[doc-arg-ptr]]
 .    substring doc-str-dBla 0 0
 .    ie .\*[doc-str-dBla] \{\
@@ -3394,7 +3392,6 @@
 .    nr doc-list-indent-stack\n[doc-reg-dsgv]-saved \n[doc-list-indent-stack\n[doc-reg-dsgv]]
 .    nr doc-compact-list-stack\n[doc-reg-dsgv]-saved \n[doc-compact-list-stack\n[doc-reg-dsgv]]
 .    ds doc-tag-prefix-stack\n[doc-reg-dsgv]-saved "\*[doc-tag-prefix-stack\n[doc-reg-dsgv]]
-.    ds doc-tag-width-stack\n[doc-reg-dsgv]-saved "\*[doc-tag-width-stack\n[doc-reg-dsgv]]
 .    nr doc-list-offset-stack\n[doc-reg-dsgv]-saved \n[doc-list-offset-stack\n[doc-reg-dsgv]]
 .    nr doc-enum-list-count-stack\n[doc-reg-dsgv]-saved \n[doc-enum-list-count-stack\n[doc-reg-dsgv]]
 .    nr doc-reg-dsgv +1
@@ -3538,7 +3535,6 @@
 .    nr doc-list-indent-stack\n[doc-reg-drgv] \n[doc-list-indent-stack\n[doc-reg-drgv]-saved]
 .    nr doc-compact-list-stack\n[doc-reg-drgv] \n[doc-compact-list-stack\n[doc-reg-drgv]-saved]
 .    ds doc-tag-prefix-stack\n[doc-reg-drgv] "\*[doc-tag-prefix-stack\n[doc-reg-drgv]-saved]
-.    ds doc-tag-width-stack\n[doc-reg-drgv] "\*[doc-tag-width-stack\n[doc-reg-drgv]-saved]
 .    nr doc-list-offset-stack\n[doc-reg-drgv] \n[doc-list-offset-stack\n[doc-reg-drgv]-saved]
 .    nr doc-enum-list-count-stack\n[doc-reg-drgv] \n[doc-enum-list-count-stack\n[doc-reg-drgv]-saved]
 .    nr doc-reg-drgv +1
@@ -3765,8 +3761,6 @@
 .
 .        if \n[doc-in-files-section] \{\
 .          ds doc-saved-Pa-font "\*[doc-Pa-font]
-.          if n \
-.            ds doc-Pa-font "\*[doc-No-font]
 .        \}
 .
 .        ie (\n[doc-type1] == 1) \
@@ -4030,13 +4024,6 @@
 .  ev
 .  box
 .
-.  if !"TagwidtH"\*[doc-tag-width-stack\n[doc-list-depth]]" \{\
-.    if !\n[doc-list-have-indent-stack\n[doc-list-depth]] \{\
-.      in -(\n[doc-list-indent-stack\n[doc-list-depth]]u + \n[doc-digit-width]u)
-.      nr doc-list-have-indent-stack\n[doc-list-depth] 1
-.    \}
-.    doc-get-tag-width
-.  \}
 .  doc-set-vertical-and-indent 1
 .  nr doc-reg-dtl (\n[doc-list-indent-stack\n[doc-list-depth]]u + \n[doc-digit-width]u)
 .  ti -\n[doc-reg-dtl]u
@@ -4064,29 +4051,6 @@
 ..
 .
 .
-.\" NS doc-get-tag-width macro
-.\" NS   resolve unknown tag width (`tag' list-type only)
-.\" NS
-.\" NS modifies:
-.\" NS   doc-list-indent-stackXXX
-.\" NS   doc-tag-width-stackXXX
-.\" NS
-.\" NS requires:
-.\" NS   doc-curr-arg
-.\" NS   doc-curr-type
-.
-.de doc-get-tag-width
-.  ie (\n[doc-curr-type] == 1) \{\
-.    ds doc-tag-width-stack\n[doc-list-depth] \*[doc-curr-arg]
-.    nr doc-list-indent-stack\n[doc-list-depth] \n[\*[doc-curr-arg]]
-.  \}
-.  el \{\
-.    ds doc-tag-width-stack\n[doc-list-depth] No
-.    nr doc-list-indent-stack\n[doc-list-depth] \n[No]
-.  \}
-..
-.
-.
 .\" NS doc-set-vertical-and-indent macro
 .\" NS   set up vertical spacing (if not compact) and indentation (with
 .\" NS   offset if argument is non-zero)
@@ -4139,19 +4103,6 @@
 .ds doc-tag-prefix-stack1
 .
 .
-.\" NS doc-tag-width-stackXXX global string
-.\" NS   stack of strings indicating how to set up current element of
-.\" NS   doc-list-indent-stackXXX -- if set to TagwidtH, user has set it
-.\" NS   directly; if it is a macro name, use the macro's width value;
-.\" NS   otherwise, `doc-get-tag-width' uses width value of `No'.
-.\" NS
-.\" NS limit:
-.\" NS   doc-list-depth
-.
-.ds doc-tag-width-stack0
-.ds doc-tag-width-stack1
-.
-.
 .\" NS doc-list-offset-stackXXX global register
 .\" NS   stack of list offsets
 .\" NS
@@ -4193,7 +4144,6 @@
 .\" NS   doc-list-offset-stackXXX
 .\" NS   doc-list-type-stackXXX
 .\" NS   doc-tag-prefix-stackXXX
-.\" NS   doc-tag-width-stackXXX
 .\" NS   doc-enum-list-count-stackXXX
 .\" NS
 .\" NS local variables:
@@ -4205,7 +4155,6 @@
 .  nr doc-list-indent-stack\n[doc-reg-dils] 0
 .  nr doc-list-offset-stack\n[doc-reg-dils] 0
 .  ds doc-tag-prefix-stack\n[doc-reg-dils]
-.  ds doc-tag-width-stack\n[doc-reg-dils] \*[doc-tag-width-stack\n[doc-list-depth]]
 .  ds doc-list-type-stack\n[doc-reg-dils]
 .  nr doc-compact-list-stack\n[doc-reg-dils] 0
 .  nr doc-enum-list-count-stack\n[doc-reg-dils] 0
@@ -4222,7 +4171,6 @@
 .\" NS   doc-list-offset-stackXXX
 .\" NS   doc-list-type-stackXXX
 .\" NS   doc-tag-prefix-stackXXX
-.\" NS   doc-tag-width-stackXXX
 .\" NS   doc-enum-list-count-stackXXX
 .
 .de doc-decrement-list-stack
@@ -4231,7 +4179,6 @@
 .  nr doc-list-indent-stack\n[doc-list-depth] 0
 .  nr doc-list-offset-stack\n[doc-list-depth] 0
 .  ds doc-tag-prefix-stack\n[doc-list-depth]
-.  ds doc-tag-width-stack\n[doc-list-depth]
 .  nr doc-compact-list-stack\n[doc-list-depth] 0
 .  nr doc-enum-list-count-stack\n[doc-list-depth] 0
 ..
@@ -5296,7 +5243,7 @@
 .    unformat doc-reference-title-name-for-book
 .    chop doc-reference-title-name-for-book
 .    ie ((\n[doc-journal-count] == 1) : (\n[doc-book-count] == 1)) \{\
-.      nop \)\*[q]\)\*[doc-reference-title-name-for-book]\)\*[q]\c
+.      nop \)\*[Lq]\)\*[doc-reference-title-name-for-book]\)\*[Rq]\c
 .      doc-finish-reference \n[doc-reference-title-count]
 .    \}
 .    el \{\
@@ -6498,36 +6445,53 @@
 .\" NS   link (for conversion to HTML)
 .\" NS
 .\" NS local variables:
+.\" NS   doc-delim-Lk
 .\" NS   doc-reg-Lk
-.\" NS   doc-str-Lk
+.\" NS   doc-target-Lk
+.\" NS   doc-text-Lk
 .
 .de Lk
-.  ds doc-str-Lk Sy \$@
+.  \" The first argument is the target URI.
+.  ds doc-target-Lk \$1
+.  shift
 .
-.  ie (\n[.$] > 1) \{\
-.    doc-get-arg-type \$2
-.    ie (\n[doc-arg-type] < 3) \{\
-.      Em \)\$2:
-.      ds doc-str-Lk Sy "\$1"
-.      doc-get-width "\$1"
-.      shift 2
-.      if \n[.$] \
-.        as doc-str-Lk " \$@
+.  \" Split the remaining arguments into link text and delimiters.
+.  ds doc-text-Lk
+.  ds doc-delim-Lk
+.  while \n[.$] \{\
+.    doc-get-width "\$1"
+.    doc-get-arg-type \$1
+.    ie (\n[doc-arg-type] > 2) \
+.      as doc-delim-Lk \$1
+.    el \{\
+.      if !'\*[doc-delim-Lk]'' \{\
+.        \" More text follows delimiter(s); go back to text mode.
+.        as doc-text-Lk \*[doc-delim-Lk]
+.        ds doc-delim-Lk
+.      \}
+.      ie '\*[doc-text-Lk]'' \
+.        ds doc-text-Lk \$1
+.      el \
+.        as doc-text-Lk " \$1
 .    \}
-.    el \
-.      doc-get-width "\$1"
+.    shift
 .  \}
-.  el \
-.    doc-get-width "\$1"
 .
+.  \" Print the link text, if any.
+.  if !'\*[doc-text-Lk]'' \
+.      Em \*[doc-text-Lk] Ns :
+.
+.  \" Print the link target.
 .  ie n \
 .    nr doc-reg-Lk 26
 .  el \
 .    nr doc-reg-Lk 38
+.  doc-get-width "\*[doc-target-Lk]"
 .  ie (\n[doc-width] >= \n[doc-reg-Lk]) \
-.    D1 \*[doc-str-Lk]
-.  el \
-.    \*[doc-str-Lk]
+.    D1 Sy \*[doc-target-Lk] Ns \*[doc-delim-Lk]\&
+.  el .ie \n[doc-width] \
+.    Sy \*[doc-target-Lk] Ns \*[doc-delim-Lk]\&
+.  el \*[doc-delim-Lk]\&
 ..
 .
 .
