From 3df51bf5a57eb9d3a96fc4742a1b4b16998d701d Mon Sep 17 00:00:00 2001 From: "rasmus.pank" Date: Sat, 25 May 2013 15:31:45 +0200 Subject: [PATCH 2/4] Trying to get good default for email and author. * ox-koma-letter.el (org-koma-letter-author): defaults to a function that returns =`user-full-name'= * ox-koma-letter.el (org-koma-letter-email): defaults to a function that returns =`user-mail-address'= With the old after-init-hook method my user name was always set to "". Now org-koma-letter will (i) allow for default nil values (good if you use LCO files); (ii) default to =`user-full-name'= and =`user-mail-address'= like =ox-latex.el=. These values are obtained on-the-fly. The two variables in question can also be strings or functions returning strings. --- contrib/lisp/ox-koma-letter.el | 58 ++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 24c1ac5..c8be5ab 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -82,32 +82,30 @@ :group 'org-export-koma-letter :type 'string) -(defcustom org-koma-letter-author (if (boundp 'org-koma-letter-author) - user-full-name - ;; Empty string means "not set yet." - "") +(defcustom org-koma-letter-author 'user-full-name "The sender's name. -This variable defaults to the value of `user-full-name'." +This variable defaults to calling the function `user-full-name' +which just returns the current `user-full-name'. Alternatively a +string, nil or a function may be given. Functions must return a +string." :group 'org-export-koma-letter - :type 'string) - -(add-hook 'after-init-hook - (lambda () - (if (string= org-koma-letter-author "") - (setq org-koma-letter-author user-full-name)))) + :type '(radio (function-item user-full-name) + (string) + (function) + (const nil))) -(defcustom org-koma-letter-email user-mail-address +(defcustom org-koma-letter-email 'org-koma-letter-email "The sender's email address. -This variable defaults to the value of `user-mail-address'." +This variable defaults to the value `org-koma-letter-email' which +returns `user-mail-address'. Alternatively a string, nil or a +function may be given. Functions must return a string." :group 'org-export-koma-letter - :type 'string) - -(add-hook 'after-init-hook - (lambda () - (if (string= org-koma-letter-email "") - (setq org-koma-letter-email user-mail-address)))) + :type '(radio (function-item org-koma-letter-email) + (string) + (function) + (const nil))) (defcustom org-koma-letter-from-address nil "Sender's address, as a string." @@ -134,12 +132,6 @@ This variable defaults to the value of `user-mail-address'." :group 'org-export-koma-letter :type 'string) -(defcustom org-koma-letter-email user-mail-address - "The default email address stored in the letter." ) - -(defcustom org-koma-letter-author user-full-name - "The default name of the sender." ) - (defcustom org-koma-letter-signature "\\usekomavar{fromname}" "String used as the signature." :group 'org-export-koma-letter @@ -232,17 +224,16 @@ content temporarily.") (org-export-define-derived-backend 'koma-letter 'latex :options-alist '((:lco "LCO" nil org-koma-letter-class-option-file) - (:author "AUTHOR" nil org-koma-letter-author t) + (:author "AUTHOR" nil (org-koma-letter--get-custom org-koma-letter-author) t) (:from-address "FROM_ADDRESS" nil org-koma-letter-from-address newline) (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number) - (:email "EMAIL" nil org-koma-letter-email t) + (:email "EMAIL" nil (org-koma-letter--get-custom org-koma-letter-email) t) (:to-address "TO_ADDRESS" nil nil newline) (:place "PLACE" nil org-koma-letter-place) (: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) @@ -266,6 +257,17 @@ content temporarily.") (org-open-file (org-koma-letter-export-to-pdf nil s v b)))))))) +;;; Helper functions + +(defun org-koma-letter-email () + "Return the current `user-mail-address'" + user-mail-address) + +(defun org-koma-letter--get-custom (value) + (when value + (cond ((stringp value) value) + ((symbolp value) (funcall value))))) + ;;; Transcode Functions ;;;; Export Block -- 1.8.2.3