From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: [patch] ox-koma-letter.el: credit [3/4] Date: Mon, 20 May 2013 02:51:15 +0200 Message-ID: <87ip2esccc.fsf@pank.eu> References: <87wqqusder.fsf@pank.eu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:56571) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UeEJw-0007mR-Tw for emacs-orgmode@gnu.org; Sun, 19 May 2013 20:51:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UeEJt-0000Ao-I1 for emacs-orgmode@gnu.org; Sun, 19 May 2013 20:51:24 -0400 Received: from mout.gmx.net ([212.227.17.22]:55805) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UeEJt-0000Ai-7n for emacs-orgmode@gnu.org; Sun, 19 May 2013 20:51:21 -0400 In-Reply-To: <87wqqusder.fsf@pank.eu> (rasmus@gmx.us's message of "Mon, 20 May 2013 02:28:12 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Cc: alan.schmitt@polytechnique.org, n.goaziou@gmail.com, papoanaya@hotmail.com --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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=C2=A0=C2=B9. 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). =E2=80=93Rasmus Footnotes:=20 =C2=A0=C2=B9 http://orgmode.org/worg/org-tutorials/org-e-groff-documentat= ion.html#sec-1-5 --=20 Powered by magic pixies! --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0003-Added-support-for-after-closing-and-after-document-e.patch >From eeaa129b6807465566be881b96a94e14706c9a28 Mon Sep 17 00:00:00 2001 From: "rasmus.pank" 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.") + + ;;; 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}" + )) ;;; Commands -- 1.8.2.3 --=-=-=--