1 #+TITLE: Emacs Configuration file
3 #+EMAIL: seudut@gmail.com
7 Most config are just copied from [[https://github.com/howardabrams/dot-files][howardabrams]]'s and [[https://github.com/abo-abo/oremacs][abo-abo's]] dotfiles
11 ** Setting loading Path
13 Set system PATH and emacs exec path
15 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
17 (setenv "PATH" (concat (getenv "PATH")
19 ":" "/Library/TeX/texbin"))
20 (setq exec-path (append exec-path '("/usr/local/bin")))
21 (setq exec-path (append exec-path '("/Library/TeX/texbin/")))
25 Set the emacs load path
27 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
29 (add-to-list 'load-path "~/.emacs.d/elisp")
33 ** Package Initialization
35 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
39 (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
40 ("gnu" . "http://elpa.gnu.org/packages/")
41 ("org" . "http://orgmode.org/elpa/")))
49 Disable scroll bar, tool-bar and menu-bar
51 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
57 (setq debug-on-error t)
58 (setq inhibit-startup-message t)
60 (defalias 'yes-or-no-p 'y-or-n-p)
69 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
71 (setq custom-file "~/.emacs.d/custom.el")
72 (if (file-exists-p custom-file)
77 Switch the focus to help window when it appears
79 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
81 (setq help-window-select t)
85 * Package Management Tools
89 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
91 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
93 (unless (package-installed-p 'use-package)
94 (package-refresh-contents)
95 (package-install 'use-package))
97 (require 'use-package)
103 [[https://github.com/dimitri/el-get][El-get]] is package management tool, whicl allows to install external elisp package from any git repository not in mepla.
104 Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
106 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
111 (add-to-list 'load-path "~/.emacs.d/el-get"))
115 * Color and Fonts Settings
117 ** highlight current line
119 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
121 (global-hl-line-mode)
127 [[https://github.com/paldepind/smart-comment][smart-comments]]
129 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
131 (use-package smart-comment
133 :bind ("M-;" . smart-conmment))
141 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
143 (global-font-lock-mode 1)
147 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
149 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
152 (defvar sd/fixed-font-family
153 (cond ((x-list-fonts "Hasklig") "Hasklig")
154 ((x-list-fonts "Source Code Pro") "Source Code Pro")
155 ((x-list-fonts "Anonymous Pro") "Anonymous Pro")
156 ((x-list-fonts "M+ 1mn") "M+ 1mn"))
157 "The fixed width font based on what is installed, `nil' if not defined."))
163 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
166 (when sd/fixed-font-family
167 (set-frame-font sd/fixed-font-family)
168 (set-face-attribute 'default nil :font sd/fixed-font-family :height 120)
169 (set-face-font 'default sd/fixed-font-family)))
175 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
177 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
179 (setq vc-follow-symlinks t)
181 (use-package color-theme
183 :init (require 'color-theme)
184 :config (use-package color-theme-sanityinc-tomorrow
188 (load-theme 'sanityinc-tomorrow-bright t)))
190 ;(eval-after-load 'color-theme
191 ; (load-theme 'sanityinc-tomorrow-bright t))
195 Change the Org-mode colors
197 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
199 (defun org-src-color-blocks-light ()
200 "Colors the block headers and footers to make them stand out more for lighter themes"
203 '(org-block-begin-line
204 ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
205 '(org-block-background
206 ((t (:background "#FFFFEA"))))
208 ((t (:background "#FFFFEA"))))
210 ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
212 '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
213 '(which-func ((t (:foreground "#008000"))))))
215 (defun org-src-color-blocks-dark ()
216 "Colors the block headers and footers to make them stand out more for dark themes"
219 '(org-block-begin-line
220 ((t (:foreground "#008ED1" :background "#002E41"))))
221 '(org-block-background
222 ((t (:background "#000000"))))
224 ((t (:background "#000000"))))
226 ((t (:foreground "#008ED1" :background "#002E41"))))
228 '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
229 '(which-func ((t (:foreground "green"))))))
231 (org-src-color-blocks-dark)
235 improve color for org-mode
236 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
237 (deftheme ha/org-theme "Sub-theme to beautify org mode")
240 (defvar sd/variable-font-tuple
241 (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
242 ((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
243 ((x-list-fonts "Verdana") '(:font "Verdana"))
244 ((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
245 (nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro.")))
246 "My variable width font available to org-mode files and whatnot."))
248 (defun sd/org-color ()
249 (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
250 (base-font-color (face-foreground 'default nil 'default))
251 (background-color (face-background 'default nil 'default))
252 (primary-color (face-foreground 'mode-line nil))
253 (secondary-color (face-background 'secondary-selection nil 'region))
254 (base-height (face-attribute 'default :height))
255 (headline `(:inherit default :weight bold :foreground ,base-font-color)))
256 (custom-theme-set-faces 'ha/org-theme
257 `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
258 `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
259 `(org-table ((t (:inherit 'fixed-pitched))))
260 `(org-block ((t (:inherit 'fixed-pitched))))
261 `(org-block-background ((t (:inherit 'fixed-pitched))))
262 `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
263 `(org-block-end-line ((t (:inherit 'fixed-pitched))))
264 `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
265 `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
266 `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
267 `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
268 `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
269 :height ,(round (* 1.1 base-height))))))
270 `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
271 :height ,(round (* 1.25 base-height))))))
272 `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
273 :height ,(round (* 1.5 base-height))))))
274 `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
275 :height ,(round (* 1.75 base-height))))))
276 `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
283 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
285 (use-package rainbow-delimiters
288 (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
294 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
296 (use-package page-break-lines
299 (turn-on-page-break-lines-mode))
305 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)
318 clean mode line, Refer to [[https://www.masteringemacs.org/article/hiding-replacing-modeline-strings][Marstering Emacs]]
320 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
321 (defvar mode-line-cleaner-alist
322 `((auto-complete-mode . " α")
323 (yas/minor-mode . " Ï…")
324 (paredit-mode . " π")
327 (projectile-mode . "")
329 (undo-tree-mode . "")
331 (which-key-mode . "")
333 (smartparens-mode . "")
337 (lisp-interaction-mode . "λ")
340 (emacs-lisp-mode . "EL")
341 (nxhtml-mode . "nx"))
342 "Alist for `clean-mode-line'.
344 When you add a new element to the alist, keep in mind that you
345 must pass the correct minor/major mode symbol and a string you
346 want to use in the modeline *in lieu of* the original.")
349 (defun clean-mode-line ()
351 (loop for cleaner in mode-line-cleaner-alist
352 do (let* ((mode (car cleaner))
353 (mode-str (cdr cleaner))
354 (old-mode-str (cdr (assq mode minor-mode-alist))))
356 (setcar old-mode-str mode-str))
358 (when (eq mode major-mode)
359 (setq mode-name mode-str)))))
362 (add-hook 'after-change-major-mode-hook 'clean-mode-line)
365 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
366 (use-package powerline
369 (powerline-center-theme))
371 ;; (use-package smart-mode-line
373 ;; (use-package smart-mode-line-powerline-theme
377 Fix the issue in mode line when showing triangle
379 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
381 (setq ns-use-srgb-colorspace nil)
387 ** Org-mode Basic setting
389 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
391 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
396 (setq org-startup-indented t)
397 (setq org-hide-leading-starts t)
398 (setq org-src-fontify-natively t)
399 (setq org-src-tab-acts-natively t)
400 (setq org-confirm-babel-evaluate nil)
401 (setq org-use-speed-commands t)
402 (setq org-completion-use-ido t))
404 (org-babel-do-load-languages
405 'org-babel-load-languages
419 ;; use current window for org source buffer editting
420 (setq org-src-window-setup 'current-window )
426 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
428 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
430 (use-package org-bullets
433 (add-hook 'org-mode-hook
435 (org-bullets-mode t))))
441 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
442 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
443 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
444 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
446 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
451 :init (add-hook 'org-mode-hook 'worf-mode)
453 ;; (define-key worf-mode-map "[" nil)
454 ;; (define-key worf-mode-map "]" nil)
455 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
456 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
467 Install MacTex-basic and some tex packages
471 sudo tlmgr update --self
473 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
477 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
478 ;; ;; allow for export=>beamer by placing
480 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
481 ;; #+LaTeX_CLASS: beamer in org files
482 (unless (boundp 'org-export-latex-classes)
483 (setq org-export-latex-classes nil))
484 (add-to-list 'org-export-latex-classes
485 ;; beamer class, for presentations
487 "\\documentclass[11pt]{beamer}\n
488 \\mode<{{{beamermode}}}>\n
489 \\usetheme{{{{beamertheme}}}}\n
490 \\usecolortheme{{{{beamercolortheme}}}}\n
491 \\beamertemplateballitem\n
492 \\setbeameroption{show notes}
493 \\usepackage[utf8]{inputenc}\n
494 \\usepackage[T1]{fontenc}\n
495 \\usepackage{hyperref}\n
497 \\usepackage{listings}
498 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
501 showspaces=false,showstringspaces=false,
503 keywordstyle=\\color{blue}\\bfseries,
504 commentstyle=\\color{red},
506 \\usepackage{verbatim}\n
507 \\institute{{{{beamerinstitute}}}}\n
508 \\subject{{{{beamersubject}}}}\n"
510 ("\\section{%s}" . "\\section*{%s}")
512 ("\\begin{frame}[fragile]\\frametitle{%s}"
514 "\\begin{frame}[fragile]\\frametitle{%s}"
517 ;; letter class, for formal letters
519 (add-to-list 'org-export-latex-classes
522 "\\documentclass[11pt]{letter}\n
523 \\usepackage[utf8]{inputenc}\n
524 \\usepackage[T1]{fontenc}\n
527 ("\\section{%s}" . "\\section*{%s}")
528 ("\\subsection{%s}" . "\\subsection*{%s}")
529 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
530 ("\\paragraph{%s}" . "\\paragraph*{%s}")
531 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
537 (setq org-latex-pdf-process
538 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
539 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
540 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
542 (setq TeX-parse-self t)
544 (setq TeX-PDF-mode t)
545 (add-hook 'LaTeX-mode-hook
548 (setq TeX-master t)))
554 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]]
556 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
558 (setq org-todo-keywords '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
559 (sequence "âš‘ WAITING(w)" "|")
560 (sequence "|" "✘ CANCELED(c)")))
564 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
566 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
568 (add-to-list 'org-structure-template-alist
569 '("E" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"))
570 (add-to-list 'org-structure-template-alist
571 '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
572 (add-to-list 'org-structure-template-alist
573 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
579 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
581 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
585 :commands magit-status magit-blame)
594 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
598 :init (setq ido-enable-flex-matching t
599 ido-ignore-extensions t
600 ido-use-virtual-buffers t
605 (add-to-list 'completion-ignored-extensions ".pyc"))
613 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
617 :init (setq ido-enable-flex-matching t
619 :config (flx-ido-mode 1))
625 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
627 (use-package ido-vertical-mode
630 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
632 (ido-vertical-mode 1))
638 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
642 :init (smex-initialize)
645 ("M-X" . smex-major-mode-commands))
651 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
653 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
655 (use-package ido-ubiquitous
658 (setq magit-completing-read-function 'magit-ido-completing-read)
659 (setq gnus-completing-read-function 'gnus-ido-completing-read)
661 (ido-ubiquitous-mode 1))
667 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
669 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
671 (use-package ido-exit-target
674 (define-key ido-common-completion-map (kbd "C-j") #'ido-exit-target-split-window-right)
675 (define-key ido-common-completion-map (kbd "C-l") #'ido-exit-target-split-window-below))
681 ** Remove prefix =ESC=, refer [[http://emacs.stackexchange.com/questions/14755/how-to-remove-bindings-to-the-esc-prefix-key][here]]
683 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
685 ;; (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
691 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
693 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
695 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
696 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
697 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
698 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
699 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
700 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
701 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
702 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
703 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
705 ;; Also map s-h same as C-g
706 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
710 ** =Ctrl= key bindings
712 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
716 ;; C-j newline and indent
718 ;; C-l recenter-top-bottom
719 ;; (global-set-key (kbd "C-;") 'ido-switch-buffer)
756 ** =Super= bindings for file, buffer and windows
758 Some global bindings on =Super=, on Mac, it is =Command=
760 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
762 (global-set-key (kbd "s-h") 'keyboard-quit)
763 (global-set-key (kbd "s-j") 'ido-switch-buffer)
764 (global-set-key (kbd "s-k") 'ido-find-file)
765 ;; s-k --> kill-this-buffer
766 (global-set-key (kbd "s-l") (lambda ()
768 (if (> (length (window-list)) 1)
770 (message "Only one Windows now!"))))
772 (global-set-key (kbd "s-;") 'swiper)
774 ;; s-' --> 'next-multiframe-window
775 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
777 ;; (global-set-key (kbd "s-y") 'projectile-find-file)
778 (global-set-key (kbd "s-f") 'projectile-find-file)
779 (global-set-key (kbd "s-[") 'persp-next)
780 (global-set-key (kbd "s-]") 'persp-prev)
782 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
784 (global-set-key (kbd "s-n") 'persp-next)
785 (global-set-key (kbd "s-p") 'persp-prev)
789 ;; someothers default mapping on super (command) key
791 ;; s-k kill-this-buffer
794 ;; s-h --> ns-do-hide-emacs
795 ;; s-j --> ido-switch-buffer +
796 ;; s-k --> kill-this-buffer
799 ;; s-' --> next-multiframe-window
800 ;; s-ret --> toggle-frame-fullscreen +
802 ;; s-y --> ns-paste-secondary
803 ;; s-u --> revert-buffer
804 ;; s-i --> undefined - but used for iterm globally
805 ;; s-o --> used for emacs globally
806 ;; s-p --> projectile-persp-switch-project +
807 ;; s-[ --> next-buffer +
808 ;; s-] --> previous-buffer +
815 ;; s-- --> center-line
818 ;; s-n --> make-frame
819 ;; s-m --> iconify-frame
825 ;; s-g --> isearch-repeat-forward
826 ;; s-f --> projectile-find-file +
827 ;; s-d --> isearch-repeat-background
828 ;; s-s --> save-buffer
829 ;; s-a --> make-whole-buffer
833 ;; s-c --> ns-copy-including-secondary
835 ;; s-t --> ns-popup-font-panel
837 ;; s-e --> isearch-yanqk-kill
838 ;; s-w --> delete-frame
839 ;; s-q --> same-buffers-kill-emacs
841 ;; s-` --> other-frame
844 ** =M-s= bindings for searching
846 I use the prefix =M-s= for searching in buffers
848 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
850 (defun pl-make-keymap (key bindings)
851 (setq keymap (make-sparse-keymap))
852 (dolist (binding bindings)
853 (define-key keymap (car binding) (cdr binding)))
854 (global-set-key key keymap))
856 (define-key minibuffer-local-map "\M-s" nil)
858 (global-set-key (kbd "M-s s") 'isearch-forward-regexp)
859 (define-key isearch-mode-map "\M-s" 'isearch-repeat-forward)
860 (global-set-key (kbd "M-s r") 'isearch-backward-regexp)
861 (define-key isearch-mode-map "\M-r" 'isearch-repeat-backward)
863 (global-set-key (kbd "s-/") 'isearch-forward-regexp)
864 (define-key isearch-mode-map (kbd "s-/") 'isearch-repeat-forward)
865 (define-key isearch-mode-map (kbd "C-n") 'isearch-repeat-forward)
868 (set-face-background 'ido-first-match "white")
871 ;; M-s s --> isearch-forward-regexp
872 ;; M-s r --> isearch-backward-regexp
873 ;; M-s w --> isearch-forward-word
874 ;; M-s . --> isearch-forward-symbol-at-point
875 ;; M-s _ --> isearch-forward-symbol
877 ;; highlight bindings
878 ;; M-s h . --> highlight-symbol-at-point
879 ;; M-s h r --> highlight-regexp
880 ;; M-s h u --> unhighlight-regexp
881 ;; M-s h l --> highlight-lines-match-regexp
882 ;; M-s h p --> highlight-phrase
883 ;; M-s h f --> hi-lock-find-patterns
886 ;; (global-set-key (kbd "M-s M-r") 'isearch-backward-regexp)
895 Occur search key bindings
897 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
899 (define-key occur-mode-map (kbd "C-n")
903 (occur-mode-goto-occurrence-other-window)
907 (define-key occur-mode-map (kbd "C-p")
911 (occur-mode-goto-occurrence-other-window)
918 ** =M-o= as prefix key for windows
920 ** =M-g= as prefix key for launcher
924 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
935 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
937 (defalias 'e 'ido-find-file)
938 (defalias 'ff 'ido-find-file)
939 (defalias 'ee 'ido-find-file-other-window)
943 Quickly start eshll in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
945 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
952 (defun eshell-here ()
953 "Opens up a new shell in the directory associated with the
954 current buffer's file. The eshell is renamed to match that
955 directory to make multiple eshell windows easier."
957 (let* ((parent (if (buffer-file-name)
958 (file-name-directory (buffer-file-name))
960 (height (/ (window-total-height) 3))
961 (name (car (last (split-string parent "/" t))))
962 (eshell-name (concat "*eshell: " name "*")))
963 (split-window-vertically (- height))
965 (if (get-buffer eshell-name)
967 (message "buffer exist")
968 (switch-to-buffer eshell-name))
971 (rename-buffer eshell-name)
973 (insert (concat "ls"))
974 (eshell-send-input)))))
976 ;; (global-set-key (kbd "M-`") (lambda ()
978 ;; (if (buffer-name))))
984 ** [[https://github.com/abo-abo/hydra][Hydra]]
986 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
995 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
997 (defhydra sd/font-zoom (global-map "<f2>")
999 ("g" text-scale-increase "in")
1000 ("l" text-scale-decrease "out"))
1004 *** Windmove Splitter
1006 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1008 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1010 (defun hydra-move-splitter-left (arg)
1011 "Move window splitter left."
1013 (if (let ((windmove-wrap-around))
1014 (windmove-find-other-window 'right))
1015 (shrink-window-horizontally arg)
1016 (enlarge-window-horizontally arg)))
1018 (defun hydra-move-splitter-right (arg)
1019 "Move window splitter right."
1021 (if (let ((windmove-wrap-around))
1022 (windmove-find-other-window 'right))
1023 (enlarge-window-horizontally arg)
1024 (shrink-window-horizontally arg)))
1026 (defun hydra-move-splitter-up (arg)
1027 "Move window splitter up."
1029 (if (let ((windmove-wrap-around))
1030 (windmove-find-other-window 'up))
1031 (enlarge-window arg)
1032 (shrink-window arg)))
1034 (defun hydra-move-splitter-down (arg)
1035 "Move window splitter down."
1037 (if (let ((windmove-wrap-around))
1038 (windmove-find-other-window 'up))
1040 (enlarge-window arg)))
1046 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1050 (defhydra sd/hydra-window (:color red :columns nil)
1052 ("h" windmove-left nil)
1053 ("j" windmove-down nil)
1054 ("k" windmove-up nil)
1055 ("l" windmove-right nil)
1056 ("H" hydra-move-splitter-left nil)
1057 ("J" hydra-move-splitter-down nil)
1058 ("K" hydra-move-splitter-up nil)
1059 ("L" hydra-move-splitter-right nil)
1062 (split-window-right)
1067 (split-window-below)
1070 ("o" delete-other-windows "one" :exit t)
1071 ("a" ace-window "ace")
1072 ("s" ace-swap-window "swap")
1073 ("d" ace-delete-window "ace-one" :exit t)
1074 ("i" ace-maximize-window "ace-one" :exit t)
1075 ("b" ido-switch-buffer "buf")
1076 ("m" headlong-bookmark-jump "bmk")
1078 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
1079 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
1082 (global-unset-key (kbd "M-o"))
1083 (global-set-key (kbd "M-o") 'sd/hydra-window/body)
1085 (defun triggle-windows-max-size ()
1087 (if (> (length (window-list)) 1)
1088 (delete-other-windows)
1095 Enable linum mode on programming modes
1097 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1099 (add-hook 'prog-mode-hook 'linum-mode)
1103 Fix the font size of line number
1105 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1107 (defun fix-linum-size ()
1109 (set-face-attribute 'linum nil :height 110))
1111 (add-hook 'linum-mode-hook 'fix-linum-size)
1115 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1117 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1119 (use-package linum-relative
1122 (defun linum-new-mode ()
1123 "If line numbers aren't displayed, then display them.
1124 Otherwise, toggle between absolute and relative numbers."
1127 (linum-relative-toggle)
1131 ("A-k" . linum-new-mode))
1133 ;; auto enable linum-new-mode in programming modes
1134 (add-hook 'prog-mode-hook 'linum-relative-mode)
1138 ** Save File Position
1140 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1142 (require 'saveplace)
1143 (setq-default save-place t)
1144 (setq save-place-forget-unreadable-files t)
1145 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1151 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1153 (use-package multi-term
1160 [[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
1161 Type =o= to go to the link
1163 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1165 (use-package ace-link
1168 (ace-link-setup-default))
1174 [[https://github.com/re5et/emux][emux]] is
1176 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1178 (el-get-bundle re5et/emux)
1184 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1186 (use-package smartparens
1190 (require 'smartparens-config)
1191 (add-hook 'prog-mode-hook 'smartparens-mode)))
1197 [[https://github.com/abo-abo/ace-window][ace-window]]
1199 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1201 (use-package ace-window
1205 ; (global-set-key (kbd "M-o") 'ace-window)
1207 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1213 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1215 (use-package projectile
1218 (setq projectile-enable-caching t)
1220 (projectile-global-mode t))
1222 (use-package persp-projectile
1227 (:map projectile-mode-map
1228 ("s-t" . projectile-persp-switch-project)))
1230 ;; projectile-find-file
1231 ;; projectile-switch-buffer
1232 ;; projectile-find-file-other-window
1237 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1239 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1241 (use-package which-key
1250 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1252 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1257 (setq emms-source-file-default-directory "~/Music/emms/")
1260 (emms-default-players)
1261 (define-emms-simple-player mplayer '(file url)
1262 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1263 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1264 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1265 ".m4a" ".flv" ".ogv" ".pls"))
1266 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1267 (emms-history-load))
1273 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
1275 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1281 (require 'gnugo-imgen)
1282 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1283 (add-hook 'gnugo-start-game-hook '(lambda ()
1284 (gnugo-image-display-mode)
1287 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1293 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1295 (use-package undo-tree
1298 (global-undo-tree-mode 1))
1304 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1311 (setq ivy-use-virtual-buffers t)
1312 ;; (global-set-key "\C-s" 'swiper)
1313 ;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
1314 ;; (global-set-key (kbd "<f6>") 'ivy-resume)
1315 ;; ;; (global-set-key (kbd "M-x") 'counsel-M-x)
1316 ;; ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
1317 ;; (global-set-key (kbd "<f1> f") 'counsel-describe-function)
1318 ;; (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
1319 ;; (global-set-key (kbd "<f1> l") 'counsel-load-library)
1320 ;; (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
1321 ;; (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
1322 ;; (global-set-key (kbd "C-c g") 'counsel-git)
1323 ;; (global-set-key (kbd "C-c j") 'counsel-git-grep)
1324 ;; (global-set-key (kbd "C-c k") 'counsel-ag)
1325 ;; (global-set-key (kbd "C-x l") 'counsel-locate)
1326 ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
1327 ;; ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
1333 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1335 ;; (use-package tabbar-ruler
1338 ;; (setq tabbar-ruler-global-tabbar t)
1339 ;; (setq tabbar-ruler-global-ruler t)
1340 ;; (setq tabbar-ruler-popu-menu t)
1341 ;; (setq tabbar-ruler-popu-toolbar t)
1342 ;; (setq tabbar-use-images t)
1344 ;; (tabbar-ruler-group-by-projectile-project)
1345 ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
1346 ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1356 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1358 (use-package color-identifiers-mode
1361 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1363 :diminish color-identifiers-mode)
1365 (global-prettify-symbols-mode t)
1371 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1372 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1374 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1379 (eval-after-load 'lispy
1381 (define-key lispy-mode-map (kbd "M-o") nil)))
1383 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1389 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1391 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1393 (defalias 'perl-mode 'cperl-mode)
1395 ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
1396 (setq cperl-auto-newline t)
1397 (setq cperl-highlight-variables-indiscriminately t)
1398 ;(setq cperl-indent-level 4)
1399 ;(setq cperl-continued-statement-offset 4)
1400 (setq cperl-close-paren-offset -4)
1401 (setq cperl-indent-parents-as-block t)
1402 (setq cperl-tab-always-indent t)
1403 ;(setq cperl-brace-offset 0)
1405 (add-hook 'cperl-mode-hook
1407 (cperl-set-style "C++")))
1409 ;(require 'template)
1410 ;(template-initialize)
1418 Change the compile-command to set the default command run when call =compile=
1419 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1420 to call =compilation= interactively.
1422 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1424 (defun my-perl-hook ()
1426 (setq-local compilation-read-command nil)
1427 (set (make-local-variable 'compile-command)
1428 (concat "/usr/bin/perl "
1429 (if buffer-file-name
1430 (shell-quote-argument buffer-file-name))))
1431 (local-set-key (kbd "s-r")
1434 ; (setq current-prefix-arg '(4)) ; C-u
1435 (call-interactively 'compile)))))
1437 (add-hook 'cperl-mode-hook 'my-perl-hook)
1444 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1446 (setq c-default-style "stroustrup"
1453 Set the environments vairables in compilation mode
1455 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1457 (use-package compile
1460 (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
1466 Enable auto-insert mode
1468 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1470 (auto-insert-mode t)
1471 (setq auto-insert-query nil)
1477 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1479 (eval-after-load 'autoinsert
1480 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1482 "Short description:"
1484 "\n * " (file-name-nondirectory (buffer-file-name))
1486 "#include <iostream>" \n
1488 (file-name-sans-extension
1489 (file-name-nondirectory (buffer-file-name)))
1491 "using namespace std;" \n \n
1499 (eval-after-load 'autoinsert
1500 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1502 "Short description:"
1504 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1506 "#include <stdio.h>" \n
1508 (file-name-sans-extension
1509 (file-name-nondirectory (buffer-file-name)))
1520 *** Perl Auto Insert
1522 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1524 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1526 (eval-after-load 'autoinsert
1527 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1530 "#!/usr/bin/perl -w" \n
1541 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1543 (use-package company
1545 :diminish company-mode
1546 :init (setq company-idle-delay 0.1)
1548 (global-company-mode))
1552 [[https://github.com/company-mode/company-statistics][company-statistics]]
1554 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1556 (use-package company-statistics
1559 (company-statistics-mode))
1565 - change M-o to trigger to delete other windows and restore previous config