2d3aab5bbfadef83cdaa54160b523ec7965ea165
[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-mode Basic setting
235
236 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent= 
237
238 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
239
240
241     (setq org-startup-indented t)
242     (setq org-hide-leading-starts t)
243     (setq org-src-fontify-natively t)
244     (setq org-src-tab-acts-natively t)
245     (setq org-confirm-babel-evaluate nil)
246
247   (org-babel-do-load-languages
248    'org-babel-load-languages
249    '((python . t)
250      (C . t)
251      (calc . t)
252      (latex . t)
253      (java . t)
254      (ruby . t)
255      (lisp . t)
256      (scheme . t)
257      (sh . t)
258      (sqlite . t)
259      (js . t)))
260
261   (setq org-use-speed-commands t
262         org-completion-use-ido t)
263  
264
265 #+END_SRC
266
267 ** Org-bullets
268
269 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
270
271 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
272
273   (use-package org-bullets
274     :ensure t
275     :init
276     (add-hook 'org-mode-hook
277               (lambda ()
278                 (org-bullets-mode t))))
279
280 #+END_SRC
281
282 ** Worf Mode
283
284 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode
285
286 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
287
288   (use-package worf
289     :ensure t
290     :commands worf-mode
291     :init (add-hook 'org-mode-hook 'worf-mode))
292
293
294 #+END_SRC
295 ** Task Management
296
297 ** Capture
298
299 * Magit
300
301 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
302
303 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
304
305   (use-package magit
306     :ensure t
307     :commands magit-status magit-blame)
308
309
310 #+END_SRC
311
312 * IDO & SMEX
313
314 ** IDO
315
316 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
317
318   (use-package ido
319     :ensure t
320     :init (setq ido-enable-flex-matching t
321                 ido-ignore-extensions t
322                 ido-use-virtual-buffers t
323                 ido-everywhere t)
324     :config
325     (ido-mode 1)
326     (ido-everywhere 1)
327     (add-to-list 'completion-ignored-extensions ".pyc"))
328
329 #+END_SRC
330
331 ** FLX
332
333 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
334
335   (use-package flx-ido
336     :ensure t
337     :init (setq ido-enable-flex-matching t
338                 ido-use-faces nil)
339     :config (flx-ido-mode 1))
340
341 #+END_SRC
342
343 ** IDO-vertically
344
345 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
346
347   (use-package ido-vertical-mode
348     :ensure t
349     :init
350     (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
351     :config
352     (ido-vertical-mode 1))
353
354 #+END_SRC
355
356 ** SMEX
357
358 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
359
360   (use-package smex
361     :ensure t
362     :init (smex-initialize)
363     :bind
364     ("M-x" . smex)
365     ("M-X" . smex-major-mode-commands))
366
367 #+END_SRC
368
369 * Misc Settings
370
371 ** Line Number
372
373 Enable linum mode on programming modes
374
375 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
376
377   (add-hook 'prog-mode-hook 'linum-mode)
378
379 #+END_SRC
380
381 Fix the font size of line number
382
383 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
384
385   (defun fix-linum-size ()
386        (interactive)
387        (set-face-attribute 'linum nil :height 110))
388
389   (add-hook 'linum-mode-hook 'fix-linum-size)
390
391 #+END_SRC
392
393 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
394
395 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
396
397   (use-package linum-relative
398     :ensure t
399     :config
400     (defun linum-new-mode ()
401       "If line numbers aren't displayed, then display them.
402   Otherwise, toggle between absolute and relative numbers."
403       (interactive)
404       (if linum-mode
405           (linum-relative-toggle)
406         (linum-mode 1)))
407
408     :bind
409     ("A-k" . linum-new-mode))
410
411   ;; auto enable linum-new-mode in programming modes
412   (add-hook 'prog-mode-hook 'linum-relative-mode)
413
414 #+END_SRC
415
416 ** Save File Position
417
418 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
419
420   (require 'saveplace)
421   (setq-default save-place t)
422   (setq save-place-forget-unreadable-files t)
423   (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
424
425 #+END_SRC
426
427 * Eshell Setting
428
429 Setting PATH environment variable
430
431 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
432
433   (setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin"))
434
435 #+END_SRC
436
437 * Programming Languages
438
439 ** Emacs Lisp
440
441 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
442
443   (use-package color-identifiers-mode
444     :ensure t
445     :init
446     (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
447     :diminish color-identifiers-mode)
448
449 #+END_SRC
450
451 * Others
452
453 ** Shell pop mode
454
455 ** Smartparens mode
456
457 **