summaryrefslogtreecommitdiffstats
path: root/.emacs.d/site-lisp/org-init.el
blob: 6c2720b9e0d7714f57bb82fb221f91b2c73d737d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
;;; org-init.el --- Org initialization

;; Copyright (C) 2012  Tom Willemse

;; Author: Tom Willemse <slash@drd>
;; Keywords:

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;;

;;; Code:

(require 'appt)
(require 'org-habit)
(require 'org-protocol)

(eval-after-load "org"
  '(require 'org-contacts))

(eval-when-compile
  (require 'desktop)
  (require 'org-capture))

(autoload 'org-clocking-p "org-clock")

(eval-after-load "org-crypt"
  '(org-crypt-use-before-save-magic))

(defun tagify (str)
  "Remove dots, replace - with _ in STR."
  (replace-regexp-in-string
   "-" "_" (replace-regexp-in-string "\\." "" (downcase str))))

(defun filter-by-agenda (entry)
  "Return ENTRY if it has no tags or a tag corresponding to the desktop."
  (require 'desktop)
  (let ((label (when desktop-dirname
                 (tagify (file-name-base
                          (directory-file-name
                           (expand-file-name desktop-dirname))))))
        (tags (get-text-property 0 'tags entry)))
    (when (or (null desktop-dirname) (null tags) (member label tags))
      entry)))

(defun oni:note-template ()
  (concat
   "* %<%c>\n"
   "  :DIRECTORY: =" default-directory "=\n"
   (when (buffer-file-name) "  :FILE: [[file:%F][%F]]\n")
   (when (org-clocking-p) "  :TASK: %K\n")
   "\n  %?"))

(defun oni:org-maybe-outline-path ()
  (let ((outline-path (org-format-outline-path (org-get-outline-path))))
    (unless (string= outline-path "")
      (setq outline-path (concat "[ " outline-path " ] ")))
    outline-path))

(defun org-init-filter-by-desktop ()
  "Filter agenda by current label."
  (when desktop-dirname
    (let ((label (tagify (file-name-base
                          (directory-file-name
                           (expand-file-name desktop-dirname))))))
      (org-agenda-filter-apply (cons label nil) 'tag))))

(setq org-agenda-files '("~/documents/org/tasks"))

;; (setq org-agenda-before-sorting-filter-function #'filter-by-agenda)
(setq org-agenda-cmp-user-defined (lambda (a b) 1))
(setq org-agenda-prefix-format
      '((agenda . " %i %-12:c%?-12t% s")
        (timeline . "  % s")
        (todo . " %i %-12:c %(oni:org-maybe-outline-path)")
        (tags . " %i %-12:c %(oni:org-maybe-outline-path)")
        (search . " %i %-12:c")))
(setq org-agenda-sorting-strategy
      '((agenda habit-down time-up priority-down category-keep)
        (todo priority-down user-defined-down)
        (tags priority-down category-keep)
        (search category-keep)))
(setq org-agenda-tags-column (1+ (- (window-width))))
(setq org-directory (expand-file-name "~/documents/org"))
(setq org-default-notes-file (concat org-directory "/org"))
(setq org-capture-templates
      `(("t" "Task" entry (file "~/documents/org/tasks")
         "* TODO %?  %(let ((dname (desktop-registry-current-desktop)))
                        (if dname
                            (concat \":\" dname \":\")
                          \"\"))")
        ("T" "Linked task" entry (file "~/documents/org/tasks")
         "* TODO %?  %(let ((dname (desktop-registry-current-desktop)))
                        (if dname
                            (concat \":\" dname \":\")
                          \"\"))\n\n  %a")
        ("a" "Appointment" entry (file "~/documents/org/tasks")
         "* %?\n  %^T\n\n  %a")
        ("n" "General note" entry (file ,org-default-notes-file)
         (function oni:note-template))))
(setq org-contacts-files '("~/documents/org/misc/contacts.org"))
(setq org-agenda-show-outline-path nil)
(setq org-agenda-todo-ignore-deadlines 'far)
(setq org-agenda-todo-ignore-scheduled t)
(setq org-export-htmlize-output-type 'css)
(setq org-feed-alist
      '(("MyEpisodes"
         "http://www.myepisodes.com/rss.php?feed=mylist&uid=Slash&pwdmd5=04028968e1f0b7ee678b748a4320ac17"
         "~/documents/org/tasks" "MyEpisodes"
         :formatter oni:myepisodes-formatter)))
(setq org-fontify-done-headline t)
(setq org-hide-emphasis-markers t)
(setq org-outline-path-complete-in-steps t)
(setq org-refile-allow-creating-parent-nodes t)
(setq org-refile-use-outline-path 'file)
(setq org-return-follows-link t)
(setq org-src-fontify-natively t)
(setq org-tags-column (- 70))
(setq org-tags-exclude-from-inheritance '("crypt"))
(setq org-todo-keyword-faces
      '(("TODO"        :foreground "#ff756e" :background "#171719" :box (:width 1 :color "#282830"))
        ("DONE"        :foreground "#9ad870" :background "#222224" :box (:width 1 :color "#333335"))
        ("SUCCEEDED"   :foreground "#9ad870" :background "#222224" :box (:width 1 :color "#333335"))
        ("WAITING"     :foreground "#ffbb56" :background "#171719" :box (:width 1 :color "#282830"))
        ("CANCELLED"   :foreground "#93d8d8" :background "#222224" :box (:width 1 :color "#333335"))
        ("FAILED"      :foreground "#93d8d8" :background "#222224" :box (:width 1 :color "#333335"))
        ("WIP"         :foreground "#ff756e" :background "#171719" :box (:width 1 :color "#282830"))
        ("HOLD"        :foreground "#ffbb56" :background "#171719" :box (:width 1 :color "#282830"))
        ("ACQUIRE"     :foreground "#ff756e" :background "#171719" :box (:width 1 :color "#282830"))
        ("IGNORED"     :foreground "#999999" :background "#222224" :box (:width 1 :color "#333335"))
        ("COMMENT"     :foreground "#969696" :background "#3d3d3d" :box (:line-width 2 :color "#3d3d3d"))))
(setq org-use-fast-todo-selection t)
(setq org-agenda-skip-function-global 'oni:skip-ex-tag)
(setq org-use-property-inheritance '("slug"))

(add-hook 'org-agenda-mode-hook 'org-agenda-to-appt)
(add-hook 'org-agenda-finalize-hook 'org-init-filter-by-desktop)

(add-to-list 'org-modules 'habit)

(org-agenda-to-appt)
(ad-activate 'org-agenda-redo)

(provide 'org-init)
;;; org-init.el ends here