emacs - define super key for file, buffer and windows
[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 the emacs load path
14
15 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
16
17   (add-to-list 'load-path "~/.emacs.d/elisp")
18
19 #+END_SRC
20
21 ** Package Initialization
22
23 #+BEGIN_SRC emacs-lisp :tangle yes
24
25   (require 'package)
26
27   (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
28                            ("org" . "http://orgmode.org/elpa/")))
29
30   (package-initialize)
31
32 #+END_SRC
33
34 ** General Setting
35
36 Disable scroll bar, tool-bar and menu-bar
37
38 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
39
40   (scroll-bar-mode 0)
41   (tool-bar-mode 0)
42   (menu-bar-mode 1)
43
44   (setq debug-on-error t)
45   (setq inhibit-startup-message t)
46
47   (defalias 'yes-or-no-p 'y-or-n-p)
48   (show-paren-mode 1)
49
50
51
52 #+END_SRC
53
54 Switch the focus to help window when it appears
55
56 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
57
58   (setq help-window-select t)
59
60 #+END_SRC
61
62 * Package Management Tools
63
64 ** Use-package
65
66 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
67
68 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
69
70   (unless (package-installed-p 'use-package)
71     (package-refresh-contents)
72     (package-install 'use-package))
73
74   (require 'use-package)
75
76 #+END_SRC
77
78 ** El-get
79
80 [[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. 
81 Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
82
83 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
84
85   (use-package el-get
86     :ensure t
87     :init
88     (add-to-list 'load-path "~/.emacs.d/el-get"))
89
90 #+END_SRC
91
92 * Color and Fonts Settings
93
94 ** highlight current line
95
96 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
97
98   (global-hl-line-mode)
99
100 #+END_SRC
101
102 ** Smart Comments
103
104 [[https://github.com/paldepind/smart-comment][smart-comments]]
105
106 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
107
108   (use-package smart-comment
109     :ensure t
110     :bind ("M-;" . smart-conmment))
111
112 #+END_SRC
113
114 ** Font Setting
115
116 syntax highlighting
117
118 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
119
120   (global-font-lock-mode 1)
121
122 #+END_SRC
123
124 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
125
126 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
127
128   (if window-system
129       (defvar sd/fixed-font-family
130         (cond ((x-list-fonts "Hasklig")         "Hasklig")
131               ((x-list-fonts "Source Code Pro") "Source Code Pro")
132               ((x-list-fonts "Anonymous Pro")   "Anonymous Pro")
133               ((x-list-fonts "M+ 1mn")          "M+ 1mn"))
134         "The fixed width font based on what is installed, `nil' if not defined."))
135
136 #+END_SRC
137
138 Setting the fonts 
139
140 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
141
142   (if window-system
143       (when sd/fixed-font-family
144         (set-frame-font sd/fixed-font-family)
145         (set-face-attribute 'default nil :font sd/fixed-font-family :height 120)
146         (set-face-font 'default sd/fixed-font-family)))
147
148 #+END_SRC
149
150 ** Color Theme
151
152 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
153
154 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
155
156   (setq vc-follow-symlinks t)
157
158   (use-package color-theme
159     :ensure t
160     :init (require 'color-theme)
161     :config (use-package color-theme-sanityinc-tomorrow
162               :ensure t
163               :no-require t
164               :config
165               (load-theme 'sanityinc-tomorrow-bright t)))
166
167   ;(eval-after-load 'color-theme
168   ;  (load-theme 'sanityinc-tomorrow-bright t))
169
170 #+END_SRC
171
172 Change the Org-mode colors 
173
174 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
175
176   (defun org-src-color-blocks-light ()
177     "Colors the block headers and footers to make them stand out more for lighter themes"
178     (interactive)
179     (custom-set-faces
180      '(org-block-begin-line
181       ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
182      '(org-block-background
183        ((t (:background "#FFFFEA"))))
184      '(org-block
185        ((t (:background "#FFFFEA"))))
186      '(org-block-end-line
187        ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
188
189      '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
190      '(which-func ((t (:foreground "#008000"))))))
191
192   (defun org-src-color-blocks-dark ()
193     "Colors the block headers and footers to make them stand out more for dark themes"
194     (interactive)
195     (custom-set-faces
196      '(org-block-begin-line
197        ((t (:foreground "#008ED1" :background "#002E41"))))
198      '(org-block-background
199        ((t (:background "#000000"))))
200      '(org-block
201        ((t (:background "#000000"))))
202      '(org-block-end-line
203        ((t (:foreground "#008ED1" :background "#002E41"))))
204
205      '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
206      '(which-func ((t (:foreground "green"))))))
207
208   (org-src-color-blocks-dark)
209
210 #+END_SRC
211
212 improve color for org-mode
213 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
214   (deftheme ha/org-theme "Sub-theme to beautify org mode")
215
216   (if window-system
217       (defvar sd/variable-font-tuple
218         (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
219               ((x-list-fonts "Lucida Grande")   '(:font "Lucida Grande"))
220               ((x-list-fonts "Verdana")         '(:font "Verdana"))
221               ((x-family-fonts "Sans Serif")    '(:family "Sans Serif"))
222               (nil (warn "Cannot find a Sans Serif Font.  Install Source Sans Pro.")))
223         "My variable width font available to org-mode files and whatnot."))
224
225   (defun sd/org-color ()
226     (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
227            (base-font-color     (face-foreground 'default nil 'default))
228            (background-color    (face-background 'default nil 'default))
229            (primary-color       (face-foreground 'mode-line nil))
230            (secondary-color     (face-background 'secondary-selection nil 'region))
231            (base-height         (face-attribute 'default :height))
232            (headline           `(:inherit default :weight bold :foreground ,base-font-color)))
233       (custom-theme-set-faces 'ha/org-theme
234                               `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
235                               `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
236                               `(org-table ((t (:inherit 'fixed-pitched))))
237                               `(org-block ((t (:inherit 'fixed-pitched))))
238                               `(org-block-background ((t (:inherit 'fixed-pitched))))
239                               `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
240                               `(org-block-end-line ((t (:inherit 'fixed-pitched))))
241                               `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
242                               `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
243                               `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
244                               `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
245                               `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
246                                                             :height ,(round (* 1.1 base-height))))))
247                               `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
248                                                             :height ,(round (* 1.25 base-height))))))
249                               `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
250                                                             :height ,(round (* 1.5 base-height))))))
251                               `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
252                                                             :height ,(round (* 1.75 base-height))))))
253                               `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
254
255
256 #+END_SRC
257
258 * Org-mode Settings
259
260 ** Org-mode Basic setting
261
262 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent= 
263
264 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
265
266   (use-package org
267     :ensure t
268     :init
269     (setq org-startup-indented t)
270     (setq org-hide-leading-starts t)
271     (setq org-src-fontify-natively t)
272     (setq org-src-tab-acts-natively t)
273     (setq org-confirm-babel-evaluate nil)
274     (setq org-use-speed-commands t)
275     (setq org-completion-use-ido t))
276
277   (org-babel-do-load-languages
278    'org-babel-load-languages
279    '((python . t)
280      (C . t)
281      (perl . t)
282      (calc . t)
283      (latex . t)
284      (java . t)
285      (ruby . t)
286      (lisp . t)
287      (scheme . t)
288      (sh . t)
289      (sqlite . t)
290      (js . t)))
291
292   ;; use current window for org source buffer editting
293   (setq org-src-window-setup 'current-window )
294
295 #+END_SRC
296
297 ** Org-bullets
298
299 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
300
301 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
302
303   (use-package org-bullets
304     :ensure t
305     :init
306     (add-hook 'org-mode-hook
307               (lambda ()
308                 (org-bullets-mode t))))
309
310 #+END_SRC
311
312 ** Worf Mode
313
314 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode. 
315 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
316 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
317 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
318
319 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
320
321   (use-package worf
322     :ensure t
323     :commands worf-mode
324     :init (add-hook 'org-mode-hook 'worf-mode)
325     ;; :config
326     ;; (define-key worf-mode-map "[" nil)
327     ;; (define-key worf-mode-map "]" nil)
328     ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
329     ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
330     )
331
332 #+END_SRC
333
334 ** Task Management
335
336 ** Capture
337
338 * Magit
339
340 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
341
342 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
343
344   (use-package magit
345     :ensure t
346     :commands magit-status magit-blame)
347
348
349 #+END_SRC
350
351 * IDO & SMEX
352
353 ** IDO
354
355 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
356
357   (use-package ido
358     :ensure t
359     :init (setq ido-enable-flex-matching t
360                 ido-ignore-extensions t
361                 ido-use-virtual-buffers t
362                 ido-everywhere t)
363     :config
364     (ido-mode 1)
365     (ido-everywhere 1)
366     (add-to-list 'completion-ignored-extensions ".pyc"))
367
368   (icomplete-mode t)
369
370 #+END_SRC
371
372 ** FLX
373
374 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
375
376   (use-package flx-ido
377     :ensure t
378     :init (setq ido-enable-flex-matching t
379                 ido-use-faces nil)
380     :config (flx-ido-mode 1))
381
382 #+END_SRC
383
384 ** IDO-vertically
385
386 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
387
388   (use-package ido-vertical-mode
389     :ensure t
390     :init
391     (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
392     :config
393     (ido-vertical-mode 1))
394
395 #+END_SRC
396
397 ** SMEX
398
399 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
400
401   (use-package smex
402     :ensure t
403     :init (smex-initialize)
404     :bind
405     ("M-x" . smex)
406     ("M-X" . smex-major-mode-commands))
407
408 #+END_SRC
409
410 ** Ido-ubiquitous
411
412 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
413
414 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
415
416   (use-package ido-ubiquitous
417     :ensure t
418     :init
419     (setq magit-completing-read-function 'magit-ido-completing-read)
420     (setq gnus-completing-read-function 'gnus-ido-completing-read)
421     :config
422     (ido-ubiquitous-mode 1))
423
424 #+END_SRC
425
426 * File and Buffer Operation
427
428 ** Esc on Minibuffer
429
430 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
431
432 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
433
434   (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
435   (define-key minibuffer-local-map [escape]  'keyboard-escape-quit)
436   (define-key minibuffer-local-ns-map [escape]  'keyboard-escape-quit)
437   (define-key minibuffer-local-isearch-map [escape]  'keyboard-escape-quit)
438   (define-key minibuffer-local-completion-map [escape]  'keyboard-escape-quit)
439   (define-key minibuffer-local-must-match-map [escape]  'keyboard-escape-quit)
440   (define-key minibuffer-local-must-match-filename-map [escape]  'keyboard-escape-quit)
441   (define-key minibuffer-local-filename-completion-map [escape]  'keyboard-escape-quit)
442   (define-key minibuffer-local-filename-must-match-map [escape]  'keyboard-escape-quit)
443
444   ;; Also map s-h same as C-g
445   (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
446
447 #+END_SRC
448
449 ** =Super= bindings for file, buffer and windows
450
451 Some global bindings on =Super=, on Mac, it is =Command=
452
453 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
454
455   (global-set-key (kbd "s-h") 'keyboard-quit)
456   (global-set-key (kbd "s-j") 'ido-switch-buffer)
457   ;; s-k  -->  kill-this-buffer
458   ;; s-l  -->  goto-line
459   ;; s-;  -->
460   ;; s-'  -->  'next-multiframe-window
461   (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
462
463   ;; (global-set-key (kbd "s-y") 'projectile-find-file)
464   (global-set-key (kbd "s-f") 'projectile-find-file)
465   (global-set-key (kbd "s-[") 'next-buffer)
466   (global-set-key (kbd "s-]") 'previous-buffer)
467
468   (global-set-key (kbd "s-`") 'mode-line-other-buffer)
469
470
471
472   ;; someothers default mapping on super (command) key
473   ;; s-s save-buffer
474   ;; s-k kill-this-buffer
475
476
477   ;; s-h  -->  ns-do-hide-emacs
478   ;; s-j  -->  ido-switch-buffer  +
479   ;; s-k  -->  kill-this-buffer
480   ;; s-l  -->  goto-line
481   ;; s-;  -->  undefined
482   ;; s-'  -->  next-multiframe-window
483   ;; s-ret --> toggle-frame-fullscreen +
484
485   ;; s-y  -->  ns-paste-secondary
486   ;; s-u  -->  revert-buffer
487   ;; s-i  -->  undefined - but used for iterm globally
488   ;; s-o  -->  used for emacs globally
489   ;; s-p  -->  projectile-persp-switch-project  +  
490   ;; s-[  -->  next-buffer  +    
491   ;; s-]  -->  previous-buffer +
492
493   ;; s-0  -->  undefined
494   ;; s-9  -->  undefined
495   ;; s-8  -->  undefined
496   ;; s-7  -->  undefined
497   ;; s-6  -->  undefined
498   ;; s--  -->  center-line
499   ;; s-=  -->  undefined
500
501   ;; s-n  -->  make-frame
502   ;; s-m  -->  iconify-frame
503   ;; s-b  -->  undefined
504   ;; s-,  -->  customize
505   ;; s-.  -->  undefined
506   ;; s-/  -->  undefined
507
508   ;; s-g  -->  isearch-repeat-forward
509   ;; s-f  -->  projectile-find-file   +
510   ;; s-d  -->  isearch-repeat-background
511   ;; s-s  -->  save-buffer
512   ;; s-a  -->  make-whole-buffer
513
514   ;; s-b  -->  undefined
515   ;; s-v  -->  yank
516   ;; s-c  -->  ns-copy-including-secondary
517
518   ;; s-t  -->  ns-popup-font-panel
519   ;; s-r  -->  undefined
520   ;; s-e  -->  isearch-yanqk-kill
521   ;; s-w  -->  delete-frame
522   ;; s-q  -->  same-buffers-kill-emacs
523
524   ;; s-`  -->  other-frame
525 #+END_SRC
526
527 ** =M-s= bindings for searching
528
529 I use the prefix =M-s= for searching in buffers
530
531 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
532
533   (defun pl-make-keymap (key bindings)
534     (setq keymap (make-sparse-keymap))
535     (dolist (binding bindings)
536       (define-key keymap (car binding) (cdr binding)))
537     (global-set-key key keymap))
538
539   (global-set-key (kbd "M-s M-s") 'isearch-forward-regexp)
540   (global-set-key (kbd "M-s M-r") 'isearch-forward-regexp)
541
542   (define-key isearch-mode-map (kbd "M-s") 'isearch-forward-regexp)
543
544 #+END_SRC
545 * Misc Settings
546
547
548 ** [[https://github.com/abo-abo/hydra][Hydra]]
549
550 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
551
552   (use-package hydra
553     :ensure t)
554
555 #+END_SRC
556
557 *** Font Zoom
558
559 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
560
561   (defhydra sd/font-zoom (global-map "<f2>")
562     "zoom"
563     ("g" text-scale-increase "in")
564     ("l" text-scale-decrease "out"))
565
566 #+END_SRC
567
568 *** Windmove Splitter
569
570 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
571
572 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
573
574   (defun hydra-move-splitter-left (arg)
575     "Move window splitter left."
576     (interactive "p")
577     (if (let ((windmove-wrap-around))
578           (windmove-find-other-window 'right))
579         (shrink-window-horizontally arg)
580       (enlarge-window-horizontally arg)))
581
582   (defun hydra-move-splitter-right (arg)
583     "Move window splitter right."
584     (interactive "p")
585     (if (let ((windmove-wrap-around))
586           (windmove-find-other-window 'right))
587         (enlarge-window-horizontally arg)
588       (shrink-window-horizontally arg)))
589
590   (defun hydra-move-splitter-up (arg)
591     "Move window splitter up."
592     (interactive "p")
593     (if (let ((windmove-wrap-around))
594           (windmove-find-other-window 'up))
595         (enlarge-window arg)
596       (shrink-window arg)))
597
598   (defun hydra-move-splitter-down (arg)
599     "Move window splitter down."
600     (interactive "p")
601     (if (let ((windmove-wrap-around))
602           (windmove-find-other-window 'up))
603         (shrink-window arg)
604       (enlarge-window arg)))
605
606 #+END_SRC
607
608 *** hydra-window
609
610 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
611
612   (winner-mode 1)
613
614   (defhydra sd/hydra-window (:color red :columns nil)
615     "window"
616     ("h" windmove-left nil)
617     ("j" windmove-down nil)
618     ("k" windmove-up nil)
619     ("l" windmove-right nil)
620     ("H" hydra-move-splitter-left nil)
621     ("J" hydra-move-splitter-down nil)
622     ("K" hydra-move-splitter-up nil)
623     ("L" hydra-move-splitter-right nil)
624     ("v" (lambda ()
625            (interactive)
626            (split-window-right)
627            (windmove-right))
628      "vert")
629     ("x" (lambda ()
630            (interactive)
631            (split-window-below)
632            (windmove-down))
633      "horz")
634     ("o" delete-other-windows "one" :exit t)
635     ("a" ace-window "ace")
636     ("s" ace-swap-window "swap")
637     ("d" ace-delete-window "ace-one" :exit t)
638     ("i" ace-maximize-window "ace-one" :exit t)
639     ("b" ido-switch-buffer "buf")
640     ("m" headlong-bookmark-jump "bmk")
641     ("q" nil "cancel")
642     ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
643     ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
644     ("f" nil))
645
646   (global-unset-key (kbd "M-o"))
647   (global-set-key (kbd "M-o") 'sd/hydra-window/body)
648
649 #+END_SRC
650
651 ** Line Number
652
653 Enable linum mode on programming modes
654
655 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
656
657   (add-hook 'prog-mode-hook 'linum-mode)
658
659 #+END_SRC
660
661 Fix the font size of line number
662
663 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
664
665   (defun fix-linum-size ()
666        (interactive)
667        (set-face-attribute 'linum nil :height 110))
668
669   (add-hook 'linum-mode-hook 'fix-linum-size)
670
671 #+END_SRC
672
673 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
674
675 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
676
677   (use-package linum-relative
678     :ensure t
679     :config
680     (defun linum-new-mode ()
681       "If line numbers aren't displayed, then display them.
682   Otherwise, toggle between absolute and relative numbers."
683       (interactive)
684       (if linum-mode
685           (linum-relative-toggle)
686         (linum-mode 1)))
687
688     :bind
689     ("A-k" . linum-new-mode))
690
691   ;; auto enable linum-new-mode in programming modes
692   (add-hook 'prog-mode-hook 'linum-relative-mode)
693
694 #+END_SRC
695
696 ** Save File Position
697
698 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
699
700   (require 'saveplace)
701   (setq-default save-place t)
702   (setq save-place-forget-unreadable-files t)
703   (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
704
705 #+END_SRC
706
707 ** Multi-term
708
709 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
710
711   (use-package multi-term
712     :ensure t)
713
714 #+END_SRC
715
716 ** ace-link
717
718 [[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
719 Type =o= to go to the link
720
721 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
722
723   (use-package ace-link
724     :ensure t
725     :init
726     (ace-link-setup-default))
727
728 #+END_SRC
729
730 ** Emux
731
732 [[https://github.com/re5et/emux][emux]] is 
733
734 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
735
736   (el-get-bundle re5et/emux)
737
738 #+END_SRC
739
740 ** Smart Parens
741
742 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
743
744   (use-package smartparens
745     :ensure t
746     :config
747     (progn
748       (require 'smartparens-config)
749       (add-hook 'prog-mode-hook 'smartparens-mode)))
750
751 #+END_SRC
752
753 ** Ace-Windows
754
755 [[https://github.com/abo-abo/ace-window][ace-window]] 
756
757 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
758
759   (use-package ace-window
760     :ensure t
761     :defer t
762   ;  :init
763   ;  (global-set-key (kbd "M-o") 'ace-window)
764     :config
765     (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
766
767 #+END_SRC
768
769 ** Projectile
770
771 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
772
773   (use-package projectile
774     :ensure t
775     :init
776     (setq projectile-enable-caching t)
777     :config
778     (projectile-global-mode t))
779
780   (use-package persp-projectile
781     :ensure t
782     :config
783     (persp-mode)
784     :bind
785     (:map projectile-mode-map
786           ("s-p" . projectile-persp-switch-project)))
787
788 #+END_SRC
789 * Programming
790
791 ** Languages
792
793 *** Emacs Lisp
794
795 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
796
797   (use-package color-identifiers-mode
798     :ensure t
799     :init
800     (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
801
802     :diminish color-identifiers-mode)
803
804 #+END_SRC
805
806 **** Lispy Mode
807
808 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
809 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
810
811 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
812
813   (use-package lispy
814     :ensure t
815     :init
816     (eval-after-load 'lispy
817       '(progn
818          (define-key lispy-mode-map (kbd "M-o") nil)))
819     :config
820     (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
821
822 #+END_SRC
823
824 *** Perl
825
826 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
827
828 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
829
830   (defalias 'perl-mode 'cperl-mode)
831
832   ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
833   (setq cperl-auto-newline t)
834   (setq cperl-highlight-variables-indiscriminately t)
835   ;(setq cperl-indent-level 4)
836   ;(setq cperl-continued-statement-offset 4)
837   (setq cperl-close-paren-offset -4)
838   (setq cperl-indent-parents-as-block t)
839   (setq cperl-tab-always-indent t)
840   ;(setq cperl-brace-offset  0)
841
842   (add-hook 'cperl-mode-hook
843             '(lambda ()
844                (cperl-set-style "C++")))
845
846   ;(require 'template)
847   ;(template-initialize)
848   ;(require 'perlnow)
849
850 #+END_SRC
851
852 - auto insert
853 - run script 
854
855 Change the compile-command to set the default command run when call =compile=
856 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
857 to call =compilation=  interactively.
858
859 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
860
861   (defun my-perl-hook ()
862     (progn
863       (setq-local compilation-read-command nil)
864       (set (make-local-variable 'compile-command)
865            (concat "/usr/bin/perl "
866                    (if buffer-file-name
867                        (shell-quote-argument buffer-file-name))))
868       (local-set-key (kbd "s-r")
869                        (lambda ()
870                          (interactive)
871   ;                       (setq current-prefix-arg '(4)) ; C-u
872                          (call-interactively 'compile)))))
873
874   (add-hook 'cperl-mode-hook 'my-perl-hook)
875
876
877 #+END_SRC
878
879 *** C & C++
880
881 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
882
883   (setq c-default-style "stroustrup"
884         c-basic-offset 4)
885
886 #+END_SRC
887
888 ** Compile
889
890 Set the environments vairables in compilation mode
891
892 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
893
894   (use-package compile
895     :commands compile
896     :config
897     (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
898
899 #+END_SRC
900
901 ** Auto-Insert
902
903 Enable auto-insert mode
904
905 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
906
907   (auto-insert-mode t)
908   (setq auto-insert-query nil)
909
910 #+END_SRC
911
912 *** C++ Auto Insert
913
914 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
915
916   (eval-after-load 'autoinsert
917     '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
918        '(
919          "Short description:"
920          "/*"
921          "\n * " (file-name-nondirectory (buffer-file-name))
922          "\n */" > \n \n
923          "#include <iostream>" \n
924          "#include \""
925          (file-name-sans-extension
926           (file-name-nondirectory (buffer-file-name)))
927          ".hpp\"" \n \n
928          "using namespace std;" \n \n
929          "int main ()"
930          "\n{" \n 
931          > _ \n
932          "return 1;"
933          "\n}" > \n
934          )))
935
936   (eval-after-load 'autoinsert
937     '(define-auto-insert '("\\.c\\'" . "C skeleton")
938        '(
939          "Short description:"
940          "/*\n"
941          " * " (file-name-nondirectory (buffer-file-name)) "\n"
942          " */" > \n \n
943          "#include <stdio.h>" \n
944          "#include \""
945          (file-name-sans-extension
946           (file-name-nondirectory (buffer-file-name)))
947          ".h\"" \n \n
948          "int main ()\n"
949          "{" \n
950          > _ \n
951          "return 1;\n"
952          "}" > \n
953          )))
954        
955 #+END_SRC
956
957 *** Perl Auto Insert
958
959 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
960
961 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
962
963   (eval-after-load 'autoinsert
964     '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
965        '(
966          "Description: "
967          "#!/usr/bin/perl -w" \n
968          \n
969          "use strict;" \n \n
970          )))
971
972 #+END_SRC
973
974 ** Completion
975
976 company mode
977
978 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
979
980   (use-package company
981     :ensure t
982     :diminish company-mode
983     :init (setq company-idle-delay 0.1)
984     :config
985     (global-company-mode))
986
987 #+END_SRC
988
989 * Todo 
990
991 - change M-o to trigger to delete other windows and restore previous config
992