emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: are heading properties always strings?
Date: Wed, 1 Jan 2014 09:36:38 -0500	[thread overview]
Message-ID: <CAJ51ETrjjVacweXRvuiWcBHMHCPdX+JONbwBDceNpsdGA4f1bA@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2014-01-01 14:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-01 14:36 John Kitchin [this message]
2014-01-03  8:48 ` are heading properties always strings? 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

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=CAJ51ETrjjVacweXRvuiWcBHMHCPdX+JONbwBDceNpsdGA4f1bA@mail.gmail.com \
    --to=jkitchin@andrew.cmu.edu \
    --cc=emacs-orgmode@gnu.org \
    /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).