emacs : add worf-mode for org-mode
[dotfiles.git] / emacs.d_2 / config.org
1 #+TITLE: Emacs Configuration file
2 #+AUTHOR: Peng Li
3 #+EMAIL: seudut@gmail.com
4
5 * Introduction
6
7 Most config are just copied from [[https://github.com/howardabrams/dot-files][howardabrams]]'s dotfiles
8
9 * Basic Settings
10
11 ** Setting loading Path
12
13 Set the emacs load path
14
15 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
16
17   (add-to-list 'load-path "~/.emacs.d/elisp")
18
19 #+END_SRC
20
21 ** Package Initialization
22
23 #+BEGIN_SRC emacs-lisp :tangle yes
24
25   (require 'package)
26
27   (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
28                            ("org" . "http://orgmode.org/elpa/")))
29
30   (package-initialize)
31
32 #+END_SRC
33
34 ** Windows Setting
35
36 Disable scroll bar, tool-bar and menu-bar
37
38 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
39
40   (scroll-bar-mode 0)
41   (tool-bar-mode 0)
42   (menu-bar-mode 0)
43
44   (setq debug-on-error t)
45   (setq inhibit-startup-message t)
46
47   (defalias 'yes-or-no-p 'y-or-n-p)
48   (show-paren-mode 1)
49
50 #+END_SRC
51
52 * Use-package
53
54 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
55
56 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
57
58   (unless (package-installed-p 'use-package)
59     (package-refresh-contents)
60     (package-install 'use-package))
61
62   (require 'use-package)
63
64 #+END_SRC
65
66 * Color and Fonts Settings
67
68 ** highlight current line
69
70 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
71
72   (global-hl-line-mode)
73
74 #+END_SRC
75
76 ** Smart Comments
77
78 [[https://github.com/paldepind/smart-comment][smart-comments]]
79
80 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
81
82   (use-package smart-comment
83     :ensure t
84     :bind ("M-;" . smart-conmment))
85
86 #+END_SRC
87
88 ** Font Setting
89
90 syntax highlighting
91
92 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
93
94   (global-font-lock-mode 1)
95
96 #+END_SRC
97
98 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
99
100 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
101
102   (if window-system
103       (defvar sd/fixed-font-family
104         (cond ((x-list-fonts "Hasklig")         "Hasklig")
105               ((x-list-fonts "Source Code Pro") "Source Code Pro")
106               ((x-list-fonts "Anonymous Pro")   "Anonymous Pro")
107               ((x-list-fonts "M+ 1mn")          "M+ 1mn"))
108         "The fixed width font based on what is installed, `nil' if not defined."))
109
110 #+END_SRC
111
112 Setting the fonts 
113
114 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
115
116   (if window-system
117       (when sd/fixed-font-family
118         (set-frame-font sd/fixed-font-family)
119         (set-face-attribute 'default nil :font sd/fixed-font-family :height 140)
120         (set-face-font 'default sd/fixed-font-family)))
121
122 #+END_SRC
123
124 ** Color Theme
125
126 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
127
128 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
129
130   (setq vc-follow-symlinks t)
131
132   (use-package color-theme
133     :ensure t
134     :init (require 'color-theme)
135     :config (use-package color-theme-sanityinc-tomorrow
136               :ensure t
137               :no-require t
138               :config
139               (load-theme 'sanityinc-tomorrow-bright t)))
140
141   ;(eval-after-load 'color-theme
142   ;  (load-theme 'sanityinc-tomorrow-bright t))
143
144 #+END_SRC
145
146 Change the Org-mode colors 
147
148 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
149
150   (defun org-src-color-blocks-light ()
151     "Colors the block headers and footers to make them stand out more for lighter themes"
152     (interactive)
153     (custom-set-faces
154      '(org-block-begin-line
155       ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
156      '(org-block-background
157        ((t (:background "#FFFFEA"))))
158      '(org-block
159        ((t (:background "#FFFFEA"))))
160      '(org-block-end-line
161        ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
162
163      '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
164      '(which-func ((t (:foreground "#008000"))))))
165
166   (defun org-src-color-blocks-dark ()
167     "Colors the block headers and footers to make them stand out more for dark themes"
168     (interactive)
169     (custom-set-faces
170      '(org-block-begin-line
171        ((t (:foreground "#008ED1" :background "#002E41"))))
172      '(org-block-background
173        ((t (:background "#000000"))))
174      '(org-block
175        ((t (:background "#000000"))))
176      '(org-block-end-line
177        ((t (:foreground "#008ED1" :background "#002E41"))))
178
179      '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
180      '(which-func ((t (:foreground "green"))))))
181
182   (org-src-color-blocks-dark)
183
184 #+END_SRC
185
186 improve color for org-mode
187 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
188   (deftheme ha/org-theme "Sub-theme to beautify org mode")
189
190   (if window-system
191       (defvar sd/variable-font-tuple
192         (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
193               ((x-list-fonts "Lucida Grande")   '(:font "Lucida Grande"))
194               ((x-list-fonts "Verdana")         '(:font "Verdana"))
195               ((x-family-fonts "Sans Serif")    '(:family "Sans Serif"))
196               (nil (warn "Cannot find a Sans Serif Font.  Install Source Sans Pro.")))
197         "My variable width font available to org-mode files and whatnot."))
198
199   (defun sd/org-color ()
200     (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
201            (base-font-color     (face-foreground 'default nil 'default))
202            (background-color    (face-background 'default nil 'default))
203            (primary-color       (face-foreground 'mode-line nil))
204            (secondary-color     (face-background 'secondary-selection nil 'region))
205            (base-height         (face-attribute 'default :height))
206            (headline           `(:inherit default :weight bold :foreground ,base-font-color)))
207       (custom-theme-set-faces 'ha/org-theme
208                               `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
209                               `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
210                               `(org-table ((t (:inherit 'fixed-pitched))))
211                               `(org-block ((t (:inherit 'fixed-pitched))))
212                               `(org-block-background ((t (:inherit 'fixed-pitched))))
213                               `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
214                               `(org-block-end-line ((t (:inherit 'fixed-pitched))))
215                               `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
216                               `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
217                               `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
218                               `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
219                               `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
220                                                             :height ,(round (* 1.1 base-height))))))
221                               `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
222                                                             :height ,(round (* 1.25 base-height))))))
223                               `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
224                                                             :height ,(round (* 1.5 base-height))))))
225                               `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
226                                                             :height ,(round (* 1.75 base-height))))))
227                               `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
228
229
230 #+END_SRC
231
232 * Org-mode Settings
233
234 ** Org-bullets
235
236 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
237
238 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
239
240   (use-package org-bullets
241     :ensure t
242     :init
243     (add-hook 'org-mode-hook
244               (lambda ()
245                 (org-bullets-mode t))))
246
247 #+END_SRC
248
249 ** Org-mode Basic setting
250
251 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent= 
252
253 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
254
255   (setq org-startup-indented t)
256   (setq org-hide-leading-starts t)
257   ;(setq org-src-fontify-natively t)
258   (setq org-src-tab-acts-natively t)
259   (setq org-confirm-babel-evaluate nil)
260
261   (org-babel-do-load-languages
262    'org-babel-load-languages
263    '((python . t)
264      (C . t)
265      (calc . t)
266      (latex . t)
267      (java . t)
268      (ruby . t)
269      (lisp . t)
270      (scheme . t)
271      (sh . t)
272      (sqlite . t)
273      (js . t)))
274
275   (setq org-use-speed-commands t
276         org-completion-use-ido t)
277      
278
279 #+END_SRC
280
281 ** Worf Mode
282
283 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode
284
285 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
286
287   (use-package worf
288     :ensure t
289     :commands worf-mode
290     :init (add-hook 'org-mode-hook 'worf-mode))
291
292
293 #+END_SRC
294 ** Task Management
295
296 ** Capture
297
298 * Magit
299
300 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
301
302 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
303
304   (use-package magit
305     :ensure t
306     :commands magit-status magit-blame)
307
308
309 #+END_SRC
310
311 * IDO & SMEX
312
313 ** IDO
314
315 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
316
317   (use-package ido
318     :ensure t
319     :init (setq ido-enable-flex-matching t
320                 ido-ignore-extensions t
321                 ido-use-virtual-buffers t
322                 ido-everywhere t)
323     :config
324     (ido-mode 1)
325     (ido-everywhere 1)
326     (add-to-list 'completion-ignored-extensions ".pyc"))
327
328 #+END_SRC
329
330 ** FLX
331
332 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
333
334   (use-package flx-ido
335     :ensure t
336     :init (setq ido-enable-flex-matching t
337                 ido-use-faces nil)
338     :config (flx-ido-mode 1))
339
340 #+END_SRC
341
342 ** IDO-vertically
343
344 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
345
346   (use-package ido-vertical-mode
347     :ensure t
348     :init
349     (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
350     :config
351     (ido-vertical-mode 1))
352
353 #+END_SRC
354
355 ** SMEX
356
357 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
358
359   (use-package smex
360     :ensure t
361     :init (smex-initialize)
362     :bind
363     ("M-x" . smex)
364     ("M-X" . smex-major-mode-commands))
365
366 #+END_SRC
367
368 * Misc Settings
369
370 ** Line Number
371
372 Enable linum mode on programming modes
373
374 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
375
376   (add-hook 'prog-mode-hook 'linum-mode)
377
378 #+END_SRC
379
380 Fix the font size of line number
381
382 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
383
384   (defun fix-linum-size ()
385        (interactive)
386        (set-face-attribute 'linum nil :height 110))
387
388   (add-hook 'linum-mode-hook 'fix-linum-size)
389
390 #+END_SRC
391
392 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
393
394 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
395
396   (use-package linum-relative
397     :ensure t
398     :config
399     (defun linum-new-mode ()
400       "If line numbers aren't displayed, then display them.
401   Otherwise, toggle between absolute and relative numbers."
402       (interactive)
403       (if linum-mode
404           (linum-relative-toggle)
405         (linum-mode 1)))
406
407     :bind
408     ("A-k" . linum-new-mode))
409
410   ;; auto enable linum-new-mode in programming modes
411   (add-hook 'prog-mode-hook 'linum-relative-mode)
412
413 #+END_SRC
414
415 ** Save File Position
416
417 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
418
419   (require 'saveplace)
420   (setq-default save-place t)
421   (setq save-place-forget-unreadable-files t)
422   (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
423
424 #+END_SRC
425
426 * Eshell Setting
427
428 Setting PATH environment variable
429
430 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
431
432   (setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin"))
433
434 #+END_SRC
435
436 * Programming Languages
437
438 ** Emacs Lisp
439
440 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
441
442   (use-package color-identifiers-mode
443     :ensure t
444     :init
445     (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
446     :diminish color-identifiers-mode)
447
448 #+END_SRC
449
450 * Others
451
452 ** Shell pop mode
453
454 ** Smartparens mode
455
456 **