emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Cc: alan.schmitt@polytechnique.org, n.goaziou@gmail.com,
	papoanaya@hotmail.com
Subject: [patch] ox-koma-letter.el: credit [3/4]
Date: Mon, 20 May 2013 02:51:15 +0200	[thread overview]
Message-ID: <87ip2esccc.fsf@pank.eu> (raw)
In-Reply-To: <87wqqusder.fsf@pank.eu> (rasmus@gmx.us's message of "Mon, 20 May 2013 02:28:12 +0200")

[-- Attachment #1: Type: text/plain, Size: 1005 bytes --]


This is probably the most fun change.  It adds special tags PS, ENCL,
CC, AFTER_CLOSING as in my last patch set, but it uses heading this
time.  E.g. ENCLs are under the heading * ENCL :ENCL:.  This was
suggested by Nicolas, and it's nicer.  The ideas comes from
ox-groff.el file ¹.  Thanks Luis!

One thing I'd like to discuss is whether to adopt headings for TO and
FROM also.  The Groff exporter already does so for it's letters.  The
main benefit is that it allows for org-syntax.  IMO it's a lot nicer
to look at as well.  Check the org-groff site in the footnote for an
example.

I'd be happy to look into this the next time I have a free day for
programming if you guys (also) find in a more appealing.  (One
additional benefit would be that for simple documents it wouldn't
matter whether groff or scrlttr2 was used as backend).

–Rasmus


Footnotes: 
 ¹   http://orgmode.org/worg/org-tutorials/org-e-groff-documentation.html#sec-1-5

-- 
Powered by magic pixies!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-Added-support-for-after-closing-and-after-document-e.patch --]
[-- Type: text/x-patch, Size: 7222 bytes --]

From eeaa129b6807465566be881b96a94e14706c9a28 Mon Sep 17 00:00:00 2001
From: "rasmus.pank" <rasmus.pank@gmail.com>
Date: Sun, 19 May 2013 21:50:14 +0200
Subject: [PATCH 3/4] Added support for after closing and after document
 entities in ox-koma-letter.

* ox-koma-letter.el (org-koma-letter-special-tags-after-closing): specials tags inserted after =\end{closing}=
* ox-koma-letter.el (org-koma-letter-special-tags-other): other special tags
* ox-koma-letter.el (org-koma-letter-special-tags): collect
the two previoues lists (this might be done in a wrong way).
* ox-koma-letter.el (org-koma-letter-ps-prefix): a prefix for
PS since scrlttr does not provide it.
* ox-koma-letter.el (org-koma-letter-headline): stores content
in a special list if it is =`org-koma-letter-special-tags'= as
in ox-groff.  Only returns contents if not tags not in special
tags.
* ox-koma-letter.el (org-koma-letter-special-content): holds special
content temporarily.
* ox-koma-letter.el (org-koma-letter-template): added support
for the headings with special tags.

The following example will now export a sensible manner.

* my letter
here's a letter
* PS :PS:
it's requires this patch
* CC :CC:
Nicolas, Viktor and Alan
* ENCL :ENCL:
many patches
1. this patch
2. another patch.
* include patches :AFTER_LETTER:
\myspecial macro

Namely, content of PS, ENCL and CC headings will be exported after
\closing{.}  in the order prescribed by
=`org-koma-letter-special-tags-after-closing'=.  The concent
of the =AFTER_LETTER= heading will be inserted after
=\end{letter}=, ideal for e.g. =pdfpages= commands.
---
 contrib/lisp/ox-koma-letter.el | 86 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 81 insertions(+), 5 deletions(-)

diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el
index 77d21c7..8ae9fc5 100644
--- a/contrib/lisp/ox-koma-letter.el
+++ b/contrib/lisp/ox-koma-letter.el
@@ -183,6 +183,29 @@ Use `foldmarks:true' to activate default fold marks or
   :group 'org-export-koma-letter
   :type 'boolean)
 
+(defcustom org-koma-letter-ps-prefix "\\textsc{ps}: "
+  "The prefix of PS.  Used to construct PS as \"PS-SUFFIX PS\""
+  :group 'org-export-koma-letter
+  :type 'string)
+
+
+(defconst org-koma-letter-special-tags-after-closing
+  '("PS" "ENCL" "CC")
+  "Headers tags to be inserted after closing")
+
+(defconst org-koma-letter-special-tags-other
+  '("FROM" "AFTER_LETTER")
+  "Headers tags to be inserted after closing")
+
+(defconst org-koma-letter-special-tags
+  (append org-koma-letter-special-tags-other
+	  org-koma-letter-special-tags-after-closing)
+  "Header tags with special meaning")
+
+(defvar org-koma-letter-special-content nil "holds special
+content temporarily.")
+
+
 \f
 ;;; Define Back-End
 
@@ -198,15 +221,18 @@ Use `foldmarks:true' to activate default fold marks or
     (:opening "OPENING" nil org-koma-letter-opening)
     (:closing "CLOSING" nil org-koma-letter-closing)
     (:signature "SIGNATURE" nil org-koma-letter-signature newline)
+    (:ps-prefix nil "ps-prefix" org-koma-letter-ps-prefix)
 
     (:with-backaddress nil "backaddress" org-koma-letter-use-backaddress)
     (:with-foldmarks nil "foldmarks" org-koma-letter-use-foldmarks)
     (:with-phone nil "phone" org-koma-letter-use-phone)
     (:with-email nil "email" org-koma-letter-use-email)
     (:with-place nil "place" org-koma-letter-use-place)
+    (:with-after-closing nil "after-closing-order" org-koma-letter-special-tags-after-closing)
     (:with-subject nil "subject" org-koma-letter-subject-format))
   :translate-alist '((export-block . org-koma-letter-export-block)
 		     (export-snippet . org-koma-letter-export-snippet)
+		     (headline . org-koma-letter-headline)
 		     (keyword . org-koma-letter-keyword)
 		     (template . org-koma-letter-template))
   :menu-entry
@@ -253,12 +279,47 @@ channel."
     (if (equal key "KOMA-LETTER") value
       (org-export-with-backend 'latex keyword contents info))))
 
+
+;; The following is taken from/inspired by ox-grof.el
+;; Thanks, Luis!
+
+(defun org-koma-letter--get-tagged-content  (tag info)
+  (cdr  (assoc tag org-koma-letter-special-content)))
+
+
+(defun org-koma-letter-headline (headline conents info)
+  "Transcode a HEADLINE element from Org to LaTeX.
+CONTENTS holds the contents of the headline.  INFO is a plist
+holding contextual informatio.n
+
+Note that if a headline is tagged with a tag from
+`org-koma-letter-special-tags' it will not be exported, but
+stored in `org-koma-letter-special-content' and included at the
+appropriate place."
+  (let*
+      ((tags (and (plist-get info :with-tags)
+		 (org-export-get-tags headline info))))
+    (if (member (car tags) org-koma-letter-special-tags)
+    	(cond ((member (car tags) '("PS" "ps"))
+    	       (progn
+    		 (push (cons (car tags) (concat (plist-get info :ps-prefix) contents))
+    		       org-koma-letter-special-content) nil))
+    	      (t (progn
+    		   (push (cons (car tags) contents)
+    			 org-koma-letter-special-content) nil)))
+      contents)))
+
+
 ;;;; Template
 
 (defun org-koma-letter-template (contents info)
   "Return complete document string after KOMA Scrlttr2 conversion.
 CONTENTS is the transcoded contents string.  INFO is a plist
 holding export options."
+  ;; FIXME: instead of setq'ing org-koma-letter-special-content and
+  ;; callying varioues stuff it might be nice to put a big let* around the templace
+  ;; as in org-groff...
+  (setq org-koma-letter-special-content nil)
   (concat
    ;; Time-stamp.
    (and (plist-get info :time-stamp-file)
@@ -327,14 +388,14 @@ holding export options."
    ;; Subject
    (let* ((with-subject (plist-get info :with-subject))
 	  (subject-format (if (member with-subject '("True" t "true" "TRUE"))
-				  ;; FIXME: could this be done more elegantly?
-				  ;; I.e. force lower face of with-subject if string.
+			      ;; FIXME: could this be done more elegantly?
+			      ;; I.e. force lower face of with-subject if string.
 			      org-koma-letter-subject-format
 			    with-subject))
 	  (subject (org-export-data (plist-get info :title) info)))
      (concat
       (when with-subject
-	(format "\\KOMAoption{subject}{%s}\n\n" subject-format))
+	(format "\\KOMAoption{subject}{%s}\n" subject-format))
       (when (and subject with-subject)
 	(format "\\setkomavar{subject}{%s}\n\n" subject))))
    ;; Letter start
@@ -346,9 +407,24 @@ holding export options."
    contents
    ;; Closing.
    (format "\n\\closing{%s}\n\n" (plist-get info :closing))
+   (let (after-closing)
+     (dolist (ac org-koma-letter-special-tags-after-closing after-closing)
+       (let ((x (org-koma-letter--get-tagged-content ac info)))
+	 (when x (setq after-closing
+		       (concat after-closing
+			       ;; sometimes LaTeX complains about newlines
+			       ;; at the end of macros.  Remove them.
+			       (replace-regexp-in-string
+				"\n+$" ""
+				(format "\\%s{%s}" (downcase ac) x)))))
+	 )))
    ;; Letter end.
-   "\\end{letter}\n\\end{document}"))
-
+   "\\end{letter}\n"
+   (let ((x (org-koma-letter--get-tagged-content "AFTER_LETTER" info)))
+     (when x (format x)))
+   ;; Document end.
+   "\\end{document}"
+   ))
 
 \f
 ;;; Commands
-- 
1.8.2.3


  parent reply	other threads:[~2013-05-20  0:51 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-20  0:28 [patch] ox-koma-letter.el: credit [1/4] Rasmus
2013-05-20  0:40 ` [patch] ox-koma-letter.el: subject changes [2/4] Rasmus
2013-05-20 15:49   ` Alan Schmitt
2013-05-20 18:23     ` Rasmus
2013-05-21  7:24       ` Alan Schmitt
2013-05-21 15:52         ` Viktor Rosenfeld
2013-05-21 17:48           ` Rasmus
2013-05-20  0:51 ` Rasmus [this message]
2013-05-20 15:52   ` [patch] ox-koma-letter.el: credit [3/4] Alan Schmitt
2013-05-21 16:56   ` Viktor Rosenfeld
2013-05-21 17:35     ` Rasmus
2013-05-21 20:06       ` Viktor Rosenfeld
     [not found]         ` <87zjvo7xkl.fsf@pank.eu>
     [not found]           ` <20130522145312.GB61443@kenny.local>
2013-05-22 17:16             ` Rasmus
2013-05-22 17:38               ` Viktor Rosenfeld
2013-05-20  0:54 ` [patch] ox-koma-letter.el: clean-up/semantic bug [4/4] Rasmus
     [not found]   ` <m2ehd1tziq.fsf@polytechnique.org>
2013-05-21  9:05     ` Rasmus
2013-05-21 11:32       ` Alan Schmitt
2013-05-21 12:22         ` Rasmus
2013-05-21 17:02           ` Viktor Rosenfeld
2013-05-21 18:13             ` Rasmus
2013-05-21 19:54               ` Viktor Rosenfeld
2013-05-21 23:23                 ` Rasmus
2013-05-22 14:39                   ` Viktor Rosenfeld
2013-05-22 22:06                     ` [PATCH] ox-koma-letter.el: Reintroduce variables removed in commit 832c6fd with proper defaults (was Re: [patch] ox-koma-letter.el: clean-up/semantic bug [4/4]) Viktor Rosenfeld
2013-05-25  5:13                       ` Robert Klein
2013-05-25  8:05                         ` Viktor Rosenfeld
2013-05-25  9:20                           ` Alan Schmitt
2013-05-25 13:57                             ` Rasmus
2013-05-25 17:03                               ` Viktor Rosenfeld
2013-05-25 17:48                                 ` [PATCH][ox-koma-letter]: sender, email and cleanup (was: [PATCH] ox-koma-letter.el: Reintroduce variables removed in commit 832c6fd with proper defaults) Rasmus
2013-05-25 21:27                                   ` [PATCH][ox-koma-letter]: sender, email and cleanup Rasmus
2013-05-26 10:58                                     ` Viktor Rosenfeld
2013-05-26 14:38                                       ` Rasmus
2013-05-26 10:54                                   ` [PATCH][ox-koma-letter]: sender, email and cleanup (was: [PATCH] ox-koma-letter.el: Reintroduce variables removed in commit 832c6fd with proper defaults) Viktor Rosenfeld
2013-05-26 14:36                                     ` [PATCH][ox-koma-letter]: sender, email and cleanup Rasmus
2013-05-27  6:25                                       ` Alan Schmitt
2013-05-27  9:22                                         ` Xavier Garrido
2013-05-27  9:51                                           ` Rasmus
2013-05-27 18:31                                           ` Viktor Rosenfeld
2013-05-27 20:42                                             ` Xavier Garrido
2013-05-26 14:51                                     ` Rasmus
2013-05-25 20:51                               ` [PATCH] ox-koma-letter.el: Reintroduce variables removed in commit 832c6fd with proper defaults (was Re: [patch] ox-koma-letter.el: clean-up/semantic bug [4/4]) Robert Klein
2013-05-25 21:41                                 ` [PATCH] ox-koma-letter.el: Reintroduce variables removed in commit 832c6fd with proper defaults Rasmus
2013-05-26 11:04                                 ` [PATCH] ox-koma-letter.el: Reintroduce variables removed in commit 832c6fd with proper defaults (was Re: [patch] ox-koma-letter.el: clean-up/semantic bug [4/4]) Viktor Rosenfeld
2013-05-20 15:44 ` [patch] ox-koma-letter.el: credit [1/4] Alan Schmitt
2013-05-20 15:49   ` Rasmus
2013-05-20 16:01     ` Alan Schmitt
2013-05-21 17:06 ` Viktor Rosenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ip2esccc.fsf@pank.eu \
    --to=rasmus@gmx.us \
    --cc=alan.schmitt@polytechnique.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=n.goaziou@gmail.com \
    --cc=papoanaya@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).