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))
283 ** Org-mode Basic setting
285 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
287 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
292 (setq org-startup-indented t)
293 (setq org-hide-leading-starts t)
294 (setq org-src-fontify-natively t)
295 (setq org-src-tab-acts-natively t)
296 (setq org-confirm-babel-evaluate nil)
297 (setq org-use-speed-commands t)
298 (setq org-completion-use-ido t))
300 (org-babel-do-load-languages
301 'org-babel-load-languages
315 ;; use current window for org source buffer editting
316 (setq org-src-window-setup 'current-window )
322 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
324 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
326 (use-package org-bullets
329 (add-hook 'org-mode-hook
331 (org-bullets-mode t))))
337 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
338 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
339 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
340 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
342 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
347 :init (add-hook 'org-mode-hook 'worf-mode)
349 ;; (define-key worf-mode-map "[" nil)
350 ;; (define-key worf-mode-map "]" nil)
351 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
352 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
363 Install MacTex-basic and some tex packages
367 sudo tlmgr update --self
369 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
373 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
374 ;; ;; allow for export=>beamer by placing
376 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
377 ;; #+LaTeX_CLASS: beamer in org files
378 (unless (boundp 'org-export-latex-classes)
379 (setq org-export-latex-classes nil))
380 (add-to-list 'org-export-latex-classes
381 ;; beamer class, for presentations
383 "\\documentclass[11pt]{beamer}\n
384 \\mode<{{{beamermode}}}>\n
385 \\usetheme{{{{beamertheme}}}}\n
386 \\usecolortheme{{{{beamercolortheme}}}}\n
387 \\beamertemplateballitem\n
388 \\setbeameroption{show notes}
389 \\usepackage[utf8]{inputenc}\n
390 \\usepackage[T1]{fontenc}\n
391 \\usepackage{hyperref}\n
393 \\usepackage{listings}
394 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
397 showspaces=false,showstringspaces=false,
399 keywordstyle=\\color{blue}\\bfseries,
400 commentstyle=\\color{red},
402 \\usepackage{verbatim}\n
403 \\institute{{{{beamerinstitute}}}}\n
404 \\subject{{{{beamersubject}}}}\n"
406 ("\\section{%s}" . "\\section*{%s}")
408 ("\\begin{frame}[fragile]\\frametitle{%s}"
410 "\\begin{frame}[fragile]\\frametitle{%s}"
413 ;; letter class, for formal letters
415 (add-to-list 'org-export-latex-classes
418 "\\documentclass[11pt]{letter}\n
419 \\usepackage[utf8]{inputenc}\n
420 \\usepackage[T1]{fontenc}\n
423 ("\\section{%s}" . "\\section*{%s}")
424 ("\\subsection{%s}" . "\\subsection*{%s}")
425 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
426 ("\\paragraph{%s}" . "\\paragraph*{%s}")
427 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
433 (setq org-latex-pdf-process
434 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
435 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
436 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
438 (setq TeX-parse-self t)
440 (setq TeX-PDF-mode t)
441 (add-hook 'LaTeX-mode-hook
444 (setq TeX-master t)))
450 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
452 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
456 :commands magit-status magit-blame)
465 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
469 :init (setq ido-enable-flex-matching t
470 ido-ignore-extensions t
471 ido-use-virtual-buffers t
476 (add-to-list 'completion-ignored-extensions ".pyc"))
484 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
488 :init (setq ido-enable-flex-matching t
490 :config (flx-ido-mode 1))
496 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
498 (use-package ido-vertical-mode
501 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
503 (ido-vertical-mode 1))
509 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
513 :init (smex-initialize)
516 ("M-X" . smex-major-mode-commands))
522 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
524 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
526 (use-package ido-ubiquitous
529 (setq magit-completing-read-function 'magit-ido-completing-read)
530 (setq gnus-completing-read-function 'gnus-ido-completing-read)
532 (ido-ubiquitous-mode 1))
538 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
540 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
542 (use-package ido-exit-target
545 (define-key ido-common-completion-map (kbd "C-j") #'ido-exit-target-split-window-right)
546 (define-key ido-common-completion-map (kbd "C-l") #'ido-exit-target-split-window-below))
552 ** Remove prefix =ESC=, refer [[http://emacs.stackexchange.com/questions/14755/how-to-remove-bindings-to-the-esc-prefix-key][here]]
554 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
556 ;; (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
562 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
564 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
566 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
567 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
568 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
569 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
570 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
571 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
572 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
573 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
574 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
576 ;; Also map s-h same as C-g
577 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
581 ** =Ctrl= key bindings
583 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
587 ;; C-j newline and indent
589 ;; C-l recenter-top-bottom
590 ;; (global-set-key (kbd "C-;") 'ido-switch-buffer)
627 ** =Super= bindings for file, buffer and windows
629 Some global bindings on =Super=, on Mac, it is =Command=
631 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
633 (global-set-key (kbd "s-h") 'keyboard-quit)
634 (global-set-key (kbd "s-j") 'ido-switch-buffer)
635 (global-set-key (kbd "s-k") 'ido-find-file)
636 ;; s-k --> kill-this-buffer
637 (global-set-key (kbd "s-l") (lambda ()
639 (if (> (length (window-list)) 1)
641 (message "Only one Windows now!"))))
643 (global-set-key (kbd "s-;") 'swiper)
645 ;; s-' --> 'next-multiframe-window
646 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
648 ;; (global-set-key (kbd "s-y") 'projectile-find-file)
649 (global-set-key (kbd "s-f") 'projectile-find-file)
650 (global-set-key (kbd "s-[") 'next-buffer)
651 (global-set-key (kbd "s-]") 'previous-buffer)
653 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
657 ;; someothers default mapping on super (command) key
659 ;; s-k kill-this-buffer
662 ;; s-h --> ns-do-hide-emacs
663 ;; s-j --> ido-switch-buffer +
664 ;; s-k --> kill-this-buffer
667 ;; s-' --> next-multiframe-window
668 ;; s-ret --> toggle-frame-fullscreen +
670 ;; s-y --> ns-paste-secondary
671 ;; s-u --> revert-buffer
672 ;; s-i --> undefined - but used for iterm globally
673 ;; s-o --> used for emacs globally
674 ;; s-p --> projectile-persp-switch-project +
675 ;; s-[ --> next-buffer +
676 ;; s-] --> previous-buffer +
683 ;; s-- --> center-line
686 ;; s-n --> make-frame
687 ;; s-m --> iconify-frame
693 ;; s-g --> isearch-repeat-forward
694 ;; s-f --> projectile-find-file +
695 ;; s-d --> isearch-repeat-background
696 ;; s-s --> save-buffer
697 ;; s-a --> make-whole-buffer
701 ;; s-c --> ns-copy-including-secondary
703 ;; s-t --> ns-popup-font-panel
705 ;; s-e --> isearch-yanqk-kill
706 ;; s-w --> delete-frame
707 ;; s-q --> same-buffers-kill-emacs
709 ;; s-` --> other-frame
712 ** =M-s= bindings for searching
714 I use the prefix =M-s= for searching in buffers
716 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
718 (defun pl-make-keymap (key bindings)
719 (setq keymap (make-sparse-keymap))
720 (dolist (binding bindings)
721 (define-key keymap (car binding) (cdr binding)))
722 (global-set-key key keymap))
724 (define-key minibuffer-local-map "\M-s" nil)
726 (global-set-key (kbd "M-s s") 'isearch-forward-regexp)
727 (define-key isearch-mode-map "\M-s" 'isearch-repeat-forward)
728 (global-set-key (kbd "M-s r") 'isearch-backward-regexp)
729 (define-key isearch-mode-map "\M-r" 'isearch-repeat-backward)
731 (global-set-key (kbd "s-/") 'isearch-forward-regexp)
732 (define-key isearch-mode-map (kbd "s-/") 'isearch-repeat-forward)
733 (define-key isearch-mode-map (kbd "C-n") 'isearch-repeat-forward)
736 (set-face-background 'ido-first-match "white")
739 ;; M-s s --> isearch-forward-regexp
740 ;; M-s r --> isearch-backward-regexp
741 ;; M-s w --> isearch-forward-word
742 ;; M-s . --> isearch-forward-symbol-at-point
743 ;; M-s _ --> isearch-forward-symbol
745 ;; highlight bindings
746 ;; M-s h . --> highlight-symbol-at-point
747 ;; M-s h r --> highlight-regexp
748 ;; M-s h u --> unhighlight-regexp
749 ;; M-s h l --> highlight-lines-match-regexp
750 ;; M-s h p --> highlight-phrase
751 ;; M-s h f --> hi-lock-find-patterns
754 ;; (global-set-key (kbd "M-s M-r") 'isearch-backward-regexp)
763 Occur search key bindings
765 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
767 (define-key occur-mode-map (kbd "C-n")
771 (occur-mode-goto-occurrence-other-window)
775 (define-key occur-mode-map (kbd "C-p")
779 (occur-mode-goto-occurrence-other-window)
786 ** =M-o= as prefix key for windows
788 ** =M-g= as prefix key for launcher
792 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
803 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
805 (defalias 'e 'ido-find-file)
806 (defalias 'ff 'ido-find-file)
807 (defalias 'ee 'ido-find-file-other-window)
811 Quickly start eshll in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
813 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
820 (defun eshell-here ()
821 "Opens up a new shell in the directory associated with the
822 current buffer's file. The eshell is renamed to match that
823 directory to make multiple eshell windows easier."
825 (let* ((parent (if (buffer-file-name)
826 (file-name-directory (buffer-file-name))
828 (height (/ (window-total-height) 3))
829 (name (car (last (split-string parent "/" t))))
830 (eshell-name (concat "*eshell: " name "*")))
831 (split-window-vertically (- height))
833 (if (get-buffer eshell-name)
835 (message "buffer exist")
836 (switch-to-buffer eshell-name))
839 (rename-buffer eshell-name)
841 (insert (concat "ls"))
842 (eshell-send-input)))))
844 (global-set-key (kbd "M-`") (lambda ()
852 ** [[https://github.com/abo-abo/hydra][Hydra]]
854 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
863 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
865 (defhydra sd/font-zoom (global-map "<f2>")
867 ("g" text-scale-increase "in")
868 ("l" text-scale-decrease "out"))
872 *** Windmove Splitter
874 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
876 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
878 (defun hydra-move-splitter-left (arg)
879 "Move window splitter left."
881 (if (let ((windmove-wrap-around))
882 (windmove-find-other-window 'right))
883 (shrink-window-horizontally arg)
884 (enlarge-window-horizontally arg)))
886 (defun hydra-move-splitter-right (arg)
887 "Move window splitter right."
889 (if (let ((windmove-wrap-around))
890 (windmove-find-other-window 'right))
891 (enlarge-window-horizontally arg)
892 (shrink-window-horizontally arg)))
894 (defun hydra-move-splitter-up (arg)
895 "Move window splitter up."
897 (if (let ((windmove-wrap-around))
898 (windmove-find-other-window 'up))
900 (shrink-window arg)))
902 (defun hydra-move-splitter-down (arg)
903 "Move window splitter down."
905 (if (let ((windmove-wrap-around))
906 (windmove-find-other-window 'up))
908 (enlarge-window arg)))
914 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
918 (defhydra sd/hydra-window (:color red :columns nil)
920 ("h" windmove-left nil)
921 ("j" windmove-down nil)
922 ("k" windmove-up nil)
923 ("l" windmove-right nil)
924 ("H" hydra-move-splitter-left nil)
925 ("J" hydra-move-splitter-down nil)
926 ("K" hydra-move-splitter-up nil)
927 ("L" hydra-move-splitter-right nil)
938 ("o" delete-other-windows "one" :exit t)
939 ("a" ace-window "ace")
940 ("s" ace-swap-window "swap")
941 ("d" ace-delete-window "ace-one" :exit t)
942 ("i" ace-maximize-window "ace-one" :exit t)
943 ("b" ido-switch-buffer "buf")
944 ("m" headlong-bookmark-jump "bmk")
946 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
947 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
950 (global-unset-key (kbd "M-o"))
951 (global-set-key (kbd "M-o") 'sd/hydra-window/body)
953 (defun triggle-windows-max-size ()
955 (if (> (length (window-list)) 1)
956 (delete-other-windows)
963 Enable linum mode on programming modes
965 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
967 (add-hook 'prog-mode-hook 'linum-mode)
971 Fix the font size of line number
973 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
975 (defun fix-linum-size ()
977 (set-face-attribute 'linum nil :height 110))
979 (add-hook 'linum-mode-hook 'fix-linum-size)
983 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
985 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
987 (use-package linum-relative
990 (defun linum-new-mode ()
991 "If line numbers aren't displayed, then display them.
992 Otherwise, toggle between absolute and relative numbers."
995 (linum-relative-toggle)
999 ("A-k" . linum-new-mode))
1001 ;; auto enable linum-new-mode in programming modes
1002 (add-hook 'prog-mode-hook 'linum-relative-mode)
1006 ** Save File Position
1008 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1010 (require 'saveplace)
1011 (setq-default save-place t)
1012 (setq save-place-forget-unreadable-files t)
1013 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1019 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1021 (use-package multi-term
1028 [[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
1029 Type =o= to go to the link
1031 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1033 (use-package ace-link
1036 (ace-link-setup-default))
1042 [[https://github.com/re5et/emux][emux]] is
1044 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1046 (el-get-bundle re5et/emux)
1052 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1054 (use-package smartparens
1058 (require 'smartparens-config)
1059 (add-hook 'prog-mode-hook 'smartparens-mode)))
1065 [[https://github.com/abo-abo/ace-window][ace-window]]
1067 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1069 (use-package ace-window
1073 ; (global-set-key (kbd "M-o") 'ace-window)
1075 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1081 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1083 (use-package projectile
1086 (setq projectile-enable-caching t)
1088 (projectile-global-mode t))
1090 (use-package persp-projectile
1095 (:map projectile-mode-map
1096 ("s-p" . projectile-persp-switch-project)))
1098 ;; projectile-find-file
1099 ;; projectile-switch-buffer
1100 ;; projectile-find-file-other-window
1105 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1107 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1109 (use-package which-key
1118 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1120 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1125 (setq emms-source-file-default-directory "~/Music/emms/")
1128 (emms-default-players)
1129 (define-emms-simple-player mplayer '(file url)
1130 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1131 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1132 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1133 ".m4a" ".flv" ".ogv" ".pls"))
1134 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1135 (emms-history-load))
1141 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
1143 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1149 (require 'gnugo-imgen)
1150 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1151 (add-hook 'gnugo-start-game-hook '(lambda ()
1152 (gnugo-image-display-mode)
1155 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1161 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1163 (use-package undo-tree
1166 (global-undo-tree-mode 1))
1172 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1179 (setq ivy-use-virtual-buffers t)
1180 (global-set-key "\C-s" 'swiper)
1181 (global-set-key (kbd "C-c C-r") 'ivy-resume)
1182 (global-set-key (kbd "<f6>") 'ivy-resume)
1183 ;; (global-set-key (kbd "M-x") 'counsel-M-x)
1184 ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
1185 (global-set-key (kbd "<f1> f") 'counsel-describe-function)
1186 (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
1187 (global-set-key (kbd "<f1> l") 'counsel-load-library)
1188 (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
1189 (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
1190 (global-set-key (kbd "C-c g") 'counsel-git)
1191 (global-set-key (kbd "C-c j") 'counsel-git-grep)
1192 (global-set-key (kbd "C-c k") 'counsel-ag)
1193 (global-set-key (kbd "C-x l") 'counsel-locate)
1194 (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
1195 ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
1205 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1207 (use-package color-identifiers-mode
1210 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1212 :diminish color-identifiers-mode)
1214 (global-prettify-symbols-mode t)
1220 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1221 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1223 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1228 (eval-after-load 'lispy
1230 (define-key lispy-mode-map (kbd "M-o") nil)))
1232 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1238 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1240 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1242 (defalias 'perl-mode 'cperl-mode)
1244 ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
1245 (setq cperl-auto-newline t)
1246 (setq cperl-highlight-variables-indiscriminately t)
1247 ;(setq cperl-indent-level 4)
1248 ;(setq cperl-continued-statement-offset 4)
1249 (setq cperl-close-paren-offset -4)
1250 (setq cperl-indent-parents-as-block t)
1251 (setq cperl-tab-always-indent t)
1252 ;(setq cperl-brace-offset 0)
1254 (add-hook 'cperl-mode-hook
1256 (cperl-set-style "C++")))
1258 ;(require 'template)
1259 ;(template-initialize)
1267 Change the compile-command to set the default command run when call =compile=
1268 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1269 to call =compilation= interactively.
1271 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1273 (defun my-perl-hook ()
1275 (setq-local compilation-read-command nil)
1276 (set (make-local-variable 'compile-command)
1277 (concat "/usr/bin/perl "
1278 (if buffer-file-name
1279 (shell-quote-argument buffer-file-name))))
1280 (local-set-key (kbd "s-r")
1283 ; (setq current-prefix-arg '(4)) ; C-u
1284 (call-interactively 'compile)))))
1286 (add-hook 'cperl-mode-hook 'my-perl-hook)
1293 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1295 (setq c-default-style "stroustrup"
1302 Set the environments vairables in compilation mode
1304 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1306 (use-package compile
1309 (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
1315 Enable auto-insert mode
1317 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1319 (auto-insert-mode t)
1320 (setq auto-insert-query nil)
1326 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1328 (eval-after-load 'autoinsert
1329 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1331 "Short description:"
1333 "\n * " (file-name-nondirectory (buffer-file-name))
1335 "#include <iostream>" \n
1337 (file-name-sans-extension
1338 (file-name-nondirectory (buffer-file-name)))
1340 "using namespace std;" \n \n
1348 (eval-after-load 'autoinsert
1349 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1351 "Short description:"
1353 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1355 "#include <stdio.h>" \n
1357 (file-name-sans-extension
1358 (file-name-nondirectory (buffer-file-name)))
1369 *** Perl Auto Insert
1371 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1373 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1375 (eval-after-load 'autoinsert
1376 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1379 "#!/usr/bin/perl -w" \n
1390 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1392 (use-package company
1394 :diminish company-mode
1395 :init (setq company-idle-delay 0.1)
1397 (global-company-mode))
1403 - change M-o to trigger to delete other windows and restore previous config