emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Cecil Westerhof <cldwesterhof@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Check checkbox and move to end of list
Date: Thu, 23 Jan 2014 00:50:37 +0100	[thread overview]
Message-ID: <CAG-LmmBMJvP3X32QepOb=+nEsbEO+JWkbWk2XZ_YuYB-r8h4Gw@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2014-01-22 23:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-22 23:50 Cecil Westerhof [this message]
2014-01-23  0:46 ` Check checkbox and move to end of list Cecil Westerhof
2014-01-23  1:07   ` Cecil Westerhof
2014-01-23 19:51 ` Cecil Westerhof

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAG-LmmBMJvP3X32QepOb=+nEsbEO+JWkbWk2XZ_YuYB-r8h4Gw@mail.gmail.com' \
    --to=cldwesterhof@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).