emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: mail@christianmoe.com, Nicolas Goaziou <n.goaziou@gmail.com>,
	Org Mode List <emacs-orgmode@gnu.org>, Bastien <bzg@altern.org>
Subject: Re: About commit named "Allow multi-line properties to be specified in property blocks"
Date: Mon, 07 Nov 2011 15:09:37 -0700	[thread overview]
Message-ID: <87ty6ffuu6.fsf@gmail.com> (raw)
In-Reply-To: <877h3felm2.fsf@gmail.com> (Eric Schulte's message of "Fri, 04 Nov 2011 13:25:09 -0600")

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

The attached patch implements this latest "propname+" suggestion.  When
applied it results in the behavior shown below.

I'm inclined to go with this as a solution moving forward.

Thoughts?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: something.org --]
[-- Type: text/x-org, Size: 683 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

* overwriting a file-wide property
  :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=7

* appending to a file-wide property
  :PROPERTIES:
  :var+:      , baz=3
  :END:

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

#+results:
: 6

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

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-property-names-ending-in-plus-accumulate.patch --]
[-- Type: text/x-diff, Size: 10799 bytes --]

From 1bb2009c419e5ae6c912e863b13cb02a1f1ea720 Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
Date: Mon, 7 Nov 2011 14:49:42 -0700
Subject: [PATCH] property names ending in plus accumulate

This results 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

  * overwriting a file-wide property
    :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=7

  * appending to a file-wide property
    :PROPERTIES:
    :var+:      , baz=3
    :END:

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

  #+results:
  : 6

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

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

* lisp/org.el (org-update-property-plist): Updates a given property
  list with a property name and a property value.
  (org-set-regexps-and-options): Use org-update-property-plist.
  (org-entry-get): Use org-update-property-plist.
* testing/examples/property-inheritance.org: Example file for testing
  appending property behavior.
* testing/lisp/test-property-inheritance.el: Tests of appending
  property behavior.
properties with names ending in "+" accumulate rather than overwrite

This results 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

  * overwriting a file-wide property
    :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=7

  * appending to a file-wide property
    :PROPERTIES:
    :var+:      , baz=3
    :END:

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

  #+results:
  : 6

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

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

* lisp/org.el (org-update-property-plist): Updates a given property
  list with a property name and a property value.
  (org-set-regexps-and-options): Use org-update-property-plist.
  (org-entry-get): Use org-update-property-plist.
* testing/examples/property-inheritance.org: Example file for testing
  appending property behavior.
* testing/lisp/test-property-inheritance.el: Tests of appending
  property behavior.
properties with names ending in "+" accumulate rather than overwrite

This results 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

  * overwriting a file-wide property
    :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=7

  * appending to a file-wide property
    :PROPERTIES:
    :var+:      , baz=3
    :END:

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

  #+results:
  : 6

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

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

* lisp/org.el (org-update-property-plist): Updates a given property
  list with a property name and a property value.
  (org-set-regexps-and-options): Use org-update-property-plist.
  (org-entry-get): Use org-update-property-plist.
* testing/examples/property-inheritance.org: Example file for testing
  appending property behavior.
* testing/lisp/test-property-inheritance.el: Tests of appending
  property behavior.
---
 lisp/org.el                               |   47 +++++++++++++++-------
 testing/examples/property-inheritance.org |   36 +++++++++++++++++
 testing/lisp/test-property-inheritance.el |   62 +++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+), 15 deletions(-)
 create mode 100644 testing/examples/property-inheritance.org
 create mode 100644 testing/lisp/test-property-inheritance.el

diff --git a/lisp/org.el b/lisp/org.el
index 92ced78..8739ee0 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4437,6 +4437,15 @@ 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.")
 
+(defun org-update-property-plist (key val props)
+  "Update PROPS with KEY and VAL."
+  (if (string= "+" (substring key (- (length key) 1)))
+      (let* ((key (substring key 0 (- (length key) 1)))
+	     (previous (cdr (assoc key props))))
+	(cons (cons key (concat previous val))
+	      (org-remove-if (lambda (p) (string= (car p) key)) props)))
+    (cons (cons key val) props)))
+
 (defun org-set-regexps-and-options ()
   "Precompute regular expressions for current buffer."
   (when (eq major-mode 'org-mode)
@@ -4498,8 +4507,9 @@ 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)))
+		(setq props (org-update-property-plist (match-string 1 value)
+						       (match-string 2 value)
+						       props))))
 	     ((equal key "FILETAGS")
 	      (when (string-match "\\S-" value)
 		(setq ftags
@@ -4551,8 +4561,9 @@ means to push this value onto the list in the variable.")
 	      (setq value (replace-regexp-in-string
 			   "[\n\r]" " " (match-string 4)))
 	      (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value)
-		(push (cons (match-string 1 value) (match-string 2 value))
-		      props))))))
+		(setq props (org-update-property-plist (match-string 1 value)
+						       (match-string 2 value)
+						       props)))))))
       (org-set-local 'org-use-sub-superscripts scripts)
       (when cat
 	(org-set-local 'org-category (intern cat))
@@ -14082,17 +14093,23 @@ when a \"nil\" value can supersede a non-nil value higher up the hierarchy."
 	  (cdr (assoc property (org-entry-properties nil 'special property)))
 	(let ((range (unless (org-before-first-heading-p)
 		       (org-get-property-block))))
-	  (if (and range
-		   (goto-char (car range))
-		   (re-search-forward
-		    (org-re-property property)
-		    (cdr range) t))
-	      ;; Found the property, return it.
-	      (if (match-end 1)
-		  (if literal-nil
-		      (org-match-string-no-properties 1)
-		    (org-not-nil (org-match-string-no-properties 1)))
-		"")))))))
+	  (when (and range (goto-char (car range)))
+	    ((lambda (val) (when val (if literal-nil val (org-not-nil val))))
+	     (cond
+	      ((re-search-forward
+		(org-re-property property) (cdr range) t)
+	       (if (match-end 1) (org-match-string-no-properties 1) ""))
+	      ((re-search-forward
+		(org-re-property (concat property "+")) (cdr range) t)
+	       (cdr (assoc
+		     property
+		     (org-update-property-plist
+		      (concat property "+")
+		      (if (match-end 1) (org-match-string-no-properties 1) "")
+		      (list (or (assoc property org-file-properties)
+				(assoc property org-global-properties)
+				(assoc property org-global-properties-fixed)
+				))))))))))))))
 
 (defun org-property-or-variable-value (var &optional inherit)
   "Check if there is a property fixing the value of VAR.
diff --git a/testing/examples/property-inheritance.org b/testing/examples/property-inheritance.org
new file mode 100644
index 0000000..b19ed6a
--- /dev/null
+++ b/testing/examples/property-inheritance.org
@@ -0,0 +1,36 @@
+#+property: var    foo=1
+#+property: var+ , bar=2
+
+#+begin_src emacs-lisp
+  (+ foo bar)
+#+end_src
+
+#+begin_src emacs-lisp
+  (org-entry-get (point) "var" t)
+#+end_src
+
+* overwriting a file-wide property
+  :PROPERTIES:
+  :var:      foo=7
+  :END:
+
+#+begin_src emacs-lisp
+  foo
+#+end_src
+
+#+begin_src emacs-lisp
+  (org-entry-get (point) "var" t)
+#+end_src
+
+* appending to a file-wide property
+  :PROPERTIES:
+  :var+:      , baz=3
+  :END:
+
+#+begin_src emacs-lisp
+  (+ foo bar baz)
+#+end_src
+
+#+begin_src emacs-lisp
+  (org-entry-get (point) "var" t)
+#+end_src
diff --git a/testing/lisp/test-property-inheritance.el b/testing/lisp/test-property-inheritance.el
new file mode 100644
index 0000000..6bbb0f7
--- /dev/null
+++ b/testing/lisp/test-property-inheritance.el
@@ -0,0 +1,62 @@
+;;; test-ob-R.el --- tests for ob-R.el
+
+;; Copyright (c) 2011 Eric Schulte
+;; Authors: Eric Schulte
+
+;; Released under the GNU General Public License version 3
+;; see: http://www.gnu.org/licenses/gpl-3.0.html
+
+(let ((load-path (cons (expand-file-name
+			".." (file-name-directory
+			      (or load-file-name buffer-file-name)))
+		       load-path)))
+  (require 'org-test)
+  (require 'org-test-ob-consts))
+
+(defmacro test-org-in-property-buffer (&rest body)
+  `(with-temp-buffer
+     (insert-file-contents (expand-file-name "property-inheritance.org"
+					     org-test-example-dir))
+     (org-mode)
+     ,@body))
+
+(ert-deftest test-org-property-accumulation-top-use ()
+  (test-org-in-property-buffer
+   (goto-char (point-min))
+   (org-babel-next-src-block 1)
+   (should (equal 3 (org-babel-execute-src-block)))))
+
+(ert-deftest test-org-property-accumulation-top-val ()
+  (test-org-in-property-buffer
+   (goto-char (point-min))
+   (org-babel-next-src-block 2)
+   (should (string= "foo=1, bar=2" (org-babel-execute-src-block)))))
+
+(ert-deftest test-org-property-accumulation-overwrite-use ()
+  (test-org-in-property-buffer
+   (goto-char (point-min))
+   (org-babel-next-src-block 3)
+   (should (= 7 (org-babel-execute-src-block)))))
+
+(ert-deftest test-org-property-accumulation-overwrite-val ()
+  (test-org-in-property-buffer
+   (goto-char (point-min))
+   (org-babel-next-src-block 4)
+   (should (string= "foo=7" (org-babel-execute-src-block)))))
+
+(ert-deftest test-org-property-accumulation-append-use ()
+  (test-org-in-property-buffer
+   (goto-char (point-min))
+   (org-babel-next-src-block 5)
+   (should (= 6 (org-babel-execute-src-block)))))
+
+(ert-deftest test-org-property-accumulation-append-val ()
+  (test-org-in-property-buffer
+   (goto-char (point-min))
+   (org-babel-next-src-block 6)
+   (should (string= "foo=1, bar=2, baz=3" (org-babel-execute-src-block)))))
+
+(provide 'test-ob-R)
+
+;;; test-ob-R.el ends here
+ 
-- 
1.7.4.1


[-- Attachment #4: Type: text/plain, Size: 47 bytes --]


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

  reply	other threads:[~2011-11-07 21:09 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
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 [this message]
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=87ty6ffuu6.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=bzg@altern.org \
    --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).