From 173826ce58954f24b268f09f45e07ac877d751de Mon Sep 17 00:00:00 2001 From: "rasmus.pank" Date: Sat, 25 May 2013 19:08:37 +0200 Subject: [PATCH 3/4] bug-fix for special headers. * ox-koma-letter.el(org-koma-letter-ps-prefix): removed * ox-koma-letter.el(org-koma-letter-special-tags-after-closing): downcased to correspond to actual LaTeX-functions * ox-koma-letter.el(org-koma-letter-special-tags-after-letter): list of headings to be inserted after =\end{letter}= * ox-koma-letter.el(org-koma-letter-special-tags): removed. generated on the go. * ox-koma-letter.el(org-koma-letter-special-contents): special headings are controlled via =:with-after-closing= and =:with-after-letter=. These can also be used for reordering the way headers are inserted. * ox-koma-letter.el: some cleaning up. * ox-koma-letter.el(org-koma-letter--prepare-special-contents-as-macro): new function for inserting macros based on list of special tags. --- contrib/lisp/ox-koma-letter.el | 111 +++++++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 49 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index c8be5ab..bbfe168 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -196,23 +196,13 @@ 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") + '("ps" "encl" "cc") + "Header 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") +(defconst org-koma-letter-special-tags-after-letter + '("after_letter") + "Header tags to be inserted after closing") (defvar org-koma-letter-special-contents nil "holds special content temporarily.") @@ -233,13 +223,15 @@ content temporarily.") (: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-after-closing nil "after-closing-order" + org-koma-letter-special-tags-after-closing) + (:with-after-letter nil "after-letter-order" + org-koma-letter-special-tags-after-letter) (: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) @@ -263,11 +255,47 @@ content temporarily.") "Return the current `user-mail-address'" user-mail-address) +;; The following is taken from/inspired by ox-grof.el +;; Thanks, Luis! + +(defun org-koma-letter--get-tagged-contents (tag) + "Get tagged content from `org-koma-letter-special-contents'" + (cdr (assoc tag org-koma-letter-special-contents))) + (defun org-koma-letter--get-custom (value) + "Determines whether a value is nil, a string or a +function (a symobl). If it is a function it it evaluates it." (when value (cond ((stringp value) value) ((symbolp value) (funcall value))))) + +(defun org-koma-letter--prepare-special-contents-as-macro (a-list &optional keep-newlines no-tag) + "Finds all the components of `org-koma-letter-special-contents' +corresponding to members of the `a-list' and return them as a +string to be formatted. The function is used for inserting +content of speciall headings such as PS. + +If keep-newlines is t newlines will not be removed. If no-tag is +is t the content in `org-koma-letter-special-contents' will not +be wrapped in a macro named whatever the members of a-list are called. +" + (let (output) + (dolist (ac a-list output) + (let + ((x (org-koma-letter--get-tagged-contents ac)) + (regexp (if keep-newlines "" "\\`\n+\\|\n*\\'"))) + (when x + (setq output + (concat + output "\n" + ;; sometimes LaTeX complains about newlines + ;; at the end or beginning of macros. Remove them. + (unless no-tag (format "\\%s{" ac)) + (format "%s" (replace-regexp-in-string regexp "" x)) + (unless no-tag "}") + ))))))) + ;;; Transcode Functions ;;;; Export Block @@ -302,17 +330,12 @@ channel." (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-contents))) - +;; Headline (defun org-koma-letter-headline (headline contents info) "Transcode a HEADLINE element from Org to LaTeX. CONTENTS holds the contents of the headline. INFO is a plist -holding contextual informatio.n +holding contextual information. Note that if a headline is tagged with a tag from `org-koma-letter-special-tags' it will not be exported, but @@ -320,16 +343,14 @@ stored in `org-koma-letter-special-contents' and included at the appropriate place." (let* ((tags (and (plist-get info :with-tags) - (org-export-get-tags headline info)))) - (if (member (upcase (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-contents) nil)) + (org-export-get-tags headline info))) + (tag (downcase (car tags)))) + (if (member tag + (append (plist-get info :with-after-letter) + (plist-get info :with-after-closing))) (progn - (push (cons (upcase (car tags)) contents) - org-koma-letter-special-contents) + (push (cons tag contents) + org-koma-letter-special-contents) nil) contents))) @@ -441,23 +462,15 @@ holding export options." ;; Letter body. 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 (upcase 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)))))))) + (format "\n\\closing{%s}\n" (plist-get info :closing)) + (org-koma-letter--prepare-special-contents-as-macro + (plist-get info :with-after-closing)) ;; Letter end. - "\\end{letter}\n" - (let ((x (org-koma-letter--get-tagged-content "AFTER_LETTER" info))) - (when x (format x))) + "\n\\end{letter}\n" + (org-koma-letter--prepare-special-contents-as-macro + (plist-get info :with-after-letter) t t) ;; Document end. - "\\end{document}" + "\n\\end{document}" )) @@ -487,7 +500,7 @@ contents of hidden elements. When optional argument BODY-ONLY is non-nil, only write code between \"\\begin{letter}\" and \"\\end{letter}\". -EXT-PLIST, when provided, is a property list with external +EXT-PLIST, when provided, is a proeprty list with external parameters overriding Org default settings, but still inferior to file-local settings. -- 1.8.2.3