branch: externals/org
commit 8ace4093816b979a70c3b1b0b4781f286eec55a3
Author: GrĂ©goire Scano <[email protected]>
Commit: Ihor Radchenko <[email protected]>

    ox-man: Add support for footer-inside and header-middle
    
    * etc/ORG-NEWS (ox-man): Announce the change.
    * lisp/ox-man.el (org-man-template): Support footer-inside and
    header-middle with #+MAN_CLASS_OPTIONS: :release "" :header "".
    
    TINYCHANGE
---
 etc/ORG-NEWS   |  6 ++++++
 lisp/ox-man.el | 28 ++++++++++++++++++----------
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index ec2b402b39..ac84ba6bdc 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -724,6 +724,12 @@ Previously, ox-man ignored =#+DATE:= keyword even when
 and specified in the =footer-middle= argument of =.TH= macro (see ~man
 7 man~).
 
+*** ox-man: Support specifying =:release= and =:header= in 
=#+MAN_CLASS_OPTIONS:= in addition to =:section-id=
+
+The newly added =:release= and =:header= options of =#+MAN_CLASS_OPTIONS=
+are respectively mapped to the =footer-inside= and =header-middle=
+arguments of the =.TH= macro (see ~man 7 groff_man~).
+
 *** ~org-timer-done-hook~ is now run before the timer is stopped
 
 Previously, ~org-timer-countdown-timer~ and ~org-timer-start-time~
diff --git a/lisp/ox-man.el b/lisp/ox-man.el
index 51cfa5ed1c..abae2742aa 100644
--- a/lisp/ox-man.el
+++ b/lisp/ox-man.el
@@ -33,7 +33,11 @@
 ;; See ox.el for more details on how this exporter works.
 ;;
 ;; It introduces one new buffer keywords:
-;; "MAN_CLASS_OPTIONS".
+;; "MAN_CLASS_OPTIONS" that accepts the following options:
+;;   - `:section-id', the section, a string (eg. ':section-id "2"');
+;;   - `:release', the footer middle, a string (eg. ':release "Emacs 13"');
+;;   - `:header', the header middle, a string (eg. ':header "GNU"').
+
 
 ;;; Code:
 
@@ -328,20 +332,24 @@ holding export options."
                               (list (plist-get info :man-class-options))
                               " "))))
          (section-item (plist-get attr :section-id))
+         (release (plist-get attr :release))
+         (header (plist-get attr :header))
          ;; Note: groff linter suggests date to be the third argument
          ;; of .TH
          (date (and (plist-get info :with-date)
                    (org-export-data (org-export-get-date info) info))))
     (concat
-     (cond
-      ((and title (stringp section-item))
-       (format ".TH \"%s\" \"%s\" \"%s\" \n" title section-item date))
-      ((and (string= "" title) (stringp section-item))
-       (format ".TH \"%s\" \"%s\" \"%s\" \n" " " section-item date))
-      (title
-       (format ".TH \"%s\" \"1\" \"%s\" \n" title date))
-      (t
-       (format ".TH \" \" \"1\" \"%s\" " date)))
+     (format ".TH \"%s\" \"%s\"" ;; only two required by groff_man(7).
+             (if title title " ")
+             (if (stringp section-item) section-item "1"))
+     (if date (format " \"%s\""  date)
+       " \"\"") ;; in case later options are present.
+     (if release (format " \"%s\"" release)
+       " \"\"") ;; in case later options are present.
+     ;; Do not write an empty footer-outside, otherwise man(1) will
+     ;; no longer generate its content, see groff_man(7).
+     (if header (format " \"%s\"" header))
+     " \n"
      contents)))
 
 

Reply via email to