* [patch][ox-koma-letter] Support for to and from headings @ 2013-06-01 18:04 Rasmus 2013-06-03 13:48 ` Rasmus 2013-06-04 10:07 ` Bastien 0 siblings, 2 replies; 7+ messages in thread From: Rasmus @ 2013-06-01 18:04 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 380 bytes --] Hi, Some more patches that should work against the master branch. Patch 1: bug fixes. Most notably use symbols some places rather than strings. Patch 2 adds support for TO and FROM headings. If you've got time for testing I would appreciate feedback. It's explained in the top of the patch. –Rasmus -- This is the kind of tedious nonsense up with which I will not put [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Bug-fixes-for-ox-koma-letter.el.patch --] [-- Type: text/x-patch, Size: 3764 bytes --] From 8cc0953849b7b3e7d791c7ad4fd4a9a71581ada5 Mon Sep 17 00:00:00 2001 From: "rasmus.pank" <rasmus.pank@gmail.com> Date: Mon, 27 May 2013 17:29:14 +0200 Subject: [PATCH 1/2] Bug fixes for ox-koma-letter.el * ox-koma-letter.el: If tag wasn't given a headline could cause trouble. * ox-koma-letter.el: bug in subject-format defcustom. * ox-koma-letter.el: some newline changes * ox-koma-letter.el: changed varioues quoted things to symbols. --- contrib/lisp/ox-koma-letter.el | 51 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 4af0ba7..82bdf33 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -93,7 +93,7 @@ string." :type '(radio (function-item user-full-name) (string) (function) - (const nil))) + (const :tag "Do not export author" nil))) (defcustom org-koma-letter-email 'org-koma-letter-email "The sender's email address. @@ -105,7 +105,7 @@ function may be given. Functions must return a string." :type '(radio (function-item org-koma-letter-email) (string) (function) - (const nil))) + (const :tag "Do not export email" nil))) (defcustom org-koma-letter-from-address nil "Sender's address, as a string." @@ -153,17 +153,19 @@ writing the following values are allowed: Please refer to the KOMA-script manual (Table 4.16. in the English manual of 2012-07-22)" - :type '(set (const "afteropening") - (const "beforeopening") - (const "centered") - (const "left") - (const "right") - (const "underlined") - (const "titled") - (const "untitled") - (const :tag "No export" nil) - (const :tag "Default options" t) - (string)) + :type '(radio + (const :tag "No export" nil) + (const :tag "Default options" t) + (set :tag "selection" + (const 'afteropening) + (const 'beforeopening) + (const 'centered) + (const 'left) + (const 'right) + (const 'underlined) + (const 'titled) + (const 'untitled)) + (string)) :group 'org-export-koma-letter) @@ -198,15 +200,16 @@ Use `foldmarks:true' to activate default fold marks or :group 'org-export-koma-letter :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") -(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") -(defvar org-koma-letter-special-contents nil "holds special -content temporarily.") +(defvar org-koma-letter-special-contents nil + "holds special content temporarily.") \f @@ -286,9 +289,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. " (let (output) - (dolist (ac a-list output) - (let - ((x (org-koma-letter--get-tagged-contents ac)) + (dolist (ac* a-list output) + (let* + ((ac (cond ((symbolp ac*) (symbol-name ac*)) (t ac*))) + (x (org-koma-letter--get-tagged-contents ac)) (regexp (if keep-newlines "" "\\`\n+\\|\n*\\'"))) (when x (setq output @@ -354,8 +358,9 @@ appropriate place." (let* ((tags (and (plist-get info :with-tags) (org-export-get-tags headline info))) - (tag (downcase (car tags)))) - (if (member tag (plist-get info :special-tags)) + (tag (if tags (downcase (car tags))))) + (if (member tag + (mapcar 'symbol-name (plist-get info :special-tags))) (progn (push (cons tag contents) org-koma-letter-special-contents) -- 1.8.3 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #3: 0002-Added-support-for-to-and-from-heading.patch --] [-- Type: text/x-patch, Size: 9254 bytes --] From 7fbc3b4b9ef742b895b1af67ba1a05c93d511eea Mon Sep 17 00:00:00 2001 From: rasmus <rasmus@gmx.us> Date: Sat, 1 Jun 2013 19:52:36 +0200 Subject: [PATCH 2/2] Added support for to and from heading. * ox-koma-letter.el (org-koma-letter-special-tags-in-letter): list of tags that are typeset as part of the letter. * ox-koma-letter.el (org-koma-letter--determine-special-value): determine which value to use (for to and from currentlly) if more than candidate is available. Which value is selected depends on `org-koma-letter-prefer-special-headings'. * ox-koma-letter.el (org-koma-letter-prefer-special-headings): a boolean stating whether to prefer headings with to/from or the #+X_ADDRESS. The following letter now exports "as expected". In particular when special-headings is t heading values have presedence so the from address would be ="Rasmus\nEmacs\nOrg-mode"= where the =\n=s would be escaped. If specia-headings is nil (default) the from would be my-adr. The same is true for TO address. #+BEGIN_SRC org #+FROM_ADDRESS: my-adr #+TO_ADDRESS: your-adr #+LATEX_CLASS: koma-letter #+OPTIONS: special-headings:t Here's the contents * from :from: Rasmus Emacs Org-mode #+END_SRC On a technical note, note that the default value will be used if neither #+X_ADDRESS or a heading is given. --- contrib/lisp/ox-koma-letter.el | 77 ++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 82bdf33..c8999e3 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -132,6 +132,13 @@ function may be given. Functions must return a string." :group 'org-export-koma-letter :type 'string) + +(defcustom org-koma-letter-prefer-special-headings nil + "If both a TO or FROM is specified two places should the + heading version be preferred?" + :group 'org-export-koma-letter + :type 'boolean) + (defcustom org-koma-letter-signature nil "String used as the signature." :group 'org-export-koma-letter @@ -200,7 +207,8 @@ Use `foldmarks:true' to activate default fold marks or :group 'org-export-koma-letter :type 'boolean) - +(defconst org-koma-letter-special-tags-in-letter '(to from) + "header tags related to the letter itself") (defconst org-koma-letter-special-tags-after-closing '(ps encl cc) "Header tags to be inserted after closing") @@ -219,7 +227,7 @@ Use `foldmarks:true' to activate default fold marks or :options-alist '((:lco "LCO" nil org-koma-letter-class-option-file) (:author "AUTHOR" nil (org-koma-letter--get-custom org-koma-letter-author) t) - (:from-address "FROM_ADDRESS" nil org-koma-letter-from-address newline) + (:from-address "FROM_ADDRESS" nil nil newline) (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number) (:email "EMAIL" nil (org-koma-letter--get-custom org-koma-letter-email) t) (:to-address "TO_ADDRESS" nil nil newline) @@ -227,9 +235,12 @@ 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) - (:special-tags nil nil - (append org-koma-letter-special-tags-after-closing - org-koma-letter-special-tags-after-letter)) + (:special-tags nil nil (append + org-koma-letter-special-tags-in-letter + org-koma-letter-special-tags-after-closing + org-koma-letter-special-tags-after-letter)) + (:special-headings nil "special-headings" + org-koma-letter-prefer-special-headings) (:with-after-closing nil "after-closing-order" org-koma-letter-special-tags-after-closing) (:with-after-letter nil "after-letter-order" @@ -265,9 +276,9 @@ Use `foldmarks:true' to activate default fold marks or ;; The following is taken from/inspired by ox-grof.el ;; 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'" - (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) "Determines whether a value is nil, a string or a @@ -275,8 +286,8 @@ function (a symobl). If it is a function it it evaluates it." (when value (cond ((stringp value) 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) "Finds all the components of `org-koma-letter-special-contents' @@ -291,9 +302,8 @@ be wrapped in a macro named whatever the members of a-list are called. (let (output) (dolist (ac* a-list output) (let* - ((ac (cond ((symbolp ac*) (symbol-name ac*)) (t ac*))) - (x (org-koma-letter--get-tagged-contents ac)) - (regexp (if keep-newlines "" "\\`\n+\\|\n*\\'"))) + ((ac (org-koma-letter--get-custom ac*)) + (x (org-koma-letter--get-tagged-contents ac))) (when x (setq output (concat @@ -301,7 +311,7 @@ be wrapped in a macro named whatever the members of a-list are called. ;; sometimes LaTeX complains about newlines ;; at the end or beginning of macros. Remove them. (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))))))))) (defun org-koma-letter--format-string-as-macro (string &optional macro) @@ -310,10 +320,39 @@ be wrapped in a macro named whatever the members of a-list are called. (format "\\%s{%s}" macro 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+\\|\n*\\'" "" string)) + + +(defun org-koma-letter--determine-special-value (info key) + "Determine who the letter is to and whom it is from. + oxkoma-letter allows two ways to specify these things. If both + are present return the preferred one as determined by + `org-koma-letter-prefer-special-headings'. When `from' is t " + (let* ((plit-alist '((from . :from-address) + (to . ::to-address))) + (default-alist `((from ,org-koma-letter-from-address) + (to "\\mbox{}"))) + (option-value (plist-get info (cdr-safe (assoc key plit-alist)))) + (head-value (org-koma-letter--get-tagged-contents key)) + (order (append + (funcall + (if (plist-get info :special-headings) + 'reverse 'identity) + `(,option-value ,head-value)) + (cdr-safe (assoc key default-alist)))) + (adr (cond ((car order)) ((cadr order)) ((caddr order)) (t nil)))) + (when adr + (replace-regexp-in-string + "\n" "\\\\\\\\\n" + (org-koma-letter--remove-offending-new-lines adr))))) + ;;; Transcode Functions ;;;; Export Block + (defun org-koma-letter-export-block (export-block contents info) "Transcode an EXPORT-BLOCK element into KOMA Scrlttr2 code. CONTENTS is nil. INFO is a plist used as a communication @@ -323,6 +362,7 @@ channel." ;;;; Export Snippet + (defun org-koma-letter-export-snippet (export-snippet contents info) "Transcode an EXPORT-SNIPPET object into KOMA Scrlttr2 code. CONTENTS is nil. INFO is a plist used as a communication @@ -332,12 +372,14 @@ channel." ;;;; Keyword + + (defun org-koma-letter-keyword (keyword contents info) "Transcode a KEYWORD element into KOMA Scrlttr2 code. CONTENTS is nil. INFO is a plist used as a communication channel." (let ((key (org-element-property :key keyword)) - (value (org-element-property :value keyword))) + (value (org-element-property :value keyword))) ;; Handle specifically BEAMER and TOC (headlines only) keywords. ;; Otherwise, fallback to `latex' back-end. (if (equal key "KOMA-LETTER") value @@ -405,7 +447,7 @@ holding export options." info))))) (let ((lco (plist-get info :lco)) (author (plist-get info :author)) - (from-address (plist-get info :from-address)) + (from-address (org-koma-letter--determine-special-value info 'from)) (phone-number (plist-get info :phone-number)) (email (plist-get info :email)) (signature (plist-get info :signature))) @@ -465,7 +507,7 @@ holding export options." (format "\\setkomavar{subject}{%s}\n\n" subject)))) ;; Letter start (format "\\begin{letter}{%%\n%s}\n\n" - (or (plist-get info :to-address) "no address given")) + (org-koma-letter--determine-special-value info 'to)) ;; Opening. (format "\\opening{%s}\n\n" (plist-get info :opening)) ;; Letter body. @@ -569,7 +611,8 @@ directory. Return output file's name." (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 (org-export-async-start (lambda (f) (org-export-add-to-stack f 'koma-letter)) -- 1.8.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [patch][ox-koma-letter] Support for to and from headings 2013-06-01 18:04 [patch][ox-koma-letter] Support for to and from headings Rasmus @ 2013-06-03 13:48 ` Rasmus 2013-06-11 21:53 ` Rasmus 2013-06-04 10:07 ` Bastien 1 sibling, 1 reply; 7+ messages in thread From: Rasmus @ 2013-06-03 13:48 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1.1: Type: text/plain, Size: 612 bytes --] Rasmus <rasmus@gmx.us> writes: > Hi, > > Some more patches that should work against the master branch. > > Patch 1: bug fixes. Most notably use symbols some places rather than > strings. > > Patch 2 adds support for TO and FROM headings. If you've got time for > testing I would appreciate feedback. It's explained in the top of the > patch. Patch 1 and 2 are updated. Patch three adds support for an `org-koma-letter-default-class' and a plug-in function to make it easier to use letters. They should apply against master. –Rasmus -- If you can mix business and politics wonderful things can happen! [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1.2: 0001-Bug-fixes-for-ox-koma-letter.el.patch --] [-- Type: text/x-patch, Size: 8137 bytes --] From 4c993600fb032e91a0122520a1e41c0f8d1caade Mon Sep 17 00:00:00 2001 From: "rasmus.pank" <rasmus.pank@gmail.com> Date: Mon, 27 May 2013 17:29:14 +0200 Subject: [PATCH 1/3] Bug fixes for ox-koma-letter.el * ox-koma-letter.el: If tag wasn't given a headline could cause trouble. * ox-koma-letter.el: bug in subject-format defcustom. * ox-koma-letter.el: some newline changes * ox-koma-letter.el: changed varioues quoted things to symbols. * ox-koma-letter.el: updated documentation in the top of the file. --- contrib/lisp/ox-koma-letter.el | 106 +++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 35 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 4af0ba7..f1b18bf 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -33,12 +33,37 @@ ;; ;; On top of buffer keywords supported by `latex' back-end (see ;; `org-latex-options-alist'), this back-end introduces the following -;; keywords: "CLOSING" (see `org-koma-letter-closing'), "FROM_ADDRESS" -;; (see `org-koma-letter-from-address'), "LCO" (see -;; `org-koma-letter-class-option-file'), "OPENING" (see -;; `org-koma-letter-opening'), "PHONE_NUMBER" (see -;; `org-koma-letter-phone-number'), "SIGNATURE" (see -;; `org-koma-letter-signature') and "TO_ADDRESS". +;; keywords: +;; - "CLOSING" (see `org-koma-letter-closing'), +;; - "FROM_ADDRESS" (see `org-koma-letter-from-address'), +;; - "LCO" (see `org-koma-letter-class-option-file'), +;; - "OPENING" (see `org-koma-letter-opening'), +;; - "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 ordering after letter +;; (see `org-koma-letter-special-tags-after-closing') +;; - after-letter-order, as above +;; (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), commencements (encl) and code to be inserted after +;; \end{letter} (after_letter). ;; ;; You will need to add an appropriate association in ;; `org-latex-classes' in order to use the KOMA Scrlttr2 class. For @@ -93,7 +118,7 @@ string." :type '(radio (function-item user-full-name) (string) (function) - (const nil))) + (const :tag "Do not export author" nil))) (defcustom org-koma-letter-email 'org-koma-letter-email "The sender's email address. @@ -105,7 +130,7 @@ function may be given. Functions must return a string." :type '(radio (function-item org-koma-letter-email) (string) (function) - (const nil))) + (const :tag "Do not export email" nil))) (defcustom org-koma-letter-from-address nil "Sender's address, as a string." @@ -153,17 +178,19 @@ writing the following values are allowed: Please refer to the KOMA-script manual (Table 4.16. in the English manual of 2012-07-22)" - :type '(set (const "afteropening") - (const "beforeopening") - (const "centered") - (const "left") - (const "right") - (const "underlined") - (const "titled") - (const "untitled") - (const :tag "No export" nil) - (const :tag "Default options" t) - (string)) + :type '(radio + (const :tag "No export" nil) + (const :tag "Default options" t) + (set :tag "selection" + (const 'afteropening) + (const 'beforeopening) + (const 'centered) + (const 'left) + (const 'right) + (const 'underlined) + (const 'titled) + (const 'untitled)) + (string)) :group 'org-export-koma-letter) @@ -198,15 +225,16 @@ Use `foldmarks:true' to activate default fold marks or :group 'org-export-koma-letter :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") -(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") -(defvar org-koma-letter-special-contents nil "holds special -content temporarily.") +(defvar org-koma-letter-special-contents nil + "holds special content temporarily.") \f @@ -262,9 +290,10 @@ content temporarily.") ;; The following is taken from/inspired by ox-grof.el ;; 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'" - (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) "Determines whether a value is nil, a string or a @@ -272,7 +301,8 @@ function (a symobl). If it is a function it it evaluates it." (when value (cond ((stringp value) 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) @@ -286,10 +316,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. " (let (output) - (dolist (ac a-list output) - (let - ((x (org-koma-letter--get-tagged-contents ac)) - (regexp (if keep-newlines "" "\\`\n+\\|\n*\\'"))) + (dolist (ac* a-list output) + (let* + ((ac (org-koma-letter--get-custom ac*)) + (x (org-koma-letter--get-tagged-contents ac))) (when x (setq output (concat @@ -297,7 +327,7 @@ be wrapped in a macro named whatever the members of a-list are called. ;; sometimes LaTeX complains about newlines ;; at the end or beginning of macros. Remove them. (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))))))))) (defun org-koma-letter--format-string-as-macro (string &optional macro) @@ -306,6 +336,10 @@ be wrapped in a macro named whatever the members of a-list are called. (format "\\%s{%s}" macro 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+\\|\n*\\'" "" string)) + ;;; Transcode Functions ;;;; Export Block @@ -354,8 +388,9 @@ appropriate place." (let* ((tags (and (plist-get info :with-tags) (org-export-get-tags headline info))) - (tag (downcase (car tags)))) - (if (member tag (plist-get info :special-tags)) + (tag (if tags (downcase (car tags))))) + (if (member tag + (mapcar 'symbol-name (plist-get info :special-tags))) (progn (push (cons tag contents) org-koma-letter-special-contents) @@ -564,7 +599,8 @@ directory. Return output file's name." (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 (org-export-async-start (lambda (f) (org-export-add-to-stack f 'koma-letter)) -- 1.8.3 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1.3: 0002-Added-support-for-to-and-from-heading.patch --] [-- Type: text/x-patch, Size: 6134 bytes --] From 68d94e6736083b148f8f7725aec12c4add834478 Mon Sep 17 00:00:00 2001 From: rasmus <rasmus@gmx.us> Date: Sat, 1 Jun 2013 19:52:36 +0200 Subject: [PATCH 2/3] Added support for to and from heading. * ox-koma-letter.el (org-koma-letter-special-tags-in-letter): list of tags that are typeset as part of the letter. * ox-koma-letter.el (org-koma-letter--determine-special-value): determine which value to use (for to and from currentlly) if more than candidate is available. Which value is selected depends on `org-koma-letter-prefer-special-headings'. * ox-koma-letter.el (org-koma-letter-prefer-special-headings): a boolean stating whether to prefer headings with to/from or the #+X_ADDRESS. The following letter now exports "as expected". In particular when special-headings is t heading values have presedence so the from address would be ="Rasmus\nEmacs\nOrg-mode"= where the =\n=s would be escaped. If specia-headings is nil (default) the from would be my-adr. The same is true for TO address. Here's the contents * from :from: Rasmus Emacs Org-mode On a technical note, note that the default value will be used if neither #+X_ADDRESS or a heading is given. --- contrib/lisp/ox-koma-letter.el | 53 +++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index f1b18bf..e70b8c4 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -157,6 +157,12 @@ function may be given. Functions must return a string." :group 'org-export-koma-letter :type 'string) +(defcustom org-koma-letter-prefer-special-headings nil + "If both a TO or FROM is specified two places should the + heading version be preferred?" + :group 'org-export-koma-letter + :type 'boolean) + (defcustom org-koma-letter-signature nil "String used as the signature." :group 'org-export-koma-letter @@ -225,7 +231,8 @@ Use `foldmarks:true' to activate default fold marks or :group 'org-export-koma-letter :type 'boolean) - +(defconst org-koma-letter-special-tags-in-letter '(to from) + "header tags related to the letter itself") (defconst org-koma-letter-special-tags-after-closing '(ps encl cc) "Header tags to be inserted after closing") @@ -244,7 +251,7 @@ Use `foldmarks:true' to activate default fold marks or :options-alist '((:lco "LCO" nil org-koma-letter-class-option-file) (:author "AUTHOR" nil (org-koma-letter--get-custom org-koma-letter-author) t) - (:from-address "FROM_ADDRESS" nil org-koma-letter-from-address newline) + (:from-address "FROM_ADDRESS" nil nil newline) (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number) (:email "EMAIL" nil (org-koma-letter--get-custom org-koma-letter-email) t) (:to-address "TO_ADDRESS" nil nil newline) @@ -252,9 +259,12 @@ 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) - (:special-tags nil nil - (append org-koma-letter-special-tags-after-closing - org-koma-letter-special-tags-after-letter)) + (:special-tags nil nil (append + org-koma-letter-special-tags-in-letter + org-koma-letter-special-tags-after-closing + org-koma-letter-special-tags-after-letter)) + (:special-headings nil "special-headings" + org-koma-letter-prefer-special-headings) (:with-after-closing nil "after-closing-order" org-koma-letter-special-tags-after-closing) (:with-after-letter nil "after-letter-order" @@ -340,6 +350,33 @@ be wrapped in a macro named whatever the members of a-list are called. "Remove new lines in the begging and end of `string'" (replace-regexp-in-string "\\`\n+\\|\n*\\'" "" string)) + +(defun org-koma-letter--determine-special-value (info key) + "Determine who the letter is to and whom it is from. + oxkoma-letter allows two ways to specify these things. If both + are present return the preferred one as determined by + `org-koma-letter-prefer-special-headings'. When `from' is t " + (let* ((plit-alist '((from . :from-address) + (to . ::to-address))) + (default-alist `((from ,org-koma-letter-from-address) + (to "\\mbox{}"))) + (option-value (plist-get info (cdr-safe (assoc key plit-alist)))) + (head-value (org-koma-letter--get-tagged-contents key)) + (order (append + (funcall + (if (plist-get info :special-headings) + 'reverse 'identity) + `(,option-value ,head-value)) + (cdr-safe (assoc key default-alist)))) + tmp + (adr (dolist (x order tmp) + (when (and (not tmp) x) + (setq tmp x))))) + (when adr + (replace-regexp-in-string + "\n" "\\\\\\\\\n" + (org-koma-letter--remove-offending-new-lines adr))))) + ;;; Transcode Functions ;;;; Export Block @@ -367,7 +404,7 @@ channel." CONTENTS is nil. INFO is a plist used as a communication channel." (let ((key (org-element-property :key keyword)) - (value (org-element-property :value keyword))) + (value (org-element-property :value keyword))) ;; Handle specifically BEAMER and TOC (headlines only) keywords. ;; Otherwise, fallback to `latex' back-end. (if (equal key "KOMA-LETTER") value @@ -435,7 +472,7 @@ holding export options." info))))) (let ((lco (plist-get info :lco)) (author (plist-get info :author)) - (from-address (plist-get info :from-address)) + (from-address (org-koma-letter--determine-special-value info 'from)) (phone-number (plist-get info :phone-number)) (email (plist-get info :email)) (signature (plist-get info :signature))) @@ -495,7 +532,7 @@ holding export options." (format "\\setkomavar{subject}{%s}\n\n" subject)))) ;; Letter start (format "\\begin{letter}{%%\n%s}\n\n" - (or (plist-get info :to-address) "no address given")) + (org-koma-letter--determine-special-value info 'to)) ;; Opening. (format "\\opening{%s}\n\n" (plist-get info :opening)) ;; Letter body. -- 1.8.3 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1.4: 0003-Possible-to-set-default-class-for-ox-koma-letters.patch --] [-- Type: text/x-patch, Size: 3569 bytes --] From f74eaae6c4610701899f7127537acbc8fa88a10f Mon Sep 17 00:00:00 2001 From: rasmus <rasmus@gmx.us> Date: Sun, 2 Jun 2013 17:59:48 +0200 Subject: [PATCH 3/3] Possible to set default class for ox koma letters. * ox-koma-letter.el (org-koma-letter-default-class): default class for =ox-koma-letter=. Default is nil. * ox-koma-letter.el (org-koma-letter-plug-into-ox): add a sparse letter class to =`org-latex-class'= and set it to default. By default it will use =`org-latex-default-class'=. --- contrib/lisp/ox-koma-letter.el | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index e70b8c4..61df703 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -65,9 +65,21 @@ ;; copy (cc), commencements (encl) and code to be inserted after ;; \end{letter} (after_letter). ;; +;; Headlines with two and from may also be used rather than the +;; keyword approach described above. If both a keyword and a headline +;; with information is present precedence is determined by +;; `org-koma-letter-prefer-special-headings'. +;; ;; You will need to add an appropriate association in -;; `org-latex-classes' in order to use the KOMA Scrlttr2 class. For -;; example, you can use the following code: +;; `org-latex-classes' in order to use the KOMA Scrlttr2 class. +;; The easiest way to do this is by adding +;; +;; (eval-after-load "ox-koma-letter" +;; '(org-koma-letter-plug-into-ox)) +;; +;; to your init file. This will add a very sparse scrlttr2 class and +;; set it as the default `org-koma-latex-default-class'. You can also +;; add you own letter class. For instace: ;; ;; (add-to-list 'org-latex-classes ;; '("my-letter" @@ -88,7 +100,8 @@ ;; with : ;; ;; #+LATEX_CLASS: my-letter - +;; +;; Or by setting `org-koma-letter-default-class'. ;;; Code: @@ -231,6 +244,12 @@ Use `foldmarks:true' to activate default fold marks or :group 'org-export-koma-letter :type 'boolean) +(defcustom org-koma-letter-default-class nil + "Default class for `org-koma-letter'. Must be a member of + `org-latex-classes'" + :group 'org-export-koma-letter + :type 'string) + (defconst org-koma-letter-special-tags-in-letter '(to from) "header tags related to the letter itself") @@ -250,6 +269,9 @@ Use `foldmarks:true' to activate default fold marks or (org-export-define-derived-backend 'koma-letter 'latex :options-alist '((:lco "LCO" nil org-koma-letter-class-option-file) + (:latex-class "LATEX_CLASS" nil (if org-koma-letter-default-class + org-koma-letter-default-class + org-latex-default-class) t) (:author "AUTHOR" nil (org-koma-letter--get-custom org-koma-letter-author) t) (:from-address "FROM_ADDRESS" nil nil newline) (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number) @@ -291,6 +313,19 @@ Use `foldmarks:true' to activate default fold marks or (org-open-file (org-koma-letter-export-to-pdf nil s v b)))))))) \f +;;; Initialize class function + +(defun org-koma-letter-plug-into-ox () + "Add a sparse `default-koma-letter' to `org-latex-classes' and set +`org-koma-letter-default-class' to `default-koma-letter'" + (let ((class "default-koma-letter")) + (eval-after-load "ox-latex" + '(add-to-list 'org-latex-classes + `(,class + "\\documentclass[11pt]{scrlttr2}") ())) + (setq org-koma-letter-default-class class))) + + ;;; Helper functions (defun org-koma-letter-email () -- 1.8.3 [-- Attachment #2: Type: text/plain, Size: 29 bytes --] -- Summon the Mothership! ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [patch][ox-koma-letter] Support for to and from headings 2013-06-03 13:48 ` Rasmus @ 2013-06-11 21:53 ` Rasmus 2013-06-12 11:40 ` Alan Schmitt 0 siblings, 1 reply; 7+ messages in thread From: Rasmus @ 2013-06-11 21:53 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 744 bytes --] Rasmus <rasmus@gmx.us> writes: > Rasmus <rasmus@gmx.us> writes: > >> Hi, >> >> Some more patches that should work against the master branch. >> >> Patch 1: bug fixes. Most notably use symbols some places rather than >> strings. >> >> Patch 2 adds support for TO and FROM headings. If you've got time for >> testing I would appreciate feedback. It's explained in the top of the >> patch. > > Patch 1 and 2 are updated. Patch three adds support for an > `org-koma-letter-default-class' and a plug-in function to make it > easier to use letters. They should apply against master. Updated again and hopefully better changelog etc. . . –Rasmus -- This is the kind of tedious nonsense up with which I will not put [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Bug-fixes-for-ox-koma-letter.el.patch --] [-- Type: text/x-patch, Size: 8977 bytes --] From b3d3d781a32990e3b7e5ca5f2812a106a458814c Mon Sep 17 00:00:00 2001 From: "rasmus.pank" <rasmus.pank@gmail.com> Date: Mon, 27 May 2013 17:29:14 +0200 Subject: [PATCH 1/4] 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 --- contrib/lisp/ox-koma-letter.el | 118 ++++++++++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 37 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 4af0ba7..8f24d83 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -33,12 +33,43 @@ ;; ;; On top of buffer keywords supported by `latex' back-end (see ;; `org-latex-options-alist'), this back-end introduces the following -;; keywords: "CLOSING" (see `org-koma-letter-closing'), "FROM_ADDRESS" -;; (see `org-koma-letter-from-address'), "LCO" (see -;; `org-koma-letter-class-option-file'), "OPENING" (see -;; `org-koma-letter-opening'), "PHONE_NUMBER" (see -;; `org-koma-letter-phone-number'), "SIGNATURE" (see -;; `org-koma-letter-signature') and "TO_ADDRESS". +;; keywords: +;; - "CLOSING" (see `org-koma-letter-closing'), +;; - "FROM_ADDRESS" (see `org-koma-letter-from-address'), +;; - "LCO" (see `org-koma-letter-class-option-file'), +;; - "OPENING" (see `org-koma-letter-opening'), +;; - "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 ;; `org-latex-classes' in order to use the KOMA Scrlttr2 class. For @@ -93,7 +124,7 @@ string." :type '(radio (function-item user-full-name) (string) (function) - (const nil))) + (const :tag "Do not export author" nil))) (defcustom org-koma-letter-email 'org-koma-letter-email "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) (string) (function) - (const nil))) + (const :tag "Do not export email" nil))) (defcustom org-koma-letter-from-address nil "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 English manual of 2012-07-22)" - :type '(set (const "afteropening") - (const "beforeopening") - (const "centered") - (const "left") - (const "right") - (const "underlined") - (const "titled") - (const "untitled") - (const :tag "No export" nil) - (const :tag "Default options" t) - (string)) + :type '(radio + (const :tag "No export" nil) + (const :tag "Default options" t) + (set :tag "selection" + (const 'afteropening) + (const 'beforeopening) + (const 'centered) + (const 'left) + (const 'right) + (const 'underlined) + (const 'titled) + (const 'untitled)) + (string)) :group 'org-export-koma-letter) @@ -198,15 +231,16 @@ Use `foldmarks:true' to activate default fold marks or :group 'org-export-koma-letter :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") -(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") -(defvar org-koma-letter-special-contents nil "holds special -content temporarily.") +(defvar org-koma-letter-special-contents nil + "holds special content temporarily.") \f @@ -262,9 +296,10 @@ content temporarily.") ;; The following is taken from/inspired by ox-grof.el ;; 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'" - (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) "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 (cond ((stringp value) 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) @@ -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. " (let (output) - (dolist (ac a-list output) - (let - ((x (org-koma-letter--get-tagged-contents ac)) - (regexp (if keep-newlines "" "\\`\n+\\|\n*\\'"))) + (dolist (ac* a-list output) + (let* + ((ac (org-koma-letter--get-custom ac*)) + (x (org-koma-letter--get-tagged-contents ac))) (when x (setq output (concat @@ -297,7 +333,7 @@ be wrapped in a macro named whatever the members of a-list are called. ;; sometimes LaTeX complains about newlines ;; at the end or beginning of macros. Remove them. (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))))))))) (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" 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 ;;;; 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 appropriate place." (let* - ((tags (and (plist-get info :with-tags) - (org-export-get-tags headline info))) - (tag (downcase (car tags)))) - (if (member tag (plist-get info :special-tags)) + ((tags (org-export-get-tags headline info)) + (tag* (car tags)) + (tag (when tag* + (car (member-ignore-case + tag* + (mapcar 'symbol-name (plist-get info :special-tags))))))) + (if tag (progn (push (cons tag contents) org-koma-letter-special-contents) @@ -564,7 +607,8 @@ directory. Return output file's name." (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 (org-export-async-start (lambda (f) (org-export-add-to-stack f 'koma-letter)) -- 1.8.3 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #3: 0002-Added-support-for-to-and-from-heading.patch --] [-- Type: text/x-patch, Size: 6868 bytes --] From 877e9234fe98cab43d937eb4706755ae4172493b Mon Sep 17 00:00:00 2001 From: rasmus <rasmus@gmx.us> Date: Sat, 1 Jun 2013 19:52:36 +0200 Subject: [PATCH 2/4] Added support for to and from heading. * ox-koma-letter.el: documentatoin. (org-koma-letter-special-tags-in-letter): list of tags that are typeset as part of the letter. (org-koma-letter--determine-special-value): determine which value to use (for to and from currentlly) if more than candidate is available. Which value is selected depends on `org-koma-letter-prefer-special-headings'. (org-koma-letter-prefer-special-headings): a boolean stating whether to prefer headings with to/from or the #+X_ADDRESS. The following letter now exports "as expected". In particular when special-headings is t heading values have presedence so the from address would be ="Rasmus\nEmacs\nOrg-mode"= where the =\n=s would be escaped. If specia-headings is nil (default) the from would be my-adr. The same is true for TO address. Here's the contents * from :from: Rasmus Emacs Org-mode On a technical note, note that the default value will be used if neither #+X_ADDRESS or a heading is given. --- contrib/lisp/ox-koma-letter.el | 62 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 8f24d83..84fb083 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -41,7 +41,15 @@ ;; - "PHONE_NUMBER" (see `org-koma-letter-phone-number'), ;; - "SIGNATURE" (see `org-koma-letter-signature') ;; - "PLACE" (see `org-koma-letter-place') -;; - and "TO_ADDRESS". +;; - and "TO_ADDRESS". If unspecified this is set to "\mbox{}". +;; +;; TO_ADDRESS and FROM_ADDRESS can also be specified using heading +;; with the special tags specified in +;; `org-koma-letter-special-tags-in-letter', namely "to" and "from". +;; LaTeX line breaks are not necessary if using these headings. If +;; both a headline and a keyword specify a to or from address the +;; value is determined in accordance with +;; `org-koma-letter-prefer-special-headings'. ;; ;; A number of OPTIONS settings can be set to change which contents is ;; exported. @@ -163,6 +171,12 @@ function may be given. Functions must return a string." :group 'org-export-koma-letter :type 'string) +(defcustom org-koma-letter-prefer-special-headings nil + "If both a TO or FROM is specified two places should the + heading version be preferred?" + :group 'org-export-koma-letter + :type 'boolean) + (defcustom org-koma-letter-signature nil "String used as the signature." :group 'org-export-koma-letter @@ -231,7 +245,8 @@ Use `foldmarks:true' to activate default fold marks or :group 'org-export-koma-letter :type 'boolean) - +(defconst org-koma-letter-special-tags-in-letter '(to from) + "header tags related to the letter itself") (defconst org-koma-letter-special-tags-after-closing '(ps encl cc) "Header tags to be inserted after closing") @@ -250,7 +265,7 @@ Use `foldmarks:true' to activate default fold marks or :options-alist '((:lco "LCO" nil org-koma-letter-class-option-file) (:author "AUTHOR" nil (org-koma-letter--get-custom org-koma-letter-author) t) - (:from-address "FROM_ADDRESS" nil org-koma-letter-from-address newline) + (:from-address "FROM_ADDRESS" nil nil newline) (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number) (:email "EMAIL" nil (org-koma-letter--get-custom org-koma-letter-email) t) (:to-address "TO_ADDRESS" nil nil newline) @@ -258,9 +273,12 @@ 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) - (:special-tags nil nil - (append org-koma-letter-special-tags-after-closing - org-koma-letter-special-tags-after-letter)) + (:special-tags nil nil (append + org-koma-letter-special-tags-in-letter + org-koma-letter-special-tags-after-closing + org-koma-letter-special-tags-after-letter)) + (:special-headings nil "special-headings" + org-koma-letter-prefer-special-headings) (:with-after-closing nil "after-closing-order" org-koma-letter-special-tags-after-closing) (:with-after-letter nil "after-letter-order" @@ -346,6 +364,32 @@ be wrapped in a macro named whatever the members of a-list are called. "Remove new lines in the begging and end of `string'" (replace-regexp-in-string "\\`[ \n\t]+\\|[\n\t ]*\\'" "" string)) +(defun org-koma-letter--determine-special-value (info key) + "Determine who the letter is to and whom it is from. + oxkoma-letter allows two ways to specify these things. If both + are present return the preferred one as determined by + `org-koma-letter-prefer-special-headings'." + (let* ((plist-alist '((from . :from-address) + (to . :to-address))) + (default-alist `((from ,org-koma-letter-from-address) + (to "\\mbox{}"))) + (option-value (plist-get info (cdr-safe (assoc key plist-alist)))) + (head-value (org-koma-letter--get-tagged-contents key)) + (order (append + (funcall + (if (plist-get info :special-headings) + 'reverse 'identity) + `(,option-value ,head-value)) + (cdr-safe (assoc key default-alist)))) + tmp + (adr (dolist (x order tmp) + (when (and (not tmp) x) + (setq tmp x))))) + (when adr + (replace-regexp-in-string + "\n" "\\\\\\\\\n" + (org-koma-letter--remove-offending-new-lines adr))))) + ;;; Transcode Functions ;;;; Export Block @@ -373,7 +417,7 @@ channel." CONTENTS is nil. INFO is a plist used as a communication channel." (let ((key (org-element-property :key keyword)) - (value (org-element-property :value keyword))) + (value (org-element-property :value keyword))) ;; Handle specifically BEAMER and TOC (headlines only) keywords. ;; Otherwise, fallback to `latex' back-end. (if (equal key "KOMA-LETTER") value @@ -443,7 +487,7 @@ holding export options." info))))) (let ((lco (plist-get info :lco)) (author (plist-get info :author)) - (from-address (plist-get info :from-address)) + (from-address (org-koma-letter--determine-special-value info 'from)) (phone-number (plist-get info :phone-number)) (email (plist-get info :email)) (signature (plist-get info :signature))) @@ -503,7 +547,7 @@ holding export options." (format "\\setkomavar{subject}{%s}\n\n" subject)))) ;; Letter start (format "\\begin{letter}{%%\n%s}\n\n" - (or (plist-get info :to-address) "no address given")) + (org-koma-letter--determine-special-value info 'to)) ;; Opening. (format "\\opening{%s}\n\n" (plist-get info :opening)) ;; Letter body. -- 1.8.3 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #4: 0003-Possible-to-set-default-class-for-ox-koma-letters.patch --] [-- Type: text/x-patch, Size: 3628 bytes --] From aab832514c3b7f6df464c883b853b6feb0f58af3 Mon Sep 17 00:00:00 2001 From: rasmus <rasmus@gmx.us> Date: Sun, 2 Jun 2013 17:59:48 +0200 Subject: [PATCH 3/4] Possible to set default class for ox koma letters. * ox-koma-letter.el (org-koma-letter-default-class): default class for =ox-koma-letter=. Default is nil. * ox-koma-letter.el (org-koma-letter-plug-into-ox): add a sparse letter class to =`org-latex-class'= and set it to default. By default it will use =`org-latex-default-class'=. --- contrib/lisp/ox-koma-letter.el | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 84fb083..22a11e4 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -79,9 +79,21 @@ ;; `org-koma-letter-special-tags-after-closing' used as macros and the ;; content of the headline is the argument. ;; +;; Headlines with two and from may also be used rather than the +;; keyword approach described above. If both a keyword and a headline +;; with information is present precedence is determined by +;; `org-koma-letter-prefer-special-headings'. +;; ;; You will need to add an appropriate association in -;; `org-latex-classes' in order to use the KOMA Scrlttr2 class. For -;; example, you can use the following code: +;; `org-latex-classes' in order to use the KOMA Scrlttr2 class. +;; The easiest way to do this is by adding +;; +;; (eval-after-load "ox-koma-letter" +;; '(org-koma-letter-plug-into-ox)) +;; +;; to your init file. This will add a very sparse scrlttr2 class and +;; set it as the default `org-koma-latex-default-class'. You can also +;; add you own letter class. For instace: ;; ;; (add-to-list 'org-latex-classes ;; '("my-letter" @@ -102,7 +114,8 @@ ;; with : ;; ;; #+LATEX_CLASS: my-letter - +;; +;; Or by setting `org-koma-letter-default-class'. ;;; Code: @@ -245,6 +258,12 @@ Use `foldmarks:true' to activate default fold marks or :group 'org-export-koma-letter :type 'boolean) +(defcustom org-koma-letter-default-class nil + "Default class for `org-koma-letter'. Must be a member of + `org-latex-classes'" + :group 'org-export-koma-letter + :type 'string) + (defconst org-koma-letter-special-tags-in-letter '(to from) "header tags related to the letter itself") @@ -264,6 +283,9 @@ Use `foldmarks:true' to activate default fold marks or (org-export-define-derived-backend 'koma-letter 'latex :options-alist '((:lco "LCO" nil org-koma-letter-class-option-file) + (:latex-class "LATEX_CLASS" nil (if org-koma-letter-default-class + org-koma-letter-default-class + org-latex-default-class) t) (:author "AUTHOR" nil (org-koma-letter--get-custom org-koma-letter-author) t) (:from-address "FROM_ADDRESS" nil nil newline) (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number) @@ -305,6 +327,19 @@ Use `foldmarks:true' to activate default fold marks or (org-open-file (org-koma-letter-export-to-pdf nil s v b)))))))) \f +;;; Initialize class function + +(defun org-koma-letter-plug-into-ox () + "Add a sparse `default-koma-letter' to `org-latex-classes' and set +`org-koma-letter-default-class' to `default-koma-letter'" + (let ((class "default-koma-letter")) + (eval-after-load "ox-latex" + '(unless (member ,class 'org-latex-classes) + (add-to-list 'org-latex-classes + `(,class + "\\documentclass[11pt]{scrlttr2}") ()) + (setq org-koma-letter-default-class class))))) + ;;; Helper functions (defun org-koma-letter-email () -- 1.8.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [patch][ox-koma-letter] Support for to and from headings 2013-06-11 21:53 ` Rasmus @ 2013-06-12 11:40 ` Alan Schmitt 2013-06-12 14:32 ` Rasmus 0 siblings, 1 reply; 7+ messages in thread From: Alan Schmitt @ 2013-06-12 11:40 UTC (permalink / raw) To: Rasmus; +Cc: emacs-orgmode Hi Rasmus, Rasmus writes: > Rasmus <rasmus@gmx.us> writes: > >> Rasmus <rasmus@gmx.us> writes: >> >>> Hi, >>> >>> Some more patches that should work against the master branch. >>> >>> Patch 1: bug fixes. Most notably use symbols some places rather than >>> strings. >>> >>> Patch 2 adds support for TO and FROM headings. If you've got time for >>> testing I would appreciate feedback. It's explained in the top of the >>> patch. >> >> Patch 1 and 2 are updated. Patch three adds support for an >> `org-koma-letter-default-class' and a plug-in function to make it >> easier to use letters. They should apply against master. > > Updated again and hopefully better changelog etc. . . I applied the patches (just changing a small typo in the changelog). Alan ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch][ox-koma-letter] Support for to and from headings 2013-06-12 11:40 ` Alan Schmitt @ 2013-06-12 14:32 ` Rasmus 0 siblings, 0 replies; 7+ messages in thread From: Rasmus @ 2013-06-12 14:32 UTC (permalink / raw) To: alan.schmitt; +Cc: emacs-orgmode Alan Schmitt <alan.schmitt@polytechnique.org> writes: > I applied the patches (just changing a small typo in the changelog). Thanks, let me know if any errors pop up. –Rasmus -- When in doubt, do it! ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch][ox-koma-letter] Support for to and from headings 2013-06-01 18:04 [patch][ox-koma-letter] Support for to and from headings Rasmus 2013-06-03 13:48 ` Rasmus @ 2013-06-04 10:07 ` Bastien 2013-06-04 10:37 ` Rasmus 1 sibling, 1 reply; 7+ messages in thread From: Bastien @ 2013-06-04 10:07 UTC (permalink / raw) To: Rasmus; +Cc: emacs-orgmode Hi Rasmus, Rasmus <rasmus@gmx.us> writes: > * ox-koma-letter.el: If tag wasn't given a headline could cause > trouble. > * ox-koma-letter.el: bug in subject-format defcustom. > * ox-koma-letter.el: some newline changes > * ox-koma-letter.el: changed varioues quoted things to symbols. You need to tell what functions or variables are modified. Simply open the diff in Emacs, use `n' to navigate to the next difference, then hit `C-x 4 a' to create a changelog entry, Emacs change-log-mode will handle the formatting correctly. Hope this helps! -- Bastien ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch][ox-koma-letter] Support for to and from headings 2013-06-04 10:07 ` Bastien @ 2013-06-04 10:37 ` Rasmus 0 siblings, 0 replies; 7+ messages in thread From: Rasmus @ 2013-06-04 10:37 UTC (permalink / raw) To: bzg; +Cc: emacs-orgmode Bastien, >> * ox-koma-letter.el: If tag wasn't given a headline could cause >> trouble. >> * ox-koma-letter.el: bug in subject-format defcustom. >> * ox-koma-letter.el: some newline changes >> * ox-koma-letter.el: changed varioues (sic) quoted things to symbols. > > You need to tell what functions or variables are modified. > > Simply open the diff in Emacs, use `n' to navigate to the > next difference, then hit `C-x 4 a' to create a changelog > entry, Emacs change-log-mode will handle the formatting > correctly. > > Hope this helps! Yes it does as I wasn't aware of that function. I'll try to update with a proper patch. Please do let me know if you find other mistakes. –Rasmus -- And let me remind you also that moderation in the pursuit of justice is no virtue ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-06-12 14:33 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-06-01 18:04 [patch][ox-koma-letter] Support for to and from headings Rasmus 2013-06-03 13:48 ` Rasmus 2013-06-11 21:53 ` Rasmus 2013-06-12 11:40 ` Alan Schmitt 2013-06-12 14:32 ` Rasmus 2013-06-04 10:07 ` Bastien 2013-06-04 10:37 ` Rasmus
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).