-
Notifications
You must be signed in to change notification settings - Fork 8
/
org-setting.el
439 lines (433 loc) · 19.4 KB
/
org-setting.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
;; -*- coding: utf-8 -*-
;; File: org-setting.el
;;
;; Author: Denny Zhang(https://www.dennyzhang.com/contact)
;; Copyright 2020, https://DennyZhang.com
;; Created:2008-10-01
;; Updated: Time-stamp: <2020-06-13 00:14:49>
;; --8<-------------------------- separator ------------------------>8--
;;(add-to-list 'load-path (concat CONF-EMACS-VENDOR "/org-7.8/lisp"))
;;(add-to-list 'load-path (concat CONF-EMACS-VENDOR "/org-7.8/contrib/lisp"))
;; (add-to-list 'load-path (concat CONF-EMACS-VENDOR "/org-mode/lisp"))
;; (add-to-list 'load-path (concat CONF-EMACS-VENDOR "/org-mode/contrib/lisp"))
(require 'org)
(require 'org-install)
;; --8<-------------------------- separator ------------------------>8--
(require 'ox-md)
(defadvice org-md-export-to-markdown (after org-export-to-file activate)
(if (file-exists-p "./README.md")
(with-current-buffer (find-file "README.md")
(progn
(goto-char 0)
(while (search-forward "[]" nil t)
(replace-match ""))
(save-buffer)
(kill-buffer)
))))
;; --8<-------------------------- separator ------------------------>8--
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
;; set org-agenda-files
(dolist (org-agenda-file-var (list
(concat CONF-SHARE-DIR "/org_data/current.org")
))
(add-to-list 'org-agenda-files org-agenda-file-var))
;; --8<-------------------------- separator ------------------------>8--
;; log the time of the things I have done
(setq-default org-log-done t)
;; write diary in org-mode
(setq org-agenda-diary-file (concat CONF-SHARE-DIR "/org_data/life/diary.org"))
(global-set-key "\C-cl" 'org-store-link) ;; define global keys
(global-set-key "\C-ca" 'org-agenda)
;;(global-set-key "\C-cb" 'org-iswitchb)
(add-hook 'org-mode-hook
(lambda ()
'turn-on-font-lock
(setq word-wrap 1)
;;(make-local-variable 'highlight-changes-mode)
;;(highlight-changes-mode 0)
;;(make-local-variable 'highlight-tail-mode)
;;(highlight-tail-mode 0)
(setq truncate-lines t)
;;(iimage-mode 't)
))
(setq org-todo-keyword-faces
'(("TODO" . org-warning)
("DEFERRED" . shadow)
("CANCELED" . (:foreground "blue" :weight bold))))
(setq org-export-headline-levels 5);;set export headline level
;;set export css
;; (setq org-export-table-row-tags
;; '("<tr onMouseOver = \"this.className = 'highlight'\" onMouseOut = \"this.className = 'initial'\">" . "</tr>"))
;;set table
;; (setq org-export-html-table-tag "<table border = \"2\" bgcolor = \"#DDDDDD\" >" )
(setq org-time-stamp-custom-formats (quote ("<%Y-%m-%d>" . "<%Y-%m-%d %H:%M>")))
;; 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)
;; 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)
(setq org-agenda-custom-commands
'(("h" "Daily habits"
((agenda ""))
((org-agenda-show-log t)
(org-agenda-ndays 7)
(org-agenda-log-mode-items '(state))
(org-agenda-skip-function '(org-agenda-skip-entry-if 'notregexp ":Habit:"))))
;; other commands here
))
;; --8<-------------------------- separator ------------------------>8--
(require 'org-habit)
(setq org-habit-graph-column 80)
;; --8<-------------------------- separator ------------------------>8--
(setq org-todo-keyword-faces
'(("TODO" . org-warning)
("DEFERRED" . shadow)
("CANCELED" . (:foreground "CornflowerBlue" :weight bold))))
;; --8<-------------------------- separator ------------------------>8--
(setq org-agenda-custom-commands
'(("X" agenda ""
((ps-number-of-columns 2)
(ps-landscape-mode t)
(org-agenda-prefix-format " [ ] ")
(org-agenda-with-colors nil)
(org-agenda-remove-tags t))
("theagenda.ps"))))
;; --8<-------------------------- separator ------------------------>8--
;; set css for html export in org-mode
(setq user-full-name "Denny Zhang")
(setq user-mail-address "[email protected]")
;; (load-file (concat CONF-DENNY-EMACS "/org-css-setting.el")) ;; TODO
(load-file (concat CONF-DENNY-EMACS "/patch-src-code/ox-md-patch.el"))
;; --8<-------------------------- separator ------------------------>8--
(load-file (concat CONF-DENNY-EMACS "/emacs-aggregation/emacs-aggregation-setup.el"))
;; --8<-------------------------- separator ------------------------>8--
;; TODO: enable this
;; 加载随机签名
;;(load-file (concat CONF-DENNY-EMACS "/signature-motto.el"))
;;(setq gnus-posting-styles
;; '(
;; (".*" ; Matches all groups of messages
;; (signature get-mail-signature)) ;; 使用随机签名
;; (signature get-mail-signature))
;; ((header "subject" "[^ ]*")
;; (signature get-short-mail-signature)) ;; use short signature, when replying mail
;; ))
;; --8<-------------------------- separator ------------------------>8--
(load-file (concat CONF-DENNY-EMACS "/org-publish/org-publish-to-wordpress.el"))
;;(load-file (concat CONF-DENNY-EMACS "/org-publish/wordpress-devops-post.el")) ;; TODO
;; --8<-------------------------- separator ------------------------>8--
;;TODO: need to be enhanced
(require 'org-mobile)
;; (setq org-mobile-directory (concat CONF-DENNY-EMACS "../../Apps/MobileOrg"))
;; (setq org-mobile-files (list (concat CONF-SHARE-DIR "/org_data/tomobile.org")))
(setq org-directory (concat CONF-SHARE-DIR "/org_data/"))
;; pulling from MobileOrg
(setq org-mobile-inbox-for-pull (concat CONF-SHARE-DIR "/org_data/frommobile.org"))
;; --8<-------------------------- separator ------------------------>8--
;; active Babel languages
;; (org-babel-do-load-languages ;; TODO
;; 'org-babel-load-languages
;; '((emacs-lisp . t)
;; (perl . t)
;; (python . t)
;; (sh . t)
;; (ditaa . t)
;; (ledger . t)
;; (ruby . t)
;; ))
;; --8<-------------------------- separator ------------------------>8--
(setq org-agenda-include-diary t) ;集成日历
;; --8<-------------------------- separator ------------------------>8--
(defun jump-to-org-agenda ()
(interactive)
(unless (featurep 'org-agenda)
(load ".org"))
(let ((buf (get-buffer "*Org Agenda*"))
wind)
(if buf
(if (setq wind (get-buffer-window buf))
(when (called-interactively-p 'any)
(select-window wind)
(org-fit-window-to-buffer))
(if (called-interactively-p 'any)
(progn
(select-window (display-buffer buf t t))
(org-fit-window-to-buffer))
(with-selected-window (display-buffer buf)
(org-fit-window-to-buffer))))
(call-interactively 'org-agenda-list))))
;;(run-with-idle-timer 3600 t 'jump-to-org-agenda)
(setq org-agenda-repeating-timestamp-show-all nil)
(setq org-agenda-restore-windows-after-quit t)
;; --8<-------------------------- separator ------------------------>8--
;; change org local key
(org-defkey org-mode-map (kbd "C-M-.") 'org-shiftmetaright)
(org-defkey org-mode-map (kbd "C-M-,") 'org-shiftmetaleft)
(org-defkey org-mode-map [(control return)] 'switch-to-mode-nex-buffer)
(org-defkey org-mode-map [(control shift up)] 'enlarge-window)
(org-defkey org-mode-map [(control shift down)] 'shrink-window)
(org-defkey org-mode-map [(meta .)] 'occur-org-title)
;; (org-defkey org-mode-map [(tab)] 'yas/expand)
(org-defkey org-mode-map (kbd "M-p i") 'my-insert-time)
(org-defkey org-mode-map "\C-c<" 'recent-jump-jump-backward)
(org-defkey org-mode-map "\C-c>" 'recent-jump-jump-forward)
;;(org-defkey org-mode-map [(meta return)] 'my-org-meta-return)
(defun my-org-meta-return(&optional arg)
(interactive "P")
(if (org-in-item-p)
(org-meta-return)
(org-meta-return)
(insert "\n#+BEGIN_EXAMPLE\n\n#+END_EXAMPLE")
(forward-line -3)
(org-end-of-line)
)
)
(defun occur-org-title()
"when regexp search, only search title of org-mode entries"
(interactive)
(let (regexp)
(setq regexp
(read-string "Search org entries whose title matching regexp: " "^\\\*+ .*"))
(occur-1 regexp 0 (list (current-buffer)))))
(defun replace-entry(entry_title)
;; filter entries whose title contains entry_title, then quote
;; content by #+BEGIN_EXAMPLE and #+END_EXAMPLE
(interactive)
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp (format "^\\*.*%s" entry_title) nil t)
(if (search-forward-regexp "\n" nil t)
;; make sure the code is re-entrant
(if (< (+ 2 (point)) (point-max))
(unless (string= (buffer-substring-no-properties
(point) (+ 2 (point))) "#+")
(insert "#+BEGIN_EXAMPLE\n")
(if (search-forward-regexp "^\*" nil t)
(backward-char 1)
(goto-char (point-max)))
(insert "#+END_EXAMPLE\n")
))
))))
(defun remove-entry-quote(entry_title)
;; filter entries whose title contains entry_title, then remove quote
;; of #+BEGIN_EXAMPLE and #+END_EXAMPLE
(interactive)
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp (format "^\\*.*%s" entry_title) nil t)
(if (search-forward-regexp "\n" nil t)
;; make sure the code is re-entrant
(if (< (+ 2 (point)) (point-max))
(when (string= (buffer-substring-no-properties
(point) (+ 2 (point))) "#+")
(org-narrow-to-subtree)
(goto-char (point-min))
(flush-lines "^#+")
(widen)
))
))))
(defun url-link-quote()
(interactive)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "^\\( *http://[^ \\\n\"]+\\)\\\\*$" nil t)
(replace-match (format "%s\\\\\\\\" (match-string 1)) nil nil))
)
)
;; --8<-------------------------- separator ------------------------>8--
(require 'graphviz-dot-mode)
;; --8<-------------------------- separator ------------------------>8--
(setq org-directory (concat CONF-SHARE-DIR "/org_data/"))
(setq org-default-notes-file "current.org")
;; --8<-------------------------- separator ------------------------>8--
;; auto add "TODO " for top task
(defadvice org-meta-return (after cond activate)
(when (and (= 1 (org-current-level))
(not (member (file-name-nondirectory buffer-file-name) '("learn.org"))))
(insert "TODO "))
)
;; (defadvice get-page-title (after insert activate)
;; (when (string= "Org" mode-name)
;; (let ((link-str "useful link"))
;; (unless (string= link-str (org-no-properties (org-get-heading)))
;; (move-beginning-of-line nil)
;; (insert (make-string (org-current-level) ?*) " " link-str "\n")
;; ))))
;; --8<-------------------------- separator ------------------------>8--
(setq org-src-fontify-natively t)
;; --8<-------------------------- separator ------------------------>8--
;; (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))))
;; --8<-------------------------- separator ------------------------>8--
(setq org-completion-use-ido t)
;; --8<-------------------------- separator ------------------------>8--
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(org-checkbox ((t (:inherit bold))))
'(org-checkbox-statistics-todo ((t (:inherit org-todo :foreground "DarkKhaki"))) t)
'(org-level-1 ((t (:inherit outline-1 :foreground "LimeGreen"))))
'(org-level-2 ((t (:inherit outline-2 :foreground "YellowGreen"))))
'(org-level-3 ((t (:inherit outline-3 :foreground "SeaGreen3"))))
'(org-todo ((t (:weight bold))))
'(org-warning ((t (:inherit font-lock-warning-face :foreground "LightGoldenrod")))))
;; --8<-------------------------- separator ------------------------>8--
;; (require 'org-contacts)
;; (add-to-list 'org-contacts-files (concat CONF-SHARE-DIR "/org_data/contacts.org"))
;; --8<-------------------------- separator ------------------------>8--
(setq org-export-with-tasks 'done
org-export-creator-info nil)
;; --8<-------------------------- separator ------------------------>8--
;; (org-tags-view-list "Motto" '("Attitude"))
;; (org-tags-view-list "Attitude")
(defun org-tags-view-list (tag-name &optional filter-tag-list)
(let (retrieve-content entry-list (orig-buffer (current-buffer)))
(save-excursion
(org-tags-view nil tag-name)
(goto-char (point-min))
(forward-line 2)
;; obtain and wash data
(setq retrieve-content
(buffer-substring-no-properties (point) (point-max)))
(setq retrieve-content
(replace-regexp-in-string "^ [^:]+: +" "" retrieve-content))
(setq entry-list (split-string retrieve-content "\n"))
;; restore cursor location
(kill-buffer org-agenda-buffer-name)
(switch-to-buffer orig-buffer)
(delete-other-windows)
;;(kill-buffer)
;; exclude entries of given tag list
(dolist (filter-tag filter-tag-list)
(setq entry-list
(delq nil
(mapcar #'(lambda (x)
(if (string-match (format ":%s" filter-tag) x)
nil x))
entry-list))))
;; remove tags from entry
(setq entry-list
(mapcar #'(lambda (x) (replace-regexp-in-string " *:[^ ]+$" "" x))
entry-list))
;; limit too short entry
(setq entry-list
(delq nil (mapcar #'(lambda (x)
(if (> (length x ) 15)
x nil))
entry-list)))
)))
;; --8<-------------------------- separator ------------------------>8--
;; Automatically copy DONE tasks in copylog-monitor-orgfiles to copylog-dest-orgfile
(setq copylog-monitor-orgfiles '("current.org" "top.org"))
(setq copylog-dest-orgfile (concat CONF-SHARE-DIR "/org_data/life/diary.org"))
(defadvice org-kill-line (after kill-region activate)
(if (member (buffer-name) copylog-monitor-orgfiles)
(unless (null (string-match "^\*+ DONE" (org-no-properties (car kill-ring))))
(let ((old-buffer (current-buffer)))
;; open buffer to store the worklog
(if (null (get-file-buffer copylog-dest-orgfile))
(find-file copylog-dest-orgfile))
(set-buffer (get-file-buffer copylog-dest-orgfile))
(goto-char (point-max))
(defvar my-string)
(defvar my-entry)
(setq my-string (org-no-properties (car kill-ring)))
(if (listp my-string) (setq my-string (car my-string)))
(setq my-entry (replace-regexp-in-string "\* DONE"
(concat "\*\* " (format-time-string "%Y-%m-%d:" (current-time)))
my-string))
(insert (concat "\n" my-entry))
(write-file copylog-dest-orgfile)
(switch-to-buffer old-buffer))
)
))
;; --8<-------------------------- separator ------------------------>8--
(require 'org-mime)
(setq org-mime-library 'mml) ;; tell org-mime which Emacs mail agent you use
(setq org-export-with-special-strings nil)
;; don't interpret "_" and "^" for export
(setq org-export-with-sub-superscripts nil)
(add-hook 'org-mime-html-hook
(lambda ()
(save-excursion
(goto-char (point-min))
(org-mime-change-element-style
"p" "margin:0;border:0;padding:0;background:#2f4f4f;color:#6495ed")
(goto-char (point-min))
(org-mime-change-element-style
"table" "background:#2f4f4f;color:#6495ed;width:100%")
(goto-char (point-min))
(org-mime-change-element-style
"li" "margin:0;border:0;padding:0;background:#2f4f4f;color:#6495ed")
(goto-char (point-min))
(org-mime-change-element-style
"ul" "margin:0;border:0;padding:0;background:#2f4f4f;color:#6495ed")
(goto-char (point-min))
(org-mime-change-element-style
"a" "background:#2f4f4f;color:#6495ed")
)))
;; sending html mail as default
;;(add-hook 'message-send-hook #'(lambda() (org-mime-htmlize nil)))
(add-hook 'message-mode-hook
(lambda ()
(local-set-key "\C-c\M-o" 'org-mime-htmlize)))
(add-hook 'message-mode-hook
(lambda ()
(local-set-key "\C-c\C-h" 'message-html-send)))
(defun message-html-send ()
(interactive)
(org-mime-htmlize nil)
(message-send)
)
;; --8<-------------------------- separator ------------------------>8--
;; use org-bullets-mode for utf8 symbols as org bullets
;; (require 'org-bullets) ;; TODO
;; make available "org-bullet-face" such that I can control the font size individually
;; (setq org-bullets-face-name (quote org-bullet-face))
;; (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
;; (setq org-bullets-bullet-list '("✣" "✙" "♱" "♰" "☥" "✞" "✟" "✝" "†" "✠" "✚" "✜" "✛" "✢" "✤" "✥"))
;; --8<-------------------------- separator ------------------------>8--
(defadvice org-md-export-to-markdown (after org-export-to-file activate)
(if (file-exists-p "./work.md")
(with-current-buffer (find-file "work.md")
(progn
(goto-char 0)
(while (re-search-forward "<colgroup>\n<col class=\"org-left\" />\n\n<col class=\"org-left\" />\n</colgroup>" nil t)
(replace-match ""))
(goto-char 0)
(while (re-search-forward "<colgroup>\n<col class=\"org-left\" />\n\n<col class=\"org-left\" />\n\n<col class=\"org-left\" />\n</colgroup>" nil t)
(replace-match ""))
(goto-char 0)
(while (re-search-forward "<colgroup>\n<col class=\"org-right\" />\n\n<col class=\"org-left\" />\n\n<col class=\"org-left\" />\n</colgroup>" nil t)
(replace-match ""))
(goto-char 0)
(while (re-search-forward "<colgroup>\n<col class=\"org-right\" />\n\n<col class=\"org-left\" />\n</colgroup>" nil t)
(replace-match ""))
)
(save-buffer)
(kill-buffer)
)))
;; (defadvice org-export-to-file (after insert activate)
;; (progn
;; (goto-char (point-min))
;; (replace-regexp "<colgroup>\n<col class=\"org-left\" />\n\n<col class=\"org-left\" />\n</colgroup>" "")))
;; --8<-------------------------- separator ------------------------>8--
;; File: org-setting.el ends here