tweak org stuff, more helm-org-habits work.

This commit is contained in:
Ivan Malison 2014-12-05 15:05:18 -08:00
parent cb6c99d501
commit 9a5948c540
2 changed files with 31 additions and 10 deletions

23
init.el
View File

@ -160,7 +160,26 @@
(let ((org-todo-log-states (let ((org-todo-log-states
(mapcar (lambda (state) (mapcar (lambda (state)
(list state 'note 'time)) (list state 'note 'time))
(apply 'append org-todo-sets)))))) (apply 'append org-todo-sets))))
(cond ((eq major-mode 'org-mode) (org-todo))
((eq major-mode 'org-agenda-mode) (org-agenda-todo)))))
(defun org-todo-force-notes ()
(interactive)
(let ((org-todo-log-states
(mapcar (lambda (state)
(list state 'note 'time))
(apply 'append org-todo-sets))))
(org-todo)
))
(defun org-agenda-todo-force-notes ()
(interactive)
(let ((org-todo-log-states
(mapcar (lambda (state)
(list state 'note 'time))
(apply 'append org-todo-sets))))
(org-agenda-todo)))
(defun org-todo-no-note () (defun org-todo-no-note ()
(interactive) (interactive)
@ -589,7 +608,7 @@ The current directory is assumed to be the project's root otherwise."
:config :config
(progn (progn
(setq org-habit-graph-column 50) (setq org-habit-graph-column 50)
(setq org-habit-show-habits-only-for-today nil) (setq org-habit-show-habits-only-for-today t)
(unless (boundp 'org-gtd-file) (unless (boundp 'org-gtd-file)
(defvar org-gtd-file "~/org/gtd.org")) (defvar org-gtd-file "~/org/gtd.org"))
(unless (boundp 'org-habits-file) (unless (boundp 'org-habits-file)

View File

@ -2,7 +2,6 @@
(interactive) (interactive)
(helm :sources (helm-source-org-headlines-for-files org-agenda-files))) (helm :sources (helm-source-org-headlines-for-files org-agenda-files)))
(defun helm-org-goto-marker (marker) (defun helm-org-goto-marker (marker)
(switch-to-buffer (marker-buffer marker)) (switch-to-buffer (marker-buffer marker))
(goto-char (marker-position marker)) (goto-char (marker-position marker))
@ -13,7 +12,7 @@
(unless min-depth (setq min-depth 1)) (unless min-depth (setq min-depth 1))
(unless max-depth (setq max-depth 8)) (unless max-depth (setq max-depth 8))
(helm-build-sync-source "Org Headlines" (helm-build-sync-source "Org Headlines"
:candidates (helm-org-get-candidates filenames) :candidates (helm-org-get-candidates filenames min-depth max-depth)
:action 'helm-org-goto-marker :action 'helm-org-goto-marker
:action-transformer :action-transformer
(lambda (actions candidate) (lambda (actions candidate)
@ -25,22 +24,25 @@
(defun helm-org-headline-refile (marker) (defun helm-org-headline-refile (marker)
(with-helm-current-buffer (with-helm-current-buffer
(org-cut-subtree)) (org-cut-subtree))
(helm-org-goto-marker marker) (let ((target-level (with-current-buffer (marker-buffer marker)
(goto-char (marker-position marker)) (goto-char (marker-position marker))
(let (destination-level (org-current-level)) (org-current-level))))
(helm-org-goto-marker marker)
(org-end-of-subtree t t) (org-end-of-subtree t t)
(org-paste-subtree (+ destination-level 1)))) (org-paste-subtree (+ target-level 1))))
(defun helm-org-get-candidates (filenames) (defun helm-org-get-candidates (filenames min-depth max-depth)
(-flatten (-flatten
(mapcar (lambda (filename) (mapcar (lambda (filename)
(helm-get-org-candidates-in-file (helm-get-org-candidates-in-file
filename min-depth max-depth)) filename min-depth max-depth))
org-agenda-files))) filenames)))
(defun helm-get-org-candidates-in-file (filename min-depth max-depth) (defun helm-get-org-candidates-in-file (filename min-depth max-depth)
(with-current-buffer (find-file-noselect filename) (with-current-buffer (find-file-noselect filename)
(save-excursion (save-excursion
(beginning-of-buffer) (beginning-of-buffer)
(cl-loop while (re-search-forward org-complex-heading-regexp nil t) (cl-loop while (re-search-forward org-complex-heading-regexp nil t)
if (let ((num-stars (length (match-string-no-properties 1))))
(and (>= num-stars min-depth) (<= num-stars max-depth)))
collect `(,(match-string-no-properties 0) . ,(point-marker)))))) collect `(,(match-string-no-properties 0) . ,(point-marker))))))