-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
149 lines (124 loc) · 5.02 KB
/
init.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
(defvar my-os
(cond ((eq system-type 'windows-nt) "windows")
((eq system-type 'darwin) "mac")
((eq system-type 'gnu/linux) "linux")
(t "unknown")))
(defvar plugin-path
(cond ((equal my-os "windows") "c:/emacs/plugins")
((equal my-os "mac") "~/Code/emacs/plugins")
((equal my-os "linux") "~/Code/emacs/plugins")
(t "~/default")))
(defvar default-font
(cond ((equal my-os "windows") "Cascadia Code 10")
((equal my-os "mac") "Monaco 15")
((equal my-os "linux") "Ubuntu Mono 14")
(t "Monaco 15")))
(defvar default-spelling-program
(cond ((equal my-os "windows") "ispell")
((equal my-os "mac") "/usr/local/bin/aspell")
((equal my-os "linux") "/usr/bin/aspell")
(t "/usr/bin/aspell")))
(defvar default-notes-path
(cond ((equal my-os "windows") "c:/orgnotes/")
((equal my-os "mac") "~/orgnotes/")
((equal my-os "linux") "~/orgnotes/")
(t "~/orgnotes/")))
;; Fullscreen
(add-to-list 'default-frame-alist '(fullscreen . maximized))
;; Don't show the splash screen
(setq inhibit-startup-message t)
(setq visible-bell nil)
(setq ring-bell-function 'ignore)
;; Theme
(load-theme 'deeper-blue t)
;; Bars
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
;; Line numbers
(global-display-line-numbers-mode 1)
;; Font
(set-frame-font default-font)
;; Confirm before exit
(setq confirm-kill-emacs #'yes-or-no-p)
;; Plugins
(add-to-list 'load-path (format "%s/%s" plugin-path "evil"))
(add-to-list 'load-path (format "%s/%s" plugin-path "evil-org-mode"))
(add-to-list 'load-path (format "%s/%s" plugin-path "org-bullets"))
;; Org Mode
(require 'org)
(require 'org-bullets)
(setq org-hide-emphasis-markers t)
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
;; Spelling
(setq ispell-program-name default-spelling-program)
(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
(add-hook 'org-mode-hook 'turn-on-flyspell)
;; Enable Evil
(setq evil-want-C-i-jump nil) ;; Enable TAB in org mode
(require 'evil)
(require 'evil-org)
(evil-mode 1)
(setf evil-org-key-theme '(navigation insert textobjects additional))
;; TODO Keywords
(setq org-todo-keywords
'((sequence "TODO" "FEEDBACK" "RELEASE" "|" "DONE")))
(setq org-todo-keyword-faces
'(("RELEASE" . "orange") ("FEEDBACK" . "magenta") ("DONE" . "green"))
)
;; Disable auto-save
(setq auto-save-default nil)
;; TODAYS NOTES
(defun create-or-open-note-for-todo ()
"Create or open a note file for the parent heading of the current TODO item."
(interactive)
(save-excursion
(setq todo-pos (org-entry-beginning-position))
(org-back-to-heading)
(outline-up-heading 1)
(let* ((parent-heading (nth 4 (org-heading-components)))
(note-dir (expand-file-name (concat "~/orgnotes/" parent-heading))) ;; TODO set this as a variable for platform independenc
(note-file (read-file-name "Note file name: " note-dir))
(note-link (concat "[[" note-file "][Note]]")))
(make-directory note-dir t)
(goto-char todo-pos)
(end-of-line)
(insert " " note-link)
(find-file note-file)
(unless (file-exists-p note-file)
(insert "#+TITLE: " note-file "\n\n"))
(end-of-buffer)
(unless (search-backward "#+END:" nil t)
(insert "\n\n#+END:\n")))))
(global-set-key (kbd "C-c n") 'create-or-open-note-for-todo)
(defun find-and-open-file-by-date (directory)
"Check for a file in DIRECTORY with a date-based filename and open it if found."
(let ((current-date (format-time-string "%Y-%m-%d"))
(days-to-check 0)
(found-file nil)
(file-path nil)
(is-today nil))
(while (and (not found-file) (< days-to-check 7))
(let* ((date-to-check (time-subtract (current-time) (days-to-time days-to-check)))
(file-to-check (concat directory (format-time-string "%Y-%m-%d" date-to-check) ".org")))
(when (file-exists-p file-to-check)
(setq found-file t
file-path file-to-check)
(if (equal current-date (format-time-string "%Y-%m-%d" date-to-check))
(setq is-today t)
)))
(setq days-to-check (1+ days-to-check)))
(values found-file file-path is-today)))
(defun todays-notes (directory)
(let ((result (find-and-open-file-by-date directory))
(today (format-time-string "%Y-%m-%d"))
(template-file (expand-file-name "todo-template.org" directory))
)
(multiple-value-bind (file-found file-path is-today) result
(if (eq file-found t)
(if (eq is-today t)
(find-file file-path) ;; We have a file for today, just open it
(copy-file file-path (expand-file-name (concat today ".org") directory)) ;; We have an older file, copy it and open
(find-file (expand-file-name (concat today ".org") directory)))
(copy-file template-file (expand-file-name (concat today ".org") directory)))))) ;; We have no file, copy from template
(global-set-key (kbd "C-c o") (lambda () (interactive) (todays-notes default-notes-path)))