Bug fixes for ox-koma-letter.el

* ox-koma-letter.el: updated documentation and improved defcustoms.
(org-koma-letter-special-tags-after-letter)
(org-koma-letter-special-tags-after-closing): now symbol.
(org-koma-letter--get-custom): falls back to value
(org-koma-letter--prepare-special-contents-as-macro): let
newlines be handled outside of the function
(org-koma-letter--remove-offending-new-lines): function to add
new lines.
(org-koma-letter-headline): updated to work with symbols and
made more robust.
(org-koma-letter-export-to-latex): reset
=`org-koma-letter-special-contents'= to nil

Signed-off-by: Alan Schmitt <alan.schmitt@polytechnique.org>
This commit is contained in:
rasmus.pank 2013-05-27 17:29:14 +02:00 committed by Alan Schmitt
parent d3fb1812fa
commit 8dd2aa4041
1 changed files with 81 additions and 37 deletions

View File

@ -33,12 +33,43 @@
;; ;;
;; On top of buffer keywords supported by `latex' back-end (see ;; On top of buffer keywords supported by `latex' back-end (see
;; `org-latex-options-alist'), this back-end introduces the following ;; `org-latex-options-alist'), this back-end introduces the following
;; keywords: "CLOSING" (see `org-koma-letter-closing'), "FROM_ADDRESS" ;; keywords:
;; (see `org-koma-letter-from-address'), "LCO" (see ;; - "CLOSING" (see `org-koma-letter-closing'),
;; `org-koma-letter-class-option-file'), "OPENING" (see ;; - "FROM_ADDRESS" (see `org-koma-letter-from-address'),
;; `org-koma-letter-opening'), "PHONE_NUMBER" (see ;; - "LCO" (see `org-koma-letter-class-option-file'),
;; `org-koma-letter-phone-number'), "SIGNATURE" (see ;; - "OPENING" (see `org-koma-letter-opening'),
;; `org-koma-letter-signature') and "TO_ADDRESS". ;; - "PHONE_NUMBER" (see `org-koma-letter-phone-number'),
;; - "SIGNATURE" (see `org-koma-letter-signature')
;; - "PLACE" (see `org-koma-letter-place')
;; - and "TO_ADDRESS".
;;
;; A number of OPTIONS settings can be set to change which contents is
;; exported.
;; - backaddress (see `org-koma-letter-use-backaddress')
;; - foldmarks (see `org-koma-letter-use-foldmarks')
;; - phone (see `org-koma-letter-use-phone')
;; - email (see `org-koma-letter-use-email')
;; - place (see `org-koma-letter-use-place')
;; - subject, a list of format options
;; (see `org-koma-letter-subject-format')
;; - after-closing-order, a list of the ordering of headings with
;; special tags after closing (see
;; `org-koma-letter-special-tags-after-closing') -
;; after-letter-order, as above, but after the end of the letter
;; (see `org-koma-letter-special-tags-after-letter').
;;
;; The following variables works differently from the main LaTeX class
;; - "AUTHOR": default to user-full-name but may be disabled. (see org-koma-letter-author),
;; - "EMAIL": same as AUTHOR, (see org-koma-letter-email),
;;
;; Headlines are in general ignored. However, headlines with special
;; tags can be used for specified contents like postscript (ps),
;; carbon copy (cc), enclosures (encl) and code to be inserted after
;; \end{letter} (after_letter). Specials tags are defined in
;; `org-koma-letter-special-tags-after-closing' and
;; `org-koma-letter-special-tags-after-letter'. Currently members of
;; `org-koma-letter-special-tags-after-closing' used as macros and the
;; content of the headline is the argument.
;; ;;
;; You will need to add an appropriate association in ;; You will need to add an appropriate association in
;; `org-latex-classes' in order to use the KOMA Scrlttr2 class. For ;; `org-latex-classes' in order to use the KOMA Scrlttr2 class. For
@ -93,7 +124,7 @@ string."
:type '(radio (function-item user-full-name) :type '(radio (function-item user-full-name)
(string) (string)
(function) (function)
(const nil))) (const :tag "Do not export author" nil)))
(defcustom org-koma-letter-email 'org-koma-letter-email (defcustom org-koma-letter-email 'org-koma-letter-email
"The sender's email address. "The sender's email address.
@ -105,7 +136,7 @@ function may be given. Functions must return a string."
:type '(radio (function-item org-koma-letter-email) :type '(radio (function-item org-koma-letter-email)
(string) (string)
(function) (function)
(const nil))) (const :tag "Do not export email" nil)))
(defcustom org-koma-letter-from-address nil (defcustom org-koma-letter-from-address nil
"Sender's address, as a string." "Sender's address, as a string."
@ -153,17 +184,19 @@ writing the following values are allowed:
Please refer to the KOMA-script manual (Table 4.16. in the Please refer to the KOMA-script manual (Table 4.16. in the
English manual of 2012-07-22)" English manual of 2012-07-22)"
:type '(set (const "afteropening") :type '(radio
(const "beforeopening") (const :tag "No export" nil)
(const "centered") (const :tag "Default options" t)
(const "left") (set :tag "selection"
(const "right") (const 'afteropening)
(const "underlined") (const 'beforeopening)
(const "titled") (const 'centered)
(const "untitled") (const 'left)
(const :tag "No export" nil) (const 'right)
(const :tag "Default options" t) (const 'underlined)
(string)) (const 'titled)
(const 'untitled))
(string))
:group 'org-export-koma-letter) :group 'org-export-koma-letter)
@ -198,15 +231,16 @@ Use `foldmarks:true' to activate default fold marks or
:group 'org-export-koma-letter :group 'org-export-koma-letter
:type 'boolean) :type 'boolean)
(defconst org-koma-letter-special-tags-after-closing
'("ps" "encl" "cc")
(defconst org-koma-letter-special-tags-after-closing '(ps encl cc)
"Header tags to be inserted after closing") "Header tags to be inserted after closing")
(defconst org-koma-letter-special-tags-after-letter '("after_letter") (defconst org-koma-letter-special-tags-after-letter '(after_letter)
"Header tags to be inserted after closing") "Header tags to be inserted after closing")
(defvar org-koma-letter-special-contents nil "holds special (defvar org-koma-letter-special-contents nil
content temporarily.") "holds special content temporarily.")
@ -262,9 +296,10 @@ content temporarily.")
;; The following is taken from/inspired by ox-grof.el ;; The following is taken from/inspired by ox-grof.el
;; Thanks, Luis! ;; Thanks, Luis!
(defun org-koma-letter--get-tagged-contents (tag) (defun org-koma-letter--get-tagged-contents (key)
"Get tagged content from `org-koma-letter-special-contents'" "Get tagged content from `org-koma-letter-special-contents'"
(cdr (assoc tag org-koma-letter-special-contents))) (cdr (assoc (org-koma-letter--get-custom key)
org-koma-letter-special-contents)))
(defun org-koma-letter--get-custom (value) (defun org-koma-letter--get-custom (value)
"Determines whether a value is nil, a string or a "Determines whether a value is nil, a string or a
@ -272,7 +307,8 @@ function (a symobl). If it is a function it it evaluates it."
(when value (when value
(cond ((stringp value) value) (cond ((stringp value) value)
((functionp value) (funcall value)) ((functionp value) (funcall value))
((symbolp value) (symbol-name value))))) ((symbolp value) (symbol-name value))
(t value))))
(defun org-koma-letter--prepare-special-contents-as-macro (a-list &optional keep-newlines no-tag) (defun org-koma-letter--prepare-special-contents-as-macro (a-list &optional keep-newlines no-tag)
@ -286,10 +322,10 @@ 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. be wrapped in a macro named whatever the members of a-list are called.
" "
(let (output) (let (output)
(dolist (ac a-list output) (dolist (ac* a-list output)
(let (let*
((x (org-koma-letter--get-tagged-contents ac)) ((ac (org-koma-letter--get-custom ac*))
(regexp (if keep-newlines "" "\\`\n+\\|\n*\\'"))) (x (org-koma-letter--get-tagged-contents ac)))
(when x (when x
(setq output (setq output
(concat (concat
@ -297,7 +333,7 @@ be wrapped in a macro named whatever the members of a-list are called.
;; sometimes LaTeX complains about newlines ;; sometimes LaTeX complains about newlines
;; at the end or beginning of macros. Remove them. ;; at the end or beginning of macros. Remove them.
(org-koma-letter--format-string-as-macro (org-koma-letter--format-string-as-macro
(format "%s" (replace-regexp-in-string regexp "" x)) (if keep-newlines x (org-koma-letter--remove-offending-new-lines x))
(unless no-tag ac))))))))) (unless no-tag ac)))))))))
(defun org-koma-letter--format-string-as-macro (string &optional macro) (defun org-koma-letter--format-string-as-macro (string &optional macro)
@ -306,6 +342,10 @@ be wrapped in a macro named whatever the members of a-list are called.
(format "\\%s{%s}" macro string) (format "\\%s{%s}" macro string)
(format "%s" string))) (format "%s" string)))
(defun org-koma-letter--remove-offending-new-lines (string)
"Remove new lines in the begging and end of `string'"
(replace-regexp-in-string "\\`[ \n\t]+\\|[\n\t ]*\\'" "" string))
;;; Transcode Functions ;;; Transcode Functions
;;;; Export Block ;;;; Export Block
@ -352,10 +392,13 @@ Note that if a headline is tagged with a tag from
stored in `org-koma-letter-special-contents' and included at the stored in `org-koma-letter-special-contents' and included at the
appropriate place." appropriate place."
(let* (let*
((tags (and (plist-get info :with-tags) ((tags (org-export-get-tags headline info))
(org-export-get-tags headline info))) (tag* (car tags))
(tag (downcase (car tags)))) (tag (when tag*
(if (member tag (plist-get info :special-tags)) (car (member-ignore-case
tag*
(mapcar 'symbol-name (plist-get info :special-tags)))))))
(if tag
(progn (progn
(push (cons tag contents) (push (cons tag contents)
org-koma-letter-special-contents) org-koma-letter-special-contents)
@ -564,7 +607,8 @@ directory.
Return output file's name." Return output file's name."
(interactive) (interactive)
(let ((outfile (org-export-output-file-name ".tex" subtreep))) (let ((outfile (org-export-output-file-name ".tex" subtreep))
org-koma-letter-special-contents)
(if async (if async
(org-export-async-start (org-export-async-start
(lambda (f) (org-export-add-to-stack f 'koma-letter)) (lambda (f) (org-export-add-to-stack f 'koma-letter))