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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
(require 'fcuny-vars)
(use-package dash
:ensure t)
(use-package org
:ensure t
:after (dash)
:hook ((org-mode . org-indent-mode)
(org-mode . visual-line-mode)
(org-mode . org-hide-block-all))
:bind (("C-c c" . org-capture)
("C-c a" . org-agenda)
("C-c o" . hydra-org-menu/body))
:config
(progn ()
(org-babel-do-load-languages
'org-babel-load-languages
'((shell . t)
(python . t)
(emacs-lisp . t))))
(defhydra hydra-org-menu (:hint nil)
"
^go to ^ ^action ^
^-------------------^ ^---------------^
_g i_: go to inbox _s_: save files
_g p_: go to personal
_g w_: go to work
_g n_: go to notes
"
("g i" (find-file-other-window org-default-inbox-file))
("g p" (find-file-other-window org-default-tasks-file))
("g w" (find-file-other-window org-default-work-tasks-file))
("g n" (find-file-other-window org-default-work-notes-file))
("s" (org-save-all-org-buffers)))
:custom
(org-id-locations-file (concat fcuny/path-emacs-var "/org-id-locations"))
(org-directory (expand-file-name "~/Documents/notebooks"))
(org-default-tasks-file (concat org-directory "/tasks.org"))
(org-default-journal-file (concat org-directory "/journal.org"))
(org-default-notes-file (concat org-directory "/notes.org"))
(org-default-work-tasks-file (concat org-directory "/work-tasks.org"))
(org-default-work-journal-file (concat org-directory "/work-journal.org"))
(org-default-work-notes-file (concat org-directory "/work-notes.org"))
(org-default-inbox-file (concat org-directory "/inbox.org"))
;; cosmetic
(org-pretty-entities t)
(org-startup-indented nil)
(org-blank-before-new-entry nil)
;;
(org-log-done 'time)
;; look
(org-agenda-window-setup 'current-window)
;; priorities
(org-priority-start-cycle-with-default nil) ;; Start one over/under default value.
(org-lowest-priority ?F)
(org-default-priority ?D) ;; Ensures unset tasks have low priority.
;; how to manage tasks
(org-todo-keywords '((sequence "TODO(t)" "STARTED(s)" "DELEGATED(D)" "|" "DONE(d)")
(sequence "SOMEDAY" "|" "CANCELED(c)")))
;; agenda related
(calendar-week-start-day 1) ;; org-mode uses calendar for the date picker, and I want this to start on Monday
(org-agenda-start-on-weekday 1) ;; this is specific to org-agenda
(org-agenda-span 10)
(org-agenda-start-day "-7d")
(org-agenda-files `(,org-default-tasks-file
,org-default-work-tasks-file))
;; org babel related
;; prevent the conversion of spaces into tabs (necessary for Python code exports)
(org-src-fontify-natively t)
(org-fontify-done-headline t)
(org-src-preserve-indentation t)
(org-edit-src-content-indentation t)
;; behavior
;; I want to follow links on RET
(org-return-follows-link t)
(org-enforce-todo-dependencies t)
(org-export-with-toc nil)
(org-export-with-section-numbers nil)
;; A few abbreviations I use regularly
(org-link-abbrev-alist
'(("src" . "~/workspace/%s")
("jira" . "https://jira.twitter.biz/browse/%s")
("ph" . "https://phabricator.twitter.biz/%s")
("go" . "http://go/%s")))
;; entries
(org-blank-before-new-entry (quote ((heading . nil)
(plain-list-item . nil))))
;; see https://github.com/abo-abo/swiper/issues/986
(org-goto-interface 'outline-path-completion)
;; refile and capture
(org-refile-use-outline-path 'file)
(org-outline-path-complete-in-steps nil)
(org-refile-allow-creating-parent-nodes 'confirm)
(org-refile-targets (quote ((org-default-tasks-file :level . 0)
(org-default-work-tasks-file :level . 0)
(org-default-notes-file :level . 0)
(org-default-work-notes-file :level . 0))))
(org-reverse-note-order t)
(org-capture-templates
`(("t" "Add task" entry
(file ,org-default-inbox-file)
"* TODO [#C] %?\n:PROPERTIES:\n:ID: %(shell-command-to-string \"uuidgen\"):CREATED: %U\n:END:\n")
("n" "Note" entry
(file ,org-default-inbox-file)
"* %?\n:PROPERTIES:\n:ID: %(shell-command-to-string \"uuidgen\"):CREATED: %U\n:END:\n")
("j" "Journal" entry
(file+olp+datetree ,org-default-journal-file)
"* %?\n:PROPERTIES:\n:ID: %(shell-command-to-string \"uuidgen\"):CREATED: %U\n:END:\n" :tree-type month :unnarrowed t)
("m" "Meeting notes" entry
(file ,org-default-inbox-file)
"* %? %^g:meeting:\n:PROPERTIES:\n:ID: %(shell-command-to-string \"uuidgen\"):CREATED: %U\n:END:\n")
("i" "Interview notes" entry
(file ,org-default-inbox-file)
(file ,(concat fcuny/path-emacs-etc "/interview.org")))
("J" "Work Journal" entry
(file+olp+datetree ,org-default-work-journal-file)
"* %?\n:PROPERTIES:\n:ID: %(shell-command-to-string \"uuidgen\"):CREATED: %U\n:END:\n" :tree-type month :unnarrowed t))))
(use-package htmlize
:ensure t)
;; can't use it for now, my version of org is too old
;(use-package orgit
; :ensure t)
(defun fcuny/org-todo-age-time (&optional pos)
(let ((stamp (org-entry-get (or pos (point)) "CREATED" t)))
(when stamp
(time-subtract (current-time)
(org-time-string-to-time
(org-entry-get (or pos (point)) "CREATED" t))))))
(defun fcuny/org-todo-age (&optional pos)
(let ((days (time-to-number-of-days (fcuny/org-todo-age-time pos))))
(cond
((< days 1) "today")
((< days 7) (format "%dd" days))
((< days 30) (format "%.1fw" (/ days 7.0)))
((< days 358) (format "%.1fM" (/ days 30.0)))
(t (format "%.1fY" (/ days 365.0))))))
(defun fcuny/org-refile-to-datetree (&optional file)
"Refile current subtree to a datetree in FILE corresponding to it's timestamp.
The current time is used if the entry has no timestamp. If FILE
is nil, refile in the current file."
(interactive)
(require 'org-datetree)
(let* ((file (cond
(file (find-file-noselect file))
(t (current-buffer))))
(datetree-date (or (org-entry-get nil "CREATED" t)
(org-read-date t nil "now")))
(date (org-date-to-gregorian datetree-date)))
(org-refile nil nil (list nil (buffer-file-name file) nil
(with-current-buffer file
(save-excursion
(org-datetree-find-date-create date)
(point)))))))
(defun fcuny/org-refile-to-work-journal ()
"Refile current subtree to a datetree in work journal corresponding to it's timestamp.
The current time is used if the entry has no timestamp."
(interactive)
(fcuny/org-refile-to-datetree org-default-work-journal-file))
(defun fcuny/org-subtree-region ()
"Return a list of the start and end of a subtree."
(save-excursion
(list (progn (org-back-to-heading) (point))
(progn (org-end-of-subtree) (point)))))
(defun fcuny/org-refile-directly (file-dest)
"Move the current subtree to the end of FILE-DEST.
If SHOW-AFTER is non-nil, show the destination window,
otherwise, this destination buffer is not shown."
(interactive "fDestination: ")
(defun dump-it (file contents)
(find-file-other-window file-dest)
(goto-char (point-max))
(insert "\n" contents))
(save-excursion
(let* ((region (fcuny/org-subtree-region))
(contents (buffer-substring (first region) (second region))))
(apply 'kill-region region)
(save-window-excursion (dump-it file-dest contents)))))
(provide 'fcuny-org)
|