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