082b9ba4d69580b4820ebaf08dce099be7c82cff
[dotfiles.git] / emacs.d / 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 and [[https://github.com/abo-abo/oremacs][abo-abo's]] dotfiles
8
9 * Basic Settings
10
11 ** Setting loading Path
12
13 Set system PATH and emacs exec path
14
15 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
16
17   (setenv "PATH" (concat (getenv "PATH")
18                          ":" "/usr/local/bin"
19                          ":" "/Library/TeX/texbin"))
20   (setq exec-path (append exec-path '("/usr/local/bin")))
21   (setq exec-path (append exec-path '("/Library/TeX/texbin/")))
22
23 #+END_SRC
24
25 Set the emacs load path
26
27 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
28
29   (add-to-list 'load-path "~/.emacs.d/elisp")
30
31 #+END_SRC
32
33 ** Package Initialization
34
35 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
36
37   (require 'package)
38
39   (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
40                            ("gnu" . "http://elpa.gnu.org/packages/")
41                            ("org" . "http://orgmode.org/elpa/")))
42
43   (package-initialize)
44
45 #+END_SRC       
46
47 ** General Setting
48
49 Disable scroll bar, tool-bar and menu-bar
50
51 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
52
53   (scroll-bar-mode 0)
54   (tool-bar-mode 0)
55   (menu-bar-mode 1)
56
57   (setq debug-on-error t)
58   (setq inhibit-startup-message t)
59
60   (defalias 'yes-or-no-p 'y-or-n-p)
61   (show-paren-mode 1)
62
63
64
65 #+END_SRC
66
67 set custom file 
68
69 #+BEGIN_SRC emacs-lisp :tangle yes :results silent 
70
71   (setq custom-file "~/.emacs.d/custom.el")
72   (if (file-exists-p custom-file)
73       (load custom-file))
74
75 #+END_SRC
76
77 Switch the focus to help window when it appears
78
79 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
80
81   (setq help-window-select t)
82
83 #+END_SRC
84
85 * Package Management Tools
86
87 ** Use-package
88
89 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
90
91 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
92
93   (unless (package-installed-p 'use-package)
94     (package-refresh-contents)
95     (package-install 'use-package))
96
97   (require 'use-package)
98
99 #+END_SRC
100
101 ** El-get
102
103 [[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. 
104 Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
105
106 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
107
108   (use-package el-get
109     :ensure t
110     :init
111     (add-to-list 'load-path "~/.emacs.d/el-get"))
112
113 #+END_SRC
114
115 * Color and Fonts Settings
116
117 ** highlight current line
118
119 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
120
121   (global-hl-line-mode)
122
123 #+END_SRC
124
125 ** Smart Comments
126
127 [[https://github.com/paldepind/smart-comment][smart-comments]]
128
129 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
130
131   (use-package smart-comment
132     :ensure t
133     :bind ("M-;" . smart-conmment))
134
135 #+END_SRC
136
137 ** Font Setting
138
139 syntax highlighting
140
141 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
142
143   (global-font-lock-mode 1)
144
145 #+END_SRC
146
147 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
148
149 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
150
151   (if window-system
152       (defvar sd/fixed-font-family
153         (cond ((x-list-fonts "Hasklig")         "Hasklig")
154               ((x-list-fonts "Source Code Pro") "Source Code Pro")
155               ((x-list-fonts "Anonymous Pro")   "Anonymous Pro")
156               ((x-list-fonts "M+ 1mn")          "M+ 1mn"))
157         "The fixed width font based on what is installed, `nil' if not defined."))
158
159 #+END_SRC
160
161 Setting the fonts 
162
163 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
164
165   (if window-system
166       (when sd/fixed-font-family
167         (set-frame-font sd/fixed-font-family)
168         (set-face-attribute 'default nil :font sd/fixed-font-family :height 120)
169         (set-face-font 'default sd/fixed-font-family)))
170
171 #+END_SRC
172
173 ** Color Theme
174
175 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
176
177 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
178
179   (setq vc-follow-symlinks t)
180
181   (use-package color-theme
182     :ensure t
183     :init (require 'color-theme)
184     :config (use-package color-theme-sanityinc-tomorrow
185               :ensure t
186               :no-require t
187               :config
188               (load-theme 'sanityinc-tomorrow-bright t)))
189
190   ;(eval-after-load 'color-theme
191   ;  (load-theme 'sanityinc-tomorrow-bright t))
192
193 #+END_SRC
194
195 Change the Org-mode colors 
196
197 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
198
199   (defun org-src-color-blocks-light ()
200     "Colors the block headers and footers to make them stand out more for lighter themes"
201     (interactive)
202     (custom-set-faces
203      '(org-block-begin-line
204       ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
205      '(org-block-background
206        ((t (:background "#FFFFEA"))))
207      '(org-block
208        ((t (:background "#FFFFEA"))))
209      '(org-block-end-line
210        ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
211
212      '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
213      '(which-func ((t (:foreground "#008000"))))))
214
215   (defun org-src-color-blocks-dark ()
216     "Colors the block headers and footers to make them stand out more for dark themes"
217     (interactive)
218     (custom-set-faces
219      '(org-block-begin-line
220        ((t (:foreground "#008ED1" :background "#002E41"))))
221      '(org-block-background
222        ((t (:background "#000000"))))
223      '(org-block
224        ((t (:background "#000000"))))
225      '(org-block-end-line
226        ((t (:foreground "#008ED1" :background "#002E41"))))
227
228      '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
229      '(which-func ((t (:foreground "green"))))))
230
231   (org-src-color-blocks-dark)
232
233 #+END_SRC
234
235 improve color for org-mode
236 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
237   (deftheme ha/org-theme "Sub-theme to beautify org mode")
238
239   (if window-system
240       (defvar sd/variable-font-tuple
241         (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
242               ((x-list-fonts "Lucida Grande")   '(:font "Lucida Grande"))
243               ((x-list-fonts "Verdana")         '(:font "Verdana"))
244               ((x-family-fonts "Sans Serif")    '(:family "Sans Serif"))
245               (nil (warn "Cannot find a Sans Serif Font.  Install Source Sans Pro.")))
246         "My variable width font available to org-mode files and whatnot."))
247
248   (defun sd/org-color ()
249     (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
250            (base-font-color     (face-foreground 'default nil 'default))
251            (background-color    (face-background 'default nil 'default))
252            (primary-color       (face-foreground 'mode-line nil))
253            (secondary-color     (face-background 'secondary-selection nil 'region))
254            (base-height         (face-attribute 'default :height))
255            (headline           `(:inherit default :weight bold :foreground ,base-font-color)))
256       (custom-theme-set-faces 'ha/org-theme
257                               `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
258                               `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
259                               `(org-table ((t (:inherit 'fixed-pitched))))
260                               `(org-block ((t (:inherit 'fixed-pitched))))
261                               `(org-block-background ((t (:inherit 'fixed-pitched))))
262                               `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
263                               `(org-block-end-line ((t (:inherit 'fixed-pitched))))
264                               `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
265                               `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
266                               `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
267                               `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
268                               `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
269                                                             :height ,(round (* 1.1 base-height))))))
270                               `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
271                                                             :height ,(round (* 1.25 base-height))))))
272                               `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
273                                                             :height ,(round (* 1.5 base-height))))))
274                               `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
275                                                             :height ,(round (* 1.75 base-height))))))
276                               `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
277
278
279 #+END_SRC
280
281 ** Rainbow-delimiter
282
283 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
284
285   (use-package rainbow-delimiters
286     :ensure t
287     :init
288     (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
289
290 #+END_SRC
291
292 ** page-break-lines
293
294 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
295
296   (use-package page-break-lines
297     :ensure t
298     :config
299     (turn-on-page-break-lines-mode))
300
301 #+END_SRC
302
303 * Org-mode Settings
304
305 ** Org-mode Basic setting
306
307 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent= 
308
309 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
310
311   (use-package org
312     :ensure t
313     :init
314     (setq org-startup-indented t)
315     (setq org-hide-leading-starts t)
316     (setq org-src-fontify-natively t)
317     (setq org-src-tab-acts-natively t)
318     (setq org-confirm-babel-evaluate nil)
319     (setq org-use-speed-commands t)
320     (setq org-completion-use-ido t))
321
322   (org-babel-do-load-languages
323    'org-babel-load-languages
324    '((python . t)
325      (C . t)
326      (perl . t)
327      (calc . t)
328      (latex . t)
329      (java . t)
330      (ruby . t)
331      (lisp . t)
332      (scheme . t)
333      (sh . t)
334      (sqlite . t)
335      (js . t)))
336
337   ;; use current window for org source buffer editting
338   (setq org-src-window-setup 'current-window )
339
340 #+END_SRC
341
342 ** Org-bullets
343
344 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
345
346 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
347
348   (use-package org-bullets
349     :ensure t
350     :init
351     (add-hook 'org-mode-hook
352               (lambda ()
353                 (org-bullets-mode t))))
354
355 #+END_SRC
356
357 ** Worf Mode
358
359 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode. 
360 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
361 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
362 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
363
364 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
365
366   (use-package worf
367     :ensure t
368     :commands worf-mode
369     :init (add-hook 'org-mode-hook 'worf-mode)
370     ;; :config
371     ;; (define-key worf-mode-map "[" nil)
372     ;; (define-key worf-mode-map "]" nil)
373     ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
374     ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
375     )
376
377 #+END_SRC
378
379 ** Task Management
380
381 ** Capture
382
383 ** Export PDF
384
385 Install MacTex-basic and some tex packages
386
387 #+BEGIN_SRC bash 
388
389   sudo tlmgr update --self
390
391   sudo tlmgr install titlesec framed threeparttable wrapfig multirow enumitem bbding titling tabu mdframed tcolorbox textpos import varwidth needspace tocloft ntheorem environ trimspaces collection-fontsrecommended capt-of
392
393 #+END_SRC
394
395 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
396   ;; ;; allow for export=>beamer by placing
397
398   ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
399   ;; #+LaTeX_CLASS: beamer in org files
400   (unless (boundp 'org-export-latex-classes)
401     (setq org-export-latex-classes nil))
402   (add-to-list 'org-export-latex-classes
403     ;; beamer class, for presentations
404     '("beamer"
405        "\\documentclass[11pt]{beamer}\n
406         \\mode<{{{beamermode}}}>\n
407         \\usetheme{{{{beamertheme}}}}\n
408         \\usecolortheme{{{{beamercolortheme}}}}\n
409         \\beamertemplateballitem\n
410         \\setbeameroption{show notes}
411         \\usepackage[utf8]{inputenc}\n
412         \\usepackage[T1]{fontenc}\n
413         \\usepackage{hyperref}\n
414         \\usepackage{color}
415         \\usepackage{listings}
416         \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
417     frame=single,
418     basicstyle=\\small,
419     showspaces=false,showstringspaces=false,
420     showtabs=false,
421     keywordstyle=\\color{blue}\\bfseries,
422     commentstyle=\\color{red},
423     }\n
424         \\usepackage{verbatim}\n
425         \\institute{{{{beamerinstitute}}}}\n          
426          \\subject{{{{beamersubject}}}}\n"
427
428        ("\\section{%s}" . "\\section*{%s}")
429  
430        ("\\begin{frame}[fragile]\\frametitle{%s}"
431          "\\end{frame}"
432          "\\begin{frame}[fragile]\\frametitle{%s}"
433          "\\end{frame}")))
434
435     ;; letter class, for formal letters
436
437     (add-to-list 'org-export-latex-classes
438
439     '("letter"
440        "\\documentclass[11pt]{letter}\n
441         \\usepackage[utf8]{inputenc}\n
442         \\usepackage[T1]{fontenc}\n
443         \\usepackage{color}"
444  
445        ("\\section{%s}" . "\\section*{%s}")
446        ("\\subsection{%s}" . "\\subsection*{%s}")
447        ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
448        ("\\paragraph{%s}" . "\\paragraph*{%s}")
449        ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
450
451
452   (require 'ox-md)
453   (require 'ox-beamer)
454
455   (setq org-latex-pdf-process
456         '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
457           "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
458           "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
459
460   (setq TeX-parse-self t)
461
462   (setq TeX-PDF-mode t)
463   (add-hook 'LaTeX-mode-hook
464             (lambda ()
465               (LaTeX-math-mode)
466               (setq TeX-master t)))
467
468 #+END_SRC
469
470 ** others
471
472 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]]
473
474 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
475
476   (setq org-todo-keywords '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
477                             (sequence "âš‘ WAITING(w)" "|")
478                             (sequence "|" "✘ CANCELED(c)")))
479
480 #+END_SRC
481
482 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
483
484 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
485
486   (add-to-list 'org-structure-template-alist
487                '("E" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"))
488   (add-to-list 'org-structure-template-alist
489                '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
490   (add-to-list 'org-structure-template-alist
491                '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
492
493 #+END_SRC
494
495 * Magit
496
497 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
498
499 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
500
501   (use-package magit
502     :ensure t
503     :commands magit-status magit-blame)
504
505
506 #+END_SRC
507
508 * IDO & SMEX
509
510 ** IDO
511
512 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
513
514   (use-package ido
515     :ensure t
516     :init (setq ido-enable-flex-matching t
517                 ido-ignore-extensions t
518                 ido-use-virtual-buffers t
519                 ido-everywhere t)
520     :config
521     (ido-mode 1)
522     (ido-everywhere 1)
523     (add-to-list 'completion-ignored-extensions ".pyc"))
524
525   (icomplete-mode t)
526
527 #+END_SRC
528
529 ** FLX
530
531 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
532
533   (use-package flx-ido
534     :ensure t
535     :init (setq ido-enable-flex-matching t
536                 ido-use-faces nil)
537     :config (flx-ido-mode 1))
538
539 #+END_SRC
540
541 ** IDO-vertically
542
543 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
544
545   (use-package ido-vertical-mode
546     :ensure t
547     :init
548     (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
549     :config
550     (ido-vertical-mode 1))
551
552 #+END_SRC
553
554 ** SMEX
555
556 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
557
558   (use-package smex
559     :ensure t
560     :init (smex-initialize)
561     :bind
562     ("M-x" . smex)
563     ("M-X" . smex-major-mode-commands))
564
565 #+END_SRC
566
567 ** Ido-ubiquitous
568
569 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
570
571 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
572
573   (use-package ido-ubiquitous
574     :ensure t
575     :init
576     (setq magit-completing-read-function 'magit-ido-completing-read)
577     (setq gnus-completing-read-function 'gnus-ido-completing-read)
578     :config
579     (ido-ubiquitous-mode 1))
580
581 #+END_SRC
582
583 ** Ido-exit-target
584
585 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
586
587 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
588
589   (use-package ido-exit-target
590     :ensure t
591     :init
592     (define-key ido-common-completion-map (kbd "C-j") #'ido-exit-target-split-window-right)
593     (define-key ido-common-completion-map (kbd "C-l") #'ido-exit-target-split-window-below))
594
595 #+END_SRC
596
597 * Key bindings
598
599 ** Remove prefix =ESC=, refer [[http://emacs.stackexchange.com/questions/14755/how-to-remove-bindings-to-the-esc-prefix-key][here]]
600
601 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
602
603   ;; (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
604
605 #+END_SRC
606
607 ** Esc on Minibuffer
608
609 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
610
611 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
612
613   (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
614   (define-key minibuffer-local-map [escape]  'keyboard-escape-quit)
615   (define-key minibuffer-local-ns-map [escape]  'keyboard-escape-quit)
616   (define-key minibuffer-local-isearch-map [escape]  'keyboard-escape-quit)
617   (define-key minibuffer-local-completion-map [escape]  'keyboard-escape-quit)
618   (define-key minibuffer-local-must-match-map [escape]  'keyboard-escape-quit)
619   (define-key minibuffer-local-must-match-filename-map [escape]  'keyboard-escape-quit)
620   (define-key minibuffer-local-filename-completion-map [escape]  'keyboard-escape-quit)
621   (define-key minibuffer-local-filename-must-match-map [escape]  'keyboard-escape-quit)
622
623   ;; Also map s-h same as C-g
624   (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
625
626 #+END_SRC
627
628 ** =Ctrl= key bindings
629
630 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
631   ;;
632
633   ;; C-h    help    
634   ;; C-j    newline and indent
635   ;; C-k    kill line
636   ;; C-l    recenter-top-bottom
637   ;; (global-set-key (kbd "C-;") 'ido-switch-buffer)
638   ;; C-;
639   ;; C-'   
640   ;; C-ret  
641
642   ;; C-n    next-line
643   ;; C-m
644   ;; C-,
645   ;; C-.
646   ;; C-/
647
648   ;; C-y
649   ;; C-u
650   ;; C-i
651   ;; C-o
652   ;; C-p
653   ;; C-[
654   ;; C-]
655   ;; C-\
656
657   ;; C-=
658   ;; C--
659   ;; C-0
660   ;; C-9
661   ;; C-8
662   ;; C-7
663
664   ;; C-Space
665
666
667
668
669
670
671
672 #+END_SRC
673
674 ** =Super= bindings for file, buffer and windows
675
676 Some global bindings on =Super=, on Mac, it is =Command=
677
678 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
679
680   (global-set-key (kbd "s-h") 'keyboard-quit)
681   (global-set-key (kbd "s-j") 'ido-switch-buffer)
682   (global-set-key (kbd "s-k") 'ido-find-file)
683   ;; s-k  -->  kill-this-buffer
684   (global-set-key (kbd "s-l") (lambda ()
685                                 (interactive)
686                                 (if (> (length (window-list)) 1) 
687                                     (delete-window)
688                                   (message "Only one Windows now!"))))
689   ;; s-l  -->  goto-line
690   (global-set-key (kbd "s-;") 'swiper)
691   ;; s-;  -->
692   ;; s-'  -->  'next-multiframe-window
693   (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
694
695   ;; (global-set-key (kbd "s-y") 'projectile-find-file)
696   (global-set-key (kbd "s-f") 'projectile-find-file)
697   (global-set-key (kbd "s-[") 'persp-next)
698   (global-set-key (kbd "s-]") 'persp-prev)
699
700   (global-set-key (kbd "s-`") 'mode-line-other-buffer)
701
702   (global-set-key (kbd "s-n") 'persp-next)
703   (global-set-key (kbd "s-p") 'persp-prev)
704
705
706
707   ;; someothers default mapping on super (command) key
708   ;; s-s save-buffer
709   ;; s-k kill-this-buffer
710
711
712   ;; s-h  -->  ns-do-hide-emacs
713   ;; s-j  -->  ido-switch-buffer  +
714   ;; s-k  -->  kill-this-buffer
715   ;; s-l  -->  goto-line
716   ;; s-;  -->  undefined
717   ;; s-'  -->  next-multiframe-window
718   ;; s-ret --> toggle-frame-fullscreen +
719
720   ;; s-y  -->  ns-paste-secondary
721   ;; s-u  -->  revert-buffer
722   ;; s-i  -->  undefined - but used for iterm globally
723   ;; s-o  -->  used for emacs globally
724   ;; s-p  -->  projectile-persp-switch-project  +  
725   ;; s-[  -->  next-buffer  +    
726   ;; s-]  -->  previous-buffer +
727
728   ;; s-0  -->  undefined
729   ;; s-9  -->  undefined
730   ;; s-8  -->  undefined
731   ;; s-7  -->  undefined
732   ;; s-6  -->  undefined
733   ;; s--  -->  center-line
734   ;; s-=  -->  undefined
735
736   ;; s-n  -->  make-frame
737   ;; s-m  -->  iconify-frame
738   ;; s-b  -->  undefined
739   ;; s-,  -->  customize
740   ;; s-.  -->  undefined
741   ;; s-/  -->  undefined
742
743   ;; s-g  -->  isearch-repeat-forward
744   ;; s-f  -->  projectile-find-file   +
745   ;; s-d  -->  isearch-repeat-background
746   ;; s-s  -->  save-buffer
747   ;; s-a  -->  make-whole-buffer
748
749   ;; s-b  -->  undefined
750   ;; s-v  -->  yank
751   ;; s-c  -->  ns-copy-including-secondary
752
753   ;; s-t  -->  ns-popup-font-panel
754   ;; s-r  -->  undefined
755   ;; s-e  -->  isearch-yanqk-kill
756   ;; s-w  -->  delete-frame
757   ;; s-q  -->  same-buffers-kill-emacs
758
759   ;; s-`  -->  other-frame
760 #+END_SRC
761
762 ** =M-s= bindings for searching
763
764 I use the prefix =M-s= for searching in buffers
765
766 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
767
768   (defun pl-make-keymap (key bindings)
769     (setq keymap (make-sparse-keymap))
770     (dolist (binding bindings)
771       (define-key keymap (car binding) (cdr binding)))
772     (global-set-key key keymap))
773
774   (define-key minibuffer-local-map "\M-s" nil)
775
776   (global-set-key (kbd "M-s s") 'isearch-forward-regexp)
777   (define-key isearch-mode-map "\M-s" 'isearch-repeat-forward)
778   (global-set-key (kbd "M-s r") 'isearch-backward-regexp)
779   (define-key isearch-mode-map "\M-r" 'isearch-repeat-backward)
780
781   (global-set-key (kbd "s-/") 'isearch-forward-regexp)
782   (define-key isearch-mode-map (kbd  "s-/") 'isearch-repeat-forward)
783   (define-key isearch-mode-map (kbd  "C-n") 'isearch-repeat-forward)
784
785
786   (set-face-background 'ido-first-match "white")
787
788   ;; M-s o  -->  occur
789   ;; M-s s  -->  isearch-forward-regexp
790   ;; M-s r  -->  isearch-backward-regexp
791   ;; M-s w  -->  isearch-forward-word
792   ;; M-s .  -->  isearch-forward-symbol-at-point
793   ;; M-s _  -->  isearch-forward-symbol
794
795   ;; highlight bindings
796   ;; M-s h .  -->  highlight-symbol-at-point
797   ;; M-s h r  -->  highlight-regexp
798   ;; M-s h u  -->  unhighlight-regexp
799   ;; M-s h l  -->  highlight-lines-match-regexp
800   ;; M-s h p  -->  highlight-phrase
801   ;; M-s h f  -->  hi-lock-find-patterns
802
803   ;; 
804   ;; (global-set-key (kbd "M-s M-r") 'isearch-backward-regexp)
805   ;;
806
807   ;; M-c
808   ;; M-r
809   ;; M-t
810   ;; M-u, 
811 #+END_SRC
812
813 Occur search key bindings
814
815 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
816
817   (define-key occur-mode-map (kbd "C-n")
818     (lambda ()
819       (interactive)
820       (occur-next)
821       (occur-mode-goto-occurrence-other-window)
822       (recenter)
823       (other-window 1)))
824
825   (define-key occur-mode-map (kbd "C-p")
826     (lambda ()
827       (interactive)
828       (occur-prev)
829       (occur-mode-goto-occurrence-other-window)
830       (recenter)
831       (other-window 1)))
832
833 #+END_SRC
834
835
836 ** =M-o= as prefix key for windows
837
838 ** =M-g= as prefix key for launcher
839
840 ** others
841
842 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
843
844
845   ;; C-'    undefined
846   ;; C-.    undefined
847 #+END_SRC
848
849 * Eshell
850
851 Eshell alias
852
853 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
854
855   (defalias 'e 'ido-find-file)
856   (defalias 'ff 'ido-find-file)
857   (defalias 'ee 'ido-find-file-other-window)
858
859 #+END_SRC
860
861 Quickly start eshll in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
862
863 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
864
865   (defun eshell-x ()
866     (insert "exit")
867     (eshell-send-input)
868     (delete-window))
869
870   (defun eshell-here ()
871     "Opens up a new shell in the directory associated with the
872   current buffer's file. The eshell is renamed to match that
873   directory to make multiple eshell windows easier."
874     (interactive)
875     (let* ((parent (if (buffer-file-name)
876                        (file-name-directory (buffer-file-name))
877                      default-directory))
878            (height (/ (window-total-height) 3))
879            (name   (car (last (split-string parent "/" t))))
880            (eshell-name (concat "*eshell: " name "*")))
881       (split-window-vertically (- height))
882       (other-window 1)
883       (if (get-buffer eshell-name)
884           (progn
885             (message "buffer exist")
886             (switch-to-buffer eshell-name))
887         (progn
888           (eshell "new")
889           (rename-buffer eshell-name)
890
891           (insert (concat "ls"))
892           (eshell-send-input)))))
893
894   ;; (global-set-key (kbd "M-`") (lambda ()
895   ;;                               (interactive)
896   ;;                               (if (buffer-name))))
897
898 #+END_SRC
899
900 * Misc Settings
901
902 ** [[https://github.com/abo-abo/hydra][Hydra]]
903
904 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
905
906   (use-package hydra
907     :ensure t)
908
909 #+END_SRC
910
911 *** Font Zoom
912
913 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
914
915   (defhydra sd/font-zoom (global-map "<f2>")
916     "zoom"
917     ("g" text-scale-increase "in")
918     ("l" text-scale-decrease "out"))
919
920 #+END_SRC
921
922 *** Windmove Splitter
923
924 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
925
926 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
927
928   (defun hydra-move-splitter-left (arg)
929     "Move window splitter left."
930     (interactive "p")
931     (if (let ((windmove-wrap-around))
932           (windmove-find-other-window 'right))
933         (shrink-window-horizontally arg)
934       (enlarge-window-horizontally arg)))
935
936   (defun hydra-move-splitter-right (arg)
937     "Move window splitter right."
938     (interactive "p")
939     (if (let ((windmove-wrap-around))
940           (windmove-find-other-window 'right))
941         (enlarge-window-horizontally arg)
942       (shrink-window-horizontally arg)))
943
944   (defun hydra-move-splitter-up (arg)
945     "Move window splitter up."
946     (interactive "p")
947     (if (let ((windmove-wrap-around))
948           (windmove-find-other-window 'up))
949         (enlarge-window arg)
950       (shrink-window arg)))
951
952   (defun hydra-move-splitter-down (arg)
953     "Move window splitter down."
954     (interactive "p")
955     (if (let ((windmove-wrap-around))
956           (windmove-find-other-window 'up))
957         (shrink-window arg)
958       (enlarge-window arg)))
959
960 #+END_SRC
961
962 *** hydra-window
963
964 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
965
966   (winner-mode 1)
967
968   (defhydra sd/hydra-window (:color red :columns nil)
969     "window"
970     ("h" windmove-left nil)
971     ("j" windmove-down nil)
972     ("k" windmove-up nil)
973     ("l" windmove-right nil)
974     ("H" hydra-move-splitter-left nil)
975     ("J" hydra-move-splitter-down nil)
976     ("K" hydra-move-splitter-up nil)
977     ("L" hydra-move-splitter-right nil)
978     ("v" (lambda ()
979            (interactive)
980            (split-window-right)
981            (windmove-right))
982      "vert")
983     ("x" (lambda ()
984            (interactive)
985            (split-window-below)
986            (windmove-down))
987      "horz")
988     ("o" delete-other-windows "one" :exit t)
989     ("a" ace-window "ace")
990     ("s" ace-swap-window "swap")
991     ("d" ace-delete-window "ace-one" :exit t)
992     ("i" ace-maximize-window "ace-one" :exit t)
993     ("b" ido-switch-buffer "buf")
994     ("m" headlong-bookmark-jump "bmk")
995     ("q" nil "cancel")
996     ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
997     ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
998     ("f" nil))
999
1000   (global-unset-key (kbd "M-o"))
1001   (global-set-key (kbd "M-o") 'sd/hydra-window/body)
1002
1003   (defun triggle-windows-max-size ()
1004     (interactive)
1005     (if (> (length (window-list)) 1)
1006         (delete-other-windows)
1007       (winner-undo)))
1008
1009 #+END_SRC
1010
1011 ** Line Number
1012
1013 Enable linum mode on programming modes
1014
1015 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1016
1017   (add-hook 'prog-mode-hook 'linum-mode)
1018
1019 #+END_SRC
1020
1021 Fix the font size of line number
1022
1023 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1024
1025   (defun fix-linum-size ()
1026        (interactive)
1027        (set-face-attribute 'linum nil :height 110))
1028
1029   (add-hook 'linum-mode-hook 'fix-linum-size)
1030
1031 #+END_SRC
1032
1033 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1034
1035 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1036
1037   (use-package linum-relative
1038     :ensure t
1039     :config
1040     (defun linum-new-mode ()
1041       "If line numbers aren't displayed, then display them.
1042   Otherwise, toggle between absolute and relative numbers."
1043       (interactive)
1044       (if linum-mode
1045           (linum-relative-toggle)
1046         (linum-mode 1)))
1047
1048     :bind
1049     ("A-k" . linum-new-mode))
1050
1051   ;; auto enable linum-new-mode in programming modes
1052   (add-hook 'prog-mode-hook 'linum-relative-mode)
1053
1054 #+END_SRC
1055
1056 ** Save File Position
1057
1058 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1059
1060   (require 'saveplace)
1061   (setq-default save-place t)
1062   (setq save-place-forget-unreadable-files t)
1063   (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1064
1065 #+END_SRC
1066
1067 ** Multi-term
1068
1069 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1070
1071   (use-package multi-term
1072     :ensure t)
1073
1074 #+END_SRC
1075
1076 ** ace-link
1077
1078 [[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
1079 Type =o= to go to the link
1080
1081 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1082
1083   (use-package ace-link
1084     :ensure t
1085     :init
1086     (ace-link-setup-default))
1087
1088 #+END_SRC
1089
1090 ** Emux
1091
1092 [[https://github.com/re5et/emux][emux]] is 
1093
1094 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1095
1096   (el-get-bundle re5et/emux)
1097
1098 #+END_SRC
1099
1100 ** Smart Parens
1101
1102 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1103
1104   (use-package smartparens
1105     :ensure t
1106     :config
1107     (progn
1108       (require 'smartparens-config)
1109       (add-hook 'prog-mode-hook 'smartparens-mode)))
1110
1111 #+END_SRC
1112
1113 ** Ace-Windows
1114
1115 [[https://github.com/abo-abo/ace-window][ace-window]] 
1116
1117 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1118
1119   (use-package ace-window
1120     :ensure t
1121     :defer t
1122   ;  :init
1123   ;  (global-set-key (kbd "M-o") 'ace-window)
1124     :config
1125     (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1126
1127 #+END_SRC
1128
1129 ** Projectile
1130
1131 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1132
1133   (use-package projectile
1134     :ensure t
1135     :init
1136     (setq projectile-enable-caching t)
1137     :config
1138     (projectile-global-mode t))
1139
1140   (use-package persp-projectile
1141     :ensure t
1142     :config
1143     (persp-mode)
1144     :bind
1145     (:map projectile-mode-map
1146           ("s-t" . projectile-persp-switch-project)))
1147
1148   ;; projectile-find-file
1149   ;; projectile-switch-buffer
1150   ;; projectile-find-file-other-window
1151 #+END_SRC
1152
1153 ** Which key
1154
1155 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings 
1156
1157 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1158
1159   (use-package which-key
1160     :ensure t
1161     :config
1162     (which-key-mode))
1163
1164 #+END_SRC
1165
1166 ** Emms
1167
1168 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1169
1170 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1171
1172   (use-package emms
1173     :ensure t
1174     :init
1175     (setq emms-source-file-default-directory "~/Music/emms/")
1176     :config
1177     (emms-standard)
1178     (emms-default-players)
1179     (define-emms-simple-player mplayer '(file url)
1180       (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1181                     ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1182                     "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1183                     ".m4a" ".flv" ".ogv" ".pls"))
1184       "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1185     (emms-history-load))
1186
1187 #+END_SRC
1188
1189 ** GnoGo
1190
1191 Play Go in Emacs, gnugo xpm refert [[https://github.com/okanotor/dotemacs/blob/f95b774cb292d1169748bc0a62ba647bbd8c0652/etc/my-inits/my-inits-gnugo.el][to here]]. start at image display mode and grid mode
1192
1193 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1194
1195   (use-package gnugo
1196     :ensure t
1197     :defer t
1198     :init
1199     (require 'gnugo-imgen)
1200     (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1201     (add-hook 'gnugo-start-game-hook '(lambda ()
1202                                         (gnugo-image-display-mode)
1203                                         (gnugo-grid-mode)))
1204       :config
1205     (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1206
1207 #+END_SRC
1208
1209 ** undo-tree
1210
1211 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1212
1213   (use-package undo-tree
1214     :ensure t
1215     :config
1216     (global-undo-tree-mode 1))
1217
1218 #+END_SRC
1219
1220 ** swiper
1221
1222 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1223
1224   (use-package swiper
1225     :ensure t)
1226
1227
1228   (ivy-mode 1)
1229   (setq ivy-use-virtual-buffers t)
1230   (global-set-key "\C-s" 'swiper)
1231   (global-set-key (kbd "C-c C-r") 'ivy-resume)
1232   (global-set-key (kbd "<f6>") 'ivy-resume)
1233   ;; (global-set-key (kbd "M-x") 'counsel-M-x)
1234   ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
1235   (global-set-key (kbd "<f1> f") 'counsel-describe-function)
1236   (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
1237   (global-set-key (kbd "<f1> l") 'counsel-load-library)
1238   (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
1239   (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
1240   (global-set-key (kbd "C-c g") 'counsel-git)
1241   (global-set-key (kbd "C-c j") 'counsel-git-grep)
1242   (global-set-key (kbd "C-c k") 'counsel-ag)
1243   (global-set-key (kbd "C-x l") 'counsel-locate)
1244   (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
1245   ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
1246
1247 #+END_SRC
1248
1249 ** Tabbar
1250
1251 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1252
1253   ;; (use-package tabbar-ruler
1254   ;;   :ensure t
1255   ;;   :init
1256   ;;   (setq tabbar-ruler-global-tabbar t)
1257   ;;   (setq tabbar-ruler-global-ruler t)
1258   ;;   (setq tabbar-ruler-popu-menu t)
1259   ;;   (setq tabbar-ruler-popu-toolbar t)
1260   ;;   (setq tabbar-use-images t)
1261   ;;   :config
1262   ;;   (tabbar-ruler-group-by-projectile-project)
1263   ;;   (global-set-key (kbd "s-1") 'tabbar-forward-group)
1264   ;;   (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1265
1266 #+END_SRC
1267
1268 * Programming
1269
1270 ** Languages
1271
1272 *** Emacs Lisp
1273
1274 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1275
1276   (use-package color-identifiers-mode
1277     :ensure t
1278     :init
1279     (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1280
1281     :diminish color-identifiers-mode)
1282
1283   (global-prettify-symbols-mode t)
1284
1285 #+END_SRC
1286
1287 **** Lispy Mode
1288
1289 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1290 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1291
1292 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1293
1294   (use-package lispy
1295     :ensure t
1296     :init
1297     (eval-after-load 'lispy
1298       '(progn
1299          (define-key lispy-mode-map (kbd "M-o") nil)))
1300     :config
1301     (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1302
1303 #+END_SRC
1304
1305 *** Perl
1306
1307 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1308
1309 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1310
1311   (defalias 'perl-mode 'cperl-mode)
1312
1313   ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
1314   (setq cperl-auto-newline t)
1315   (setq cperl-highlight-variables-indiscriminately t)
1316   ;(setq cperl-indent-level 4)
1317   ;(setq cperl-continued-statement-offset 4)
1318   (setq cperl-close-paren-offset -4)
1319   (setq cperl-indent-parents-as-block t)
1320   (setq cperl-tab-always-indent t)
1321   ;(setq cperl-brace-offset  0)
1322
1323   (add-hook 'cperl-mode-hook
1324             '(lambda ()
1325                (cperl-set-style "C++")))
1326
1327   ;(require 'template)
1328   ;(template-initialize)
1329   ;(require 'perlnow)
1330
1331 #+END_SRC
1332
1333 - auto insert
1334 - run script 
1335
1336 Change the compile-command to set the default command run when call =compile=
1337 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1338 to call =compilation=  interactively.
1339
1340 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1341
1342   (defun my-perl-hook ()
1343     (progn
1344       (setq-local compilation-read-command nil)
1345       (set (make-local-variable 'compile-command)
1346            (concat "/usr/bin/perl "
1347                    (if buffer-file-name
1348                        (shell-quote-argument buffer-file-name))))
1349       (local-set-key (kbd "s-r")
1350                        (lambda ()
1351                          (interactive)
1352   ;                       (setq current-prefix-arg '(4)) ; C-u
1353                          (call-interactively 'compile)))))
1354
1355   (add-hook 'cperl-mode-hook 'my-perl-hook)
1356
1357
1358 #+END_SRC
1359
1360 *** C & C++
1361
1362 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1363
1364   (setq c-default-style "stroustrup"
1365         c-basic-offset 4)
1366
1367 #+END_SRC
1368
1369 ** Compile
1370
1371 Set the environments vairables in compilation mode
1372
1373 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1374
1375   (use-package compile
1376     :commands compile
1377     :config
1378     (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
1379
1380 #+END_SRC
1381
1382 ** Auto-Insert
1383
1384 Enable auto-insert mode
1385
1386 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1387
1388   (auto-insert-mode t)
1389   (setq auto-insert-query nil)
1390
1391 #+END_SRC
1392
1393 *** C++ Auto Insert
1394
1395 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1396
1397   (eval-after-load 'autoinsert
1398     '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1399        '(
1400          "Short description:"
1401          "/*"
1402          "\n * " (file-name-nondirectory (buffer-file-name))
1403          "\n */" > \n \n
1404          "#include <iostream>" \n
1405          "#include \""
1406          (file-name-sans-extension
1407           (file-name-nondirectory (buffer-file-name)))
1408          ".hpp\"" \n \n
1409          "using namespace std;" \n \n
1410          "int main ()"
1411          "\n{" \n 
1412          > _ \n
1413          "return 1;"
1414          "\n}" > \n
1415          )))
1416
1417   (eval-after-load 'autoinsert
1418     '(define-auto-insert '("\\.c\\'" . "C skeleton")
1419        '(
1420          "Short description:"
1421          "/*\n"
1422          " * " (file-name-nondirectory (buffer-file-name)) "\n"
1423          " */" > \n \n
1424          "#include <stdio.h>" \n
1425          "#include \""
1426          (file-name-sans-extension
1427           (file-name-nondirectory (buffer-file-name)))
1428          ".h\"" \n \n
1429          "int main ()\n"
1430          "{" \n
1431          > _ \n
1432          "return 1;\n"
1433          "}" > \n
1434          )))
1435        
1436 #+END_SRC
1437
1438 *** Perl Auto Insert
1439
1440 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1441
1442 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1443
1444   (eval-after-load 'autoinsert
1445     '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1446        '(
1447          "Description: "
1448          "#!/usr/bin/perl -w" \n
1449          \n
1450          "use strict;" \n \n
1451          )))
1452
1453 #+END_SRC
1454
1455 ** Completion
1456
1457 company mode
1458
1459 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1460
1461   (use-package company
1462     :ensure t
1463     :diminish company-mode
1464     :init (setq company-idle-delay 0.1)
1465     :config
1466     (global-company-mode))
1467
1468 #+END_SRC
1469
1470 [[https://github.com/company-mode/company-statistics][company-statistics]]
1471
1472 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1473
1474   (use-package company-statistics
1475     :ensure t
1476     :config
1477     (company-statistics-mode))
1478
1479 #+END_SRC
1480
1481 * Todo 
1482
1483 - change M-o to trigger to delete other windows and restore previous config
1484