-
Notifications
You must be signed in to change notification settings - Fork 5
/
org-mode-config.el
644 lines (566 loc) · 24.1 KB
/
org-mode-config.el
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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
;;; org-mode-config.el --- `org-mode' settings and customisations.
(require 'org)
(require 'org-tempo)
(require 'ox)
(require 'ox-ascii)
(require 'ox-latex)
(require 'ox-beamer)
(require 'ox-html)
(require 'ox-koma-letter)
(require 'ox-md)
;; (require 'ox-odt)
;; (require 'ox-groff)
;; (require 'ox-man) ; NB: customise org-man-pdf-process
;; (require 'ox-texinfo)
;; (require 'ox-publish)
;; links to notmuch emails in org
;; (require 'org-notmuch)
;; (require 'org-man)
(require 'org-occur-goto)
(require 'org-search-goto)
;; ;; Calendar view for org agenda
;; (require 'calfw)
;; (require 'calfw-org)
;; utilities
(require 'nifty)
;;; Code:
;; variable customisations (excluding export and templates)
(setq org-agenda-current-time-string "- - - NOW! - - -"
org-agenda-files '("~/org")
;; ;; List of extra files to be searched by text search commands.
;; org-agenda-text-search-extra-files
;; (append '(agenda-archives) ; archived agenda files
;; (sa-find-org-file-recursively "~/org/data-an" "org")
;; (sa-find-org-file-recursively "~/org/electronics" "org")
;; (sa-find-org-file-recursively "~/org/health-care" "org")
;; )
org-agenda-time-grid '((daily today)
"----------------"
(800 1000 1200 1400 1600 1800 2000))
;; reveal folded headline when trying to edit
org-catch-invisible-edits 'show
org-confirm-elisp-link-not-regexp "sa-.+"
;; Block parent TODOs if child is not completed
org-enforce-todo-dependencies t
org-export-dispatch-use-expert-ui t ; non-intrusive export dispatch
;; update TODO cookies recursively
;; use property, ":COOKIE_DATA: todo recursive"
;; to set this only for a single subtree
org-hierarchical-todo-statistics nil
;; open link in same window
org-link-frame-setup '((gnus . org-gnus-no-new-news)
(file . find-file))
;; custom links
org-link-abbrev-alist
'(("gmane" . "http://thread.gmane.org/%s")
("ddg" . "https://duckduckgo.com/?q=%s")
("bing" . "https://www.bing.com/search?q=%s")
("google" . "https://www.google.com/search?q=%s")
("arxiv" . "https://arxiv.org/abs/%s")
("cds" . "https://cds.cern.ch/record/%s")
("doi" . "https://dx.doi.org/%s"))
;; log time for TODO state changes
org-log-done 'time
;; log time on rescheduling and changing deadlines
org-log-reschedule 'time
org-log-redeadline 'time
;; To put notes inside LOGBOOK drawer
org-log-into-drawer t
org-refile-allow-creating-parent-nodes 'confirm
org-refile-targets '((org-agenda-files :maxlevel . 5))
org-refile-use-outline-path 'file
;; on links `RET' follows the link
org-return-follows-link t
org-reverse-note-order t
;; modifying behaviour of C-a/<home> & C-e/<end>
org-special-ctrl-a/e t
org-src-fontify-natively t
org-src-tab-acts-natively t
;; Note that using TODO keyword/tags list matches children tasks
org-stuck-projects '("+LEVEL=2&+SCHEDULED<\"<-1m>\"/!-DONE"
nil nil "^\\*\\+ \\+\\(DONE|FIXD|CNCL\\)")
org-todo-keywords ; @ - time stamp with note, ! - only time stamp
'((sequence "TODO(t)" "WInP(w!)" "DLAY(l@/!)" "|" "DONE(d!)" "CNCL(c@/!)")
;; (type "TEST(e!)" "DBUG(b@)" "LEAK(l@)" "SEGF(s@)" "|" "FIXD(f@/!)")
)
;; turn on speed keys for headlines
org-use-speed-commands t
)
;; easy templates special blocks in latex export
(add-to-list 'org-structure-template-alist '("f" . "figure"))
;;; Export customisations
(setq org-entities-user ; can also use "\ "
'(("space" "~" nil " " " " " " " "))
;; to circumvent reliance on Apache config, solution by Seb:
;; http://thread.gmane.org/gmane.emacs.orgmode/53856/focus=53875
org-html-xml-declaration
'(("html" . "<!-- <xml version=\"1.0\" encoding=\"utf-8\"> -->"))
org-latex-caption-above '(table)
org-latex-prefer-user-labels t
org-latex-remove-logfiles nil
org-latex-format-headline-function
'sa-org-latex-format-headline-function ; see below for definition
org-latex-table-scientific-notation "%s × 10\\(^\\text{%s}\\)"
;; convert exported odt to pdf with `soffice --convert-to pdf'
org-odt-preferred-output-format "pdf"
)
;;; ASCII export customisation for the new exporter
;; the markers for Latin is nicer, use for UTF-8 too
(setcdr (assoc 'utf-8 org-ascii-bullets) '(?§ ?¶))
;;; LaTeX export customisations (using XeLaTeX)
;; ;; hack for error free latex export with amsmath
;; ;; remove when defaults are changed in the future
;; (setcar (rassoc '("wasysym" t) org-latex-default-packages-alist)
;; "nointegrals")
;; remove "inputenc" from default packages as it clashes with xelatex
(setf org-latex-default-packages-alist
(remove '("AUTO" "inputenc" t) org-latex-default-packages-alist))
;; replace fontenc, with fontspec
(let ((pos (cl-position '("T1" "fontenc" t) ; T1 -> utf8 for pdflatex
org-latex-default-packages-alist
:test 'equal)))
(if pos
(setf (nth pos org-latex-default-packages-alist)
'("" "fontspec" t))))
;; (add-to-list 'org-latex-packages-alist '("" "fontspec" t (xelatex lualatex)) t)
(add-to-list 'org-latex-packages-alist '("" "microtype" nil) t)
(add-to-list 'org-latex-packages-alist '("" "libertine" t) t)
(add-to-list 'org-latex-packages-alist '("libertine" "newtxmath" t) t)
;; (add-to-list 'org-latex-packages-alist '("" "polyglossia" nil (xelatex lualatex)) t)
(add-to-list 'org-latex-packages-alist '("" "polyglossia" nil) t)
(add-to-list 'org-latex-packages-alist
"\\setdefaultlanguage[variant=british]{english}" t)
;; (add-to-list 'org-latex-packages-alist
;; '("backgroundcolor=green!40" "todonotes" nil) t)
(add-to-list 'org-latex-packages-alist '("" "makerobust" nil) t)
(add-to-list 'org-latex-packages-alist "\\MakeRobustCommand\\begin" t)
(add-to-list 'org-latex-packages-alist "\\MakeRobustCommand\\end" t)
(add-to-list 'org-latex-packages-alist "\\MakeRobustCommand\\item" t)
;; for code block export with minted.sty and python program pygmentize
(setq org-latex-listings 'minted)
;; (add-to-list 'org-latex-packages-alist '("" "minted"))
(setq org-latex-compiler "xelatex"
org-latex-bib-compiler "biber"
org-latex-pdf-process ; -shell-escape needed for minted
'("%latex -shell-escape -interaction nonstopmode -output-directory %o %f"
"%latex -shell-escape -interaction nonstopmode -output-directory %o %f"
"%latex -shell-escape -interaction nonstopmode -output-directory %o %f")
;; org-latex-pdf-process '("sh -v -x texi2dvi -p -b -c -V %f") ; historical
;; TODO: maybe use arara, that probably requires export changes
org-latex-default-class "scrartcl" ; was "article"
)
;; export single chapter
(add-to-list 'org-latex-classes
'("chapter" "\\documentclass[11pt]{report}"
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")))
(add-to-list 'org-latex-classes
'("titledblocks" "\\documentclass[11pt]{scrartcl}"
("\\paragraph{%s}" . "\\paragraph*{%s}")))
(add-to-list 'org-latex-classes
'("scrartcl" "\\documentclass[11pt]{scrartcl}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")))
(add-to-list 'org-latex-classes
'("scrreprt" "\\documentclass[11pt]{scrreprt}"
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")))
(add-to-list 'org-latex-classes
'("scrbook" "\\documentclass[11pt]{scrbook}"
("\\part{%s}" . "\\part*{%s}")
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
(add-to-list 'org-latex-classes
`("scrlttr2"
,(concat "\\documentclass\[a4paper\]\{scrlttr2\}\n"
"\[NO-DEFAULT-PACKAGES]\n"
"\[NO-PACKAGES]\n"
"\\usepackage\{fontspec\}\n"
"\\usepackage\{microtype\}\n"
"\\usepackage\{polyglossia\}\n"
"\\setdefaultlanguage[variant=british]\{english\}\n"
"\\usepackage\{libertine\}\n"
"\\usepackage\[normalem\]\{ulem\}\n"
"\\usepackage\{amsmath\}\n"
"\\usepackage\{hyperref\}\n")
("\\section\{%s\}" . "\\section*\{%s\}")
("\\subsection\{%s\}" . "\\subsection*\{%s\}")
("\\subsubsection\{%s\}" . "\\subsubsection*\{%s\}")))
;; (pop org-latex-classes) ; clean-up after experimentation
;; beamer export with the new exporter
(add-to-list 'org-beamer-environments-extra
'("onlyenv" "O" "\\begin{onlyenv}%a" "\\end{onlyenv}"))
(add-to-list 'org-beamer-environments-extra
'("minipage" "m" "\\begin{minipage}[%R]{%O}" "\\end{minipage}%"))
;; (pop org-beamer-environments-extra) ; clean-up after experimentation
(add-to-list 'org-export-snippet-translation-alist '("b" . "beamer"))
(add-to-list 'org-export-snippet-translation-alist '("l" . "latex"))
(add-to-list 'org-export-snippet-translation-alist '("h" . "html"))
(add-to-list 'org-export-snippet-translation-alist '("o" . "odt"))
;; custom headline formatting
(defun sa-org-latex-format-headline-function
(todo todo-type priority text tags info)
"Custom format function for a headline.
See `org-latex-format-headline-function' for details."
(setf colour (cond
((equal todo "TODO") "\\color{blue}")
((equal todo "WInP") "\\color{magenta}")
((equal todo "DLAY") "\\color{red}")
((equal todo "DONE") "\\color{green}")))
(concat
(and todo (format "\\texorpdfstring{{%s\\textbf{\\textsf{%s}}}}{} "
colour todo))
text
(and tags
(format "\\texorpdfstring{\\hfill{}\\textsc{%s}}{}"
(mapconcat 'identity tags ":")))))
;; filters for markups
(defun sa-beamer-bold (contents backend info)
(when (org-export-derived-backend-p backend 'beamer)
(replace-regexp-in-string "\\`\\\\[A-Za-z0-9]+" "\\\\textbf" contents)))
(add-to-list 'org-export-filter-bold-functions 'sa-beamer-bold)
(defun sa-beamer-structure (contents backend info)
(when (org-export-derived-backend-p backend 'beamer)
(replace-regexp-in-string "\\`\\\\[A-Za-z0-9]+" "\\\\structure" contents)))
(add-to-list 'org-export-filter-strike-through-functions 'sa-beamer-structure)
(defun sa-ignore-headline (contents backend info)
"Ignore headlines with tag `ignoreheading'."
(when (and (org-export-derived-backend-p backend 'latex 'html 'ascii)
(string-match "\\`.*ignoreheading.*\n"
(downcase contents)))
(replace-match "" nil nil contents)))
(add-to-list 'org-export-filter-headline-functions 'sa-ignore-headline)
;; Fix for inlinetasks in agenda
(setq org-agenda-skip-function-global ; skip END entries in inline tasks
(lambda ()
(when (and (featurep 'org-inlinetask)
(let ((case-fold-search t))
(org-looking-at-p (concat (org-inlinetask-outline-regexp)
"end[ \t]*$"))))
(or (save-excursion (outline-next-heading)) (point-max)))))
;; Export tags search result to a temporary buffer
(defun sa-org-tags-search-to-buffer(match)
"Do a tags search and copy the results to the temporary buffer
\"*temp*\"."
(interactive "sSearch for: " )
(let* ((agenda-files (org-agenda-files t)))
(switch-to-buffer "*temp*")
(org-mode)
(dolist (buf agenda-files)
(save-excursion
(find-file buf)
(org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)))
(beginning-of-buffer)
(while (condition-case nil (org-occur-next-match 1) (error nil))
(if (org-inlinetask-at-task-p) (org-copy-subtree 2)
(org-copy-subtree)) (kill-append "\n" nil)
(append-next-kill))))
(switch-to-buffer "*temp*") (goto-char (point-max)) (yank)))
;; reftex setup
(defun sa-setup-reftex ()
"Load and setup `reftex'."
(interactive)
(load-library "reftex")
(and (buffer-file-name)
(file-exists-p (buffer-file-name))
(reftex-parse-all))
(define-key org-mode-map (kbd "C-c )") 'reftex-citation))
;; (when (and (not (featurep 'reftex))
;; (buffer-file-name)
;; (file-exists-p (buffer-file-name)))
;; (reftex-mode)
;; (reftex-parse-all))
;;; Custom agenda commands
(setq org-agenda-custom-commands
'(("F" "Future meetings"
tags "CATEGORY=\"meetings\"+TIMESTAMP>=\"<today>\"")
("H" "Search HEP notes" search ""
((org-agenda-files (list "~/org/research.org" "~/org/meetings.org"))
(org-agenda-text-search-extra-files
(sa-find-org-file-recursively "~/org/HEP"))))
("B" "Search Bs → Dsh files" search ""
((org-agenda-files (list "~/org/research.org" "~/org/meetings.org"))
(org-agenda-text-search-extra-files
(sa-find-org-file-recursively "~/org/LHCb-Bs2Dsh"))))
("V" "Search Velo files" search ""
((org-agenda-files (list "~/org/research.org" "~/org/meetings.org"))
(org-agenda-text-search-extra-files
(sa-find-org-file-recursively "~/org/LHCb-Velo"))))
("p" . "Pending tasks")
("pk" "Dated pending tasks"
tags-todo "TIMESTAMP<\"<today>\"-TODO={DONE\\|CNCL}"
((org-agenda-overriding-header "Pending tasks")))
("pl" "Pending entries in thesis timeline"
tags "CATEGORY=\"thesis\"+SCHEDULED<=\"<today>\"-TODO={DONE\\|CNCL}"
((org-agenda-overriding-header "Thesis future timeline")
(org-agenda-sorting-strategy '(time-up))))
("pd" "Upcoming thesis deadlines"
tags "CATEGORY=\"thesis\"+DEADLINE<\"<+1m>\"-TODO={DONE\\|CNCL}"
((org-agenda-overriding-header "Thesis deadlines")
(org-agenda-sorting-strategy '(time-up))))
("po" "Other pending thesis entries"
tags "CATEGORY=\"thesis\"+TIMESTAMP<=\"<today>\""
((org-agenda-overriding-header "Thesis pointers")
(org-agenda-sorting-strategy '(time-up))))
;; ("R" "Search any arbitrary directory" search ""
;; ((org-agenda-files nil) ; FIXME: depends on interactive fix
;; (org-agenda-text-search-extra-files
;; (sa-find-org-file-recursively))))
("W" . "Search worg")
("Wa" "Search all articles" search ""
((org-agenda-files nil)
(org-agenda-text-search-extra-files
(sa-find-org-file-recursively "~/org/worg"))))
("Wt" "Search exporter documentation" search ""
((org-agenda-files nil)
(org-agenda-text-search-extra-files
(sa-find-org-file-recursively "~/org/worg/org-tutorials"))))
("Wc" "Search orgmode configuration" search ""
((org-agenda-files nil)
(org-agenda-text-search-extra-files
(sa-find-org-file-recursively "~/org/worg/org-configs"))))
("Wt" "Search tutorials" search ""
((org-agenda-files nil)
(org-agenda-text-search-extra-files
(sa-find-org-file-recursively "~/org/worg/org-tutorials"))))
("Wp" "Search articles on contrib packages" search ""
((org-agenda-files nil)
(org-agenda-text-search-extra-files
(sa-find-org-file-recursively "~/org/worg/org-contrib"))))
("Wb" "Search babel articles" search ""
((org-agenda-files nil)
(org-agenda-text-search-extra-files
(sa-find-org-file-recursively "~/org/worg/org-contrib/babel"))))
("A" "Search ATLAS files" search ""
((org-agenda-files nil)
(org-agenda-text-search-extra-files
(sa-find-org-file-recursively "~/org/ATLAS-wprime"))))
;; ("E" . "Search and export to temporary buffer")
;; ("Et" "Export tags search result to buffer" org-tags-search-to-buffer "Qn")
("J" "Postdocs/Jobs"
((tags-todo "CATEGORY=\"jobs\"+hep"
((org-agenda-overriding-header "Postdocs")))
(tags-todo "CATEGORY=\"jobs\"+industry"
((org-agenda-overriding-header "Industry jobs"))))
((org-agenda-files (list "~/org/tasks.org"))
(org-agenda-prefix-format '((tags . " % s"))) ; not working
(org-agenda-hide-tags-regexp "hep\\|industry")
(org-agenda-compact-blocks t)))
))
;;; `org-capture' templates
(setq org-capture-templates
'(("m" "Select meeting templates")
("mb" "Create Bfys meeting" entry (file+headline "~/org/meetings.org" "Meetings")
"*** %? %^t\n"
:prepend t)
("mm" "Meeting minutes w/ clock" entry (file+datetree "~/org/meetings.org")
"**** %^{prompt} %U %^G\n\n%?"
:clock-in t)
("mn" "Meeting notes w/o clock" entry (file+datetree "~/org/meetings.org")
"**** %^{prompt} %U %^G\n%?"
:immediate-finish t :jump-to-captured t) ; :empty-lines-before 1
("d" "Add task with a DEADLINE" entry (file+headline "~/org/tasks.org" "Tasks")
"** TODO %^{prompt}\n DEADLINE: %^t\n%?"
:prepend t)
("n" "Notes" entry (file+headline "~/org/tasks.org" "Notes")
"** %^{prompt}%^{CATEGORY}p\n\n%?"
:prepend t)
("r" "Reading material" entry (file+headline "~/org/biblio.org" "Reading")
"** %?%^{CATEGORY}p %^G\n %^t"
:prepend t) ; :unnarrowed t
("s" "Schedule a task" entry (file+headline "~/org/tasks.org" "Tasks")
"** TODO %^{prompt}\n SCHEDULED: %^t\n%?"
:prepend t)
("t" "Regular task" entry (file+headline "~/org/tasks.org" "Tasks")
"** TODO %^{prompt}\n %^t\n%?"
:prepend t)
))
;; source: (notmuch-show "id:CAGOCFPUW-wQqU0OdaW5OeM60ZOosCgBO9_mdhyQ77aiH_0UtZQ@mail.gmail.com")
(defun make-org-capture-frame ()
"Run org-capture with slightly modified behaviour."
(interactive)
(cl-flet ((switch-to-buffer-other-window (buf) (switch-to-buffer buf)))
(org-capture)
(delete-other-windows)))
;; compatibility with session.el
(add-hook 'session-after-jump-to-last-change-hook
(lambda ()
(when (and (eq major-mode 'org-mode)
(outline-invisible-p))
(org-reveal))))
;; org-mode navigation commands
(defun sa-outline-forward-same-level (arg)
"If its the last outline sibling, move to the next visible outline
heading."
(interactive "p")
(if (save-excursion (outline-get-next-sibling))
(outline-forward-same-level arg)
(outline-next-visible-heading arg)))
(defun sa-outline-backward-same-level (arg)
"If its the last outline sibling, move to the previous visible outline
heading."
(interactive "p")
(if (save-excursion (outline-get-last-sibling))
(outline-backward-same-level arg)
(outline-previous-visible-heading arg)))
(defun sa-org-dwim-next()
"Move to next item or headline. If at an item move to the next item
otherwise move to next headline."
(interactive)
(unless (eq major-mode 'org-mode) (error "Not an `org-mode' buffer"))
(if (org-in-item-p)
(if (eq t (condition-case nil (org-next-item)
(error t)))
(outline-next-visible-heading 1))
(outline-next-visible-heading 1)))
(defun sa-org-dwim-previous()
"Move to next item or headline. If at an item move to the next item
otherwise move to next headline."
(interactive)
(unless (eq major-mode 'org-mode) (error "Not an `org-mode' buffer"))
(if (org-in-item-p)
(if (eq t (condition-case nil (org-previous-item)
(error t)))
(outline-previous-visible-heading 1))
(outline-previous-visible-heading 1)))
(defun org-ctrl-c-ret ()
"Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
(interactive)
(cond
((org-at-table-p) (call-interactively 'org-table-hline-and-move))
((org-at-item-p) (call-interactively 'org-insert-item))
(t (call-interactively 'org-insert-heading))))
;;; Keymaps:
;; To specify key combinations use,
;; + Quoted lisp vectors - '[(C-right)]
;; + String translated to keyboard events - (kbd "C-<right>")
;; global keymaps
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c l") 'org-store-link)
(global-set-key (kbd "C-c C-l") 'org-insert-link-global)
(global-set-key (kbd "C-c C-o") 'org-open-at-point-global)
(global-set-key (kbd "C-c b") 'org-switchb)
(global-set-key (kbd "C-c c") 'org-capture)
(global-set-key (kbd "C-h o") 'org-info)
;; Make windmove work in org-mode with 'shift as modifier:
(add-hook 'org-shiftup-final-hook 'windmove-up)
(add-hook 'org-shiftleft-final-hook 'windmove-left)
(add-hook 'org-shiftdown-final-hook 'windmove-down)
(add-hook 'org-shiftright-final-hook 'windmove-right)
;; `org-mode' keymaps
;; overload default `fill-paragraph' keybind to use org specific command
(org-defkey org-mode-map (kbd "M-q") 'org-fill-paragraph)
(org-defkey org-mode-map (kbd "C-c d") 'org-display-outline-path)
(org-defkey org-mode-map (kbd "C-c g") 'oog) ; org-occur-goto
(org-defkey org-mode-map (kbd "C-c s") 'osg) ; org-search-goto
;; table copy paste (originally C-c M-w was bound to `org-copy')
(org-defkey org-mode-map (kbd "C-c M-w") 'org-table-copy-region)
(org-defkey org-mode-map (kbd "C-c M-y") 'org-table-paste-rectangle)
;; navigating list items / headings depending on context
(org-defkey org-mode-map (kbd "<XF86Forward>") 'sa-org-dwim-next)
(org-defkey org-mode-map (kbd "<XF86Back>") 'sa-org-dwim-previous)
;; navigating elements (more generic than headlines)
(org-defkey org-mode-map (kbd "C-M-u") 'outline-up-heading) ; retain for in text use
;; super / windows key may not work on laptops
(org-defkey org-mode-map (kbd "C-M-@") 'mark-end-of-sentence)
;; see email from Rasmus: (notmuch-show "id:[email protected]")
(with-eval-after-load 'org
(add-hook 'org-mode-hook
(defun org-keyboard-purist ()
(electric-indent-mode -1)
(org-defkey org-mode-map (kbd "RET") nil)
(mapc (lambda (key)
(org-defkey org-mode-map key nil))
(list [(control return)]
[(shift control return)]
[(meta return)])))))
;; Hydra with Org: idea is to unify navigation in Org to one menu
(org-defkey org-mode-map (kbd "C-c <up>") nil) ; cleanup conflicting
(org-defkey org-mode-map (kbd "C-c <down>") nil) ; duplicate binding
(org-defkey org-mode-map (kbd "C-c <left>") nil)
(org-defkey org-mode-map (kbd "C-c <right>") nil)
(with-eval-after-load 'hydra ; loaded in keybindings.el
(defhydra hydra-orgnav (org-mode-map "C-c")
"org-nav"
("<prior>" org-previous-link "prev link") ; navigating links
("<next>" org-next-link "next link")
("<left>" org-up-element "parent element") ; navigating elements
("<right>" org-down-element "child element")
("<down>" org-forward-element "next element")
("<up>" org-backward-element "prev element")
("q" nil "quit")))
;;; requires org-link-edit.el
;; (defhydra hydra-org-link-edit (org-mode-map "C-c .")
;; "Org Link Edit"
;; ("j" org-link-edit-forward-slurp "forward slurp")
;; ("k" org-link-edit-forward-barf "forward barf")
;; ("u" org-link-edit-backward-slurp "backward slurp")
;; ("i" org-link-edit-backward-barf "backward barf")
;; ("q" nil "cancel"))
;; `org-agenda-mode' keymaps
;; (eval-after-load 'org-agenda
;; ;; set property
;; (org-defkey org-agenda-mode-map (kbd "C-c p") 'org-agenda-set-property)
;; ;; month view
;; (org-defkey org-agenda-mode-map (kbd "C-c m") 'org-agenda-month-view))
;; org-agenda config; not needed anymore, but kept as an example
;; This function is used to insert current time in the agenda buffer
;; Thanks to Julien Danjou
;; (defun jd:org-current-time ()
;; "Return current-time if date is today."
;; (when (equal date (calendar-current-date))
;; (propertize (format-time-string "%H:%M Current time") 'face
;; '(:weight bold :foreground "DodgerBlue4" :background "snow"))))
;;; Hooks
;; `org-agenda-mode' hook
(defun sa-org-agenda-mode-hook()
"My `org-agenda-mode' hook."
(visual-line-mode t))
(add-hook 'org-agenda-mode-hook 'sa-org-agenda-mode-hook)
;; `org-mode' hook
(defun sa-org-mode-hook()
"My `org-mode' hook."
(local-unset-key (kbd "C-c [")) ; add/remove agenda files
(local-unset-key (kbd "C-c ]"))
;; (flyspell-mode t)
;; ;; see: http://auto-complete.org/doc/manual.html#flyspell-mode-bug
;; (ac-flyspell-workaround)
;; line folding w/o actually folding it, use `M-q' to wrap.
(visual-line-mode t)
;; imenu for org-mode buffers
;; Submenu with TODOs
;; (add-to-list 'imenu-generic-expression
;; `("TODOs"
;; ,(concat "^\\(?:[*]+\\) +"
;; (make-regexp org-todo-keywords-1)
;; " +.*$")
;; 0))
(imenu-add-to-menubar "Headlines")
;; dynamic abbreviations for org-mode
(setq local-abbrev-table org-mode-abbrev-table))
(add-hook 'org-mode-hook 'sa-org-mode-hook)
;; Setup `org-babel' for emacs-lisp, gnuplot, latex and shell-script.
(org-babel-do-load-languages
'org-babel-load-languages
'((calc . t)
(ditaa . t)
(emacs-lisp . t)
(gnuplot . t)
(latex . t)
(octave .t)
(python . t)
(R . t)
(ruby . t)
(shell . t)))
;;; org-mode-settings.el ends here
;; Local Variables:
;; flycheck-disabled-checkers: (emacs-lisp emacs-lisp-checkdoc)
;; End: