From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cecil Westerhof Subject: Check checkbox and move to end of list Date: Thu, 23 Jan 2014 00:50:37 +0100 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b6d7e0aaacf3d04f097ca0e Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W67ZB-0007AD-FU for emacs-orgmode@gnu.org; Wed, 22 Jan 2014 18:50:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W67Z9-0007LW-No for emacs-orgmode@gnu.org; Wed, 22 Jan 2014 18:50:40 -0500 Received: from mail-qc0-x229.google.com ([2607:f8b0:400d:c01::229]:53941) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W67Z8-0007LK-LF for emacs-orgmode@gnu.org; Wed, 22 Jan 2014 18:50:39 -0500 Received: by mail-qc0-f169.google.com with SMTP id w7so1570616qcr.14 for ; Wed, 22 Jan 2014 15:50:37 -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 --047d7b6d7e0aaacf3d04f097ca0e Content-Type: text/plain; charset=ISO-8859-1 The following function does (mostly) what I want: (defun dcbl-check-checkbox-and-move-to-end () (interactive) (save-excursion (let* ((struct (org-list-struct)) (struct-old (copy-tree struct)) (item (line-beginning-position)) (item-checkbox-type (org-list-get-checkbox item struct))) (if (not item-checkbox-type) (message "No checkbox found") (if (string-equal item-checkbox-type "[X]") (message "Checkbox already checked") (org-list-set-checkbox item struct "[X]") (org-list-write-struct struct (org-list-parents-alist struct) struct-old) (org-list-send-item item 'end struct)))))) I defined the following key to use it: (global-set-key [?\C-c ?\M-c] 'dcbl-check-checkbox-and-move-to-end) For one reason or another did the following not work: (global-set-key [?\C-c e] 'dcbl-check-checkbox-and-move-to-end) A bit strange, because the following does work: (global-set-key [?\C-c t] 'dcbl-buffer-to-temp) There is still something to do, because if you have the following: - [ ] A - [-] B [2/3] - [ ] 1 - [X] 2 - [X] 3 - [ ] C - [ ] D - [ ] E And I use the function on 1, I get: - [ ] A - [X] B [2/3] - [X] 2 - [X] 3 - [X] 1 - [ ] C - [ ] D - [ ] E And I want to get: - [ ] A - [ ] C - [ ] D - [ ] E - [X] B [2/3] - [X] 2 - [X] 3 - [X] 1 But that is the following exercise. ;-) I also think it would be a good idea to change (org-list-send-item item 'end struct) to a call to a function. I think it would be useful to have a function to send a item to the end (or begin) of a list. When it could be improved: please let me know. Bastien: if you want to integrate it in org-mode, no problem. -- Cecil Westerhof --047d7b6d7e0aaacf3d04f097ca0e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
The following function does (mostly) what I want:
(defun = dcbl-check-checkbox-and-move-to-end ()
=A0 (interactive)
=A0 (save-ex= cursion
=A0=A0=A0 (let* ((struct=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (org-list-stru= ct))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (struct-old=A0=A0=A0=A0=A0=A0=A0=A0 = (copy-tree struct))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (item=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 (line-beginning-position))
=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 (item-checkbox-type (org-list-get-checkbox item struct))) =A0=A0=A0=A0=A0 (if (not item-checkbox-type)
=A0=A0=A0=A0=A0=A0=A0=A0=A0= (message "No checkbox found")
=A0=A0=A0=A0=A0=A0=A0 (if (stri= ng-equal item-checkbox-type "[X]")
=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 (message "Checkbox already checked")
=A0=A0=A0=A0=A0=A0= =A0=A0=A0 (org-list-set-checkbox item struct "[X]")
=A0=A0=A0=A0=A0=A0=A0=A0=A0 (org-list-write-struct struct (org-list-parents= -alist struct) struct-old)
=A0=A0=A0=A0=A0=A0=A0=A0=A0 (org-list-send-it= em item 'end struct))))))

I defined the following key to use it:=
(global-set-key [?\C-c ?\M-c]=A0=A0=A0 'dcbl-check-checkbox-and-mov= e-to-end)

For one reason or another did the following not work:
(global-set-ke= y [?\C-c e]=A0=A0=A0 'dcbl-check-checkbox-and-move-to-end)

A bit= strange, because the following does work:
(global-set-key [?\C-c t]=A0= =A0=A0 'dcbl-buffer-to-temp)


There is still something to do, because if you have the following:<= br>- [ ] A
- [-] B [2/3]
=A0 - [ ] 1
=A0 - [X] 2
=A0 - [X] 3- [ ] C
- [ ] D
- [ ] E

And I use the function on 1, I get: - [ ] A
- [X] B [2/3]
=A0 - [X] 2
=A0 - [X] 3
=A0 - [X] 1
- = [ ] C
- [ ] D
- [ ] E

And I want to get:
- [ ] A
- [ ] C=
- [ ] D
- [ ] E
- [X] B [2/3]
=A0 - [X] 2
=A0 - [X] 3
= =A0 - [X] 1

But that is the following exercise. ;-)

I also think it woul= d be a good idea to change
=A0=A0=A0 (org-list-send-item item 'end s= truct)
to a call to a function. I think it would be useful to have a function = to send a item to the end (or begin) of a list.

When it could be improved: please let me know.

Bastien: if you w= ant to integrate it in org-mode, no problem.

--
Cecil West= erhof
--047d7b6d7e0aaacf3d04f097ca0e--