emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* API problem
@ 2014-01-22 16:37 Cecil Westerhof
  2014-01-22 17:03 ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Cecil Westerhof @ 2014-01-22 16:37 UTC (permalink / raw)
  To: emacs-orgmode

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

To solve a problem I have the following line in an org file:
        - [ ] B (org-list-set-checkbox (line-beginning-position)
(org-list-struct) "[X]") ITEM STRUCT CHECKBOX (org-list-send-item
(line-beginning-position) 'end (org-list-struct)) ITEM DEST STRUCT

Executing the org-list-send-item brings the entry to the end of the list,
but executing org-list-set-checkbox does nothing. What am I doing wrong?
Because looking at the API I use the right parameters. I also do not get an
error message.

-- 
Cecil Westerhof

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

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

* Re: API problem
  2014-01-22 16:37 API problem Cecil Westerhof
@ 2014-01-22 17:03 ` Nicolas Goaziou
       [not found]   ` <CAG-LmmApJwvTvTYZ3cFjb_rLkiX9B_JP3FzTX-D_kW3H1=D6pA@mail.gmail.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2014-01-22 17:03 UTC (permalink / raw)
  To: Cecil Westerhof; +Cc: emacs-orgmode

Hello,

Cecil Westerhof <cldwesterhof@gmail.com> writes:

> To solve a problem I have the following line in an org file:
>         - [ ] B (org-list-set-checkbox (line-beginning-position)
> (org-list-struct) "[X]") ITEM STRUCT CHECKBOX (org-list-send-item
> (line-beginning-position) 'end (org-list-struct)) ITEM DEST STRUCT
>
> Executing the org-list-send-item brings the entry to the end of the list,
> but executing org-list-set-checkbox does nothing. What am I doing
> wrong?

`org-list-set-checkbox' modifies the structure, i.e., the internal list
representation. It doesn't modify the buffer. You would have to apply
the new structure to the buffer with `org-list-write-struct'.

Anyway, it's much simpler to use `org-toggle-checkbox'.


Regards,

-- 
Nicolas Goaziou

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

* Fwd: API problem
       [not found]   ` <CAG-LmmApJwvTvTYZ3cFjb_rLkiX9B_JP3FzTX-D_kW3H1=D6pA@mail.gmail.com>
@ 2014-01-22 20:24     ` Cecil Westerhof
  2014-01-22 20:28       ` Cecil Westerhof
  0 siblings, 1 reply; 8+ messages in thread
From: Cecil Westerhof @ 2014-01-22 20:24 UTC (permalink / raw)
  To: emacs-orgmode

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

Did not go to the list. :'(

---------- Forwarded message ----------
From: Cecil Westerhof <cldwesterhof@gmail.com>
Date: 2014/1/22
Subject: Re: API problem
To: Nicolas Goaziou <n.goaziou@gmail.com>


2014/1/22 Nicolas Goaziou <n.goaziou@gmail.com>

> > To solve a problem I have the following line in an org file:
> >         - [ ] B (org-list-set-checkbox (line-beginning-position)
> > (org-list-struct) "[X]") ITEM STRUCT CHECKBOX (org-list-send-item
> > (line-beginning-position) 'end (org-list-struct)) ITEM DEST STRUCT
> >
> > Executing the org-list-send-item brings the entry to the end of the list,
> > but executing org-list-set-checkbox does nothing. What am I doing
> > wrong?
>
> `org-list-set-checkbox' modifies the structure, i.e., the internal list
> representation. It doesn't modify the buffer. You would have to apply
> the new structure to the buffer with `org-list-write-struct'.
>

Just started today to want to do some thing, so I am a tabula rasa. ;-)



> Anyway, it's much simpler to use `org-toggle-checkbox'.
>

That goes wrong when there is a marked region. I only want to set the
current checkbox.

So I have to work out how to use org-list-wrte-struct.

-- 
Cecil Westerhof

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

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

* Re: API problem
  2014-01-22 20:24     ` Fwd: " Cecil Westerhof
@ 2014-01-22 20:28       ` Cecil Westerhof
  2014-01-22 20:40         ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Cecil Westerhof @ 2014-01-22 20:28 UTC (permalink / raw)
  To: emacs-orgmode

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

2014/1/22 Cecil Westerhof <cldwesterhof@gmail.com>

> 2014/1/22 Nicolas Goaziou <n.goaziou@gmail.com>
>
>> > To solve a problem I have the following line in an org file:
>> >         - [ ] B (org-list-set-checkbox (line-beginning-position)
>> > (org-list-struct) "[X]") ITEM STRUCT CHECKBOX (org-list-send-item
>> > (line-beginning-position) 'end (org-list-struct)) ITEM DEST STRUCT
>> >
>> > Executing the org-list-send-item brings the entry to the end of the
>> list,
>> > but executing org-list-set-checkbox does nothing. What am I doing
>> > wrong?
>>
>> `org-list-set-checkbox' modifies the structure, i.e., the internal list
>> representation. It doesn't modify the buffer. You would have to apply
>> the new structure to the buffer with `org-list-write-struct'.
>>
>
> Just started today to want to do some thing, so I am a tabula rasa. ;-)
>
>
>
>> Anyway, it's much simpler to use `org-toggle-checkbox'.
>>
>
> That goes wrong when there is a marked region. I only want to set the
> current checkbox.
>
> So I have to work out how to use org-list-wrte-struct.
>

I have an org-file wth the folowing:
- [ ] A (setq struct (org-list-struct))
- [-] B (org-list-get-checkbox 41 struct)
- [ ] C (org-list-set-checkbox 41 struct "[X]")
- [ ] D (org-list-get-checkbox 41 struct)
- [ ] E (org-list-write-struct struct (org-list-parents-alist struct))

In A I fill the struct.
B displays "[-]"
C displays "[X]"
D displays "[X]", so the struct is correctly updated.
E gives: #<marker in no buffer>

What is going wrong here?


-- 
Cecil Westerhof

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

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

* Re: API problem
  2014-01-22 20:28       ` Cecil Westerhof
@ 2014-01-22 20:40         ` Nicolas Goaziou
  2014-01-22 21:57           ` Cecil Westerhof
  2014-01-22 23:52           ` Cecil Westerhof
  0 siblings, 2 replies; 8+ messages in thread
From: Nicolas Goaziou @ 2014-01-22 20:40 UTC (permalink / raw)
  To: Cecil Westerhof; +Cc: emacs-orgmode

Cecil Westerhof <cldwesterhof@gmail.com> writes:

> I have an org-file wth the folowing:
> - [ ] A (setq struct (org-list-struct))
> - [-] B (org-list-get-checkbox 41 struct)
> - [ ] C (org-list-set-checkbox 41 struct "[X]")
> - [ ] D (org-list-get-checkbox 41 struct)
> - [ ] E (org-list-write-struct struct (org-list-parents-alist struct))
>
> In A I fill the struct.
> B displays "[-]"
> C displays "[X]"
> D displays "[X]", so the struct is correctly updated.
> E gives: #<marker in no buffer>
>
> What is going wrong here?

See `org-list-write-struct' docstring. Basically, STRUCT doesn't match
real structure anymore since step C. You need to provide the original
structure as a third argument so `org-list-write-struct' can modify
buffer by set difference.

  (let* ((struct (org-list-struct))
         (old (copy-tree struct)))
    (org-list-set-checkbox (line-beginning-position) struct "[X]")
    (org-list-write-struct struct (org-list-parents-alist struct) old))


Regards,

-- 
Nicolas Goaziou

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

* Re: API problem
  2014-01-22 20:40         ` Nicolas Goaziou
@ 2014-01-22 21:57           ` Cecil Westerhof
  2014-01-22 22:23             ` Nicolas Goaziou
  2014-01-22 23:52           ` Cecil Westerhof
  1 sibling, 1 reply; 8+ messages in thread
From: Cecil Westerhof @ 2014-01-22 21:57 UTC (permalink / raw)
  To: emacs-orgmode

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

2014/1/22 Nicolas Goaziou <n.goaziou@gmail.com>

> Cecil Westerhof <cldwesterhof@gmail.com> writes:
>
> > I have an org-file wth the folowing:
> > - [ ] A (setq struct (org-list-struct))
> > - [-] B (org-list-get-checkbox 41 struct)
> > - [ ] C (org-list-set-checkbox 41 struct "[X]")
> > - [ ] D (org-list-get-checkbox 41 struct)
> > - [ ] E (org-list-write-struct struct (org-list-parents-alist struct))
> >
> > In A I fill the struct.
> > B displays "[-]"
> > C displays "[X]"
> > D displays "[X]", so the struct is correctly updated.
> > E gives: #<marker in no buffer>
> >
> > What is going wrong here?
>
> See `org-list-write-struct' docstring. Basically, STRUCT doesn't match
> real structure anymore since step C. You need to provide the original
> structure as a third argument so `org-list-write-struct' can modify
> buffer by set difference.
>
>   (let* ((struct (org-list-struct))
>          (old (copy-tree struct)))
>     (org-list-set-checkbox (line-beginning-position) struct "[X]")
>     (org-list-write-struct struct (org-list-parents-alist struct) old))
>

This works, so I can continue.

But one thing I do not understand. When you do an org-list-write-struct,
you want to change the structure. So why is old-struct optional?



-- 
Cecil Westerhof

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

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

* Re: API problem
  2014-01-22 21:57           ` Cecil Westerhof
@ 2014-01-22 22:23             ` Nicolas Goaziou
  0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Goaziou @ 2014-01-22 22:23 UTC (permalink / raw)
  To: Cecil Westerhof; +Cc: emacs-orgmode

Hello,

Cecil Westerhof <cldwesterhof@gmail.com> writes:

> But one thing I do not understand. When you do an org-list-write-struct,
> you want to change the structure. So why is old-struct optional?

Good question.

IIRC, it's just syntactic sugar since `org-list-write-struct' will do
the `copy-tree' for you in most situations (i.e., when you don't use
a function that modifies structure by side-effect).


Regards,

-- 
Nicolas Goaziou

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

* Re: API problem
  2014-01-22 20:40         ` Nicolas Goaziou
  2014-01-22 21:57           ` Cecil Westerhof
@ 2014-01-22 23:52           ` Cecil Westerhof
  1 sibling, 0 replies; 8+ messages in thread
From: Cecil Westerhof @ 2014-01-22 23:52 UTC (permalink / raw)
  To: emacs-orgmode

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

2014/1/22 Nicolas Goaziou <n.goaziou@gmail.com>

> See `org-list-write-struct' docstring. Basically, STRUCT doesn't match
> real structure anymore since step C. You need to provide the original
> structure as a third argument so `org-list-write-struct' can modify
> buffer by set difference.
>
>   (let* ((struct (org-list-struct))
>          (old (copy-tree struct)))
>     (org-list-set-checkbox (line-beginning-position) struct "[X]")
>     (org-list-write-struct struct (org-list-parents-alist struct) old))
>

I implemented it. See my post:
    Check checkbox and move to end of list

-- 
Cecil Westerhof

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

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

end of thread, other threads:[~2014-01-22 23:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-22 16:37 API problem Cecil Westerhof
2014-01-22 17:03 ` Nicolas Goaziou
     [not found]   ` <CAG-LmmApJwvTvTYZ3cFjb_rLkiX9B_JP3FzTX-D_kW3H1=D6pA@mail.gmail.com>
2014-01-22 20:24     ` Fwd: " Cecil Westerhof
2014-01-22 20:28       ` Cecil Westerhof
2014-01-22 20:40         ` Nicolas Goaziou
2014-01-22 21:57           ` Cecil Westerhof
2014-01-22 22:23             ` Nicolas Goaziou
2014-01-22 23:52           ` Cecil Westerhof

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).