From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: are heading properties always strings? Date: Wed, 1 Jan 2014 09:36:38 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8ff24325d08f4c04eee99a54 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VyMuY-0002C7-0T for emacs-orgmode@gnu.org; Wed, 01 Jan 2014 09:36:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VyMuW-0001w0-NZ for emacs-orgmode@gnu.org; Wed, 01 Jan 2014 09:36:41 -0500 Received: from mail-pd0-x22f.google.com ([2607:f8b0:400e:c02::22f]:35325) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VyMuW-0001vu-Bc for emacs-orgmode@gnu.org; Wed, 01 Jan 2014 09:36:40 -0500 Received: by mail-pd0-f175.google.com with SMTP id w10so13296674pde.20 for ; Wed, 01 Jan 2014 06:36:39 -0800 (PST) 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: "emacs-orgmode@gnu.org" --e89a8ff24325d08f4c04eee99a54 Content-Type: text/plain; charset=ISO-8859-1 Happy New Year! I was playing around with storing data in heading properties and then using links to modify them. For example, a heading might be a quiz question, and the links are the possible answers. Clicking on a link stores which link was clicked on as a property, and also counts the number of attempts. I wrote a link type to do this that looks like this: (org-add-link-type "ans2" (lambda (path) (org-entry-put (point) "ANSWER" path) (let* ((nattempts (org-entry-get (point) "NUM-ATTEMPTS")) (num-attempts (if nattempts (string-to-number nattempts) 0))) (org-entry-put (point) "NUM-ATTEMPTS" (number-to-string (+ num-attempts 1)))) (message "You selected %s for your answer" path))) This works fine, but there were a few questions that came up in my mind about it. 1. It took two lines to set num-attempts because the first time the property does not exist and so you get nil from org-entry-get, so the var needs to be initialized to 0, and after that it does exist, and it appears the property is read as a string which must be converted to a number so i can do math on it later. Is that the most elegant way to do that? 2. I guess it makes sense that properties would be read as strings, but that wasn't obvious from the documentation they would be strings. 3. It also wasn't obvious that you have to give org-entry-put a string. If you try to set it to an integer, you get strange control characters like ^A or ^C. Thanks! John ----------------------------------- John Kitchin Associate Professor Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 http://kitchingroup.cheme.cmu.edu --e89a8ff24325d08f4c04eee99a54 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Happy New Year!

I was playing around wit= h storing data in heading properties and then using links to modify them. F= or example, a heading might be a quiz question, and the links are the possi= ble answers. Clicking on a link stores which link was clicked on as a prope= rty, and also counts the number of attempts.

I wrote a link type to do this that looks like this:
(org-add-link-type
=A0"ans2"
=A0(lambda (path)
= =A0=A0 (org-entry-put (point) "ANSWER" path)
=A0=A0 (let* ((na= ttempts (org-entry-get (point) "NUM-ATTEMPTS"))
=A0=A0=A0=A0=A0=A0=A0=A0=A0 (num-attempts (if nattempts (string-to-number n= attempts) 0)))
=A0=A0=A0=A0 (org-entry-put (point) "NUM-ATTEMPTS&qu= ot; (number-to-string (+ num-attempts 1))))
=A0=A0 (message "You se= lected %s for your answer" path)))

This works fine, but there were a few questions t= hat came up in my mind about it.

1. It took two lines to= set num-attempts because the first time the property does not exist and so= you get nil from org-entry-get, so the var needs to be initialized to 0, a= nd after that it does exist, and it appears the property is read as a strin= g which must be converted to a number so i can do math on it later. Is that= the most elegant way to do that?

2. I guess it makes sense that properties would be read as s= trings, but that wasn't obvious from the documentation they would be st= rings.

3. It also wasn't obvious that you= have to give org-entry-put a string. If you try to set it to an integer, y= ou get strange control characters like ^A or ^C.

Thanks!

John
-----------------------------------
John Kitchin
Associate Professo= r
Doherty Hall A207F
Department of Chemical Engineering
Carnegie M= ellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

<= /div>
--e89a8ff24325d08f4c04eee99a54--