From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [PATCH][ox-koma-letter]: sender, email and cleanup Date: Sun, 26 May 2013 16:36:25 +0200 Message-ID: <87wqqliz9y.fsf@pank.eu> References: <87hahrmabq.fsf@pank.eu> <20130525170322.GA734@kenny.local> <87bo7zlzln.fsf_-_@pank.eu> <20130526105400.GA716@kenny.local> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:59661) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ugc3p-00065p-K7 for emacs-orgmode@gnu.org; Sun, 26 May 2013 10:36:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ugc3k-00089y-HI for emacs-orgmode@gnu.org; Sun, 26 May 2013 10:36:37 -0400 Received: from mout.gmx.net ([212.227.15.18]:64570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ugc3k-00089Q-3I for emacs-orgmode@gnu.org; Sun, 26 May 2013 10:36:32 -0400 In-Reply-To: <20130526105400.GA716@kenny.local> (Viktor Rosenfeld's message of "Sun, 26 May 2013 12:54:00 +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: listuser36@gmail.com Cc: alan.schmitt@polytechnique.org, emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Viktor, >> 1. Viktor's latest patch. >> 2. The patch describe above that gets user name and email and works >> on my system. . . > > Your code works for me. From my point of view, the pros are that per > default `org-koma-letter-{author,sender}' pick up the values of > `user-full-name' and `user-mail-address' whenever they are changed. > That's very nice! The cons are that IHMO it's quite complicated for > setting something as simple as author and email and you mentioned a > possible crash which I did not test further. Could this be tested using > `functionp'? Still, I think we should stick with it for now. functionp seems better, yes. I didn't know about it (doh!). Thanks! While it is complicated I think it's OK given our desire to disable author and still have a similar default to ox-latex.el. Also, it allows for arbitrary functions which could potentially determine the name based on the context of the letter (I don't know since it's already initialized in the options-alist). I'll let you and Alan decide. > As a side note, I had quite a few problems working with your patches. > None of them applied against master, or against my latest patch as you > claimed.=20 Right. I was working off of branch and I guess one reasons is that it was against the history of my previoues patches=E2=80=94of which not all was applied to the master, it seems (?). I've now tried to rework the entire thing against the current master and produces simplified patches. I tested them with git am and they work on my system. There are still things I don't understand such as why git wants to re-add the authors in patch 4 but I've spend way to much time on rebasing and understanding git already and my head hurts. It seems to ignore it when using git am. Before applying the patches my git log says commit 847637f4bdacb861723438c1389f1a3bcdac48af Merge: 43cc5be 206762b Author: Nicolas Goaziou Date: Sat May 25 22:03:48 2013 +0200 Merge branch 'maint' Patches: 1. summarizes all changes in author. It uses my solution as mentioned abov= e. 2. full support for after closing keywords. See commit message 3. signature to nil 4. change handling of subject and allow for setting subject in OPTION-line. > I had to merge in some of the changes of 0002 by hand. I > suggest that we nail down the workings of AUTHOR and EMAIL first (should > be done now) and then start with clean separate branches branched from > master for your subject and heading code. > We could even use github for this, what do you think? Yeah, could be better. It's way too hectic with all the patches and keeping track of moving repos. If you think it can ease the burden of collaborating I'm all for it. I tried to make a git repo retaining the history of ox-koma-letter.el, but I ended up with a repo of 42mb even after applying all the "garbage collection" tips the interweb had to offer. . . I'm indifferent between bitbucket and github btw, but I'd prefer it someone with more git skills would set it up. -Rasmus --=20 m-mm-mmm-mmmm bacon! --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ox-koma-letter.el-org-koma-letter-author-defaults-to.patch >From bd51fc02a1345cf1005d0137fc0888d301e1089b Mon Sep 17 00:00:00 2001 From: "rasmus.pank" Date: Sun, 26 May 2013 16:13:39 +0200 Subject: [PATCH 1/4] * 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'= Setting the variables `org-koma-letter-author' and `org-koma-letter-email' to the values of `user-full-name' and `user-mail-address' respectively, allows the user to skip =#+AUTHOR:= and =#+EMAIL:= lines when configuring a letter. However, if the user wishes to set this information in LCO files, these variables need to be set to nil. 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 | 50 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 4318db1..7f50530 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -80,6 +80,30 @@ :group 'org-export-koma-letter :type 'string) +(defcustom org-koma-letter-author 'user-full-name + "The sender's 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 '(radio (function-item user-full-name) + (string) + (function) + (const nil))) + +(defcustom org-koma-letter-email 'org-koma-letter-email + "The sender's email 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 '(radio (function-item org-koma-letter-email) + (string) + (function) + (const nil))) (defcustom org-koma-letter-from-address nil "Sender's address, as a string." @@ -153,10 +177,10 @@ 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) - (:sender "AUTHOR" nil user-full-name 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 user-mail-address 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) @@ -184,6 +208,22 @@ Use `foldmarks:true' to activate default fold marks or (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) + "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) + ((functionp value) (funcall value)) + ((symbolp value) (symbol-name value))))) + + ;;; Transcode Functions ;;;; Export Block @@ -250,7 +290,7 @@ holding export options." (plist-get info :latex-header-extra)))) info))))) (let ((lco (plist-get info :lco)) - (sender (plist-get info :sender)) + (author (plist-get info :author)) (from-address (plist-get info :from-address)) (phone-number (plist-get info :phone-number)) (email (plist-get info :email)) @@ -264,8 +304,8 @@ holding export options." (setq lco-def (format "%s\\LoadLetterOption{%s}\n" lco-def lco-file))) lco-def)) ;; Define "From" data. - (when sender (format "\\setkomavar{fromname}{%s}\n" - (org-export-data sender info))) + (when author (format "\\setkomavar{fromname}{%s}\n" + (org-export-data author info))) (when from-address (format "\\setkomavar{fromaddress}{%s}\n" from-address)) (when phone-number (format "\\setkomavar{fromphone}{%s}\n" phone-number)) (when email (format "\\setkomavar{fromemail}{%s}\n" email)) -- 1.8.2.3 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Added-support-for-after-closing-and-after-document.patch >From 19c8a5bbe4efe6cfcc0f0ce39936890db384d1ec Mon Sep 17 00:00:00 2001 From: "rasmus.pank" Date: Sun, 26 May 2013 16:14:51 +0200 Subject: [PATCH 2/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): collect the special lists * ox-koma-letter.el (org-koma-letter-headline): stores content in of headline if the first tag is special. Otherwise return content. * ox-koma-letter.el (org-koma-letter-special-content): holds special content temporarily. * ox-koma-letter.el (org-koma-letter--format-string-as-macro): format a string as a macro or don't. * 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: \myspecialmacro \includepdf{pdf} 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'= as a (LaTeX) macro removing trailing and leading newlines. The macro is the same as the tag, althogh the case is determined by the special list. The concents of the =after_letter= heading will be inserted after =\end{letter}= and newlines are preserved. --- contrib/lisp/ox-koma-letter.el | 104 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 8 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 7f50530..22cfb2e 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -115,7 +115,6 @@ function may be given. Functions must return a string." :group 'org-export-koma-letter :type 'string) - (defcustom org-koma-letter-place nil "Place from which the letter is sent." :group 'org-export-koma-letter @@ -171,6 +170,17 @@ 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") + "Header tags to be inserted after closing") + +(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.") + + ;;; Define Back-End @@ -186,7 +196,13 @@ 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)) + (: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) @@ -195,6 +211,7 @@ Use `foldmarks:true' to activate default fold marks or (:with-subject nil "subject" org-koma-letter-use-subject)) :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 @@ -214,6 +231,12 @@ Use `foldmarks:true' to activate default fold marks or "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 @@ -224,6 +247,37 @@ function (a symobl). If it is a function it it evaluates it." ((symbolp value) (symbol-name 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. + (org-koma-letter--format-string-as-macro + (format "%s" (replace-regexp-in-string regexp "" x)) + (unless no-tag ac))))))))) + +(defun org-koma-letter--format-string-as-macro (string &optional macro) + "If a macro is given format as string as \"\\macro{string}\" else as \"string\"" + (if macro + (format "\\%s{%s}" macro string) + (format "%s" string))) + ;;; Transcode Functions ;;;; Export Block @@ -257,12 +311,39 @@ channel." (if (equal key "KOMA-LETTER") value (org-export-with-backend 'latex keyword contents info)))) + +;; 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 information. + +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-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)) + (progn + (push (cons tag contents) + org-koma-letter-special-contents) + 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-contents and + ;; callying varioues stuff it might be nice to put a big let* around the templace + ;; as in org-groff... (concat ;; Time-stamp. (and (plist-get info :time-stamp-file) @@ -297,7 +378,7 @@ holding export options." (signature (plist-get info :signature))) (concat ;; Letter Class Option File - (when lco + (when lco (let ((lco-files (split-string lco " ")) (lco-def "")) (dolist (lco-file lco-files lco-def) @@ -344,10 +425,16 @@ holding export options." ;; Letter body. contents ;; Closing. - (format "\n\\closing{%s}\n\n" (plist-get info :closing)) + (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\\end{document}")) - + "\n\\end{letter}\n" + (org-koma-letter--prepare-special-contents-as-macro + (plist-get info :with-after-letter) t t) + ;; Document end. + "\n\\end{document}" + )) ;;; Commands @@ -376,7 +463,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. @@ -384,6 +471,7 @@ Export is done in a buffer named \"*Org KOMA-LETTER Export*\". It will be displayed if `org-export-show-temporary-export-buffer' is non-nil." (interactive) + (let (org-koma-letter-special-contents) (if async (org-export-async-start (lambda (output) @@ -400,7 +488,7 @@ non-nil." subtreep visible-only body-only ext-plist))) (with-current-buffer outbuf (LaTeX-mode)) (when org-export-show-temporary-export-buffer - (switch-to-buffer-other-window outbuf))))) + (switch-to-buffer-other-window outbuf)))))) ;;;###autoload (defun org-koma-letter-export-to-latex -- 1.8.2.3 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0003-change-default-of-org-koma-letter-signature-to-nil.patch >From 8d0c65dfa90b2ef4b073949b610d4aba842890fc Mon Sep 17 00:00:00 2001 From: "rasmus.pank" Date: Sat, 25 May 2013 19:35:10 +0200 Subject: [PATCH 3/4] change default of org-koma-letter-signature to nil * ox-koma-letter.el(org-koma-letter-signature): set to nil The previoues value corresponds to the default value cf. the the koma manual pp. 183. --- contrib/lisp/ox-koma-letter.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 22cfb2e..30671e5 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -130,7 +130,7 @@ function may be given. Functions must return a string." :group 'org-export-koma-letter :type 'string) -(defcustom org-koma-letter-signature "\\usekomavar{fromname}" +(defcustom org-koma-letter-signature nil "String used as the signature." :group 'org-export-koma-letter :type 'string) -- 1.8.2.3 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0004-ox-koma-letter-changed-handling-of-subject.patch >From dc9589140c9fdc05290efeaedff46c35e3e902e1 Mon Sep 17 00:00:00 2001 From: "rasmus.pank" Date: Sun, 19 May 2013 17:32:44 +0200 Subject: [PATCH 4/4] ox-koma-letter: changed handling of subject * ox-koma-letter.el: =`org-koma-letter-subject-format'= can now be a list. Default is t. If nil neither subject format nor type is exported. * ox-koma-letter.el (org-koma-letter-template): better subject handling. * ox-koma-letter.el (org-koma-letter-template): allow for t value of =#+OPTIONS: subject:VALUE= * ox-koma-letter.el (org-koma-letter-template): export of subject format is independent of title, but title is not independent of =:with-subject=. The issue was with =#+OPTIONS: subject:t= one would get a LaTeX error. New behavior: If =#+OPTIONS: subject:(x,y)= then =\KOMAoption{subject}{x, y}=. If =subject:x= then =\KOMAoption{subject}{x}=. If =subject:t= then =\KOMAoption{subject}{...}= is not set but \setkomavar{subject}{...} is set (in the output file) If =subject:nil= neither are printed. --- contrib/lisp/ox-koma-letter.el | 63 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 30671e5..4af0ba7 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -4,6 +4,8 @@ ;; Author: Nicolas Goaziou ;; Alan Schmitt +;; Viktor Rosenfeld +;; Rasmus Pank Roulund ;; Keywords: org, wp, tex ;; This program is free software: you can redistribute it and/or modify @@ -135,10 +137,36 @@ function may be given. Functions must return a string." :group 'org-export-koma-letter :type 'string) -(defcustom org-koma-letter-use-subject "untitled" - "Use the title as the letter's subject." - :group 'org-export-koma-letter - :type 'string) +(defcustom org-koma-letter-subject-format t + "Use the title as the subject of the letter. At the time of +writing the following values are allowed: + + - afteropening: subject after opening + - beforeopening: subject before opening + - centered: subject centered + - left:subject left-justified + - right: subject right-justified + - titled: add title/description to subject + - underlined: set subject underlined (see note in text please) + - untitled: do not add title/description to subject. + - No-export: do no insert a subject even if present. + +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)) + :group 'org-export-koma-letter) + + (defcustom org-koma-letter-use-backaddress t "Print return address in small line above to address." @@ -208,7 +236,7 @@ content temporarily.") (: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-subject nil "subject" org-koma-letter-use-subject)) + (: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) @@ -411,12 +439,25 @@ holding export options." ;; Document start "\\begin{document}\n\n" ;; Subject - (let ((with-subject (plist-get info :with-subject))) - (when with-subject - (concat - (format "\\KOMAoption{subject}{%s}\n" with-subject) - (format "\\setkomavar{subject}{%s}\n\n" - (org-export-data (plist-get info :title) info))))) + (let* ((with-subject (plist-get info :with-subject)) + (subject-format (cond ((member with-subject '("true" "t" t)) nil) + ((stringp with-subject) (list with-subject)) + ((symbolp with-subject) + (list (symbol-name with-subject))) + (t with-subject))) + (subject (org-export-data (plist-get info :title) info)) + (l (length subject-format)) + (y "")) + (concat + (when (and with-subject subject-format) + (concat + "\\KOMAoption{subject}{" + (apply 'format + (dotimes (x l y) + (setq y (concat (if (> x 0) "%s," "%s") y))) + subject-format) "}\n")) + (when (and subject with-subject) + (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")) -- 1.8.2.3 --=-=-=--