summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-05-07 23:52:41 -0400
committerKyle Meyer <kyle@kyleam.com>2015-05-07 23:52:41 -0400
commit07c524c605ce9eefd921e472b73655df4d662477 (patch)
tree4d09e9a89daac83095d1ba9a66c4cc00c26c1fb1 /lisp
parent33f0205b324b42f646e89b9e0565759a6ab270c3 (diff)
downloademacs.d-07c524c605ce9eefd921e472b73655df4d662477.tar.gz
org-delete-checked-items: Combine lets
Diffstat (limited to 'lisp')
-rw-r--r--lisp/init-org.el79
1 files changed, 39 insertions, 40 deletions
diff --git a/lisp/init-org.el b/lisp/init-org.el
index f141adc..5e4a9a4 100644
--- a/lisp/init-org.el
+++ b/lisp/init-org.el
@@ -128,46 +128,45 @@ After deleting checked items, move to the first item of the list.
If there are no items of the list remaining, move to the parent
heading."
(interactive)
- (let ((el (org-element-lineage (org-element-context) '(plain-list) t)))
- (unless el
- (user-error "Point is not within a plain list"))
- (let* ((beg (org-element-property :begin el))
- ;; Check maximum point because, if narrowed to a heading,
- ;; org-element can return a point beyond this.
- (end (min (org-element-property :end el) (point-max)))
- (struct (org-element-property :structure el))
- (list-level (org-list-get-ind beg struct))
- (deleted-count 0)
- (text (buffer-substring beg end))
- new-text)
- (with-temp-buffer
- (insert text)
- (let ((offset (1- beg))
- (pmax (point-max))
- level box bpos epos)
- (dolist (item (reverse struct))
- (setq level (nth 1 item)
- box (nth 4 item)
- bpos (- (nth 0 item) offset)
- ;; Minimum check here is for the same reason as
- ;; above with `end'. This only comes into play for
- ;; the last item.
- epos (min (- (nth 6 item) offset) pmax))
- (when (and (= list-level level)
- (string= box "[X]"))
- (delete-region bpos epos)
- (setq deleted-count (1+ deleted-count)))))
- (setq new-text (buffer-string)))
- (if (= deleted-count 0)
- (message "No checked boxes found")
- (delete-region beg end)
- (goto-char beg)
- (insert new-text)
- (goto-char beg)
- (unless (eq (car (org-element-at-point)) 'plain-list)
- (outline-previous-heading))
- (org-update-checkbox-count-maybe)
- (message "Deleted %s item(s)" deleted-count)))))
+ (let* ((el (or (org-element-lineage (org-element-context) '(plain-list) t)
+ (user-error "Point is not within a plain list")))
+ (beg (org-element-property :begin el))
+ ;; Check maximum point because, if narrowed to a heading,
+ ;; org-element can return a point beyond this.
+ (end (min (org-element-property :end el) (point-max)))
+ (struct (org-element-property :structure el))
+ (list-level (org-list-get-ind beg struct))
+ (deleted-count 0)
+ (text (buffer-substring beg end))
+ new-text)
+ (with-temp-buffer
+ (insert text)
+ (let ((offset (1- beg))
+ (pmax (point-max))
+ level box bpos epos)
+ (dolist (item (reverse struct))
+ (setq level (nth 1 item)
+ box (nth 4 item)
+ bpos (- (nth 0 item) offset)
+ ;; Minimum check here is for the same reason as
+ ;; above with `end'. This only comes into play for
+ ;; the last item.
+ epos (min (- (nth 6 item) offset) pmax))
+ (when (and (= list-level level)
+ (string= box "[X]"))
+ (delete-region bpos epos)
+ (setq deleted-count (1+ deleted-count)))))
+ (setq new-text (buffer-string)))
+ (if (= deleted-count 0)
+ (message "No checked boxes found")
+ (delete-region beg end)
+ (goto-char beg)
+ (insert new-text)
+ (goto-char beg)
+ (unless (eq (car (org-element-at-point)) 'plain-list)
+ (outline-previous-heading))
+ (org-update-checkbox-count-maybe)
+ (message "Deleted %s item(s)" deleted-count))))
(defmacro km/org--save-pos-on-sort (&rest body)
"Try to return to the orginal position after sorting.