* Check checkbox and move to end of list
@ 2014-01-22 23:50 Cecil Westerhof
2014-01-23 0:46 ` Cecil Westerhof
2014-01-23 19:51 ` Cecil Westerhof
0 siblings, 2 replies; 4+ messages in thread
From: Cecil Westerhof @ 2014-01-22 23:50 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1792 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 2470 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Check checkbox and move to end of list
2014-01-22 23:50 Check checkbox and move to end of list Cecil Westerhof
@ 2014-01-23 0:46 ` Cecil Westerhof
2014-01-23 1:07 ` Cecil Westerhof
2014-01-23 19:51 ` Cecil Westerhof
1 sibling, 1 reply; 4+ messages in thread
From: Cecil Westerhof @ 2014-01-23 0:46 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1628 bytes --]
2014/1/23 Cecil Westerhof <cldwesterhof@gmail.com>
> 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.
>
I know have the following:
(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)
(dcbl-move-item-to-end-of-list item))))))
(defun dcbl-move-item-to-begin-of-list (&optional item)
(interactive)
(save-excursion
(when item
(goto-char item))
(org-list-send-item (line-beginning-position) 'begin (org-list-struct)))
(previous-line))
(defun dcbl-move-item-to-end-of-list (&optional item)
(interactive)
(save-excursion
(when item
(goto-char item))
(org-list-send-item (line-beginning-position) 'end (org-list-struct))))
(global-set-key [?\C-c ?\M-a] 'dcbl-move-item-to-begin-of-list)
(global-set-key [?\C-c ?\M-c] 'dcbl-check-checkbox-and-move-to-end)
(global-set-key [?\C-c ?\M-e] 'dcbl-move-item-to-end-of-list)
--
Cecil Westerhof
[-- Attachment #2: Type: text/html, Size: 2422 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Check checkbox and move to end of list
2014-01-23 0:46 ` Cecil Westerhof
@ 2014-01-23 1:07 ` Cecil Westerhof
0 siblings, 0 replies; 4+ messages in thread
From: Cecil Westerhof @ 2014-01-23 1:07 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1255 bytes --]
2014/1/23 Cecil Westerhof <cldwesterhof@gmail.com>
> (defun dcbl-move-item-to-begin-of-list (&optional item)
> (interactive)
> (save-excursion
> (when item
> (goto-char item))
> (org-list-send-item (line-beginning-position) 'begin
> (org-list-struct)))
> (previous-line))
>
> (defun dcbl-move-item-to-end-of-list (&optional item)
> (interactive)
> (save-excursion
> (when item
> (goto-char item))
> (org-list-send-item (line-beginning-position) 'end (org-list-struct))))
>
There was not enough error checking. Better is:
(defun dcbl-move-item-to-begin-of-list (&optional item)
(interactive)
(let ((list nil))
(save-excursion
(when item
(goto-char item))
(setq list (org-list-struct))
(if (not list)
(message "Not in a list")
(org-list-send-item (line-beginning-position) 'begin list)))
(when list
(previous-line))))
(defun dcbl-move-item-to-end-of-list (&optional item)
(interactive)
(let ((list nil))
(save-excursion
(when item
(goto-char item))
(setq list (org-list-struct))
(if (not list)
(message "Not in a list")
(org-list-send-item (line-beginning-position) 'end list)))))
--
Cecil Westerhof
[-- Attachment #2: Type: text/html, Size: 1989 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Check checkbox and move to end of list
2014-01-22 23:50 Check checkbox and move to end of list Cecil Westerhof
2014-01-23 0:46 ` Cecil Westerhof
@ 2014-01-23 19:51 ` Cecil Westerhof
1 sibling, 0 replies; 4+ messages in thread
From: Cecil Westerhof @ 2014-01-23 19:51 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1685 bytes --]
2014/1/23 Cecil Westerhof <cldwesterhof@gmail.com>
> 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))))))
>
Update of the count in the parent did not go correctly always. This code
does the update correct. (Only the last command is appended.)
(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)
(dcbl-move-item-to-end-of-list item)
(org-update-statistics-cookies nil))))))
--
Cecil Westerhof
[-- Attachment #2: Type: text/html, Size: 2437 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-01-23 19:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-22 23:50 Check checkbox and move to end of list Cecil Westerhof
2014-01-23 0:46 ` Cecil Westerhof
2014-01-23 1:07 ` Cecil Westerhof
2014-01-23 19:51 ` 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).