emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Check checkbox and move to end of list


From: Cecil Westerhof
Subject: [O] Check checkbox and move to end of list
Date: Thu, 23 Jan 2014 00:50:37 +0100

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]