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 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
374 (use-package powerline
377 ;; (powerline-center-theme)
380 ;; (use-package smart-mode-line
382 ;; (use-package smart-mode-line-powerline-theme
385 (defun sd/powerline-simpler-vc (s)
387 (replace-regexp-in-string "Git[:-]" "" s)
390 (defun sd/powerline-center-theme_revised ()
391 "Setup a mode-line with major and minor modes centered."
393 (setq-default mode-line-format
396 (let* ((active (powerline-selected-window-active))
397 (mode-line-buffer-id (if active 'mode-line-buffer-id 'mode-line-buffer-id-inactive))
398 (mode-line (if active 'mode-line 'mode-line-inactive))
399 (face1 (if active 'powerline-active1 'powerline-inactive1))
400 (face2 (if active 'powerline-active2 'powerline-inactive2))
401 (separator-left (intern (format "powerline-%s-%s"
402 (powerline-current-separator)
403 (car powerline-default-separator-dir))))
404 (separator-right (intern (format "powerline-%s-%s"
405 (powerline-current-separator)
406 (cdr powerline-default-separator-dir))))
407 (lhs (list (powerline-raw "%*" mode-line 'l)
408 ;; (powerline-buffer-size mode-line 'l)
409 (powerline-buffer-id mode-line-buffer-id 'l)
411 (funcall separator-left mode-line face1)
412 (powerline-narrow face1 'l)
413 ;; (powerline-vc face1)
414 (sd/powerline-simpler-vc (powerline-vc face1))
416 (rhs (list (powerline-raw global-mode-string face1 'r)
417 (powerline-raw "%4l" face1 'r)
418 (powerline-raw ":" face1)
419 (powerline-raw "%3c" face1 'r)
420 (funcall separator-right face1 mode-line)
422 (powerline-raw "%6p" mode-line 'r)
423 (powerline-hud face2 face1)))
424 (center (list (powerline-raw " " face1)
425 (funcall separator-left face1 face2)
426 (when (and (boundp 'erc-track-minor-mode) erc-track-minor-mode)
427 (powerline-raw erc-modified-channels-object face2 'l))
428 (powerline-major-mode face2 'l)
429 (powerline-process face2)
430 (powerline-raw " :" face2)
431 (powerline-minor-modes face2 'l)
432 (powerline-raw " " face2)
433 (funcall separator-right face2 face1))))
434 (concat (powerline-render lhs)
435 (powerline-fill-center face1 (/ (powerline-width center) 2.0))
436 (powerline-render center)
437 (powerline-fill face1 (powerline-width rhs))
438 (powerline-render rhs)))))))
440 (sd/powerline-center-theme_revised)
443 Fix the issue in mode line when showing triangle
445 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
446 (setq ns-use-srgb-colorspace nil)
449 set height in mode line
451 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
453 (custom-set-variables
454 '(powerline-height 14)
455 '(powerline-text-scale-factor 0.8))
457 (set-face-attribute 'mode-line nil :height 100)
463 ** Org-mode Basic setting
465 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
467 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
472 (setq org-startup-indented t)
473 (setq org-hide-leading-starts t)
474 (setq org-src-fontify-natively t)
475 (setq org-src-tab-acts-natively t)
476 (setq org-confirm-babel-evaluate nil)
477 (setq org-use-speed-commands t)
478 (setq org-completion-use-ido t))
480 (org-babel-do-load-languages
481 'org-babel-load-languages
495 ;; use current window for org source buffer editting
496 (setq org-src-window-setup 'current-window )
502 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
504 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
506 (use-package org-bullets
509 (add-hook 'org-mode-hook
511 (org-bullets-mode t))))
517 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
518 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
519 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
520 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
522 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
527 :init (add-hook 'org-mode-hook 'worf-mode)
529 ;; (define-key worf-mode-map "[" nil)
530 ;; (define-key worf-mode-map "]" nil)
531 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
532 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
543 Install MacTex-basic and some tex packages
547 sudo tlmgr update --self
549 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
553 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
554 ;; ;; allow for export=>beamer by placing
556 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
557 ;; #+LaTeX_CLASS: beamer in org files
558 (unless (boundp 'org-export-latex-classes)
559 (setq org-export-latex-classes nil))
560 (add-to-list 'org-export-latex-classes
561 ;; beamer class, for presentations
563 "\\documentclass[11pt]{beamer}\n
564 \\mode<{{{beamermode}}}>\n
565 \\usetheme{{{{beamertheme}}}}\n
566 \\usecolortheme{{{{beamercolortheme}}}}\n
567 \\beamertemplateballitem\n
568 \\setbeameroption{show notes}
569 \\usepackage[utf8]{inputenc}\n
570 \\usepackage[T1]{fontenc}\n
571 \\usepackage{hyperref}\n
573 \\usepackage{listings}
574 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
577 showspaces=false,showstringspaces=false,
579 keywordstyle=\\color{blue}\\bfseries,
580 commentstyle=\\color{red},
582 \\usepackage{verbatim}\n
583 \\institute{{{{beamerinstitute}}}}\n
584 \\subject{{{{beamersubject}}}}\n"
586 ("\\section{%s}" . "\\section*{%s}")
588 ("\\begin{frame}[fragile]\\frametitle{%s}"
590 "\\begin{frame}[fragile]\\frametitle{%s}"
593 ;; letter class, for formal letters
595 (add-to-list 'org-export-latex-classes
598 "\\documentclass[11pt]{letter}\n
599 \\usepackage[utf8]{inputenc}\n
600 \\usepackage[T1]{fontenc}\n
603 ("\\section{%s}" . "\\section*{%s}")
604 ("\\subsection{%s}" . "\\subsection*{%s}")
605 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
606 ("\\paragraph{%s}" . "\\paragraph*{%s}")
607 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
613 (setq org-latex-pdf-process
614 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
615 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
616 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
618 (setq TeX-parse-self t)
620 (setq TeX-PDF-mode t)
621 (add-hook 'LaTeX-mode-hook
624 (setq TeX-master t)))
630 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]]
632 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
634 (setq org-todo-keywords '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
635 (sequence "âš‘ WAITING(w)" "|")
636 (sequence "|" "✘ CANCELED(c)")))
640 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
642 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
644 (add-to-list 'org-structure-template-alist
645 '("E" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"))
646 (add-to-list 'org-structure-template-alist
647 '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
648 (add-to-list 'org-structure-template-alist
649 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
655 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
657 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
661 :commands magit-status magit-blame)
670 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
674 :init (setq ido-enable-flex-matching t
675 ido-ignore-extensions t
676 ido-use-virtual-buffers t
681 (add-to-list 'completion-ignored-extensions ".pyc"))
689 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
693 :init (setq ido-enable-flex-matching t
695 :config (flx-ido-mode 1))
701 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
703 (use-package ido-vertical-mode
706 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
708 (ido-vertical-mode 1))
714 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
718 :init (smex-initialize)
721 ("M-X" . smex-major-mode-commands))
727 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
729 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
731 (use-package ido-ubiquitous
734 (setq magit-completing-read-function 'magit-ido-completing-read)
735 (setq gnus-completing-read-function 'gnus-ido-completing-read)
737 (ido-ubiquitous-mode 1))
743 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
745 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
747 (use-package ido-exit-target
750 (define-key ido-common-completion-map (kbd "C-j") #'ido-exit-target-split-window-right)
751 (define-key ido-common-completion-map (kbd "C-l") #'ido-exit-target-split-window-below))
757 ** Remove prefix =ESC=, refer [[http://emacs.stackexchange.com/questions/14755/how-to-remove-bindings-to-the-esc-prefix-key][here]]
759 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
761 ;; (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
767 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
769 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
771 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
772 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
773 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
774 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
775 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
776 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
777 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
778 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
779 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
781 ;; Also map s-h same as C-g
782 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
786 ** =Ctrl= key bindings
788 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
792 ;; C-j newline and indent
794 ;; C-l recenter-top-bottom
795 ;; (global-set-key (kbd "C-;") 'ido-switch-buffer)
832 ** =Super= bindings for file, buffer and windows
834 Some global bindings on =Super=, on Mac, it is =Command=
836 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
838 (global-set-key (kbd "s-h") 'keyboard-quit)
839 (global-set-key (kbd "s-j") 'ido-switch-buffer)
840 (global-set-key (kbd "s-k") 'ido-find-file)
841 ;; s-k --> kill-this-buffer
842 (global-set-key (kbd "s-l") (lambda ()
844 (if (> (length (window-list)) 1)
846 (message "Only one Windows now!"))))
848 (global-set-key (kbd "s-;") 'swiper)
850 ;; s-' --> 'next-multiframe-window
851 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
853 ;; (global-set-key (kbd "s-y") 'projectile-find-file)
854 (global-set-key (kbd "s-f") 'projectile-find-file)
855 (global-set-key (kbd "s-[") 'persp-next)
856 (global-set-key (kbd "s-]") 'persp-prev)
858 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
860 (global-set-key (kbd "s-n") 'persp-next)
861 (global-set-key (kbd "s-p") 'persp-prev)
865 ;; someothers default mapping on super (command) key
867 ;; s-k kill-this-buffer
870 ;; s-h --> ns-do-hide-emacs
871 ;; s-j --> ido-switch-buffer +
872 ;; s-k --> kill-this-buffer
875 ;; s-' --> next-multiframe-window
876 ;; s-ret --> toggle-frame-fullscreen +
878 ;; s-y --> ns-paste-secondary
879 ;; s-u --> revert-buffer
880 ;; s-i --> undefined - but used for iterm globally
881 ;; s-o --> used for emacs globally
882 ;; s-p --> projectile-persp-switch-project +
883 ;; s-[ --> next-buffer +
884 ;; s-] --> previous-buffer +
891 ;; s-- --> center-line
894 ;; s-n --> make-frame
895 ;; s-m --> iconify-frame
901 ;; s-g --> isearch-repeat-forward
902 ;; s-f --> projectile-find-file +
903 ;; s-d --> isearch-repeat-background
904 ;; s-s --> save-buffer
905 ;; s-a --> make-whole-buffer
909 ;; s-c --> ns-copy-including-secondary
911 ;; s-t --> ns-popup-font-panel
913 ;; s-e --> isearch-yanqk-kill
914 ;; s-w --> delete-frame
915 ;; s-q --> same-buffers-kill-emacs
917 ;; s-` --> other-frame
920 ** =M-s= bindings for searching
922 I use the prefix =M-s= for searching in buffers
924 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
926 (defun pl-make-keymap (key bindings)
927 (setq keymap (make-sparse-keymap))
928 (dolist (binding bindings)
929 (define-key keymap (car binding) (cdr binding)))
930 (global-set-key key keymap))
932 (define-key minibuffer-local-map "\M-s" nil)
934 (global-set-key (kbd "M-s s") 'isearch-forward-regexp)
935 (define-key isearch-mode-map "\M-s" 'isearch-repeat-forward)
936 (global-set-key (kbd "M-s r") 'isearch-backward-regexp)
937 (define-key isearch-mode-map "\M-r" 'isearch-repeat-backward)
939 (global-set-key (kbd "s-/") 'isearch-forward-regexp)
940 (define-key isearch-mode-map (kbd "s-/") 'isearch-repeat-forward)
941 (define-key isearch-mode-map (kbd "C-n") 'isearch-repeat-forward)
944 (set-face-background 'ido-first-match "white")
947 ;; M-s s --> isearch-forward-regexp
948 ;; M-s r --> isearch-backward-regexp
949 ;; M-s w --> isearch-forward-word
950 ;; M-s . --> isearch-forward-symbol-at-point
951 ;; M-s _ --> isearch-forward-symbol
953 ;; highlight bindings
954 ;; M-s h . --> highlight-symbol-at-point
955 ;; M-s h r --> highlight-regexp
956 ;; M-s h u --> unhighlight-regexp
957 ;; M-s h l --> highlight-lines-match-regexp
958 ;; M-s h p --> highlight-phrase
959 ;; M-s h f --> hi-lock-find-patterns
962 ;; (global-set-key (kbd "M-s M-r") 'isearch-backward-regexp)
971 Occur search key bindings
973 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
975 (define-key occur-mode-map (kbd "C-n")
979 (occur-mode-goto-occurrence-other-window)
983 (define-key occur-mode-map (kbd "C-p")
987 (occur-mode-goto-occurrence-other-window)
994 ** =M-o= as prefix key for windows
996 ** =M-g= as prefix key for launcher
1000 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1011 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1013 (defalias 'e 'ido-find-file)
1014 (defalias 'ff 'ido-find-file)
1015 (defalias 'ee 'ido-find-file-other-window)
1019 Quickly start eshll in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
1021 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1028 (defun eshell-here ()
1029 "Opens up a new shell in the directory associated with the
1030 current buffer's file. The eshell is renamed to match that
1031 directory to make multiple eshell windows easier."
1033 (let* ((parent (if (buffer-file-name)
1034 (file-name-directory (buffer-file-name))
1036 (height (/ (window-total-height) 3))
1037 (name (car (last (split-string parent "/" t))))
1038 (eshell-name (concat "*eshell: " name "*")))
1039 (split-window-vertically (- height))
1041 (if (get-buffer eshell-name)
1043 (message "buffer exist")
1044 (switch-to-buffer eshell-name))
1047 (rename-buffer eshell-name)
1049 (insert (concat "ls"))
1050 (eshell-send-input)))))
1052 ;; (global-set-key (kbd "M-`") (lambda ()
1054 ;; (if (buffer-name))))
1060 ** [[https://github.com/abo-abo/hydra][Hydra]]
1062 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1071 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1073 (defhydra sd/font-zoom (global-map "<f2>")
1075 ("g" text-scale-increase "in")
1076 ("l" text-scale-decrease "out"))
1080 *** Windmove Splitter
1082 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1084 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1086 (defun hydra-move-splitter-left (arg)
1087 "Move window splitter left."
1089 (if (let ((windmove-wrap-around))
1090 (windmove-find-other-window 'right))
1091 (shrink-window-horizontally arg)
1092 (enlarge-window-horizontally arg)))
1094 (defun hydra-move-splitter-right (arg)
1095 "Move window splitter right."
1097 (if (let ((windmove-wrap-around))
1098 (windmove-find-other-window 'right))
1099 (enlarge-window-horizontally arg)
1100 (shrink-window-horizontally arg)))
1102 (defun hydra-move-splitter-up (arg)
1103 "Move window splitter up."
1105 (if (let ((windmove-wrap-around))
1106 (windmove-find-other-window 'up))
1107 (enlarge-window arg)
1108 (shrink-window arg)))
1110 (defun hydra-move-splitter-down (arg)
1111 "Move window splitter down."
1113 (if (let ((windmove-wrap-around))
1114 (windmove-find-other-window 'up))
1116 (enlarge-window arg)))
1122 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1126 (defhydra sd/hydra-window (:color red :columns nil)
1128 ("h" windmove-left nil)
1129 ("j" windmove-down nil)
1130 ("k" windmove-up nil)
1131 ("l" windmove-right nil)
1132 ("H" hydra-move-splitter-left nil)
1133 ("J" hydra-move-splitter-down nil)
1134 ("K" hydra-move-splitter-up nil)
1135 ("L" hydra-move-splitter-right nil)
1138 (split-window-right)
1143 (split-window-below)
1146 ("o" delete-other-windows "one" :exit t)
1147 ("a" ace-window "ace")
1148 ("s" ace-swap-window "swap")
1149 ("d" ace-delete-window "ace-one" :exit t)
1150 ("i" ace-maximize-window "ace-one" :exit t)
1151 ("b" ido-switch-buffer "buf")
1152 ("m" headlong-bookmark-jump "bmk")
1154 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
1155 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
1158 (global-unset-key (kbd "M-o"))
1159 (global-set-key (kbd "M-o") 'sd/hydra-window/body)
1161 (defun triggle-windows-max-size ()
1163 (if (> (length (window-list)) 1)
1164 (delete-other-windows)
1171 Enable linum mode on programming modes
1173 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1175 (add-hook 'prog-mode-hook 'linum-mode)
1179 Fix the font size of line number
1181 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1183 (defun fix-linum-size ()
1185 (set-face-attribute 'linum nil :height 110))
1187 (add-hook 'linum-mode-hook 'fix-linum-size)
1191 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1193 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1195 (use-package linum-relative
1198 (defun linum-new-mode ()
1199 "If line numbers aren't displayed, then display them.
1200 Otherwise, toggle between absolute and relative numbers."
1203 (linum-relative-toggle)
1207 ("A-k" . linum-new-mode))
1209 ;; auto enable linum-new-mode in programming modes
1210 (add-hook 'prog-mode-hook 'linum-relative-mode)
1214 ** Save File Position
1216 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1218 (require 'saveplace)
1219 (setq-default save-place t)
1220 (setq save-place-forget-unreadable-files t)
1221 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1227 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1229 (use-package multi-term
1236 [[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
1237 Type =o= to go to the link
1239 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1241 (use-package ace-link
1244 (ace-link-setup-default))
1250 [[https://github.com/re5et/emux][emux]] is
1252 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1254 (el-get-bundle re5et/emux)
1260 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1262 (use-package smartparens
1266 (require 'smartparens-config)
1267 (add-hook 'prog-mode-hook 'smartparens-mode)))
1273 [[https://github.com/abo-abo/ace-window][ace-window]]
1275 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1277 (use-package ace-window
1281 ; (global-set-key (kbd "M-o") 'ace-window)
1283 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1289 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1291 (use-package projectile
1294 (setq projectile-enable-caching t)
1296 (projectile-global-mode t))
1298 (use-package persp-projectile
1303 (:map projectile-mode-map
1304 ("s-t" . projectile-persp-switch-project)))
1306 ;; projectile-find-file
1307 ;; projectile-switch-buffer
1308 ;; projectile-find-file-other-window
1313 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1315 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1317 (use-package which-key
1326 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1328 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1333 (setq emms-source-file-default-directory "~/Music/emms/")
1336 (emms-default-players)
1337 (define-emms-simple-player mplayer '(file url)
1338 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1339 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1340 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1341 ".m4a" ".flv" ".ogv" ".pls"))
1342 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1343 (emms-history-load))
1349 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
1351 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1357 (require 'gnugo-imgen)
1358 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1359 (add-hook 'gnugo-start-game-hook '(lambda ()
1360 (gnugo-image-display-mode)
1363 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1369 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1371 (use-package undo-tree
1374 (global-undo-tree-mode 1))
1380 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1387 (setq ivy-use-virtual-buffers t)
1388 ;; (global-set-key "\C-s" 'swiper)
1389 ;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
1390 ;; (global-set-key (kbd "<f6>") 'ivy-resume)
1391 ;; ;; (global-set-key (kbd "M-x") 'counsel-M-x)
1392 ;; ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
1393 ;; (global-set-key (kbd "<f1> f") 'counsel-describe-function)
1394 ;; (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
1395 ;; (global-set-key (kbd "<f1> l") 'counsel-load-library)
1396 ;; (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
1397 ;; (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
1398 ;; (global-set-key (kbd "C-c g") 'counsel-git)
1399 ;; (global-set-key (kbd "C-c j") 'counsel-git-grep)
1400 ;; (global-set-key (kbd "C-c k") 'counsel-ag)
1401 ;; (global-set-key (kbd "C-x l") 'counsel-locate)
1402 ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
1403 ;; ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
1409 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1411 ;; (use-package tabbar-ruler
1414 ;; (setq tabbar-ruler-global-tabbar t)
1415 ;; (setq tabbar-ruler-global-ruler t)
1416 ;; (setq tabbar-ruler-popu-menu t)
1417 ;; (setq tabbar-ruler-popu-toolbar t)
1418 ;; (setq tabbar-use-images t)
1420 ;; (tabbar-ruler-group-by-projectile-project)
1421 ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
1422 ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1432 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1434 (use-package color-identifiers-mode
1437 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1439 :diminish color-identifiers-mode)
1441 (global-prettify-symbols-mode t)
1447 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1448 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1450 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1455 (eval-after-load 'lispy
1457 (define-key lispy-mode-map (kbd "M-o") nil)))
1459 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1465 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1467 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1469 (defalias 'perl-mode 'cperl-mode)
1471 ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
1472 (setq cperl-auto-newline t)
1473 (setq cperl-highlight-variables-indiscriminately t)
1474 ;(setq cperl-indent-level 4)
1475 ;(setq cperl-continued-statement-offset 4)
1476 (setq cperl-close-paren-offset -4)
1477 (setq cperl-indent-parents-as-block t)
1478 (setq cperl-tab-always-indent t)
1479 ;(setq cperl-brace-offset 0)
1481 (add-hook 'cperl-mode-hook
1483 (cperl-set-style "C++")))
1485 ;(require 'template)
1486 ;(template-initialize)
1494 Change the compile-command to set the default command run when call =compile=
1495 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1496 to call =compilation= interactively.
1498 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1500 (defun my-perl-hook ()
1502 (setq-local compilation-read-command nil)
1503 (set (make-local-variable 'compile-command)
1504 (concat "/usr/bin/perl "
1505 (if buffer-file-name
1506 (shell-quote-argument buffer-file-name))))
1507 (local-set-key (kbd "s-r")
1510 ; (setq current-prefix-arg '(4)) ; C-u
1511 (call-interactively 'compile)))))
1513 (add-hook 'cperl-mode-hook 'my-perl-hook)
1520 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1522 (setq c-default-style "stroustrup"
1529 Set the environments vairables in compilation mode
1531 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1533 (use-package compile
1536 (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
1542 Enable auto-insert mode
1544 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1546 (auto-insert-mode t)
1547 (setq auto-insert-query nil)
1553 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1555 (eval-after-load 'autoinsert
1556 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1558 "Short description:"
1560 "\n * " (file-name-nondirectory (buffer-file-name))
1562 "#include <iostream>" \n
1564 (file-name-sans-extension
1565 (file-name-nondirectory (buffer-file-name)))
1567 "using namespace std;" \n \n
1575 (eval-after-load 'autoinsert
1576 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1578 "Short description:"
1580 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1582 "#include <stdio.h>" \n
1584 (file-name-sans-extension
1585 (file-name-nondirectory (buffer-file-name)))
1596 *** Perl Auto Insert
1598 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1600 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1602 (eval-after-load 'autoinsert
1603 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1606 "#!/usr/bin/perl -w" \n
1617 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1619 (use-package company
1621 :diminish company-mode
1622 :init (setq company-idle-delay 0.1)
1624 (global-company-mode))
1628 [[https://github.com/company-mode/company-statistics][company-statistics]]
1630 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1632 (use-package company-statistics
1635 (company-statistics-mode))
1641 - change M-o to trigger to delete other windows and restore previous config