Source

emacs / config-org.org

  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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
#+TITLE: Config for Org
#+OPTIONS: toc:nil num:nil ^:nil

* Org Config
Configuration for the eminently useful [[http://orgmode.org/][Org Mode]].

Org-mode is for keeping notes, maintaining ToDo lists, doing project
planning, and authoring with a fast and effective plain-text system.
Org Mode can be used as a very simple folding outliner or as a complex
GTD system or tool for reproducible research and literate programming.

For more information on org-mode check out [[http://orgmode.org/worg/][worg]], a large Org-mode wiki
which is also *implemented using* Org-mode and [[http://git-scm.com/][git]].

** Helpful Packages
   :PROPERTIES:
   :ID:       63C73386-FBC7-425C-9AEB-0C54C61429F7
   :END:
#+begin_src emacs-lisp
  (require 'org-install)
  (require 'org-babel-ruby)      ;; requires ruby, irb, ruby-mode, and inf-ruby
  (require 'org-babel-python)    ;; requires python, and python-mode
  (require 'org-babel-clojure)   ;; requires clojure, clojure-mode, swank-clojure and slime
  (if window-system (require 'org-mouse))
#+end_src

** Org-Mode Hook
   :PROPERTIES:
   :ID:       950F795A-F1B7-49C3-A75B-7F9824D09D23
   :END:
The latest version of yasnippets doesn't play well with Org-mode, the
following function allows these two to play nicely together
#+begin_src emacs-lisp
  (defun yas/org-very-safe-expand ()
    (let ((yas/fallback-behavior 'return-nil)) (yas/expand)))
#+end_src

#+begin_src emacs-lisp
  (add-hook 'org-mode-hook
            (lambda ()
              (local-set-key "\M-\C-n" 'outline-next-visible-heading)
              (local-set-key "\M-\C-p" 'outline-previous-visible-heading)
              (local-set-key "\M-\C-u" 'outline-up-heading)
              ;; table
              (local-set-key "\M-\C-w" 'org-table-copy-region)
              (local-set-key "\M-\C-y" 'org-table-paste-rectangle)
              (local-set-key "\M-\C-l" 'org-table-sort-lines)
              ;; display images
              (local-set-key "\M-I" 'org-toggle-iimage-in-org)
              ;; yasnippet (using the new org-cycle hooks)
              (make-variable-buffer-local 'yas/trigger-key)
              (setq yas/trigger-key [tab])
              (add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand)
              (define-key yas/keymap [tab] 'yas/next-field)
              ))
#+end_src

** Support for viewing images
   :PROPERTIES:
   :ID:       1DAC3FAB-C8B6-4C16-967A-3F7BF74BA0F9
   :END:
This allows for the viewing of images in-line in Org-mode documents.

#+begin_src emacs-lisp
  (require 'iimage)
  (setq iimage-mode-image-search-path (expand-file-name "~/"))
  ;; Match org file: links
  (add-to-list 'iimage-mode-image-regex-alist
               (cons (concat "\\[\\[file:\\(~?" iimage-mode-image-filename-regex
                             "\\)\\]")  1))
  (defun org-toggle-iimage-in-org ()
    (interactive)
    (let ((turning-on (not iimage-mode)))
      (set-face-underline-p 'org-link (not turning-on))
      (iimage-mode (or turning-on 0))))
#+end_src

#+results:
: org-toggle-iimage-in-org
** Initializations
   :PROPERTIES:
   :ID:       197576A8-D39D-48D3-B2F2-EDAF2FBE56B4
   :END:
#+begin_src emacs-lisp
(setq org-directory "~/hgfiles/org/")
(add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
'(org-modules (quote (org-bbdb org-bibtex org-gnus org-info org-jsinfo org-habit org-irc org-mac-message org-mew org-mhe org-protocol org-rmail org-vm org-wl org-w3m)))
(require 'org-protocol)
(server-start)

#+end_src
** Agenda
   :PROPERTIES:
   :ID:       8F48A4C9-1786-4522-A675-49C5B2D0C799
   :END:
#+begin_src emacs-lisp
(setq org-agenda-files (quote ("~/hgfiles/org/client-projects.org"
                               "~/hgfiles/org/home-projects.org"
                               "~/hgfiles/org/studio-projects.org"
                               "~/hgfiles/org/notes.org"
                               "~/hgfiles/org/phone.org"
                               "~/hgfiles/org/inbox.org"
                               "~/hgfiles/org/mind.org")))

(defun gtd ()
   (interactive)
   (find-file "~/hgfiles/org/todo.org")
)

;; Custom Agendas
(setq org-agenda-custom-commands
      (quote (("s" "Started Tasks" todo "STARTED" ((org-agenda-todo-ignore-scheduled nil)
                                                   (org-agenda-todo-ignore-deadlines nil)
                                                   (org-agenda-todo-ignore-with-date nil)))
              ("w" "Tasks waiting on something" tags "WAITING/!" ((org-use-tag-inheritance nil)))
              ("r" "Refile New Notes and Tasks" tags "LEVEL=1+REFILE" ((org-agenda-todo-ignore-with-date nil)
                                                                       (org-agenda-todo-ignore-deadlines nil)
                                                                       (org-agenda-todo-ignore-scheduled nil)))
              ("N" "Notes" tags "NOTE" nil)
              ("n" "Next" tags "NEXT-WAITING-CANCELLED/!" nil)
              ("p" "Projects" tags-todo "LEVEL=2-NEXT-WAITING-CANCELLED/!-DONE" nil)
              ("A" "Tasks to be Archived" tags "LEVEL=2/DONE|CANCELLED" nil)
              ("h" "Habits" tags "STYLE=\"habit\"" ((org-agenda-todo-ignore-with-date nil) (org-agenda-todo-ignore-scheduled nil) (org-agenda-todo-ignore-deadlines nil))))))


;; Keep tasks with dates off the global todo lists
(setq org-agenda-todo-ignore-with-date t)

;; Remove completed deadline tasks from the agenda view
(setq org-agenda-skip-deadline-if-done t)

;; Remove completed scheduled tasks from the agenda view
(setq org-agenda-skip-scheduled-if-done t)


;; Show all future entries for repeating tasks
(setq org-agenda-repeating-timestamp-show-all t)

;; Show all agenda dates - even if they are empty
(setq org-agenda-show-all-dates t)

;; Sorting order for tasks on the agenda
(setq org-agenda-sorting-strategy
      (quote ((agenda time-up priority-down effort-up category-up)
              (todo priority-down)
              (tags priority-down))))

;; Start the weekly agenda today
(setq org-agenda-start-on-weekday nil)

;; Disable display of the time grid
(setq org-agenda-time-grid
      (quote (nil "----------------"
                  (800 1000 1200 1400 1600 1800 2000))))
#+end_src
** Key Bindings
   :PROPERTIES:
   :ID:       1E9E8D38-9D3B-4936-A33A-30834022C9CB
   :END:
#+begin_src emacs-lisp
;; Standard key bindings
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)

;; Custom Key Bindings
(global-set-key (kbd "<f12>") 'org-agenda)
(global-set-key (kbd "<f5>") 'my-org-todo)
(global-set-key (kbd "<S-f5>") 'widen)
(global-set-key (kbd "<f7>") 'set-truncate-lines)
(global-set-key (kbd "<f8>") 'org-cycle-agenda-files)
(global-set-key (kbd "<f9> b") 'bbdb)
(global-set-key (kbd "<f9> c") 'calendar)
(global-set-key (kbd "<f9> f") 'boxquote-insert-file)
(global-set-key (kbd "<f9> g") 'gnus)
(global-set-key (kbd "<f9> o") 'org-occur)
(global-set-key (kbd "<f9> r") 'boxquote-region)
(global-set-key (kbd "<f9> u") (lambda ()
                                 (interactive)
                                 (untabify (point-min) (point-max))))
(global-set-key (kbd "<f9> v") 'visible-mode)
(global-set-key (kbd "C-<f9>") 'previous-buffer)
(global-set-key (kbd "C-x n r") 'narrow-to-region)
(global-set-key (kbd "C-<f10>") 'next-buffer)
(global-set-key (kbd "<f11>") 'org-clock-goto)
(global-set-key (kbd "C-s-<f12>") 'my-save-then-publish)
#+end_src
** Drawers, Tags and Todos
   :PROPERTIES:
   :ID:       65B96A8C-04BA-413E-81B6-5358C7ADB58E
   :END:
#+begin_src emacs-lisp
(setq org-drawers (quote ("PROPERTIES" "CLOCK" "LOGBOOK" "NOTES" "COMMENTS" "LINKS")))

(setq org-todo-keywords (quote ((sequence "TODO(t)" "STARTED(s)" "|" "DONE(d!/!)")
 (sequence "WAITING(w@/!)" "SOMEDAY(S!)" "PROJECT(P@)" "OPEN(O@)" "|" "CANCELLED(c@/!)")
 (sequence "QUOTE(q!)" "QUOTED(Q!)" "|" "APPROVED(A@)" "EXPIRED(E@)" "REJECTED(R@)"))))

(setq org-todo-keyword-faces (quote (("TODO" :foreground "red" :weight bold)
 ("STARTED" :foreground "blue" :weight bold)
 ("DONE" :foreground "forest green" :weight bold)
 ("WAITING" :foreground "orange" :weight bold)
 ("SOMEDAY" :foreground "magenta" :weight bold)
 ("CANCELLED" :foreground "forest green" :weight bold)
 ("PROJECT" :foreground "red" :weight bold))))


(setq org-use-fast-todo-selection t)

(setq org-todo-state-tags-triggers
      (quote (("CANCELLED" ("CANCELLED" . t))
              ("WAITING" ("WAITING" . t) ("NEXT"))
              ("SOMEDAY" ("WAITING" . t))
              (done ("NEXT") ("WAITING"))
              ("TODO" ("WAITING") ("CANCELLED"))
              ("STARTED" ("WAITING"))
              ("PROJECT" ("CANCELLED") ("PROJECT" . t)))))

; Tags with fast selection keys
(setq org-tag-alist (quote ((:startgroup)
                            ("@Errand" . ?e)
                            ("@Work" . ?w)
                            ("@Home" . ?h)
                            ("@Phone" . ?p)
                            ("@Mind" . ?m)
                            ("@Studio" . ?s)
                            (:endgroup)
                            ("NEXT" . ?N)
                            ("PROJECT" . ?P)
                            ("WAITING" . ?W)
                            ("HOME" . ?H)
                            ("ORG" . ?O)
                            ("PLAY" . ?p)
                            ("R&D" . ?r)
                            ("MIND" . ?m)
                            ("STUDIO" . ?S)
                            ("CANCELLED" . ?C))))


; Allow setting single tags without the menu
(setq org-fast-tag-selection-single-key (quote expert))

; For tag searches ignore tasks with scheduled and deadline dates
(setq org-agenda-tags-todo-honor-ignore-options t)
#+end_src
** Clocking
   :PROPERTIES:
   :ID:       5A25A146-E856-4806-9A8F-344664093FDA
   :END:
#+begin_src emacs-lisp
;; Resume clocking tasks when emacs is restarted
(setq org-clock-persistence-insinuate)
;;
;; resolve idle time for clocks
(setq org-clock-idle-time 5)
;; Yes it's long... but more is better ;)
(setq org-clock-history-length 35)
;; Resume clocking task on clock-in if the clock is open
(setq org-clock-in-resume t)
;; Change task state to STARTED when clocking in
(setq org-clock-in-switch-to-state "STARTED")
;; Save clock data and notes in the LOGBOOK drawer
(setq org-clock-into-drawer t)
;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
(setq org-clock-out-remove-zero-time-clocks t)
;; Don't clock out when moving task to a done state
(setq org-clock-out-when-done nil)
;; Save the running clock and all clock history when exiting Emacs, load it on startup
(setq org-clock-persist t)
;; Agenda clock report parameters (no links, 2 levels deep)
(setq org-agenda-clockreport-parameter-plist (quote (:link nil :maxlevel 2)))
; Set default column view headings: Task Effort Clock_Summary
(setq org-columns-default-format "%80ITEM(Task) %10Effort(Effort){:} %10CLOCKSUM")
; global Effort estimate values
(setq org-global-properties (quote (("Effort_ALL" . "0:15 0:30 1:00 2:00 3:00 4:00 5:00 6:00 8:00"))))
(add-hook 'org-clock-in-prepare-hook 
          'my-org-mode-ask-effort)

; use org-clock-in-prepare-hook to add an effort estimate. 
; This way you can easily have a "tea-timer" for your tasks when they don't 
; already have an effort estimate.
(defun my-org-mode-ask-effort ()
  "Ask for an effort estimate when clocking in."
  (unless (org-entry-get (point) "Effort")
    (let ((effort 
           (completing-read 
            "Effort: "
            (org-entry-get-multivalued-property (point) "Effort"))))
      (unless (equal effort "")
        (org-set-property "Effort" effort)))))
#+end_src
** Reminder Config
   :PROPERTIES:
   :ID:       A7EA5F17-C05F-4A1E-A054-5A0815D03584
   :END:
#+begin_src emacs-lisp
;;
;; REMINDERS
;;
; Erase all reminders and rebuilt reminders for today from the agenda
(defun bh/org-agenda-to-appt ()
  (interactive)
  (setq appt-time-msg-list nil)
  (org-agenda-to-appt))

; Rebuild the reminders everytime the agenda is displayed
(add-hook 'org-finalize-agenda-hook 'bh/org-agenda-to-appt)

; This is at the end of my .emacs - so appointments are set up when Emacs starts
(bh/org-agenda-to-appt)

; Activate appointments so we get notifications
(appt-activate t)

; If we leave Emacs running overnight - reset the appointments one minute after midnight
(run-at-time "24:01" nil 'bh/org-agenda-to-appt)
#+end_src
** Remember
   :PROPERTIES:
   :ID:       97E037A4-0DAC-44BD-BB96-EBD47D6B770E
   :END:
#+begin_src emacs-lisp
(org-remember-insinuate)
     (setq org-directory "~/hgfiles/org/")
     (setq org-default-notes-file (concat org-directory "/notes.org"))
     (define-key global-map "\C-cr" 'org-remember)

;; Start clock if a remember buffer includes :CLOCK-IN:
(add-hook 'remember-mode-hook 'my-start-clock-if-needed 'append)


(defun my-start-clock-if-needed ()
  (save-excursion
    (goto-char (point-min))
    (when (re-search-forward " *:CLOCK-IN: *" nil t)
      (replace-match "")
      (org-clock-in))))


;; I use C-M-r to start org-remember
(global-set-key (kbd "C-M-r") 'org-remember)

;; Keep clocks running
(setq org-remember-clock-out-on-exit nil)

;; C-c C-c stores the note immediately
(setq org-remember-store-without-prompt t)

;; I don't use this -- but set it in case I forget to specify a location in a future template
(setq org-remember-default-headline "Tasks")

;; 3 remember templates for TODO tasks, Notes, and Phone calls
(setq org-remember-templates (quote (("todo" ?t "* TODO %?
  %u
  %a" "~/hgfiles/org/tasks.org" bottom nil)
                                     ("note" ?n "* %?                                      :NOTE:
  %u
  %a" nil bottom nil)
                                     ("phone" ?p "* PHONE %:name - %:company -                :PHONE:
  Contact Info: %a
  %u
  :CLOCK-IN:
  %?" "~/hgfiles/org/phone.org" bottom nil))))

#+end_src
** Refiles
#+begin_src
; Use IDO for target completion
(setq org-completion-use-ido t)

; Targets include this file and any file contributing to the agenda - up to 5 levels deep
(setq org-refile-targets (quote ((org-agenda-files :maxlevel . 5) (nil :maxlevel . 5))))

; Targets start with the file name - allows creating level 1 tasks
(setq org-refile-use-outline-path (quote file))
#+end_src
** Warning and Save hooks
   :PROPERTIES:
   :ID:       029D4F32-A7FC-430B-832C-8E6210E30990
   :END:
#+begin_src emacs-lisp
;; set appt waring to 15 minutes prior to appointment
(setq appt-message-warning-time 15)
;; save all org files every minute
(run-at-time "00:59" 3600 'org-save-all-org-buffers)
#+end_src
** Speed Commands
   :PROPERTIES:
   :ID:       8DD978AB-F815-4318-8287-CFB2669531E9
   :END:
#+begin_src emacs-lisp
;; set speed commands
(setq org-use-speed-commands t)
#+end_src
** Growl Config
   :PROPERTIES:
   :ID:       D382B7F1-FB5C-40DA-9667-F9D651D745DB
   :END:
   Growl support is provided by todochiku
#+begin_src emacs-lisp
;; use todochiku for growl notifications of events
(setq org-show-notification-handler
  '(lambda (notification)
    (todochiku-message "org-mode notification" notification
      (todochiku-icon 'emacs))))
#+end_src
** Mobile Org
   :PROPERTIES:
   :ID:       96F9B111-BF35-4266-BDEA-B9296C98EB3A
   :END:
#+begin_src emacs-lisp
;; MOBILE ORG
(require 'org-mobile)

(setq org-mobile-directory "/Volumes/busyashell/stage/") 
(setq org-mobile-inbox-for-pull "~/hgfiles/org/inbox.org")

;; after save push to mobile stage dir
(run-at-time "00:59" 3600 'org-mobile-push)
;(add-hook 'after-save-hook 'org-mobile-push)
#+end_src
** Journaling
   :PROPERTIES:
   :ID:       3F4C1BE8-EC73-423A-B7B4-EA57520AC0E8
   :END:
#+begin_src emacs-lisp
;; journaling hack taken from
;; http://metajack.im/2009/01/01/journaling-with-emacs-orgmode/
(defvar org-journal-file "~/hgfiles/org/journal.org"
  "Path to OrgMode journal file.")
(defvar org-journal-date-format "%Y-%m-%d"
  "Date format string for journal headings.")

(defun org-journal-entry ()
  "Create a new diary entry for today or append to an existing one."
  (interactive)
  (switch-to-buffer (find-file org-journal-file))
  (widen)
  (let ((today (format-time-string org-journal-date-format)))
    (beginning-of-buffer)
    (unless (org-goto-local-search-headings today nil t)
      ((lambda () 
         (org-insert-heading)
         (insert today)
         (insert "\n\n  \n"))))
    (beginning-of-buffer)
    (org-show-entry)
    (org-narrow-to-subtree)
    (end-of-buffer)
    (backward-char 2)
    (unless (= (current-column) 2)
      (insert "\n\n  "))))

(global-set-key (kbd "C-c j") 'org-journal-entry)
#+end_src

** Miscellaneous configs for org
   :PROPERTIES:
   :ID:       66F87B91-FB52-4373-8998-7104A11F4B2B
   :END:
#+begin_src emacs-lisp
(setq org-todo-keyword-faces
     '(("SDMB" . cd-org-someday-kwd-face)
       ("STARTED" . cd-org-started-kwd-face)
       ("STRT" . cd-org-started-kwd-face)
       ("WAITING" . cd-org-waiting-kwd-face)
       ("WAIT" . cd-org-waiting-kwd-face)
       ("DELG" . cd-org-delegated-kwd-face)
       ("PROJ" . cd-org-project-kwd-face)
       ("DONE" . cd-org-done-kwd-face)
       ("PRDN" . cd-org-done-kwd-face)
       ("PRCL" . cd-org-cancelled-kwd-face)
       ("CNCL" . cd-org-cancelled-kwd-face)
       ("PRCN" . cd-org-cancelled-kwd-face)
       ("TODO" . cd-org-todo-kwd-face)
       ("SELECTED" . cd-org-todo-kwd-face)
       ("INVITED" . cd-org-waiting-kwd-face)
       ("SCHEDULED" . cd-org-done-kwd-face)
       ("DECLINED" . cd-org-cancelled-kwd-face)))

(defun my-custom-handler (data)
  (let ((content (org-protocol-split-data data t)))
    (delete-other-windows)
    (sit-for 2)
    (animate-sequence content 2))
  nil)

(setq org-protocol-protocol-alist
      '(("Screencast goodie"
         :protocol "screencast"
         :function my-custom-handler)))

; generate unique attachment id's
(setq org-id-method (quote uuidgen))
; copy org attachments
(setq org-attach-method 'cp)
; set copy directory
(setq org-attach-directory "~/hgfiles/org/data")
; underline the line in the agenda that you are on
(add-hook 'org-agenda-mode-hook '(lambda () (hl-line-mode 1)))

;; NARROW THE VIEW TO A SUBTREE
(global-set-key (kbd "<f5>") 'my-org-todo)

(defun my-org-todo ()
  (interactive)
  (org-narrow-to-subtree)
  (org-show-todo-tree nil)
  (widen))

(load "~/.emacs.d/src/org-mode/contrib/lisp/org-checklist")
;; to use it in a task you simply set the property RESET_CHECK_BOXES to t like this

;; set org indent
;(setq org-indent-mode t)
#+end_src