all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* are heading properties always strings?
@ 2014-01-01 14:36 John Kitchin
  2014-01-03  8:48 ` Bastien
  0 siblings, 1 reply; 6+ messages in thread
From: John Kitchin @ 2014-01-01 14:36 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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

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

[-- Attachment #2: Type: text/html, Size: 2125 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-01-04 13:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-01 14:36 are heading properties always strings? John Kitchin
2014-01-03  8:48 ` Bastien
2014-01-03  8:52   ` Achim Gratz
2014-01-03 10:31     ` Bastien
2014-01-03 21:14       ` John Kitchin
2014-01-04 13:49         ` Bastien

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.