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