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)
69 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
71 (setq custom-file "~/.emacs.d/custom.el")
72 (if (file-exists-p custom-file)
77 Switch the focus to help window when it appears
79 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
81 (setq help-window-select t)
85 * Package Management Tools
89 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
91 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
93 (unless (package-installed-p 'use-package)
94 (package-refresh-contents)
95 (package-install 'use-package))
97 (require 'use-package)
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]].
106 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
111 (add-to-list 'load-path "~/.emacs.d/el-get"))
115 * Color and Fonts Settings
117 ** highlight current line
119 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
121 (global-hl-line-mode)
127 [[https://github.com/paldepind/smart-comment][smart-comments]]
129 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
131 (use-package smart-comment
133 :bind ("M-;" . smart-conmment))
141 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
143 (global-font-lock-mode 1)
147 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
149 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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."))
163 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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)))
175 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
177 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
179 (setq vc-follow-symlinks t)
181 (use-package color-theme
183 :init (require 'color-theme)
184 :config (use-package color-theme-sanityinc-tomorrow
188 (load-theme 'sanityinc-tomorrow-bright t)))
190 ;(eval-after-load 'color-theme
191 ; (load-theme 'sanityinc-tomorrow-bright t))
195 Change the Org-mode colors
197 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
199 (defun org-src-color-blocks-light ()
200 "Colors the block headers and footers to make them stand out more for lighter themes"
203 '(org-block-begin-line
204 ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
205 '(org-block-background
206 ((t (:background "#FFFFEA"))))
208 ((t (:background "#FFFFEA"))))
210 ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
212 '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
213 '(which-func ((t (:foreground "#008000"))))))
215 (defun org-src-color-blocks-dark ()
216 "Colors the block headers and footers to make them stand out more for dark themes"
219 '(org-block-begin-line
220 ((t (:foreground "#008ED1" :background "#002E41"))))
221 '(org-block-background
222 ((t (:background "#000000"))))
224 ((t (:background "#000000"))))
226 ((t (:foreground "#008ED1" :background "#002E41"))))
228 '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
229 '(which-func ((t (:foreground "green"))))))
231 (org-src-color-blocks-dark)
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")
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."))
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)))))))
283 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
285 (use-package rainbow-delimiters
288 (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
294 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
296 (use-package page-break-lines
299 (turn-on-page-break-lines-mode))
305 ** Org-mode Basic setting
307 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
309 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
314 (setq org-startup-indented t)
315 (setq org-hide-leading-starts t)
316 (setq org-src-fontify-natively t)
317 (setq org-src-tab-acts-natively t)
318 (setq org-confirm-babel-evaluate nil)
319 (setq org-use-speed-commands t)
320 (setq org-completion-use-ido t))
322 (org-babel-do-load-languages
323 'org-babel-load-languages
337 ;; use current window for org source buffer editting
338 (setq org-src-window-setup 'current-window )
344 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
346 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
348 (use-package org-bullets
351 (add-hook 'org-mode-hook
353 (org-bullets-mode t))))
359 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
360 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
361 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
362 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
364 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
369 :init (add-hook 'org-mode-hook 'worf-mode)
371 ;; (define-key worf-mode-map "[" nil)
372 ;; (define-key worf-mode-map "]" nil)
373 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
374 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
385 Install MacTex-basic and some tex packages
389 sudo tlmgr update --self
391 sudo tlmgr install titlesec framed threeparttable wrapfig multirow enumitem bbding titling tabu mdframed tcolorbox textpos import varwidth needspace tocloft ntheorem environ trimspaces collection-fontsrecommended capt-of
395 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
396 ;; ;; allow for export=>beamer by placing
398 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
399 ;; #+LaTeX_CLASS: beamer in org files
400 (unless (boundp 'org-export-latex-classes)
401 (setq org-export-latex-classes nil))
402 (add-to-list 'org-export-latex-classes
403 ;; beamer class, for presentations
405 "\\documentclass[11pt]{beamer}\n
406 \\mode<{{{beamermode}}}>\n
407 \\usetheme{{{{beamertheme}}}}\n
408 \\usecolortheme{{{{beamercolortheme}}}}\n
409 \\beamertemplateballitem\n
410 \\setbeameroption{show notes}
411 \\usepackage[utf8]{inputenc}\n
412 \\usepackage[T1]{fontenc}\n
413 \\usepackage{hyperref}\n
415 \\usepackage{listings}
416 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
419 showspaces=false,showstringspaces=false,
421 keywordstyle=\\color{blue}\\bfseries,
422 commentstyle=\\color{red},
424 \\usepackage{verbatim}\n
425 \\institute{{{{beamerinstitute}}}}\n
426 \\subject{{{{beamersubject}}}}\n"
428 ("\\section{%s}" . "\\section*{%s}")
430 ("\\begin{frame}[fragile]\\frametitle{%s}"
432 "\\begin{frame}[fragile]\\frametitle{%s}"
435 ;; letter class, for formal letters
437 (add-to-list 'org-export-latex-classes
440 "\\documentclass[11pt]{letter}\n
441 \\usepackage[utf8]{inputenc}\n
442 \\usepackage[T1]{fontenc}\n
445 ("\\section{%s}" . "\\section*{%s}")
446 ("\\subsection{%s}" . "\\subsection*{%s}")
447 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
448 ("\\paragraph{%s}" . "\\paragraph*{%s}")
449 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
455 (setq org-latex-pdf-process
456 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
457 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
458 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
460 (setq TeX-parse-self t)
462 (setq TeX-PDF-mode t)
463 (add-hook 'LaTeX-mode-hook
466 (setq TeX-master t)))
472 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]]
474 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
476 (setq org-todo-keywords '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
477 (sequence "âš‘ WAITING(w)" "|")
478 (sequence "|" "✘ CANCELED(c)")))
482 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
484 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
486 (add-to-list 'org-structure-template-alist
487 '("E" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"))
488 (add-to-list 'org-structure-template-alist
489 '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
490 (add-to-list 'org-structure-template-alist
491 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
497 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
499 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
503 :commands magit-status magit-blame)
512 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
516 :init (setq ido-enable-flex-matching t
517 ido-ignore-extensions t
518 ido-use-virtual-buffers t
523 (add-to-list 'completion-ignored-extensions ".pyc"))
531 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
535 :init (setq ido-enable-flex-matching t
537 :config (flx-ido-mode 1))
543 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
545 (use-package ido-vertical-mode
548 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
550 (ido-vertical-mode 1))
556 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
560 :init (smex-initialize)
563 ("M-X" . smex-major-mode-commands))
569 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
571 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
573 (use-package ido-ubiquitous
576 (setq magit-completing-read-function 'magit-ido-completing-read)
577 (setq gnus-completing-read-function 'gnus-ido-completing-read)
579 (ido-ubiquitous-mode 1))
585 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
587 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
589 (use-package ido-exit-target
592 (define-key ido-common-completion-map (kbd "C-j") #'ido-exit-target-split-window-right)
593 (define-key ido-common-completion-map (kbd "C-l") #'ido-exit-target-split-window-below))
599 ** Remove prefix =ESC=, refer [[http://emacs.stackexchange.com/questions/14755/how-to-remove-bindings-to-the-esc-prefix-key][here]]
601 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
603 ;; (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
609 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
611 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
613 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
614 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
615 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
616 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
617 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
618 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
619 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
620 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
621 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
623 ;; Also map s-h same as C-g
624 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
628 ** =Ctrl= key bindings
630 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
634 ;; C-j newline and indent
636 ;; C-l recenter-top-bottom
637 ;; (global-set-key (kbd "C-;") 'ido-switch-buffer)
674 ** =Super= bindings for file, buffer and windows
676 Some global bindings on =Super=, on Mac, it is =Command=
678 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
680 (global-set-key (kbd "s-h") 'keyboard-quit)
681 (global-set-key (kbd "s-j") 'ido-switch-buffer)
682 (global-set-key (kbd "s-k") 'ido-find-file)
683 ;; s-k --> kill-this-buffer
684 (global-set-key (kbd "s-l") (lambda ()
686 (if (> (length (window-list)) 1)
688 (message "Only one Windows now!"))))
690 (global-set-key (kbd "s-;") 'swiper)
692 ;; s-' --> 'next-multiframe-window
693 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
695 ;; (global-set-key (kbd "s-y") 'projectile-find-file)
696 (global-set-key (kbd "s-f") 'projectile-find-file)
697 (global-set-key (kbd "s-[") 'persp-next)
698 (global-set-key (kbd "s-]") 'persp-prev)
700 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
702 (global-set-key (kbd "s-n") 'persp-next)
703 (global-set-key (kbd "s-p") 'persp-prev)
707 ;; someothers default mapping on super (command) key
709 ;; s-k kill-this-buffer
712 ;; s-h --> ns-do-hide-emacs
713 ;; s-j --> ido-switch-buffer +
714 ;; s-k --> kill-this-buffer
717 ;; s-' --> next-multiframe-window
718 ;; s-ret --> toggle-frame-fullscreen +
720 ;; s-y --> ns-paste-secondary
721 ;; s-u --> revert-buffer
722 ;; s-i --> undefined - but used for iterm globally
723 ;; s-o --> used for emacs globally
724 ;; s-p --> projectile-persp-switch-project +
725 ;; s-[ --> next-buffer +
726 ;; s-] --> previous-buffer +
733 ;; s-- --> center-line
736 ;; s-n --> make-frame
737 ;; s-m --> iconify-frame
743 ;; s-g --> isearch-repeat-forward
744 ;; s-f --> projectile-find-file +
745 ;; s-d --> isearch-repeat-background
746 ;; s-s --> save-buffer
747 ;; s-a --> make-whole-buffer
751 ;; s-c --> ns-copy-including-secondary
753 ;; s-t --> ns-popup-font-panel
755 ;; s-e --> isearch-yanqk-kill
756 ;; s-w --> delete-frame
757 ;; s-q --> same-buffers-kill-emacs
759 ;; s-` --> other-frame
762 ** =M-s= bindings for searching
764 I use the prefix =M-s= for searching in buffers
766 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
768 (defun pl-make-keymap (key bindings)
769 (setq keymap (make-sparse-keymap))
770 (dolist (binding bindings)
771 (define-key keymap (car binding) (cdr binding)))
772 (global-set-key key keymap))
774 (define-key minibuffer-local-map "\M-s" nil)
776 (global-set-key (kbd "M-s s") 'isearch-forward-regexp)
777 (define-key isearch-mode-map "\M-s" 'isearch-repeat-forward)
778 (global-set-key (kbd "M-s r") 'isearch-backward-regexp)
779 (define-key isearch-mode-map "\M-r" 'isearch-repeat-backward)
781 (global-set-key (kbd "s-/") 'isearch-forward-regexp)
782 (define-key isearch-mode-map (kbd "s-/") 'isearch-repeat-forward)
783 (define-key isearch-mode-map (kbd "C-n") 'isearch-repeat-forward)
786 (set-face-background 'ido-first-match "white")
789 ;; M-s s --> isearch-forward-regexp
790 ;; M-s r --> isearch-backward-regexp
791 ;; M-s w --> isearch-forward-word
792 ;; M-s . --> isearch-forward-symbol-at-point
793 ;; M-s _ --> isearch-forward-symbol
795 ;; highlight bindings
796 ;; M-s h . --> highlight-symbol-at-point
797 ;; M-s h r --> highlight-regexp
798 ;; M-s h u --> unhighlight-regexp
799 ;; M-s h l --> highlight-lines-match-regexp
800 ;; M-s h p --> highlight-phrase
801 ;; M-s h f --> hi-lock-find-patterns
804 ;; (global-set-key (kbd "M-s M-r") 'isearch-backward-regexp)
813 Occur search key bindings
815 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
817 (define-key occur-mode-map (kbd "C-n")
821 (occur-mode-goto-occurrence-other-window)
825 (define-key occur-mode-map (kbd "C-p")
829 (occur-mode-goto-occurrence-other-window)
836 ** =M-o= as prefix key for windows
838 ** =M-g= as prefix key for launcher
842 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
853 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
855 (defalias 'e 'ido-find-file)
856 (defalias 'ff 'ido-find-file)
857 (defalias 'ee 'ido-find-file-other-window)
861 Quickly start eshll in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
863 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
870 (defun eshell-here ()
871 "Opens up a new shell in the directory associated with the
872 current buffer's file. The eshell is renamed to match that
873 directory to make multiple eshell windows easier."
875 (let* ((parent (if (buffer-file-name)
876 (file-name-directory (buffer-file-name))
878 (height (/ (window-total-height) 3))
879 (name (car (last (split-string parent "/" t))))
880 (eshell-name (concat "*eshell: " name "*")))
881 (split-window-vertically (- height))
883 (if (get-buffer eshell-name)
885 (message "buffer exist")
886 (switch-to-buffer eshell-name))
889 (rename-buffer eshell-name)
891 (insert (concat "ls"))
892 (eshell-send-input)))))
894 ;; (global-set-key (kbd "M-`") (lambda ()
896 ;; (if (buffer-name))))
902 ** [[https://github.com/abo-abo/hydra][Hydra]]
904 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
913 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
915 (defhydra sd/font-zoom (global-map "<f2>")
917 ("g" text-scale-increase "in")
918 ("l" text-scale-decrease "out"))
922 *** Windmove Splitter
924 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
926 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
928 (defun hydra-move-splitter-left (arg)
929 "Move window splitter left."
931 (if (let ((windmove-wrap-around))
932 (windmove-find-other-window 'right))
933 (shrink-window-horizontally arg)
934 (enlarge-window-horizontally arg)))
936 (defun hydra-move-splitter-right (arg)
937 "Move window splitter right."
939 (if (let ((windmove-wrap-around))
940 (windmove-find-other-window 'right))
941 (enlarge-window-horizontally arg)
942 (shrink-window-horizontally arg)))
944 (defun hydra-move-splitter-up (arg)
945 "Move window splitter up."
947 (if (let ((windmove-wrap-around))
948 (windmove-find-other-window 'up))
950 (shrink-window arg)))
952 (defun hydra-move-splitter-down (arg)
953 "Move window splitter down."
955 (if (let ((windmove-wrap-around))
956 (windmove-find-other-window 'up))
958 (enlarge-window arg)))
964 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
968 (defhydra sd/hydra-window (:color red :columns nil)
970 ("h" windmove-left nil)
971 ("j" windmove-down nil)
972 ("k" windmove-up nil)
973 ("l" windmove-right nil)
974 ("H" hydra-move-splitter-left nil)
975 ("J" hydra-move-splitter-down nil)
976 ("K" hydra-move-splitter-up nil)
977 ("L" hydra-move-splitter-right nil)
988 ("o" delete-other-windows "one" :exit t)
989 ("a" ace-window "ace")
990 ("s" ace-swap-window "swap")
991 ("d" ace-delete-window "ace-one" :exit t)
992 ("i" ace-maximize-window "ace-one" :exit t)
993 ("b" ido-switch-buffer "buf")
994 ("m" headlong-bookmark-jump "bmk")
996 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
997 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
1000 (global-unset-key (kbd "M-o"))
1001 (global-set-key (kbd "M-o") 'sd/hydra-window/body)
1003 (defun triggle-windows-max-size ()
1005 (if (> (length (window-list)) 1)
1006 (delete-other-windows)
1013 Enable linum mode on programming modes
1015 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1017 (add-hook 'prog-mode-hook 'linum-mode)
1021 Fix the font size of line number
1023 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1025 (defun fix-linum-size ()
1027 (set-face-attribute 'linum nil :height 110))
1029 (add-hook 'linum-mode-hook 'fix-linum-size)
1033 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1035 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1037 (use-package linum-relative
1040 (defun linum-new-mode ()
1041 "If line numbers aren't displayed, then display them.
1042 Otherwise, toggle between absolute and relative numbers."
1045 (linum-relative-toggle)
1049 ("A-k" . linum-new-mode))
1051 ;; auto enable linum-new-mode in programming modes
1052 (add-hook 'prog-mode-hook 'linum-relative-mode)
1056 ** Save File Position
1058 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1060 (require 'saveplace)
1061 (setq-default save-place t)
1062 (setq save-place-forget-unreadable-files t)
1063 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1069 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1071 (use-package multi-term
1078 [[https://github.com/abo-abo/ace-link][ace-link]] is a package written by [[https://github.com/abo-abo][Oleh Krehel]]. It is convenient to jump to link in help mode, info-mode, etc
1079 Type =o= to go to the link
1081 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1083 (use-package ace-link
1086 (ace-link-setup-default))
1092 [[https://github.com/re5et/emux][emux]] is
1094 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1096 (el-get-bundle re5et/emux)
1102 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1104 (use-package smartparens
1108 (require 'smartparens-config)
1109 (add-hook 'prog-mode-hook 'smartparens-mode)))
1115 [[https://github.com/abo-abo/ace-window][ace-window]]
1117 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1119 (use-package ace-window
1123 ; (global-set-key (kbd "M-o") 'ace-window)
1125 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1131 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1133 (use-package projectile
1136 (setq projectile-enable-caching t)
1138 (projectile-global-mode t))
1140 (use-package persp-projectile
1145 (:map projectile-mode-map
1146 ("s-t" . projectile-persp-switch-project)))
1148 ;; projectile-find-file
1149 ;; projectile-switch-buffer
1150 ;; projectile-find-file-other-window
1155 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1157 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1159 (use-package which-key
1168 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1170 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1175 (setq emms-source-file-default-directory "~/Music/emms/")
1178 (emms-default-players)
1179 (define-emms-simple-player mplayer '(file url)
1180 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1181 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1182 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1183 ".m4a" ".flv" ".ogv" ".pls"))
1184 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1185 (emms-history-load))
1191 Play Go in Emacs, gnugo xpm refert [[https://github.com/okanotor/dotemacs/blob/f95b774cb292d1169748bc0a62ba647bbd8c0652/etc/my-inits/my-inits-gnugo.el][to here]]. start at image display mode and grid mode
1193 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1199 (require 'gnugo-imgen)
1200 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1201 (add-hook 'gnugo-start-game-hook '(lambda ()
1202 (gnugo-image-display-mode)
1205 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1211 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1213 (use-package undo-tree
1216 (global-undo-tree-mode 1))
1222 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1229 (setq ivy-use-virtual-buffers t)
1230 (global-set-key "\C-s" 'swiper)
1231 (global-set-key (kbd "C-c C-r") 'ivy-resume)
1232 (global-set-key (kbd "<f6>") 'ivy-resume)
1233 ;; (global-set-key (kbd "M-x") 'counsel-M-x)
1234 ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
1235 (global-set-key (kbd "<f1> f") 'counsel-describe-function)
1236 (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
1237 (global-set-key (kbd "<f1> l") 'counsel-load-library)
1238 (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
1239 (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
1240 (global-set-key (kbd "C-c g") 'counsel-git)
1241 (global-set-key (kbd "C-c j") 'counsel-git-grep)
1242 (global-set-key (kbd "C-c k") 'counsel-ag)
1243 (global-set-key (kbd "C-x l") 'counsel-locate)
1244 (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
1245 ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
1251 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1253 ;; (use-package tabbar-ruler
1256 ;; (setq tabbar-ruler-global-tabbar t)
1257 ;; (setq tabbar-ruler-global-ruler t)
1258 ;; (setq tabbar-ruler-popu-menu t)
1259 ;; (setq tabbar-ruler-popu-toolbar t)
1260 ;; (setq tabbar-use-images t)
1262 ;; (tabbar-ruler-group-by-projectile-project)
1263 ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
1264 ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1274 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1276 (use-package color-identifiers-mode
1279 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1281 :diminish color-identifiers-mode)
1283 (global-prettify-symbols-mode t)
1289 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1290 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1292 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1297 (eval-after-load 'lispy
1299 (define-key lispy-mode-map (kbd "M-o") nil)))
1301 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1307 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1309 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1311 (defalias 'perl-mode 'cperl-mode)
1313 ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
1314 (setq cperl-auto-newline t)
1315 (setq cperl-highlight-variables-indiscriminately t)
1316 ;(setq cperl-indent-level 4)
1317 ;(setq cperl-continued-statement-offset 4)
1318 (setq cperl-close-paren-offset -4)
1319 (setq cperl-indent-parents-as-block t)
1320 (setq cperl-tab-always-indent t)
1321 ;(setq cperl-brace-offset 0)
1323 (add-hook 'cperl-mode-hook
1325 (cperl-set-style "C++")))
1327 ;(require 'template)
1328 ;(template-initialize)
1336 Change the compile-command to set the default command run when call =compile=
1337 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1338 to call =compilation= interactively.
1340 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1342 (defun my-perl-hook ()
1344 (setq-local compilation-read-command nil)
1345 (set (make-local-variable 'compile-command)
1346 (concat "/usr/bin/perl "
1347 (if buffer-file-name
1348 (shell-quote-argument buffer-file-name))))
1349 (local-set-key (kbd "s-r")
1352 ; (setq current-prefix-arg '(4)) ; C-u
1353 (call-interactively 'compile)))))
1355 (add-hook 'cperl-mode-hook 'my-perl-hook)
1362 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1364 (setq c-default-style "stroustrup"
1371 Set the environments vairables in compilation mode
1373 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1375 (use-package compile
1378 (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
1384 Enable auto-insert mode
1386 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1388 (auto-insert-mode t)
1389 (setq auto-insert-query nil)
1395 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1397 (eval-after-load 'autoinsert
1398 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1400 "Short description:"
1402 "\n * " (file-name-nondirectory (buffer-file-name))
1404 "#include <iostream>" \n
1406 (file-name-sans-extension
1407 (file-name-nondirectory (buffer-file-name)))
1409 "using namespace std;" \n \n
1417 (eval-after-load 'autoinsert
1418 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1420 "Short description:"
1422 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1424 "#include <stdio.h>" \n
1426 (file-name-sans-extension
1427 (file-name-nondirectory (buffer-file-name)))
1438 *** Perl Auto Insert
1440 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1442 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1444 (eval-after-load 'autoinsert
1445 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1448 "#!/usr/bin/perl -w" \n
1459 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1461 (use-package company
1463 :diminish company-mode
1464 :init (setq company-idle-delay 0.1)
1466 (global-company-mode))
1470 [[https://github.com/company-mode/company-statistics][company-statistics]]
1472 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1474 (use-package company-statistics
1477 (company-statistics-mode))
1483 - change M-o to trigger to delete other windows and restore previous config