* 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
* Re: are heading properties always strings?
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
0 siblings, 1 reply; 6+ messages in thread
From: Bastien @ 2014-01-03 8:48 UTC (permalink / raw)
To: John Kitchin; +Cc: emacs-orgmode@gnu.org
Hi John,
John Kitchin <jkitchin@andrew.cmu.edu> writes:
> 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.
Can you tell which place in the documentation you expect to find this
information? In functions' docstrings or in the manual?
Thanks,
--
Bastien
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: are heading properties always strings?
2014-01-03 8:48 ` Bastien
@ 2014-01-03 8:52 ` Achim Gratz
2014-01-03 10:31 ` Bastien
0 siblings, 1 reply; 6+ messages in thread
From: Achim Gratz @ 2014-01-03 8:52 UTC (permalink / raw)
To: emacs-orgmode
Bastien writes:
>> 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.
>
> Can you tell which place in the documentation you expect to find this
> information? In functions' docstrings or in the manual?
Besides documenting the requirement, I guess it makes sense to check for
stringiness before using the argument.
Regards,
Achim.
--
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+
SD adaptations for Waldorf Q V3.00R3 and Q+ V3.54R2:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: are heading properties always strings?
2014-01-03 8:52 ` Achim Gratz
@ 2014-01-03 10:31 ` Bastien
2014-01-03 21:14 ` John Kitchin
0 siblings, 1 reply; 6+ messages in thread
From: Bastien @ 2014-01-03 10:31 UTC (permalink / raw)
To: Achim Gratz; +Cc: emacs-orgmode
Achim Gratz <Stromeko@nexgo.de> writes:
> Bastien writes:
>>> 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.
>>
>> Can you tell which place in the documentation you expect to find this
>> information? In functions' docstrings or in the manual?
>
> Besides documenting the requirement, I guess it makes sense to check for
> stringiness before using the argument.
Indeed, done here:
http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=9758f2
--
Bastien
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: are heading properties always strings?
2014-01-03 10:31 ` Bastien
@ 2014-01-03 21:14 ` John Kitchin
2014-01-04 13:49 ` Bastien
0 siblings, 1 reply; 6+ messages in thread
From: John Kitchin @ 2014-01-03 21:14 UTC (permalink / raw)
To: Bastien; +Cc: Achim Gratz, emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1179 bytes --]
excellent, that is exactly where I would have expected it, in the
documentation for org-entry-put.
it would also make sense to say in org-entry-get that you get a string. if
you store a number in a property, it is not obvious you can't just get it
and do math on it.
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
On Fri, Jan 3, 2014 at 5:31 AM, Bastien <bzg@gnu.org> wrote:
> Achim Gratz <Stromeko@nexgo.de> writes:
>
> > Bastien writes:
> >>> 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.
> >>
> >> Can you tell which place in the documentation you expect to find this
> >> information? In functions' docstrings or in the manual?
> >
> > Besides documenting the requirement, I guess it makes sense to check for
> > stringiness before using the argument.
>
> Indeed, done here:
> http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=9758f2
>
> --
> Bastien
>
>
[-- Attachment #2: Type: text/html, Size: 1962 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: are heading properties always strings?
2014-01-03 21:14 ` John Kitchin
@ 2014-01-04 13:49 ` Bastien
0 siblings, 0 replies; 6+ messages in thread
From: Bastien @ 2014-01-04 13:49 UTC (permalink / raw)
To: John Kitchin; +Cc: Achim Gratz, emacs-orgmode@gnu.org
Hi John,
John Kitchin <jkitchin@andrew.cmu.edu> writes:
> excellent, that is exactly where I would have expected it, in the
> documentation for org-entry-put.
>
> it would also make sense to say in org-entry-get that you get a
> string.
I just added
"Return the value as a string."
in the docstring.
Thanks,
--
Bastien
^ 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 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).