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 ** Org-mode Basic setting
275 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
277 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
282 (setq org-startup-indented t)
283 (setq org-hide-leading-starts t)
284 (setq org-src-fontify-natively t)
285 (setq org-src-tab-acts-natively t)
286 (setq org-confirm-babel-evaluate nil)
287 (setq org-use-speed-commands t)
288 (setq org-completion-use-ido t))
290 (org-babel-do-load-languages
291 'org-babel-load-languages
305 ;; use current window for org source buffer editting
306 (setq org-src-window-setup 'current-window )
312 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
314 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
316 (use-package org-bullets
319 (add-hook 'org-mode-hook
321 (org-bullets-mode t))))
327 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
328 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
329 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
330 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
332 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
337 :init (add-hook 'org-mode-hook 'worf-mode)
339 ;; (define-key worf-mode-map "[" nil)
340 ;; (define-key worf-mode-map "]" nil)
341 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
342 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
353 Install MacTex-basic and some tex packages
357 sudo tlmgr update --self
359 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
363 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
364 ;; ;; allow for export=>beamer by placing
366 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
367 ;; #+LaTeX_CLASS: beamer in org files
368 (unless (boundp 'org-export-latex-classes)
369 (setq org-export-latex-classes nil))
370 (add-to-list 'org-export-latex-classes
371 ;; beamer class, for presentations
373 "\\documentclass[11pt]{beamer}\n
374 \\mode<{{{beamermode}}}>\n
375 \\usetheme{{{{beamertheme}}}}\n
376 \\usecolortheme{{{{beamercolortheme}}}}\n
377 \\beamertemplateballitem\n
378 \\setbeameroption{show notes}
379 \\usepackage[utf8]{inputenc}\n
380 \\usepackage[T1]{fontenc}\n
381 \\usepackage{hyperref}\n
383 \\usepackage{listings}
384 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
387 showspaces=false,showstringspaces=false,
389 keywordstyle=\\color{blue}\\bfseries,
390 commentstyle=\\color{red},
392 \\usepackage{verbatim}\n
393 \\institute{{{{beamerinstitute}}}}\n
394 \\subject{{{{beamersubject}}}}\n"
396 ("\\section{%s}" . "\\section*{%s}")
398 ("\\begin{frame}[fragile]\\frametitle{%s}"
400 "\\begin{frame}[fragile]\\frametitle{%s}"
403 ;; letter class, for formal letters
405 (add-to-list 'org-export-latex-classes
408 "\\documentclass[11pt]{letter}\n
409 \\usepackage[utf8]{inputenc}\n
410 \\usepackage[T1]{fontenc}\n
413 ("\\section{%s}" . "\\section*{%s}")
414 ("\\subsection{%s}" . "\\subsection*{%s}")
415 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
416 ("\\paragraph{%s}" . "\\paragraph*{%s}")
417 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
423 (setq org-latex-pdf-process
424 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
425 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
426 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
428 (setq TeX-parse-self t)
430 (setq TeX-PDF-mode t)
431 (add-hook 'LaTeX-mode-hook
434 (setq TeX-master t)))
440 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
442 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
446 :commands magit-status magit-blame)
455 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
459 :init (setq ido-enable-flex-matching t
460 ido-ignore-extensions t
461 ido-use-virtual-buffers t
466 (add-to-list 'completion-ignored-extensions ".pyc"))
474 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
478 :init (setq ido-enable-flex-matching t
480 :config (flx-ido-mode 1))
486 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
488 (use-package ido-vertical-mode
491 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
493 (ido-vertical-mode 1))
499 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
503 :init (smex-initialize)
506 ("M-X" . smex-major-mode-commands))
512 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
514 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
516 (use-package ido-ubiquitous
519 (setq magit-completing-read-function 'magit-ido-completing-read)
520 (setq gnus-completing-read-function 'gnus-ido-completing-read)
522 (ido-ubiquitous-mode 1))
528 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
530 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
532 (use-package ido-exit-target
535 (define-key ido-common-completion-map (kbd "C-j") #'ido-exit-target-split-window-right)
536 (define-key ido-common-completion-map (kbd "C-l") #'ido-exit-target-split-window-below))
542 ** Remove prefix =ESC=, refer [[http://emacs.stackexchange.com/questions/14755/how-to-remove-bindings-to-the-esc-prefix-key][here]]
544 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
546 ;; (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
552 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
554 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
556 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
557 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
558 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
559 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
560 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
561 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
562 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
563 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
564 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
566 ;; Also map s-h same as C-g
567 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
571 ** =Ctrl= key bindings
573 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
577 ;; C-j newline and indent
579 ;; C-l recenter-top-bottom
580 ;; (global-set-key (kbd "C-;") 'ido-switch-buffer)
617 ** =Super= bindings for file, buffer and windows
619 Some global bindings on =Super=, on Mac, it is =Command=
621 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
623 (global-set-key (kbd "s-h") 'keyboard-quit)
624 (global-set-key (kbd "s-j") 'ido-switch-buffer)
625 (global-set-key (kbd "s-k") 'ido-find-file)
626 ;; s-k --> kill-this-buffer
627 (global-set-key (kbd "s-l") (lambda ()
629 (if (> (length (window-list)) 1)
631 (message "Only one Windows now!"))))
633 (global-set-key (kbd "s-;") 'swiper)
635 ;; s-' --> 'next-multiframe-window
636 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
638 ;; (global-set-key (kbd "s-y") 'projectile-find-file)
639 (global-set-key (kbd "s-f") 'projectile-find-file)
640 (global-set-key (kbd "s-[") 'next-buffer)
641 (global-set-key (kbd "s-]") 'previous-buffer)
643 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
647 ;; someothers default mapping on super (command) key
649 ;; s-k kill-this-buffer
652 ;; s-h --> ns-do-hide-emacs
653 ;; s-j --> ido-switch-buffer +
654 ;; s-k --> kill-this-buffer
657 ;; s-' --> next-multiframe-window
658 ;; s-ret --> toggle-frame-fullscreen +
660 ;; s-y --> ns-paste-secondary
661 ;; s-u --> revert-buffer
662 ;; s-i --> undefined - but used for iterm globally
663 ;; s-o --> used for emacs globally
664 ;; s-p --> projectile-persp-switch-project +
665 ;; s-[ --> next-buffer +
666 ;; s-] --> previous-buffer +
673 ;; s-- --> center-line
676 ;; s-n --> make-frame
677 ;; s-m --> iconify-frame
683 ;; s-g --> isearch-repeat-forward
684 ;; s-f --> projectile-find-file +
685 ;; s-d --> isearch-repeat-background
686 ;; s-s --> save-buffer
687 ;; s-a --> make-whole-buffer
691 ;; s-c --> ns-copy-including-secondary
693 ;; s-t --> ns-popup-font-panel
695 ;; s-e --> isearch-yanqk-kill
696 ;; s-w --> delete-frame
697 ;; s-q --> same-buffers-kill-emacs
699 ;; s-` --> other-frame
702 ** =M-s= bindings for searching
704 I use the prefix =M-s= for searching in buffers
706 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
708 (defun pl-make-keymap (key bindings)
709 (setq keymap (make-sparse-keymap))
710 (dolist (binding bindings)
711 (define-key keymap (car binding) (cdr binding)))
712 (global-set-key key keymap))
714 (define-key minibuffer-local-map "\M-s" nil)
716 (global-set-key (kbd "M-s s") 'isearch-forward-regexp)
717 (define-key isearch-mode-map "\M-s" 'isearch-repeat-forward)
718 (global-set-key (kbd "M-s r") 'isearch-backward-regexp)
719 (define-key isearch-mode-map "\M-r" 'isearch-repeat-backward)
721 (global-set-key (kbd "s-/") 'isearch-forward-regexp)
722 (define-key isearch-mode-map (kbd "s-/") 'isearch-repeat-forward)
723 (define-key isearch-mode-map (kbd "C-n") 'isearch-repeat-forward)
726 (set-face-background 'ido-first-match "white")
729 ;; M-s s --> isearch-forward-regexp
730 ;; M-s r --> isearch-backward-regexp
731 ;; M-s w --> isearch-forward-word
732 ;; M-s . --> isearch-forward-symbol-at-point
733 ;; M-s _ --> isearch-forward-symbol
735 ;; highlight bindings
736 ;; M-s h . --> highlight-symbol-at-point
737 ;; M-s h r --> highlight-regexp
738 ;; M-s h u --> unhighlight-regexp
739 ;; M-s h l --> highlight-lines-match-regexp
740 ;; M-s h p --> highlight-phrase
741 ;; M-s h f --> hi-lock-find-patterns
744 ;; (global-set-key (kbd "M-s M-r") 'isearch-backward-regexp)
753 Occur search key bindings
755 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
757 (define-key occur-mode-map (kbd "C-n")
761 (occur-mode-goto-occurrence-other-window)
765 (define-key occur-mode-map (kbd "C-p")
769 (occur-mode-goto-occurrence-other-window)
776 ** =M-o= as prefix key for windows
778 ** =M-g= as prefix key for launcher
782 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
793 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
795 (defalias 'e 'ido-find-file)
796 (defalias 'ff 'ido-find-file)
797 (defalias 'ee 'ido-find-file-other-window)
801 Quickly start eshll in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
803 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
810 (defun eshell-here ()
811 "Opens up a new shell in the directory associated with the
812 current buffer's file. The eshell is renamed to match that
813 directory to make multiple eshell windows easier."
815 (let* ((parent (if (buffer-file-name)
816 (file-name-directory (buffer-file-name))
818 (height (/ (window-total-height) 3))
819 (name (car (last (split-string parent "/" t)))))
820 (split-window-vertically (- height))
822 (if (get-buffer (concat "*eshell: " name "*"))
824 (message "buffer exist")
825 (switch-to-buffer (concat "*eshell: " name "*")))
828 (rename-buffer (concat "*eshell: " name "*"))
830 (insert (concat "ls"))
831 (eshell-send-input)))))
833 ;; (global-set-key (kbd "M-`") (lambda ()
835 ;; (if (buffer-name))))
843 ** [[https://github.com/abo-abo/hydra][Hydra]]
845 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
854 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
856 (defhydra sd/font-zoom (global-map "<f2>")
858 ("g" text-scale-increase "in")
859 ("l" text-scale-decrease "out"))
863 *** Windmove Splitter
865 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
867 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
869 (defun hydra-move-splitter-left (arg)
870 "Move window splitter left."
872 (if (let ((windmove-wrap-around))
873 (windmove-find-other-window 'right))
874 (shrink-window-horizontally arg)
875 (enlarge-window-horizontally arg)))
877 (defun hydra-move-splitter-right (arg)
878 "Move window splitter right."
880 (if (let ((windmove-wrap-around))
881 (windmove-find-other-window 'right))
882 (enlarge-window-horizontally arg)
883 (shrink-window-horizontally arg)))
885 (defun hydra-move-splitter-up (arg)
886 "Move window splitter up."
888 (if (let ((windmove-wrap-around))
889 (windmove-find-other-window 'up))
891 (shrink-window arg)))
893 (defun hydra-move-splitter-down (arg)
894 "Move window splitter down."
896 (if (let ((windmove-wrap-around))
897 (windmove-find-other-window 'up))
899 (enlarge-window arg)))
905 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
909 (defhydra sd/hydra-window (:color red :columns nil)
911 ("h" windmove-left nil)
912 ("j" windmove-down nil)
913 ("k" windmove-up nil)
914 ("l" windmove-right nil)
915 ("H" hydra-move-splitter-left nil)
916 ("J" hydra-move-splitter-down nil)
917 ("K" hydra-move-splitter-up nil)
918 ("L" hydra-move-splitter-right nil)
929 ("o" delete-other-windows "one" :exit t)
930 ("a" ace-window "ace")
931 ("s" ace-swap-window "swap")
932 ("d" ace-delete-window "ace-one" :exit t)
933 ("i" ace-maximize-window "ace-one" :exit t)
934 ("b" ido-switch-buffer "buf")
935 ("m" headlong-bookmark-jump "bmk")
937 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
938 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
941 (global-unset-key (kbd "M-o"))
942 (global-set-key (kbd "M-o") 'sd/hydra-window/body)
944 (defun triggle-windows-max-size ()
946 (if (> (length (window-list)) 1)
947 (delete-other-windows)
954 Enable linum mode on programming modes
956 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
958 (add-hook 'prog-mode-hook 'linum-mode)
962 Fix the font size of line number
964 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
966 (defun fix-linum-size ()
968 (set-face-attribute 'linum nil :height 110))
970 (add-hook 'linum-mode-hook 'fix-linum-size)
974 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
976 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
978 (use-package linum-relative
981 (defun linum-new-mode ()
982 "If line numbers aren't displayed, then display them.
983 Otherwise, toggle between absolute and relative numbers."
986 (linum-relative-toggle)
990 ("A-k" . linum-new-mode))
992 ;; auto enable linum-new-mode in programming modes
993 (add-hook 'prog-mode-hook 'linum-relative-mode)
997 ** Save File Position
999 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1001 (require 'saveplace)
1002 (setq-default save-place t)
1003 (setq save-place-forget-unreadable-files t)
1004 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1010 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1012 (use-package multi-term
1019 [[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
1020 Type =o= to go to the link
1022 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1024 (use-package ace-link
1027 (ace-link-setup-default))
1033 [[https://github.com/re5et/emux][emux]] is
1035 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1037 (el-get-bundle re5et/emux)
1043 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1045 (use-package smartparens
1049 (require 'smartparens-config)
1050 (add-hook 'prog-mode-hook 'smartparens-mode)))
1056 [[https://github.com/abo-abo/ace-window][ace-window]]
1058 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1060 (use-package ace-window
1064 ; (global-set-key (kbd "M-o") 'ace-window)
1066 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1072 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1074 (use-package projectile
1077 (setq projectile-enable-caching t)
1079 (projectile-global-mode t))
1081 (use-package persp-projectile
1086 (:map projectile-mode-map
1087 ("s-p" . projectile-persp-switch-project)))
1089 ;; projectile-find-file
1090 ;; projectile-switch-buffer
1091 ;; projectile-find-file-other-window
1096 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1098 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1100 (use-package which-key
1109 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1111 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1116 (setq emms-source-file-default-directory "~/Music/emms/")
1119 (emms-default-players)
1120 (define-emms-simple-player mplayer '(file url)
1121 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1122 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1123 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1124 ".m4a" ".flv" ".ogv" ".pls"))
1125 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1126 (emms-history-load))
1132 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
1134 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1140 (require 'gnugo-imgen)
1141 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1142 (add-hook 'gnugo-start-game-hook '(lambda ()
1143 (gnugo-image-display-mode)
1146 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1152 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1154 (use-package undo-tree
1157 (global-undo-tree-mode 1))
1163 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1170 (setq ivy-use-virtual-buffers t)
1171 (global-set-key "\C-s" 'swiper)
1172 (global-set-key (kbd "C-c C-r") 'ivy-resume)
1173 (global-set-key (kbd "<f6>") 'ivy-resume)
1174 ;; (global-set-key (kbd "M-x") 'counsel-M-x)
1175 ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
1176 (global-set-key (kbd "<f1> f") 'counsel-describe-function)
1177 (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
1178 (global-set-key (kbd "<f1> l") 'counsel-load-library)
1179 (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
1180 (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
1181 (global-set-key (kbd "C-c g") 'counsel-git)
1182 (global-set-key (kbd "C-c j") 'counsel-git-grep)
1183 (global-set-key (kbd "C-c k") 'counsel-ag)
1184 (global-set-key (kbd "C-x l") 'counsel-locate)
1185 (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
1186 ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
1196 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1198 (use-package color-identifiers-mode
1201 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1203 :diminish color-identifiers-mode)
1205 (global-prettify-symbols-mode t)
1211 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1212 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1214 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1219 (eval-after-load 'lispy
1221 (define-key lispy-mode-map (kbd "M-o") nil)))
1223 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1229 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1231 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1233 (defalias 'perl-mode 'cperl-mode)
1235 ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
1236 (setq cperl-auto-newline t)
1237 (setq cperl-highlight-variables-indiscriminately t)
1238 ;(setq cperl-indent-level 4)
1239 ;(setq cperl-continued-statement-offset 4)
1240 (setq cperl-close-paren-offset -4)
1241 (setq cperl-indent-parents-as-block t)
1242 (setq cperl-tab-always-indent t)
1243 ;(setq cperl-brace-offset 0)
1245 (add-hook 'cperl-mode-hook
1247 (cperl-set-style "C++")))
1249 ;(require 'template)
1250 ;(template-initialize)
1258 Change the compile-command to set the default command run when call =compile=
1259 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1260 to call =compilation= interactively.
1262 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1264 (defun my-perl-hook ()
1266 (setq-local compilation-read-command nil)
1267 (set (make-local-variable 'compile-command)
1268 (concat "/usr/bin/perl "
1269 (if buffer-file-name
1270 (shell-quote-argument buffer-file-name))))
1271 (local-set-key (kbd "s-r")
1274 ; (setq current-prefix-arg '(4)) ; C-u
1275 (call-interactively 'compile)))))
1277 (add-hook 'cperl-mode-hook 'my-perl-hook)
1284 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1286 (setq c-default-style "stroustrup"
1293 Set the environments vairables in compilation mode
1295 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1297 (use-package compile
1300 (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
1306 Enable auto-insert mode
1308 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1310 (auto-insert-mode t)
1311 (setq auto-insert-query nil)
1317 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1319 (eval-after-load 'autoinsert
1320 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1322 "Short description:"
1324 "\n * " (file-name-nondirectory (buffer-file-name))
1326 "#include <iostream>" \n
1328 (file-name-sans-extension
1329 (file-name-nondirectory (buffer-file-name)))
1331 "using namespace std;" \n \n
1339 (eval-after-load 'autoinsert
1340 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1342 "Short description:"
1344 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1346 "#include <stdio.h>" \n
1348 (file-name-sans-extension
1349 (file-name-nondirectory (buffer-file-name)))
1360 *** Perl Auto Insert
1362 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1364 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1366 (eval-after-load 'autoinsert
1367 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1370 "#!/usr/bin/perl -w" \n
1381 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1383 (use-package company
1385 :diminish company-mode
1386 :init (setq company-idle-delay 0.1)
1388 (global-company-mode))
1394 - change M-o to trigger to delete other windows and restore previous config