1 #+TITLE: Emacs Configuration file
3 #+EMAIL: seudut@gmail.com
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
11 ** Setting loading Path
13 Set system PATH and emacs exec path
15 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
17 (setenv "PATH" (concat (getenv "PATH")
19 ":" "/Library/TeX/texbin"))
20 (setq exec-path (append exec-path '("/usr/local/bin")))
21 (setq exec-path (append exec-path '("/Library/TeX/texbin/")))
25 Set the emacs load path
27 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
29 (add-to-list 'load-path "~/.emacs.d/elisp")
33 ** Package Initialization
35 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
39 (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
40 ("gnu" . "http://elpa.gnu.org/packages/")
41 ("org" . "http://orgmode.org/elpa/")))
49 Disable scroll bar, tool-bar and menu-bar
51 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
57 (setq debug-on-error t)
58 (setq inhibit-startup-message t)
60 (defalias 'yes-or-no-p 'y-or-n-p)
67 Switch the focus to help window when it appears
69 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
71 (setq help-window-select t)
75 * Package Management Tools
79 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
81 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
83 (unless (package-installed-p 'use-package)
84 (package-refresh-contents)
85 (package-install 'use-package))
87 (require 'use-package)
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]].
96 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
101 (add-to-list 'load-path "~/.emacs.d/el-get"))
105 * Color and Fonts Settings
107 ** highlight current line
109 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
111 (global-hl-line-mode)
117 [[https://github.com/paldepind/smart-comment][smart-comments]]
119 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
121 (use-package smart-comment
123 :bind ("M-;" . smart-conmment))
131 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
133 (global-font-lock-mode 1)
137 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
139 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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."))
153 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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)))
165 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
167 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
169 (setq vc-follow-symlinks t)
171 (use-package color-theme
173 :init (require 'color-theme)
174 :config (use-package color-theme-sanityinc-tomorrow
178 (load-theme 'sanityinc-tomorrow-bright t)))
180 ;(eval-after-load 'color-theme
181 ; (load-theme 'sanityinc-tomorrow-bright t))
185 Change the Org-mode colors
187 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
189 (defun org-src-color-blocks-light ()
190 "Colors the block headers and footers to make them stand out more for lighter themes"
193 '(org-block-begin-line
194 ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
195 '(org-block-background
196 ((t (:background "#FFFFEA"))))
198 ((t (:background "#FFFFEA"))))
200 ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
202 '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
203 '(which-func ((t (:foreground "#008000"))))))
205 (defun org-src-color-blocks-dark ()
206 "Colors the block headers and footers to make them stand out more for dark themes"
209 '(org-block-begin-line
210 ((t (:foreground "#008ED1" :background "#002E41"))))
211 '(org-block-background
212 ((t (:background "#000000"))))
214 ((t (:background "#000000"))))
216 ((t (:foreground "#008ED1" :background "#002E41"))))
218 '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
219 '(which-func ((t (:foreground "green"))))))
221 (org-src-color-blocks-dark)
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")
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."))
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)))))))
273 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
275 (use-package rainbow-delimiters
278 (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
284 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
286 (use-package page-break-lines
289 (turn-on-page-break-lines-mode))
295 ** Org-mode Basic setting
297 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
299 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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))
312 (org-babel-do-load-languages
313 'org-babel-load-languages
327 ;; use current window for org source buffer editting
328 (setq org-src-window-setup 'current-window )
334 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
336 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
338 (use-package org-bullets
341 (add-hook 'org-mode-hook
343 (org-bullets-mode t))))
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]]
354 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
359 :init (add-hook 'org-mode-hook 'worf-mode)
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)
375 Install MacTex-basic and some tex packages
379 sudo tlmgr update --self
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
385 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
386 ;; ;; allow for export=>beamer by placing
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
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
405 \\usepackage{listings}
406 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
409 showspaces=false,showstringspaces=false,
411 keywordstyle=\\color{blue}\\bfseries,
412 commentstyle=\\color{red},
414 \\usepackage{verbatim}\n
415 \\institute{{{{beamerinstitute}}}}\n
416 \\subject{{{{beamersubject}}}}\n"
418 ("\\section{%s}" . "\\section*{%s}")
420 ("\\begin{frame}[fragile]\\frametitle{%s}"
422 "\\begin{frame}[fragile]\\frametitle{%s}"
425 ;; letter class, for formal letters
427 (add-to-list 'org-export-latex-classes
430 "\\documentclass[11pt]{letter}\n
431 \\usepackage[utf8]{inputenc}\n
432 \\usepackage[T1]{fontenc}\n
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}")))
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"))
450 (setq TeX-parse-self t)
452 (setq TeX-PDF-mode t)
453 (add-hook 'LaTeX-mode-hook
456 (setq TeX-master t)))
462 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]]
464 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
466 (setq org-todo-keywords '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
467 (sequence "âš‘ WAITING(w)" "|")
468 (sequence "|" "✘ CANCELED(c)")))
472 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
474 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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"))
487 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
489 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
493 :commands magit-status magit-blame)
502 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
506 :init (setq ido-enable-flex-matching t
507 ido-ignore-extensions t
508 ido-use-virtual-buffers t
513 (add-to-list 'completion-ignored-extensions ".pyc"))
521 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
525 :init (setq ido-enable-flex-matching t
527 :config (flx-ido-mode 1))
533 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
535 (use-package ido-vertical-mode
538 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
540 (ido-vertical-mode 1))
546 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
550 :init (smex-initialize)
553 ("M-X" . smex-major-mode-commands))
559 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
561 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
563 (use-package ido-ubiquitous
566 (setq magit-completing-read-function 'magit-ido-completing-read)
567 (setq gnus-completing-read-function 'gnus-ido-completing-read)
569 (ido-ubiquitous-mode 1))
575 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
577 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
579 (use-package ido-exit-target
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))
589 ** Remove prefix =ESC=, refer [[http://emacs.stackexchange.com/questions/14755/how-to-remove-bindings-to-the-esc-prefix-key][here]]
591 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
593 ;; (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
599 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
601 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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)
613 ;; Also map s-h same as C-g
614 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
618 ** =Ctrl= key bindings
620 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
624 ;; C-j newline and indent
626 ;; C-l recenter-top-bottom
627 ;; (global-set-key (kbd "C-;") 'ido-switch-buffer)
664 ** =Super= bindings for file, buffer and windows
666 Some global bindings on =Super=, on Mac, it is =Command=
668 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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 ()
676 (if (> (length (window-list)) 1)
678 (message "Only one Windows now!"))))
680 (global-set-key (kbd "s-;") 'swiper)
682 ;; s-' --> 'next-multiframe-window
683 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
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)
690 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
692 (global-set-key (kbd "s-n") 'persp-next)
693 (global-set-key (kbd "s-p") 'persp-prev)
697 ;; someothers default mapping on super (command) key
699 ;; s-k kill-this-buffer
702 ;; s-h --> ns-do-hide-emacs
703 ;; s-j --> ido-switch-buffer +
704 ;; s-k --> kill-this-buffer
707 ;; s-' --> next-multiframe-window
708 ;; s-ret --> toggle-frame-fullscreen +
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 +
723 ;; s-- --> center-line
726 ;; s-n --> make-frame
727 ;; s-m --> iconify-frame
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
741 ;; s-c --> ns-copy-including-secondary
743 ;; s-t --> ns-popup-font-panel
745 ;; s-e --> isearch-yanqk-kill
746 ;; s-w --> delete-frame
747 ;; s-q --> same-buffers-kill-emacs
749 ;; s-` --> other-frame
752 ** =M-s= bindings for searching
754 I use the prefix =M-s= for searching in buffers
756 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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))
764 (define-key minibuffer-local-map "\M-s" nil)
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)
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)
776 (set-face-background 'ido-first-match "white")
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
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
794 ;; (global-set-key (kbd "M-s M-r") 'isearch-backward-regexp)
803 Occur search key bindings
805 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
807 (define-key occur-mode-map (kbd "C-n")
811 (occur-mode-goto-occurrence-other-window)
815 (define-key occur-mode-map (kbd "C-p")
819 (occur-mode-goto-occurrence-other-window)
826 ** =M-o= as prefix key for windows
828 ** =M-g= as prefix key for launcher
832 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
843 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
845 (defalias 'e 'ido-find-file)
846 (defalias 'ff 'ido-find-file)
847 (defalias 'ee 'ido-find-file-other-window)
851 Quickly start eshll in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
853 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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."
865 (let* ((parent (if (buffer-file-name)
866 (file-name-directory (buffer-file-name))
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))
873 (if (get-buffer eshell-name)
875 (message "buffer exist")
876 (switch-to-buffer eshell-name))
879 (rename-buffer eshell-name)
881 (insert (concat "ls"))
882 (eshell-send-input)))))
884 ;; (global-set-key (kbd "M-`") (lambda ()
886 ;; (if (buffer-name))))
892 ** [[https://github.com/abo-abo/hydra][Hydra]]
894 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
903 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
905 (defhydra sd/font-zoom (global-map "<f2>")
907 ("g" text-scale-increase "in")
908 ("l" text-scale-decrease "out"))
912 *** Windmove Splitter
914 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
916 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
918 (defun hydra-move-splitter-left (arg)
919 "Move window splitter left."
921 (if (let ((windmove-wrap-around))
922 (windmove-find-other-window 'right))
923 (shrink-window-horizontally arg)
924 (enlarge-window-horizontally arg)))
926 (defun hydra-move-splitter-right (arg)
927 "Move window splitter right."
929 (if (let ((windmove-wrap-around))
930 (windmove-find-other-window 'right))
931 (enlarge-window-horizontally arg)
932 (shrink-window-horizontally arg)))
934 (defun hydra-move-splitter-up (arg)
935 "Move window splitter up."
937 (if (let ((windmove-wrap-around))
938 (windmove-find-other-window 'up))
940 (shrink-window arg)))
942 (defun hydra-move-splitter-down (arg)
943 "Move window splitter down."
945 (if (let ((windmove-wrap-around))
946 (windmove-find-other-window 'up))
948 (enlarge-window arg)))
954 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
958 (defhydra sd/hydra-window (:color red :columns nil)
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)
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")
986 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
987 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
990 (global-unset-key (kbd "M-o"))
991 (global-set-key (kbd "M-o") 'sd/hydra-window/body)
993 (defun triggle-windows-max-size ()
995 (if (> (length (window-list)) 1)
996 (delete-other-windows)
1003 Enable linum mode on programming modes
1005 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1007 (add-hook 'prog-mode-hook 'linum-mode)
1011 Fix the font size of line number
1013 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1015 (defun fix-linum-size ()
1017 (set-face-attribute 'linum nil :height 110))
1019 (add-hook 'linum-mode-hook 'fix-linum-size)
1023 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1025 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1027 (use-package linum-relative
1030 (defun linum-new-mode ()
1031 "If line numbers aren't displayed, then display them.
1032 Otherwise, toggle between absolute and relative numbers."
1035 (linum-relative-toggle)
1039 ("A-k" . linum-new-mode))
1041 ;; auto enable linum-new-mode in programming modes
1042 (add-hook 'prog-mode-hook 'linum-relative-mode)
1046 ** Save File Position
1048 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1059 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1061 (use-package multi-term
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
1071 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1073 (use-package ace-link
1076 (ace-link-setup-default))
1082 [[https://github.com/re5et/emux][emux]] is
1084 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1086 (el-get-bundle re5et/emux)
1092 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1094 (use-package smartparens
1098 (require 'smartparens-config)
1099 (add-hook 'prog-mode-hook 'smartparens-mode)))
1105 [[https://github.com/abo-abo/ace-window][ace-window]]
1107 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1109 (use-package ace-window
1113 ; (global-set-key (kbd "M-o") 'ace-window)
1115 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1121 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1123 (use-package projectile
1126 (setq projectile-enable-caching t)
1128 (projectile-global-mode t))
1130 (use-package persp-projectile
1135 (:map projectile-mode-map
1136 ("s-t" . projectile-persp-switch-project)))
1138 ;; projectile-find-file
1139 ;; projectile-switch-buffer
1140 ;; projectile-find-file-other-window
1145 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1147 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1149 (use-package which-key
1158 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1160 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1165 (setq emms-source-file-default-directory "~/Music/emms/")
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))
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
1183 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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)
1195 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1201 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1203 (use-package undo-tree
1206 (global-undo-tree-mode 1))
1212 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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)
1241 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1243 ;; (use-package tabbar-ruler
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)
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))
1264 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1266 (use-package color-identifiers-mode
1269 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1271 :diminish color-identifiers-mode)
1273 (global-prettify-symbols-mode t)
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]]
1282 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1287 (eval-after-load 'lispy
1289 (define-key lispy-mode-map (kbd "M-o") nil)))
1291 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1297 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1299 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1301 (defalias 'perl-mode 'cperl-mode)
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)
1313 (add-hook 'cperl-mode-hook
1315 (cperl-set-style "C++")))
1317 ;(require 'template)
1318 ;(template-initialize)
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.
1330 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1332 (defun my-perl-hook ()
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")
1342 ; (setq current-prefix-arg '(4)) ; C-u
1343 (call-interactively 'compile)))))
1345 (add-hook 'cperl-mode-hook 'my-perl-hook)
1352 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1354 (setq c-default-style "stroustrup"
1361 Set the environments vairables in compilation mode
1363 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1365 (use-package compile
1368 (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
1374 Enable auto-insert mode
1376 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1378 (auto-insert-mode t)
1379 (setq auto-insert-query nil)
1385 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1387 (eval-after-load 'autoinsert
1388 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1390 "Short description:"
1392 "\n * " (file-name-nondirectory (buffer-file-name))
1394 "#include <iostream>" \n
1396 (file-name-sans-extension
1397 (file-name-nondirectory (buffer-file-name)))
1399 "using namespace std;" \n \n
1407 (eval-after-load 'autoinsert
1408 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1410 "Short description:"
1412 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1414 "#include <stdio.h>" \n
1416 (file-name-sans-extension
1417 (file-name-nondirectory (buffer-file-name)))
1428 *** Perl Auto Insert
1430 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1432 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1434 (eval-after-load 'autoinsert
1435 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1438 "#!/usr/bin/perl -w" \n
1449 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1451 (use-package company
1453 :diminish company-mode
1454 :init (setq company-idle-delay 0.1)
1456 (global-company-mode))
1460 [[https://github.com/company-mode/company-statistics][company-statistics]]
1462 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1464 (use-package company-statistics
1467 (company-statistics-mode))
1473 - change M-o to trigger to delete other windows and restore previous config