emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: mail@christianmoe.com
Cc: Nicolas Goaziou <n.goaziou@gmail.com>,
	Org Mode List <emacs-orgmode@gnu.org>
Subject: Re: About commit named "Allow multi-line properties to be specified in property blocks"
Date: Tue, 01 Nov 2011 14:22:41 -0600	[thread overview]
Message-ID: <878vnzfv8u.fsf@gmail.com> (raw)
In-Reply-To: <4EB04C43.4050007@christianmoe.com> (Christian Moe's message of "Tue, 01 Nov 2011 20:45:07 +0100")

[-- Attachment #1: Type: text/plain, Size: 1054 bytes --]

Christian Moe <mail@christianmoe.com> writes:

> On 11/1/11 8:02 PM, Eric Schulte wrote:
>> As for variable handling, I think the solution is to ensure that on the
>> code-block side of things, a var string like "foo=3, bar=2, foo=1"
>> results in,
>>
>> foo=1
>> bar=2
>>
>> that is, subtree variable definitions will pre-empty earlier definitions
>> of the same variable..
>
> Yes, that sounds like the way to go. My previous message implied that
> the var string should only contain unique variable names, but I see
> that that would be needlessly complicated.
>
> This is an interesting approach; I like it better than the property
> block.

Me too.

> I'm sure we will think of other useful applications for cumulative
> properties, too (conversely, there'll probably be some side effect
> that will turn around and bite us at some point, though I can't think
> what it would be).
>

Hopefully more of the former and less of the later.

Attached is a new patch, which handles subtree inheritance
appropriately, resulting in the following behavior.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: something.org --]
[-- Type: text/x-org, Size: 414 bytes --]

#+property: var foo=1
#+property: var bar=2

#+begin_src emacs-lisp
  (+ foo bar)
#+end_src

#+results:
: 3

#+begin_src emacs-lisp
  (org-entry-get (point) "var" t)
#+end_src

#+results:
: foo=1, bar=2

* heading
  :PROPERTIES:
  :var:      foo=7
  :END:

#+begin_src emacs-lisp
  foo
#+end_src

#+results:
: 7

#+begin_src emacs-lisp
  (org-entry-get (point) "var" t)
#+end_src

#+results:
: foo=1, bar=2, foo=7

[-- Attachment #3: Type: text/plain, Size: 17 bytes --]


Thanks -- Eric


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0001-Allow-some-properties-to-accumulate-see-org-accumula.patch --]
[-- Type: text/x-diff, Size: 4760 bytes --]

From ff3330193da27a6b0dcf4be92ed54424040ddaec Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
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

  #+begin_src emacs-lisp
    (org-entry-get (point) "var" t)
  #+end_src

  #+results:
  : foo=1, bar=2

  * heading
    :PROPERTIES:
    :var:      foo=7
    :END:

  #+begin_src emacs-lisp
    foo
  #+end_src

  #+results:
  : 7

  #+begin_src emacs-lisp
    (org-entry-get (point) "var" t)
  #+end_src

  #+results:
  : foo=1, bar=2, foo=7

* 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.
  (org-property-from-plists): Return the (possibly accumulated) value
  of property from plists.
  (org-entry-get-with-inheritance): Inherit accumulated properties
  appropriately.
---
 lisp/org.el |   52 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 318ccfd..2fe8d92 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,13 @@ 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* ((prp (match-string 1 value))
+		       (val (match-string 2 value))
+		       (new (org-property-from-plists
+			     prp `((,prp . ,val)) props)))
+		  (setq props (cons (cons prp new)
+				    (org-remove-if (lambda (p) (string= (car p) prp))
+						   props))))))
 	     ((equal key "FILETAGS")
 	      (when (string-match "\\S-" value)
 		(setq ftags
@@ -14170,6 +14191,24 @@ no match, the marker will point nowhere.
 Note that also `org-entry-get' calls this function, if the INHERIT flag
 is set.")
 
+(defun org-property-from-plists (property &rest plists)
+  "Return PROPERTY from PLISTS respecting `org-accumulated-properties-alist'."
+  (flet ((until (fn lst) (when (not (null lst))
+			   (or (funcall fn (car lst))
+			       (funcall fn (cdr lst))))))
+    (let ((str (cdr (assoc property org-accumulated-properties-alist))))
+      (if str
+	  (let (result)
+	    (mapc (lambda (plist)
+		    (let ((value (cdr (assoc property plist))))
+		      (when value
+			(setq result (if result
+					 (concat value str result)
+				       value)))))
+		  plists)
+	    result)
+	(until (lambda (plist) (cdr (assoc property plist))) plists)))))
+
 (defun org-entry-get-with-inheritance (property &optional literal-nil)
   "Get entry property, and search higher levels if not present.
 The search will stop at the first ancestor which has the property defined.
@@ -14189,10 +14228,11 @@ However, if LITERAL-NIL is set, return the string value \"nil\" instead."
 		(move-marker org-entry-property-inherited-from (point))
 		(throw 'ex tmp))
 	      (or (org-up-heading-safe) (throw 'ex nil)))))))
-    (setq tmp (or tmp
-		  (cdr (assoc property org-file-properties))
-		  (cdr (assoc property org-global-properties))
-		  (cdr (assoc property org-global-properties-fixed))))
+    (setq tmp (org-property-from-plists property
+					`((,property . ,tmp))
+					org-file-properties
+					org-global-properties
+					org-global-properties-fixed))
     (if literal-nil tmp (org-not-nil tmp))))
 
 (defvar org-property-changed-functions nil
-- 
1.7.4.1


[-- Attachment #5: Type: text/plain, Size: 71 bytes --]


>
> Yours,
> Christian

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

  reply	other threads:[~2011-11-01 20:22 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-31 19:06 About commit named "Allow multi-line properties to be specified in property blocks" Nicolas Goaziou
2011-10-31 20:05 ` Eric Schulte
2011-10-31 20:49   ` Nicolas Goaziou
2011-10-31 21:30     ` Eric Schulte
2011-11-01  8:24       ` Nicolas Goaziou
2011-11-01  8:36         ` Nicolas Goaziou
2011-11-01 14:36           ` Eric Schulte
2011-11-01 15:39             ` Nicolas Goaziou
2011-11-01 16:58               ` Eric Schulte
2011-11-01 17:48                 ` Christian Moe
2011-11-01 19:02                   ` Eric Schulte
2011-11-01 19:45                     ` Christian Moe
2011-11-01 20:22                       ` Eric Schulte [this message]
2011-10-31 21:33     ` Christian Moe
2011-10-31 21:22   ` Christian Moe
2011-10-31 21:36     ` Eric Schulte
2011-11-01  7:33       ` Christian Moe
2011-11-02 15:35     ` Bastien
2011-11-02 17:39       ` Nicolas Goaziou
2011-11-03  1:26         ` Bastien
2011-11-03  8:08           ` Christian Moe
2011-11-03 15:10             ` Nick Dokos
2011-11-03 18:32           ` Eric Schulte
2011-11-03 20:01             ` Nicolas Goaziou
2011-11-03 20:18               ` Eric Schulte
2011-11-03 20:23             ` Eric Schulte
2011-11-04  8:02               ` Rainer M Krug
2011-11-04 17:48                 ` Darlan Cavalcante Moreira
2011-11-04 19:25                   ` Eric Schulte
2011-11-07 22:09                     ` Eric Schulte
2011-11-08  8:42                       ` Rainer M Krug
2011-11-08  9:31                       ` Sebastien Vauban
2011-11-08  9:41                         ` Rainer M Krug
2011-11-08  9:58                           ` Sebastien Vauban
2011-11-08 10:06                             ` Rainer M Krug
2011-11-08 14:42                               ` Darlan Cavalcante Moreira
2011-11-08 15:06                                 ` Sebastien Vauban
2011-11-08 16:03                               ` Eric Schulte
2011-11-08 22:53                                 ` Eric Schulte
2011-11-09  8:25                                   ` Rainer M Krug
2011-11-09 16:12                                     ` Eric Schulte
2011-11-09 17:18                                       ` Rainer M Krug
2011-11-09 22:31                                       ` Sebastien Vauban
2011-11-15 12:33                                         ` Rainer M Krug
2011-11-15 16:00                                           ` Eric Schulte
2011-11-15 16:37                                             ` Torsten Wagner
2011-11-15 16:56                                               ` Eric Schulte
2011-11-15 17:13                                                 ` Thomas S. Dye
2011-11-15 18:22                                                   ` Eric Schulte
2011-11-15 17:24                                             ` Rainer M Krug
2011-11-08  9:41                 ` Sebastien Vauban
2011-11-08  9:44                   ` Rainer M Krug
2011-11-08 16:01                     ` Eric Schulte
2011-11-02 21:05 ` Samuel Wales
2011-11-02 21:21   ` Samuel Wales
2011-11-03  1:42   ` Bastien
2011-11-03  8:19     ` Christian Moe
2011-11-03 18:34     ` Eric Schulte
2011-11-03 18:59       ` Eric Schulte
2011-11-09 17:40       ` Samuel Wales

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878vnzfv8u.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@christianmoe.com \
    --cc=n.goaziou@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).