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 140)
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 Enable rainbow mode in emacs lisp mode
307 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
308 (use-package rainbow-mode
311 ; (add-hook emacs-lisp-mode-hook 'rainbow-mode)
320 clean mode line, Refer to [[https://www.masteringemacs.org/article/hiding-replacing-modeline-strings][Marstering Emacs]]
322 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
323 (defvar mode-line-cleaner-alist
324 `((auto-complete-mode . " α")
325 (yas/minor-mode . " Ï…")
326 (paredit-mode . " π")
329 (projectile-mode . "")
331 (undo-tree-mode . "")
333 (which-key-mode . "")
335 (smartparens-mode . "")
337 (linum-relative-mode . "")
339 (auto-revert-mode . "")
341 (org-indent-mode . "")
343 (lisp-interaction-mode . "λ")
346 (emacs-lisp-mode . "EL")
347 (nxhtml-mode . "nx"))
348 "Alist for `clean-mode-line'.
350 When you add a new element to the alist, keep in mind that you
351 must pass the correct minor/major mode symbol and a string you
352 want to use in the modeline *in lieu of* the original.")
355 (defun clean-mode-line ()
357 (loop for cleaner in mode-line-cleaner-alist
358 do (let* ((mode (car cleaner))
359 (mode-str (cdr cleaner))
360 (old-mode-str (cdr (assq mode minor-mode-alist))))
362 (setcar old-mode-str mode-str))
364 (when (eq mode major-mode)
365 (setq mode-name mode-str)))))
368 (add-hook 'after-change-major-mode-hook 'clean-mode-line)
373 Install powerline mode [[https://github.com/milkypostman/powerline][powerline]]
375 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
376 (use-package powerline
379 ;; (powerline-center-theme)
382 ;; (use-package smart-mode-line
384 ;; (use-package smart-mode-line-powerline-theme
388 Revised powerline-center-theme
390 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
391 (defun sd/powerline-simpler-vc (s)
393 (replace-regexp-in-string "Git[:-]" "" s)
396 (defun sd/powerline-center-theme_revised ()
397 "Setup a mode-line with major and minor modes centered."
399 (setq-default mode-line-format
402 (let* ((active (powerline-selected-window-active))
403 (mode-line-buffer-id (if active 'mode-line-buffer-id 'mode-line-buffer-id-inactive))
404 (mode-line (if active 'mode-line 'mode-line-inactive))
405 (face1 (if active 'powerline-active1 'powerline-inactive1))
406 (face2 (if active 'powerline-active2 'powerline-inactive2))
407 (separator-left (intern (format "powerline-%s-%s"
408 (powerline-current-separator)
409 (car powerline-default-separator-dir))))
410 (separator-right (intern (format "powerline-%s-%s"
411 (powerline-current-separator)
412 (cdr powerline-default-separator-dir))))
413 (lhs (list (powerline-raw "%*" mode-line 'l)
414 ;; (powerline-buffer-size mode-line 'l)
415 (powerline-buffer-id mode-line-buffer-id 'l)
417 (funcall separator-left mode-line face1)
418 (powerline-narrow face1 'l)
419 ;; (powerline-vc face1)
420 (sd/powerline-simpler-vc (powerline-vc face1))
422 (rhs (list (powerline-raw global-mode-string face1 'r)
423 (powerline-raw "%4l" face1 'r)
424 (powerline-raw ":" face1)
425 (powerline-raw "%3c" face1 'r)
426 (funcall separator-right face1 mode-line)
428 (powerline-raw "%6p" mode-line 'r)
429 (powerline-hud face2 face1)))
430 (center (list (powerline-raw " " face1)
431 (funcall separator-left face1 face2)
432 (when (and (boundp 'erc-track-minor-mode) erc-track-minor-mode)
433 (powerline-raw erc-modified-channels-object face2 'l))
434 (powerline-major-mode face2 'l)
435 (powerline-process face2)
436 (powerline-raw " :" face2)
437 (powerline-minor-modes face2 'l)
438 (powerline-raw " " face2)
439 (funcall separator-right face2 face1))))
440 (concat (powerline-render lhs)
441 (powerline-fill-center face1 (/ (powerline-width center) 2.0))
442 (powerline-render center)
443 (powerline-fill face1 (powerline-width rhs))
444 (powerline-render rhs)))))))
446 (sd/powerline-center-theme_revised)
449 Fix the issue in mode line when showing triangle
451 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
452 (setq ns-use-srgb-colorspace nil)
455 set height in mode line
457 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
459 (custom-set-variables
460 '(powerline-height 14)
461 '(powerline-text-scale-factor 0.8))
463 (set-face-attribute 'mode-line nil :height 100)
469 ** Org-mode Basic setting
471 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
473 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
478 (setq org-startup-indented t)
479 (setq org-hide-leading-starts t)
480 (setq org-src-fontify-natively t)
481 (setq org-src-tab-acts-natively t)
482 (setq org-confirm-babel-evaluate nil)
483 (setq org-use-speed-commands t)
484 (setq org-completion-use-ido t))
486 (org-babel-do-load-languages
487 'org-babel-load-languages
501 ;; use current window for org source buffer editting
502 (setq org-src-window-setup 'current-window )
508 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
510 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
512 (use-package org-bullets
515 (add-hook 'org-mode-hook
517 (org-bullets-mode t))))
523 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
524 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
525 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
526 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
528 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
533 :init (add-hook 'org-mode-hook 'worf-mode)
535 ;; (define-key worf-mode-map "[" nil)
536 ;; (define-key worf-mode-map "]" nil)
537 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
538 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
549 Install MacTex-basic and some tex packages
553 sudo tlmgr update --self
555 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
559 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
560 ;; ;; allow for export=>beamer by placing
562 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
563 ;; #+LaTeX_CLASS: beamer in org files
564 (unless (boundp 'org-export-latex-classes)
565 (setq org-export-latex-classes nil))
566 (add-to-list 'org-export-latex-classes
567 ;; beamer class, for presentations
569 "\\documentclass[11pt]{beamer}\n
570 \\mode<{{{beamermode}}}>\n
571 \\usetheme{{{{beamertheme}}}}\n
572 \\usecolortheme{{{{beamercolortheme}}}}\n
573 \\beamertemplateballitem\n
574 \\setbeameroption{show notes}
575 \\usepackage[utf8]{inputenc}\n
576 \\usepackage[T1]{fontenc}\n
577 \\usepackage{hyperref}\n
579 \\usepackage{listings}
580 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
583 showspaces=false,showstringspaces=false,
585 keywordstyle=\\color{blue}\\bfseries,
586 commentstyle=\\color{red},
588 \\usepackage{verbatim}\n
589 \\institute{{{{beamerinstitute}}}}\n
590 \\subject{{{{beamersubject}}}}\n"
592 ("\\section{%s}" . "\\section*{%s}")
594 ("\\begin{frame}[fragile]\\frametitle{%s}"
596 "\\begin{frame}[fragile]\\frametitle{%s}"
599 ;; letter class, for formal letters
601 (add-to-list 'org-export-latex-classes
604 "\\documentclass[11pt]{letter}\n
605 \\usepackage[utf8]{inputenc}\n
606 \\usepackage[T1]{fontenc}\n
609 ("\\section{%s}" . "\\section*{%s}")
610 ("\\subsection{%s}" . "\\subsection*{%s}")
611 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
612 ("\\paragraph{%s}" . "\\paragraph*{%s}")
613 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
619 (setq org-latex-pdf-process
620 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
621 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
622 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
624 (setq TeX-parse-self t)
626 (setq TeX-PDF-mode t)
627 (add-hook 'LaTeX-mode-hook
630 (setq TeX-master t)))
636 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]]
638 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
640 (setq org-todo-keywords '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
641 (sequence "âš‘ WAITING(w)" "|")
642 (sequence "|" "✘ CANCELED(c)")))
646 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
648 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
650 (add-to-list 'org-structure-template-alist
651 '("E" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"))
652 (add-to-list 'org-structure-template-alist
653 '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
654 (add-to-list 'org-structure-template-alist
655 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
661 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
663 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
667 :commands magit-status magit-blame)
676 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
680 :init (setq ido-enable-flex-matching t
681 ido-ignore-extensions t
682 ido-use-virtual-buffers t
687 (add-to-list 'completion-ignored-extensions ".pyc"))
695 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
699 :init (setq ido-enable-flex-matching t
701 :config (flx-ido-mode 1))
707 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
709 (use-package ido-vertical-mode
712 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
714 (ido-vertical-mode 1))
720 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
724 :init (smex-initialize)
727 ("M-X" . smex-major-mode-commands))
733 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
735 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
737 (use-package ido-ubiquitous
740 (setq magit-completing-read-function 'magit-ido-completing-read)
741 (setq gnus-completing-read-function 'gnus-ido-completing-read)
743 (ido-ubiquitous-mode 1))
749 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
751 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
753 (use-package ido-exit-target
756 (define-key ido-common-completion-map (kbd "C-j") #'ido-exit-target-split-window-right)
757 (define-key ido-common-completion-map (kbd "C-l") #'ido-exit-target-split-window-below))
763 ** Remove prefix =ESC=, refer [[http://emacs.stackexchange.com/questions/14755/how-to-remove-bindings-to-the-esc-prefix-key][here]]
765 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
767 ;; (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
773 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
775 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
777 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
778 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
779 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
780 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
781 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
782 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
783 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
784 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
785 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
787 ;; Also map s-h same as C-g
788 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
792 ** =Ctrl= key bindings
794 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
798 ;; C-j newline and indent
800 ;; C-l recenter-top-bottom
801 ;; (global-set-key (kbd "C-;") 'ido-switch-buffer)
838 ** =Super= bindings for file, buffer and windows
840 Some global bindings on =Super=, on Mac, it is =Command=
842 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
844 (global-set-key (kbd "s-h") 'keyboard-quit)
845 (global-set-key (kbd "s-j") 'ido-switch-buffer)
846 (global-set-key (kbd "s-k") 'ido-find-file)
847 ;; s-k --> kill-this-buffer
848 (global-set-key (kbd "s-l") (lambda ()
850 (if (> (length (window-list)) 1)
852 (message "Only one Windows now!"))))
854 (global-set-key (kbd "s-;") 'swiper)
856 ;; s-' --> 'next-multiframe-window
857 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
859 ;; (global-set-key (kbd "s-y") 'projectile-find-file)
860 (global-set-key (kbd "s-f") 'projectile-find-file)
861 (global-set-key (kbd "s-[") 'persp-next)
862 (global-set-key (kbd "s-]") 'persp-prev)
864 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
866 (global-set-key (kbd "s-n") 'persp-next)
867 (global-set-key (kbd "s-p") 'persp-prev)
871 ;; someothers default mapping on super (command) key
873 ;; s-k kill-this-buffer
876 ;; s-h --> ns-do-hide-emacs
877 ;; s-j --> ido-switch-buffer +
878 ;; s-k --> kill-this-buffer
881 ;; s-' --> next-multiframe-window
882 ;; s-ret --> toggle-frame-fullscreen +
884 ;; s-y --> ns-paste-secondary
885 ;; s-u --> revert-buffer
886 ;; s-i --> undefined - but used for iterm globally
887 ;; s-o --> used for emacs globally
888 ;; s-p --> projectile-persp-switch-project +
889 ;; s-[ --> next-buffer +
890 ;; s-] --> previous-buffer +
897 ;; s-- --> center-line
900 ;; s-n --> make-frame
901 ;; s-m --> iconify-frame
907 ;; s-g --> isearch-repeat-forward
908 ;; s-f --> projectile-find-file +
909 ;; s-d --> isearch-repeat-background
910 ;; s-s --> save-buffer
911 ;; s-a --> make-whole-buffer
915 ;; s-c --> ns-copy-including-secondary
917 ;; s-t --> ns-popup-font-panel
919 ;; s-e --> isearch-yanqk-kill
920 ;; s-w --> delete-frame
921 ;; s-q --> same-buffers-kill-emacs
923 ;; s-` --> other-frame
926 ** =M-s= bindings for searching
928 I use the prefix =M-s= for searching in buffers
930 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
932 (defun pl-make-keymap (key bindings)
933 (setq keymap (make-sparse-keymap))
934 (dolist (binding bindings)
935 (define-key keymap (car binding) (cdr binding)))
936 (global-set-key key keymap))
938 (define-key minibuffer-local-map "\M-s" nil)
940 (global-set-key (kbd "M-s s") 'isearch-forward-regexp)
941 (define-key isearch-mode-map "\M-s" 'isearch-repeat-forward)
942 (global-set-key (kbd "M-s r") 'isearch-backward-regexp)
943 (define-key isearch-mode-map "\M-r" 'isearch-repeat-backward)
945 (global-set-key (kbd "s-/") 'isearch-forward-regexp)
946 (define-key isearch-mode-map (kbd "s-/") 'isearch-repeat-forward)
947 (define-key isearch-mode-map (kbd "C-n") 'isearch-repeat-forward)
950 (set-face-background 'ido-first-match "white")
953 ;; M-s s --> isearch-forward-regexp
954 ;; M-s r --> isearch-backward-regexp
955 ;; M-s w --> isearch-forward-word
956 ;; M-s . --> isearch-forward-symbol-at-point
957 ;; M-s _ --> isearch-forward-symbol
959 ;; highlight bindings
960 ;; M-s h . --> highlight-symbol-at-point
961 ;; M-s h r --> highlight-regexp
962 ;; M-s h u --> unhighlight-regexp
963 ;; M-s h l --> highlight-lines-match-regexp
964 ;; M-s h p --> highlight-phrase
965 ;; M-s h f --> hi-lock-find-patterns
968 ;; (global-set-key (kbd "M-s M-r") 'isearch-backward-regexp)
977 Occur search key bindings
979 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
981 (define-key occur-mode-map (kbd "C-n")
985 (occur-mode-goto-occurrence-other-window)
989 (define-key occur-mode-map (kbd "C-p")
993 (occur-mode-goto-occurrence-other-window)
1000 ** =M-o= as prefix key for windows
1002 ** =M-g= as prefix key for launcher
1006 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1017 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1019 (defalias 'e 'ido-find-file)
1020 (defalias 'ff 'ido-find-file)
1021 (defalias 'ee 'ido-find-file-other-window)
1025 Quickly start eshll in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
1027 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1034 (defun eshell-here ()
1035 "Opens up a new shell in the directory associated with the
1036 current buffer's file. The eshell is renamed to match that
1037 directory to make multiple eshell windows easier."
1039 (let* ((parent (if (buffer-file-name)
1040 (file-name-directory (buffer-file-name))
1042 (height (/ (window-total-height) 3))
1043 (name (car (last (split-string parent "/" t))))
1044 (eshell-name (concat "*eshell: " name "*")))
1045 (split-window-vertically (- height))
1047 (if (get-buffer eshell-name)
1049 (message "buffer exist")
1050 (switch-to-buffer eshell-name))
1053 (rename-buffer eshell-name)
1055 (insert (concat "ls"))
1056 (eshell-send-input)))))
1058 ;; (global-set-key (kbd "M-`") (lambda ()
1060 ;; (if (buffer-name))))
1066 ** [[https://github.com/abo-abo/hydra][Hydra]]
1068 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1077 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1079 (defhydra sd/font-zoom (global-map "<f2>")
1081 ("g" text-scale-increase "in")
1082 ("l" text-scale-decrease "out"))
1086 *** Windmove Splitter
1088 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1090 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1092 (defun hydra-move-splitter-left (arg)
1093 "Move window splitter left."
1095 (if (let ((windmove-wrap-around))
1096 (windmove-find-other-window 'right))
1097 (shrink-window-horizontally arg)
1098 (enlarge-window-horizontally arg)))
1100 (defun hydra-move-splitter-right (arg)
1101 "Move window splitter right."
1103 (if (let ((windmove-wrap-around))
1104 (windmove-find-other-window 'right))
1105 (enlarge-window-horizontally arg)
1106 (shrink-window-horizontally arg)))
1108 (defun hydra-move-splitter-up (arg)
1109 "Move window splitter up."
1111 (if (let ((windmove-wrap-around))
1112 (windmove-find-other-window 'up))
1113 (enlarge-window arg)
1114 (shrink-window arg)))
1116 (defun hydra-move-splitter-down (arg)
1117 "Move window splitter down."
1119 (if (let ((windmove-wrap-around))
1120 (windmove-find-other-window 'up))
1122 (enlarge-window arg)))
1128 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1132 (defhydra sd/hydra-window (:color red :columns nil)
1134 ("h" windmove-left nil)
1135 ("j" windmove-down nil)
1136 ("k" windmove-up nil)
1137 ("l" windmove-right nil)
1138 ("H" hydra-move-splitter-left nil)
1139 ("J" hydra-move-splitter-down nil)
1140 ("K" hydra-move-splitter-up nil)
1141 ("L" hydra-move-splitter-right nil)
1144 (split-window-right)
1149 (split-window-below)
1152 ("o" delete-other-windows "one" :exit t)
1153 ("a" ace-window "ace")
1154 ("s" ace-swap-window "swap")
1155 ("d" ace-delete-window "ace-one" :exit t)
1156 ("i" ace-maximize-window "ace-one" :exit t)
1157 ("b" ido-switch-buffer "buf")
1158 ("m" headlong-bookmark-jump "bmk")
1160 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
1161 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
1164 (global-unset-key (kbd "M-o"))
1165 (global-set-key (kbd "M-o") 'sd/hydra-window/body)
1167 (defun triggle-windows-max-size ()
1169 (if (> (length (window-list)) 1)
1170 (delete-other-windows)
1177 Enable linum mode on programming modes
1179 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1181 (add-hook 'prog-mode-hook 'linum-mode)
1185 Fix the font size of line number
1187 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1189 (defun fix-linum-size ()
1191 (set-face-attribute 'linum nil :height 110))
1193 (add-hook 'linum-mode-hook 'fix-linum-size)
1197 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1199 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1201 (use-package linum-relative
1204 (defun linum-new-mode ()
1205 "If line numbers aren't displayed, then display them.
1206 Otherwise, toggle between absolute and relative numbers."
1209 (linum-relative-toggle)
1213 ("A-k" . linum-new-mode))
1215 ;; auto enable linum-new-mode in programming modes
1216 (add-hook 'prog-mode-hook 'linum-relative-mode)
1220 ** Save File Position
1222 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1224 (require 'saveplace)
1225 (setq-default save-place t)
1226 (setq save-place-forget-unreadable-files t)
1227 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1233 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1235 (use-package multi-term
1242 [[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
1243 Type =o= to go to the link
1245 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1247 (use-package ace-link
1250 (ace-link-setup-default))
1256 [[https://github.com/re5et/emux][emux]] is
1258 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1260 (el-get-bundle re5et/emux)
1266 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1268 (use-package smartparens
1272 (require 'smartparens-config)
1273 (add-hook 'prog-mode-hook 'smartparens-mode)))
1279 [[https://github.com/abo-abo/ace-window][ace-window]]
1281 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1283 (use-package ace-window
1287 ; (global-set-key (kbd "M-o") 'ace-window)
1289 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1295 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1297 (use-package projectile
1300 (setq projectile-enable-caching t)
1302 (projectile-global-mode t))
1304 (use-package persp-projectile
1309 (:map projectile-mode-map
1310 ("s-t" . projectile-persp-switch-project)))
1312 ;; projectile-find-file
1313 ;; projectile-switch-buffer
1314 ;; projectile-find-file-other-window
1319 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1321 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1323 (use-package which-key
1332 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1334 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1339 (setq emms-source-file-default-directory "~/Music/emms/")
1342 (emms-default-players)
1343 (define-emms-simple-player mplayer '(file url)
1344 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1345 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1346 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1347 ".m4a" ".flv" ".ogv" ".pls"))
1348 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1349 (emms-history-load))
1355 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
1357 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1363 (require 'gnugo-imgen)
1364 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1365 (add-hook 'gnugo-start-game-hook '(lambda ()
1366 (gnugo-image-display-mode)
1369 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1375 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1377 (use-package undo-tree
1380 (global-undo-tree-mode 1))
1386 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1393 (setq ivy-use-virtual-buffers t)
1394 ;; (global-set-key "\C-s" 'swiper)
1395 ;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
1396 ;; (global-set-key (kbd "<f6>") 'ivy-resume)
1397 ;; ;; (global-set-key (kbd "M-x") 'counsel-M-x)
1398 ;; ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
1399 ;; (global-set-key (kbd "<f1> f") 'counsel-describe-function)
1400 ;; (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
1401 ;; (global-set-key (kbd "<f1> l") 'counsel-load-library)
1402 ;; (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
1403 ;; (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
1404 ;; (global-set-key (kbd "C-c g") 'counsel-git)
1405 ;; (global-set-key (kbd "C-c j") 'counsel-git-grep)
1406 ;; (global-set-key (kbd "C-c k") 'counsel-ag)
1407 ;; (global-set-key (kbd "C-x l") 'counsel-locate)
1408 ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
1409 ;; ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
1415 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1417 ;; (use-package tabbar-ruler
1420 ;; (setq tabbar-ruler-global-tabbar t)
1421 ;; (setq tabbar-ruler-global-ruler t)
1422 ;; (setq tabbar-ruler-popu-menu t)
1423 ;; (setq tabbar-ruler-popu-toolbar t)
1424 ;; (setq tabbar-use-images t)
1426 ;; (tabbar-ruler-group-by-projectile-project)
1427 ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
1428 ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1438 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1440 (use-package color-identifiers-mode
1443 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1445 :diminish color-identifiers-mode)
1447 (global-prettify-symbols-mode t)
1453 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1454 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1456 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1461 (eval-after-load 'lispy
1463 (define-key lispy-mode-map (kbd "M-o") nil)))
1465 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1471 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1473 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1475 (defalias 'perl-mode 'cperl-mode)
1477 ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
1478 (setq cperl-auto-newline t)
1479 (setq cperl-highlight-variables-indiscriminately t)
1480 ;(setq cperl-indent-level 4)
1481 ;(setq cperl-continued-statement-offset 4)
1482 (setq cperl-close-paren-offset -4)
1483 (setq cperl-indent-parents-as-block t)
1484 (setq cperl-tab-always-indent t)
1485 ;(setq cperl-brace-offset 0)
1487 (add-hook 'cperl-mode-hook
1489 (cperl-set-style "C++")))
1491 ;(require 'template)
1492 ;(template-initialize)
1500 Change the compile-command to set the default command run when call =compile=
1501 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1502 to call =compilation= interactively.
1504 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1506 (defun my-perl-hook ()
1508 (setq-local compilation-read-command nil)
1509 (set (make-local-variable 'compile-command)
1510 (concat "/usr/bin/perl "
1511 (if buffer-file-name
1512 (shell-quote-argument buffer-file-name))))
1513 (local-set-key (kbd "s-r")
1516 ; (setq current-prefix-arg '(4)) ; C-u
1517 (call-interactively 'compile)))))
1519 (add-hook 'cperl-mode-hook 'my-perl-hook)
1526 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1528 (setq c-default-style "stroustrup"
1535 Set the environments vairables in compilation mode
1537 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1539 (use-package compile
1542 (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
1548 Enable auto-insert mode
1550 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1552 (auto-insert-mode t)
1553 (setq auto-insert-query nil)
1559 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1561 (eval-after-load 'autoinsert
1562 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1564 "Short description:"
1566 "\n * " (file-name-nondirectory (buffer-file-name))
1568 "#include <iostream>" \n
1570 (file-name-sans-extension
1571 (file-name-nondirectory (buffer-file-name)))
1573 "using namespace std;" \n \n
1581 (eval-after-load 'autoinsert
1582 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1584 "Short description:"
1586 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1588 "#include <stdio.h>" \n
1590 (file-name-sans-extension
1591 (file-name-nondirectory (buffer-file-name)))
1602 *** Perl Auto Insert
1604 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1606 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1608 (eval-after-load 'autoinsert
1609 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1612 "#!/usr/bin/perl -w" \n
1623 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1625 (use-package company
1627 :diminish company-mode
1628 :init (setq company-idle-delay 0.1)
1630 (global-company-mode))
1634 [[https://github.com/company-mode/company-statistics][company-statistics]]
1636 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1638 (use-package company-statistics
1641 (company-statistics-mode))
1647 - change M-o to trigger to delete other windows and restore previous config