From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: About commit named "Allow multi-line properties to be specified in property blocks" Date: Tue, 01 Nov 2011 10:58:27 -0600 Message-ID: <87r51rhj9o.fsf@gmail.com> References: <87vcr5c76e.fsf@gmail.com> <87vcr5j5a5.fsf@gmail.com> <8762j4evjl.fsf@gmail.com> <87k47kkfwp.fsf@gmail.com> <87y5w0ckt7.fsf@gmail.com> <87ty6ock7z.fsf@gmail.com> <87pqhbj4f3.fsf@gmail.com> <871utrj1hk.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:49360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLHfW-0004CR-CN for emacs-orgmode@gnu.org; Tue, 01 Nov 2011 12:58:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLHfU-00025U-2s for emacs-orgmode@gnu.org; Tue, 01 Nov 2011 12:58:34 -0400 Received: from mail-yw0-f41.google.com ([209.85.213.41]:39263) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLHfT-00025O-Ok for emacs-orgmode@gnu.org; Tue, 01 Nov 2011 12:58:32 -0400 Received: by ywa17 with SMTP id 17so8439228ywa.0 for ; Tue, 01 Nov 2011 09:58:31 -0700 (PDT) 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: Nicolas Goaziou Cc: Org Mode List --=-=-= Content-Type: text/plain Nicolas Goaziou writes: > Eric Schulte writes: > >> This was one of the proposed options to solve this problem, namely >> introduce a list of properties whose value accumulates rather than is >> replaced. Since the property list data structure only allows each key >> to appear once, the accumulation would necessarily occur on the value >> side, so assuming "var" is an accumulating property, then >> >> #+property: var foo=1 >> #+property: var bar=2 >> >> would result in `org-file-properties' having the following value >> >> (("var" . "foo=1 bar=1")) >> >> Which with some changes in the code-block side code could be used by >> code blocks to assign multiple variables. >> >> I went with changing property syntax rather than internal behavior >> because I am not overly familiar with properties or the code with which >> they were implemented and I felt (probably incorrectly) that this would >> be a less dramatic change to Org-mode. I'm happy to work up a solution >> along the lines suggested above, which would introduce a variable like >> `org-accumulating-properties' or some-such which would default to only >> holding the "var" property name > > That sounds way better to me. It's just a matter of modifying the > following part in `org-set-regexps-and-options'. > > #+begin_src emacs-lisp > ((equal key "PROPERTY") > (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value) > (push (cons (match-string 1 value) (match-string 2 value)) > props))) > #+end_src > > If we want to be a bit more future-proof on that side, we may even > refine the `org-accumulating-properties' idea by making it an > `org-accumulated-properties-alist' where key is property's name and > value a symbol describing how they are accumulated. That symbol could > be, for example `space', `comma', `newline', `consed'. > Beautiful, The attached patch implements this idea with an alist as you specify above. If we can reach some sort of agreement that this is the best way forward I will revert the property blocks and add this patch. Unfortunately I don't know what constitutes agreement, or who the vested interest holders are in this sort of decision. I would be nice if Carsten or Bastien could weigh in. Cheers -- Eric As an aside discussions like this are part of why I really enjoy working on Org-mode. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Allow-some-properties-to-accumulate-see-org-accumula.patch >From 2496eec5ad79c7e4e4f3804efb1bbce17f913704 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 1 Nov 2011 10:56:36 -0600 Subject: [PATCH] Allow some properties to accumulate (see `org-accumulated-properties-alist'). The default value of this new variable is '(("var" . ", ")) resulting in the following behavior #+property: var foo=1 #+property: var bar=2 #+begin_src emacs-lisp (+ foo bar) #+end_src #+results: : 3 * lisp/org.el (org-accumulated-properties-alist): Adding an alist which specifies which properties may be accumulated and how. (org-set-regexps-and-options): Make use of accumulating properties when collecting said. --- lisp/org.el | 28 ++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 318ccfd..b34d274 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4431,6 +4431,22 @@ in the #+STARTUP line, the corresponding variable, and the value to set this variable to if the option is found. An optional forth element PUSH means to push this value onto the list in the variable.") +(defcustom org-accumulated-properties-alist + '(("var" . ", ")) + "Alist of properties whose values should accumulate rather than overwrite. +Each element of this alist should include both a string property +name as well as the string connector used to join multiple values +for this property. So for example using the default value of +this list which associates \"var\" with \", \", the following +Org-mode text, + + #+PROPERTY: var foo=1 + #+PROPERTY: var bar=2 + +will result in the following being added to `org-file-properties'. + + '(\"var\" . \"foo=1, bar=2\")") + (defun org-set-regexps-and-options () "Precompute regular expressions for current buffer." (when (eq major-mode 'org-mode) @@ -4492,8 +4508,16 @@ means to push this value onto the list in the variable.") (setq prio (org-split-string value " +"))) ((equal key "PROPERTY") (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value) - (push (cons (match-string 1 value) (match-string 2 value)) - props))) + (let* ((prop (match-string 1 value)) + (value (match-string 2 value)) + (str (cdr (assoc prop org-accumulated-properties-alist))) + (existing (cdr (assoc prop props)))) + (if (and str existing) + (setq props (cons (cons prop (concat existing str value)) + (org-remove-if (lambda (p) + (string= (car p) prop)) + props))) + (push (cons prop value) props))))) ((equal key "FILETAGS") (when (string-match "\\S-" value) (setq ftags -- 1.7.4.1 --=-=-= Content-Type: text/plain > > > Regards, -- Eric Schulte http://cs.unm.edu/~eschulte/ --=-=-=--