5d92caa1c66c1a84bb9c4d700990d4be6d50e2fe
[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 1)
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 * Package Management Tools
53
54 ** Use-package
55
56 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
57
58 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
59
60   (unless (package-installed-p 'use-package)
61     (package-refresh-contents)
62     (package-install 'use-package))
63
64   (require 'use-package)
65
66 #+END_SRC
67
68 ** El-get
69
70 [[https://github.com/dimitri/el-get][El-get]] is package management tool, whicl allows to install external elisp package from any git repository not in mepla. 
71 Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
72
73 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
74
75   (use-package el-get
76     :ensure t
77     :init
78     (add-to-list 'load-path "~/.emacs.d/el-get"))
79
80 #+END_SRC
81
82 * Color and Fonts Settings
83
84 ** highlight current line
85
86 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
87
88   (global-hl-line-mode)
89
90 #+END_SRC
91
92 ** Smart Comments
93
94 [[https://github.com/paldepind/smart-comment][smart-comments]]
95
96 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
97
98   (use-package smart-comment
99     :ensure t
100     :bind ("M-;" . smart-conmment))
101
102 #+END_SRC
103
104 ** Font Setting
105
106 syntax highlighting
107
108 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
109
110   (global-font-lock-mode 1)
111
112 #+END_SRC
113
114 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
115
116 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
117
118   (if window-system
119       (defvar sd/fixed-font-family
120         (cond ((x-list-fonts "Hasklig")         "Hasklig")
121               ((x-list-fonts "Source Code Pro") "Source Code Pro")
122               ((x-list-fonts "Anonymous Pro")   "Anonymous Pro")
123               ((x-list-fonts "M+ 1mn")          "M+ 1mn"))
124         "The fixed width font based on what is installed, `nil' if not defined."))
125
126 #+END_SRC
127
128 Setting the fonts 
129
130 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
131
132   (if window-system
133       (when sd/fixed-font-family
134         (set-frame-font sd/fixed-font-family)
135         (set-face-attribute 'default nil :font sd/fixed-font-family :height 140)
136         (set-face-font 'default sd/fixed-font-family)))
137
138 #+END_SRC
139
140 ** Color Theme
141
142 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
143
144 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
145
146   (setq vc-follow-symlinks t)
147
148   (use-package color-theme
149     :ensure t
150     :init (require 'color-theme)
151     :config (use-package color-theme-sanityinc-tomorrow
152               :ensure t
153               :no-require t
154               :config
155               (load-theme 'sanityinc-tomorrow-bright t)))
156
157   ;(eval-after-load 'color-theme
158   ;  (load-theme 'sanityinc-tomorrow-bright t))
159
160 #+END_SRC
161
162 Change the Org-mode colors 
163
164 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
165
166   (defun org-src-color-blocks-light ()
167     "Colors the block headers and footers to make them stand out more for lighter themes"
168     (interactive)
169     (custom-set-faces
170      '(org-block-begin-line
171       ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
172      '(org-block-background
173        ((t (:background "#FFFFEA"))))
174      '(org-block
175        ((t (:background "#FFFFEA"))))
176      '(org-block-end-line
177        ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
178
179      '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
180      '(which-func ((t (:foreground "#008000"))))))
181
182   (defun org-src-color-blocks-dark ()
183     "Colors the block headers and footers to make them stand out more for dark themes"
184     (interactive)
185     (custom-set-faces
186      '(org-block-begin-line
187        ((t (:foreground "#008ED1" :background "#002E41"))))
188      '(org-block-background
189        ((t (:background "#000000"))))
190      '(org-block
191        ((t (:background "#000000"))))
192      '(org-block-end-line
193        ((t (:foreground "#008ED1" :background "#002E41"))))
194
195      '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
196      '(which-func ((t (:foreground "green"))))))
197
198   (org-src-color-blocks-dark)
199
200 #+END_SRC
201
202 improve color for org-mode
203 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
204   (deftheme ha/org-theme "Sub-theme to beautify org mode")
205
206   (if window-system
207       (defvar sd/variable-font-tuple
208         (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
209               ((x-list-fonts "Lucida Grande")   '(:font "Lucida Grande"))
210               ((x-list-fonts "Verdana")         '(:font "Verdana"))
211               ((x-family-fonts "Sans Serif")    '(:family "Sans Serif"))
212               (nil (warn "Cannot find a Sans Serif Font.  Install Source Sans Pro.")))
213         "My variable width font available to org-mode files and whatnot."))
214
215   (defun sd/org-color ()
216     (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
217            (base-font-color     (face-foreground 'default nil 'default))
218            (background-color    (face-background 'default nil 'default))
219            (primary-color       (face-foreground 'mode-line nil))
220            (secondary-color     (face-background 'secondary-selection nil 'region))
221            (base-height         (face-attribute 'default :height))
222            (headline           `(:inherit default :weight bold :foreground ,base-font-color)))
223       (custom-theme-set-faces 'ha/org-theme
224                               `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
225                               `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
226                               `(org-table ((t (:inherit 'fixed-pitched))))
227                               `(org-block ((t (:inherit 'fixed-pitched))))
228                               `(org-block-background ((t (:inherit 'fixed-pitched))))
229                               `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
230                               `(org-block-end-line ((t (:inherit 'fixed-pitched))))
231                               `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
232                               `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
233                               `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
234                               `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
235                               `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
236                                                             :height ,(round (* 1.1 base-height))))))
237                               `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
238                                                             :height ,(round (* 1.25 base-height))))))
239                               `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
240                                                             :height ,(round (* 1.5 base-height))))))
241                               `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
242                                                             :height ,(round (* 1.75 base-height))))))
243                               `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
244
245
246 #+END_SRC
247
248 * Org-mode Settings
249
250 ** Org-mode Basic setting
251
252 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent= 
253
254 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
255
256   (use-package org
257     :ensure t
258     :init
259     (setq org-startup-indented t)
260     (setq org-hide-leading-starts t)
261     (setq org-src-fontify-natively t)
262     (setq org-src-tab-acts-natively t)
263     (setq org-confirm-babel-evaluate nil)
264     (setq org-use-speed-commands t)
265     (setq org-completion-use-ido t))
266
267   (org-babel-do-load-languages
268    'org-babel-load-languages
269    '((python . t)
270      (C . t)
271      (perl . t)
272      (calc . t)
273      (latex . t)
274      (java . t)
275      (ruby . t)
276      (lisp . t)
277      (scheme . t)
278      (sh . t)
279      (sqlite . t)
280      (js . t)))
281
282 #+END_SRC
283
284 ** Org-bullets
285
286 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
287
288 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
289
290   (use-package org-bullets
291     :ensure t
292     :init
293     (add-hook 'org-mode-hook
294               (lambda ()
295                 (org-bullets-mode t))))
296
297 #+END_SRC
298
299 ** Worf Mode
300
301 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode. 
302 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
303 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
304 =M-[= and =M-]=
305
306 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
307
308   (use-package worf
309     :ensure t
310     :commands worf-mode
311     :init (add-hook 'org-mode-hook 'worf-mode)
312     :config
313     (define-key worf-mode-map "[" nil)
314     (define-key worf-mode-map "]" nil)
315     (define-key worf-mode-map (kbd "M-[") 'worf-backward)
316     (define-key worf-mode-map (kbd "M-]") 'worf-forward))
317
318 #+END_SRC
319
320 ** Task Management
321
322 ** Capture
323
324 * Magit
325
326 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
327
328 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
329
330   (use-package magit
331     :ensure t
332     :commands magit-status magit-blame)
333
334
335 #+END_SRC
336
337 * IDO & SMEX
338
339 ** IDO
340
341 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
342
343   (use-package ido
344     :ensure t
345     :init (setq ido-enable-flex-matching t
346                 ido-ignore-extensions t
347                 ido-use-virtual-buffers t
348                 ido-everywhere t)
349     :config
350     (ido-mode 1)
351     (ido-everywhere 1)
352     (add-to-list 'completion-ignored-extensions ".pyc"))
353
354 #+END_SRC
355
356 ** FLX
357
358 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
359
360   (use-package flx-ido
361     :ensure t
362     :init (setq ido-enable-flex-matching t
363                 ido-use-faces nil)
364     :config (flx-ido-mode 1))
365
366 #+END_SRC
367
368 ** IDO-vertically
369
370 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
371
372   (use-package ido-vertical-mode
373     :ensure t
374     :init
375     (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
376     :config
377     (ido-vertical-mode 1))
378
379 #+END_SRC
380
381 ** SMEX
382
383 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
384
385   (use-package smex
386     :ensure t
387     :init (smex-initialize)
388     :bind
389     ("M-x" . smex)
390     ("M-X" . smex-major-mode-commands))
391
392 #+END_SRC
393
394 * Misc Settings
395
396 ** Line Number
397
398 Enable linum mode on programming modes
399
400 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
401
402   (add-hook 'prog-mode-hook 'linum-mode)
403
404 #+END_SRC
405
406 Fix the font size of line number
407
408 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
409
410   (defun fix-linum-size ()
411        (interactive)
412        (set-face-attribute 'linum nil :height 110))
413
414   (add-hook 'linum-mode-hook 'fix-linum-size)
415
416 #+END_SRC
417
418 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
419
420 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
421
422   (use-package linum-relative
423     :ensure t
424     :config
425     (defun linum-new-mode ()
426       "If line numbers aren't displayed, then display them.
427   Otherwise, toggle between absolute and relative numbers."
428       (interactive)
429       (if linum-mode
430           (linum-relative-toggle)
431         (linum-mode 1)))
432
433     :bind
434     ("A-k" . linum-new-mode))
435
436   ;; auto enable linum-new-mode in programming modes
437   (add-hook 'prog-mode-hook 'linum-relative-mode)
438
439 #+END_SRC
440
441 ** Save File Position
442
443 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
444
445   (require 'saveplace)
446   (setq-default save-place t)
447   (setq save-place-forget-unreadable-files t)
448   (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
449
450 #+END_SRC
451
452 ** Multi-term
453
454 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
455
456   (use-package multi-term
457     :ensure t)
458
459 #+END_SRC
460
461 ** ace-link
462
463 [[https://github.com/abo-abo/ace-link][ace-link]] is a package written by [[https://github.com/abo-abo][Oleh Krehel]]. It is convenient to jump to link in help mode, info-mode, etc
464 Type =o= to go to the link
465
466 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
467
468   (use-package ace-link
469     :ensure t
470     :init
471     (ace-link-setup-default))
472
473 #+END_SRC
474
475 * Programming Languages
476
477 ** Emacs Lisp
478
479 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
480
481   (use-package color-identifiers-mode
482     :ensure t
483     :init
484     (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
485
486     :diminish color-identifiers-mode)
487
488 #+END_SRC
489
490 ** Perl
491
492 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
493
494 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
495
496    (defalias 'perl-mode 'cperl-mode)
497
498    (setq cperl-hairy t) ;; Turns on most of the CPerlMode options
499    (setq cperl-auto-newline t)
500    (setq cperl-highlight-variables-indiscriminately t)
501
502   ;(add-to-list 'load-path "~/.emacs.d/elisp/")
503   ;(require 'template)
504   ;(template-initialize)
505   ;(require 'perlnow)
506
507 #+END_SRC
508
509 * Others
510
511 ** Shell pop mode
512
513 ** Smartparens mode
514
515 ***