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