--- /dev/null
+.*
+elpa/*
+\#*
+config.el
+ido.last
+*~
+recentf
+el-get/*
+custom.el
+projectile.cache
+projectile-bookmarks.eld
+semanticdb/*
+config.html
+company-statistics-cache.el
+emms/*
--- /dev/null
+#+TITLE: Emacs Configuration file
+#+AUTHOR: Peng Li
+#+EMAIL: seudut@gmail.com
+
+* Introduction
+
+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
+
+* Basic Settings
+
+** Setting loading Path
+
+Set system PATH and emacs exec path
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (setenv "PATH" (concat (getenv "PATH")
+ ":" "/usr/local/bin"
+ ":" "/Library/TeX/texbin"))
+ (setq exec-path (append exec-path '("/usr/local/bin")))
+ (setq exec-path (append exec-path '("/Library/TeX/texbin/")))
+
+#+END_SRC
+
+Set the emacs load path
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (add-to-list 'load-path "~/.emacs.d/elisp")
+
+#+END_SRC
+
+** Package Initialization
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (require 'package)
+
+ (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
+ ("gnu" . "http://elpa.gnu.org/packages/")
+ ("org" . "http://orgmode.org/elpa/")))
+
+ (package-initialize)
+
+#+END_SRC
+
+** General Setting
+
+Disable scroll bar, tool-bar and menu-bar
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (scroll-bar-mode 0)
+ (tool-bar-mode 0)
+ (menu-bar-mode 1)
+
+ (setq debug-on-error t)
+ (setq inhibit-startup-message t)
+
+ (defalias 'yes-or-no-p 'y-or-n-p)
+ (show-paren-mode 1)
+
+
+
+#+END_SRC
+
+set custom file
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (setq custom-file "~/.emacs.d/custom.el")
+ (load custom-file)
+
+#+END_SRC
+
+Switch the focus to help window when it appears
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (setq help-window-select t)
+
+#+END_SRC
+
+* Package Management Tools
+
+** Use-package
+
+Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (unless (package-installed-p 'use-package)
+ (package-refresh-contents)
+ (package-install 'use-package))
+
+ (require 'use-package)
+
+#+END_SRC
+
+** El-get
+
+[[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.
+Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package el-get
+ :ensure t
+ :init
+ (add-to-list 'load-path "~/.emacs.d/el-get"))
+
+#+END_SRC
+
+* Color and Fonts Settings
+
+** highlight current line
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (global-hl-line-mode)
+
+#+END_SRC
+
+** Smart Comments
+
+[[https://github.com/paldepind/smart-comment][smart-comments]]
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package smart-comment
+ :ensure t
+ :bind ("M-;" . smart-conmment))
+
+#+END_SRC
+
+** Font Setting
+
+syntax highlighting
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (global-font-lock-mode 1)
+
+#+END_SRC
+
+[[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (if window-system
+ (defvar sd/fixed-font-family
+ (cond ((x-list-fonts "Hasklig") "Hasklig")
+ ((x-list-fonts "Source Code Pro") "Source Code Pro")
+ ((x-list-fonts "Anonymous Pro") "Anonymous Pro")
+ ((x-list-fonts "M+ 1mn") "M+ 1mn"))
+ "The fixed width font based on what is installed, `nil' if not defined."))
+
+#+END_SRC
+
+Setting the fonts
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (if window-system
+ (when sd/fixed-font-family
+ (set-frame-font sd/fixed-font-family)
+ (set-face-attribute 'default nil :font sd/fixed-font-family :height 120)
+ (set-face-font 'default sd/fixed-font-family)))
+
+#+END_SRC
+
+** Color Theme
+
+Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (setq vc-follow-symlinks t)
+
+ (use-package color-theme
+ :ensure t
+ :init (require 'color-theme)
+ :config (use-package color-theme-sanityinc-tomorrow
+ :ensure t
+ :no-require t
+ :config
+ (load-theme 'sanityinc-tomorrow-bright t)))
+
+ ;(eval-after-load 'color-theme
+ ; (load-theme 'sanityinc-tomorrow-bright t))
+
+#+END_SRC
+
+Change the Org-mode colors
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (defun org-src-color-blocks-light ()
+ "Colors the block headers and footers to make them stand out more for lighter themes"
+ (interactive)
+ (custom-set-faces
+ '(org-block-begin-line
+ ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
+ '(org-block-background
+ ((t (:background "#FFFFEA"))))
+ '(org-block
+ ((t (:background "#FFFFEA"))))
+ '(org-block-end-line
+ ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
+
+ '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
+ '(which-func ((t (:foreground "#008000"))))))
+
+ (defun org-src-color-blocks-dark ()
+ "Colors the block headers and footers to make them stand out more for dark themes"
+ (interactive)
+ (custom-set-faces
+ '(org-block-begin-line
+ ((t (:foreground "#008ED1" :background "#002E41"))))
+ '(org-block-background
+ ((t (:background "#000000"))))
+ '(org-block
+ ((t (:background "#000000"))))
+ '(org-block-end-line
+ ((t (:foreground "#008ED1" :background "#002E41"))))
+
+ '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
+ '(which-func ((t (:foreground "green"))))))
+
+ (org-src-color-blocks-dark)
+
+#+END_SRC
+
+improve color for org-mode
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (deftheme ha/org-theme "Sub-theme to beautify org mode")
+
+ (if window-system
+ (defvar sd/variable-font-tuple
+ (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
+ ((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
+ ((x-list-fonts "Verdana") '(:font "Verdana"))
+ ((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
+ (nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro.")))
+ "My variable width font available to org-mode files and whatnot."))
+
+ (defun sd/org-color ()
+ (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
+ (base-font-color (face-foreground 'default nil 'default))
+ (background-color (face-background 'default nil 'default))
+ (primary-color (face-foreground 'mode-line nil))
+ (secondary-color (face-background 'secondary-selection nil 'region))
+ (base-height (face-attribute 'default :height))
+ (headline `(:inherit default :weight bold :foreground ,base-font-color)))
+ (custom-theme-set-faces 'ha/org-theme
+ `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
+ `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
+ `(org-table ((t (:inherit 'fixed-pitched))))
+ `(org-block ((t (:inherit 'fixed-pitched))))
+ `(org-block-background ((t (:inherit 'fixed-pitched))))
+ `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
+ `(org-block-end-line ((t (:inherit 'fixed-pitched))))
+ `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
+ `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
+ `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
+ `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
+ `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
+ :height ,(round (* 1.1 base-height))))))
+ `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
+ :height ,(round (* 1.25 base-height))))))
+ `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
+ :height ,(round (* 1.5 base-height))))))
+ `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
+ :height ,(round (* 1.75 base-height))))))
+ `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
+
+
+#+END_SRC
+
+** Rainbow-delimiter
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package rainbow-delimiters
+ :ensure t
+ :init
+ (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
+
+#+END_SRC
+
+** page-break-lines
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package page-break-lines
+ :ensure t
+ :config
+ (turn-on-page-break-lines-mode))
+
+#+END_SRC
+
+* Org-mode Settings
+
+** Org-mode Basic setting
+
+Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package org
+ :ensure t
+ :init
+ (setq org-startup-indented t)
+ (setq org-hide-leading-starts t)
+ (setq org-src-fontify-natively t)
+ (setq org-src-tab-acts-natively t)
+ (setq org-confirm-babel-evaluate nil)
+ (setq org-use-speed-commands t)
+ (setq org-completion-use-ido t))
+
+ (org-babel-do-load-languages
+ 'org-babel-load-languages
+ '((python . t)
+ (C . t)
+ (perl . t)
+ (calc . t)
+ (latex . t)
+ (java . t)
+ (ruby . t)
+ (lisp . t)
+ (scheme . t)
+ (sh . t)
+ (sqlite . t)
+ (js . t)))
+
+ ;; use current window for org source buffer editting
+ (setq org-src-window-setup 'current-window )
+
+#+END_SRC
+
+** Org-bullets
+
+use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package org-bullets
+ :ensure t
+ :init
+ (add-hook 'org-mode-hook
+ (lambda ()
+ (org-bullets-mode t))))
+
+#+END_SRC
+
+** Worf Mode
+
+[[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
+In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
+cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
+=M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package worf
+ :ensure t
+ :commands worf-mode
+ :init (add-hook 'org-mode-hook 'worf-mode)
+ ;; :config
+ ;; (define-key worf-mode-map "[" nil)
+ ;; (define-key worf-mode-map "]" nil)
+ ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
+ ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
+ )
+
+#+END_SRC
+
+** Task Management
+
+** Capture
+
+** Export PDF
+
+Install MacTex-basic and some tex packages
+
+#+BEGIN_SRC bash
+
+ sudo tlmgr update --self
+
+ 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
+
+#+END_SRC
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ ;; ;; allow for export=>beamer by placing
+
+ ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
+ ;; #+LaTeX_CLASS: beamer in org files
+ (unless (boundp 'org-export-latex-classes)
+ (setq org-export-latex-classes nil))
+ (add-to-list 'org-export-latex-classes
+ ;; beamer class, for presentations
+ '("beamer"
+ "\\documentclass[11pt]{beamer}\n
+ \\mode<{{{beamermode}}}>\n
+ \\usetheme{{{{beamertheme}}}}\n
+ \\usecolortheme{{{{beamercolortheme}}}}\n
+ \\beamertemplateballitem\n
+ \\setbeameroption{show notes}
+ \\usepackage[utf8]{inputenc}\n
+ \\usepackage[T1]{fontenc}\n
+ \\usepackage{hyperref}\n
+ \\usepackage{color}
+ \\usepackage{listings}
+ \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
+ frame=single,
+ basicstyle=\\small,
+ showspaces=false,showstringspaces=false,
+ showtabs=false,
+ keywordstyle=\\color{blue}\\bfseries,
+ commentstyle=\\color{red},
+ }\n
+ \\usepackage{verbatim}\n
+ \\institute{{{{beamerinstitute}}}}\n
+ \\subject{{{{beamersubject}}}}\n"
+
+ ("\\section{%s}" . "\\section*{%s}")
+
+ ("\\begin{frame}[fragile]\\frametitle{%s}"
+ "\\end{frame}"
+ "\\begin{frame}[fragile]\\frametitle{%s}"
+ "\\end{frame}")))
+
+ ;; letter class, for formal letters
+
+ (add-to-list 'org-export-latex-classes
+
+ '("letter"
+ "\\documentclass[11pt]{letter}\n
+ \\usepackage[utf8]{inputenc}\n
+ \\usepackage[T1]{fontenc}\n
+ \\usepackage{color}"
+
+ ("\\section{%s}" . "\\section*{%s}")
+ ("\\subsection{%s}" . "\\subsection*{%s}")
+ ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
+ ("\\paragraph{%s}" . "\\paragraph*{%s}")
+ ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
+
+
+ (require 'ox-md)
+ (require 'ox-beamer)
+
+ (setq org-latex-pdf-process
+ '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
+ "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
+ "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
+
+ (setq TeX-parse-self t)
+
+ (setq TeX-PDF-mode t)
+ (add-hook 'LaTeX-mode-hook
+ (lambda ()
+ (LaTeX-math-mode)
+ (setq TeX-master t)))
+
+#+END_SRC
+
+** others
+
+refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]]
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (setq org-todo-keywords '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
+ (sequence "⚑ WAITING(w)" "|")
+ (sequence "|" "✘ CANCELED(c)")))
+
+#+END_SRC
+
+extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (add-to-list 'org-structure-template-alist
+ '("E" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"))
+ (add-to-list 'org-structure-template-alist
+ '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
+ (add-to-list 'org-structure-template-alist
+ '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
+
+#+END_SRC
+
+* Magit
+
+[[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package magit
+ :ensure t
+ :commands magit-status magit-blame)
+
+
+#+END_SRC
+
+* IDO & SMEX
+
+** IDO
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package ido
+ :ensure t
+ :init (setq ido-enable-flex-matching t
+ ido-ignore-extensions t
+ ido-use-virtual-buffers t
+ ido-everywhere t)
+ :config
+ (ido-mode 1)
+ (ido-everywhere 1)
+ (add-to-list 'completion-ignored-extensions ".pyc"))
+
+ (icomplete-mode t)
+
+#+END_SRC
+
+** FLX
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package flx-ido
+ :ensure t
+ :init (setq ido-enable-flex-matching t
+ ido-use-faces nil)
+ :config (flx-ido-mode 1))
+
+#+END_SRC
+
+** IDO-vertically
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package ido-vertical-mode
+ :ensure t
+ :init
+ (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
+ :config
+ (ido-vertical-mode 1))
+
+#+END_SRC
+
+** SMEX
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package smex
+ :ensure t
+ :init (smex-initialize)
+ :bind
+ ("M-x" . smex)
+ ("M-X" . smex-major-mode-commands))
+
+#+END_SRC
+
+** Ido-ubiquitous
+
+Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package ido-ubiquitous
+ :ensure t
+ :init
+ (setq magit-completing-read-function 'magit-ido-completing-read)
+ (setq gnus-completing-read-function 'gnus-ido-completing-read)
+ :config
+ (ido-ubiquitous-mode 1))
+
+#+END_SRC
+
+** Ido-exit-target
+
+[[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package ido-exit-target
+ :ensure t
+ :init
+ (define-key ido-common-completion-map (kbd "C-j") #'ido-exit-target-split-window-right)
+ (define-key ido-common-completion-map (kbd "C-l") #'ido-exit-target-split-window-below))
+
+#+END_SRC
+
+* Key bindings
+
+** Remove prefix =ESC=, refer [[http://emacs.stackexchange.com/questions/14755/how-to-remove-bindings-to-the-esc-prefix-key][here]]
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ ;; (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
+
+#+END_SRC
+
+** Esc on Minibuffer
+
+Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
+
+ ;; Also map s-h same as C-g
+ (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
+
+#+END_SRC
+
+** =Ctrl= key bindings
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ ;;
+
+ ;; C-h help
+ ;; C-j newline and indent
+ ;; C-k kill line
+ ;; C-l recenter-top-bottom
+ ;; (global-set-key (kbd "C-;") 'ido-switch-buffer)
+ ;; C-;
+ ;; C-'
+ ;; C-ret
+
+ ;; C-n next-line
+ ;; C-m
+ ;; C-,
+ ;; C-.
+ ;; C-/
+
+ ;; C-y
+ ;; C-u
+ ;; C-i
+ ;; C-o
+ ;; C-p
+ ;; C-[
+ ;; C-]
+ ;; C-\
+
+ ;; C-=
+ ;; C--
+ ;; C-0
+ ;; C-9
+ ;; C-8
+ ;; C-7
+
+ ;; C-Space
+
+
+
+
+
+
+
+#+END_SRC
+
+** =Super= bindings for file, buffer and windows
+
+Some global bindings on =Super=, on Mac, it is =Command=
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (global-set-key (kbd "s-h") 'keyboard-quit)
+ (global-set-key (kbd "s-j") 'ido-switch-buffer)
+ (global-set-key (kbd "s-k") 'ido-find-file)
+ ;; s-k --> kill-this-buffer
+ (global-set-key (kbd "s-l") (lambda ()
+ (interactive)
+ (if (> (length (window-list)) 1)
+ (delete-window)
+ (message "Only one Windows now!"))))
+ ;; s-l --> goto-line
+ (global-set-key (kbd "s-;") 'swiper)
+ ;; s-; -->
+ ;; s-' --> 'next-multiframe-window
+ (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
+
+ ;; (global-set-key (kbd "s-y") 'projectile-find-file)
+ (global-set-key (kbd "s-f") 'projectile-find-file)
+ (global-set-key (kbd "s-[") 'persp-next)
+ (global-set-key (kbd "s-]") 'persp-prev)
+
+ (global-set-key (kbd "s-`") 'mode-line-other-buffer)
+
+ (global-set-key (kbd "s-n") 'persp-next)
+ (global-set-key (kbd "s-p") 'persp-prev)
+
+
+
+ ;; someothers default mapping on super (command) key
+ ;; s-s save-buffer
+ ;; s-k kill-this-buffer
+
+
+ ;; s-h --> ns-do-hide-emacs
+ ;; s-j --> ido-switch-buffer +
+ ;; s-k --> kill-this-buffer
+ ;; s-l --> goto-line
+ ;; s-; --> undefined
+ ;; s-' --> next-multiframe-window
+ ;; s-ret --> toggle-frame-fullscreen +
+
+ ;; s-y --> ns-paste-secondary
+ ;; s-u --> revert-buffer
+ ;; s-i --> undefined - but used for iterm globally
+ ;; s-o --> used for emacs globally
+ ;; s-p --> projectile-persp-switch-project +
+ ;; s-[ --> next-buffer +
+ ;; s-] --> previous-buffer +
+
+ ;; s-0 --> undefined
+ ;; s-9 --> undefined
+ ;; s-8 --> undefined
+ ;; s-7 --> undefined
+ ;; s-6 --> undefined
+ ;; s-- --> center-line
+ ;; s-= --> undefined
+
+ ;; s-n --> make-frame
+ ;; s-m --> iconify-frame
+ ;; s-b --> undefined
+ ;; s-, --> customize
+ ;; s-. --> undefined
+ ;; s-/ --> undefined
+
+ ;; s-g --> isearch-repeat-forward
+ ;; s-f --> projectile-find-file +
+ ;; s-d --> isearch-repeat-background
+ ;; s-s --> save-buffer
+ ;; s-a --> make-whole-buffer
+
+ ;; s-b --> undefined
+ ;; s-v --> yank
+ ;; s-c --> ns-copy-including-secondary
+
+ ;; s-t --> ns-popup-font-panel
+ ;; s-r --> undefined
+ ;; s-e --> isearch-yanqk-kill
+ ;; s-w --> delete-frame
+ ;; s-q --> same-buffers-kill-emacs
+
+ ;; s-` --> other-frame
+#+END_SRC
+
+** =M-s= bindings for searching
+
+I use the prefix =M-s= for searching in buffers
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (defun pl-make-keymap (key bindings)
+ (setq keymap (make-sparse-keymap))
+ (dolist (binding bindings)
+ (define-key keymap (car binding) (cdr binding)))
+ (global-set-key key keymap))
+
+ (define-key minibuffer-local-map "\M-s" nil)
+
+ (global-set-key (kbd "M-s s") 'isearch-forward-regexp)
+ (define-key isearch-mode-map "\M-s" 'isearch-repeat-forward)
+ (global-set-key (kbd "M-s r") 'isearch-backward-regexp)
+ (define-key isearch-mode-map "\M-r" 'isearch-repeat-backward)
+
+ (global-set-key (kbd "s-/") 'isearch-forward-regexp)
+ (define-key isearch-mode-map (kbd "s-/") 'isearch-repeat-forward)
+ (define-key isearch-mode-map (kbd "C-n") 'isearch-repeat-forward)
+
+
+ (set-face-background 'ido-first-match "white")
+
+ ;; M-s o --> occur
+ ;; M-s s --> isearch-forward-regexp
+ ;; M-s r --> isearch-backward-regexp
+ ;; M-s w --> isearch-forward-word
+ ;; M-s . --> isearch-forward-symbol-at-point
+ ;; M-s _ --> isearch-forward-symbol
+
+ ;; highlight bindings
+ ;; M-s h . --> highlight-symbol-at-point
+ ;; M-s h r --> highlight-regexp
+ ;; M-s h u --> unhighlight-regexp
+ ;; M-s h l --> highlight-lines-match-regexp
+ ;; M-s h p --> highlight-phrase
+ ;; M-s h f --> hi-lock-find-patterns
+
+ ;;
+ ;; (global-set-key (kbd "M-s M-r") 'isearch-backward-regexp)
+ ;;
+
+ ;; M-c
+ ;; M-r
+ ;; M-t
+ ;; M-u,
+#+END_SRC
+
+Occur search key bindings
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (define-key occur-mode-map (kbd "C-n")
+ (lambda ()
+ (interactive)
+ (occur-next)
+ (occur-mode-goto-occurrence-other-window)
+ (recenter)
+ (other-window 1)))
+
+ (define-key occur-mode-map (kbd "C-p")
+ (lambda ()
+ (interactive)
+ (occur-prev)
+ (occur-mode-goto-occurrence-other-window)
+ (recenter)
+ (other-window 1)))
+
+#+END_SRC
+
+
+** =M-o= as prefix key for windows
+
+** =M-g= as prefix key for launcher
+
+** others
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+
+ ;; C-' undefined
+ ;; C-. undefined
+#+END_SRC
+
+* Eshell
+
+Eshell alias
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (defalias 'e 'ido-find-file)
+ (defalias 'ff 'ido-find-file)
+ (defalias 'ee 'ido-find-file-other-window)
+
+#+END_SRC
+
+Quickly start eshll in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (defun eshell-x ()
+ (insert "exit")
+ (eshell-send-input)
+ (delete-window))
+
+ (defun eshell-here ()
+ "Opens up a new shell in the directory associated with the
+ current buffer's file. The eshell is renamed to match that
+ directory to make multiple eshell windows easier."
+ (interactive)
+ (let* ((parent (if (buffer-file-name)
+ (file-name-directory (buffer-file-name))
+ default-directory))
+ (height (/ (window-total-height) 3))
+ (name (car (last (split-string parent "/" t))))
+ (eshell-name (concat "*eshell: " name "*")))
+ (split-window-vertically (- height))
+ (other-window 1)
+ (if (get-buffer eshell-name)
+ (progn
+ (message "buffer exist")
+ (switch-to-buffer eshell-name))
+ (progn
+ (eshell "new")
+ (rename-buffer eshell-name)
+
+ (insert (concat "ls"))
+ (eshell-send-input)))))
+
+ ;; (global-set-key (kbd "M-`") (lambda ()
+ ;; (interactive)
+ ;; (if (buffer-name))))
+
+#+END_SRC
+
+* Misc Settings
+
+** [[https://github.com/abo-abo/hydra][Hydra]]
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package hydra
+ :ensure t)
+
+#+END_SRC
+
+*** Font Zoom
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (defhydra sd/font-zoom (global-map "<f2>")
+ "zoom"
+ ("g" text-scale-increase "in")
+ ("l" text-scale-decrease "out"))
+
+#+END_SRC
+
+*** Windmove Splitter
+
+Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (defun hydra-move-splitter-left (arg)
+ "Move window splitter left."
+ (interactive "p")
+ (if (let ((windmove-wrap-around))
+ (windmove-find-other-window 'right))
+ (shrink-window-horizontally arg)
+ (enlarge-window-horizontally arg)))
+
+ (defun hydra-move-splitter-right (arg)
+ "Move window splitter right."
+ (interactive "p")
+ (if (let ((windmove-wrap-around))
+ (windmove-find-other-window 'right))
+ (enlarge-window-horizontally arg)
+ (shrink-window-horizontally arg)))
+
+ (defun hydra-move-splitter-up (arg)
+ "Move window splitter up."
+ (interactive "p")
+ (if (let ((windmove-wrap-around))
+ (windmove-find-other-window 'up))
+ (enlarge-window arg)
+ (shrink-window arg)))
+
+ (defun hydra-move-splitter-down (arg)
+ "Move window splitter down."
+ (interactive "p")
+ (if (let ((windmove-wrap-around))
+ (windmove-find-other-window 'up))
+ (shrink-window arg)
+ (enlarge-window arg)))
+
+#+END_SRC
+
+*** hydra-window
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (winner-mode 1)
+
+ (defhydra sd/hydra-window (:color red :columns nil)
+ "window"
+ ("h" windmove-left nil)
+ ("j" windmove-down nil)
+ ("k" windmove-up nil)
+ ("l" windmove-right nil)
+ ("H" hydra-move-splitter-left nil)
+ ("J" hydra-move-splitter-down nil)
+ ("K" hydra-move-splitter-up nil)
+ ("L" hydra-move-splitter-right nil)
+ ("v" (lambda ()
+ (interactive)
+ (split-window-right)
+ (windmove-right))
+ "vert")
+ ("x" (lambda ()
+ (interactive)
+ (split-window-below)
+ (windmove-down))
+ "horz")
+ ("o" delete-other-windows "one" :exit t)
+ ("a" ace-window "ace")
+ ("s" ace-swap-window "swap")
+ ("d" ace-delete-window "ace-one" :exit t)
+ ("i" ace-maximize-window "ace-one" :exit t)
+ ("b" ido-switch-buffer "buf")
+ ("m" headlong-bookmark-jump "bmk")
+ ("q" nil "cancel")
+ ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
+ ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
+ ("f" nil))
+
+ (global-unset-key (kbd "M-o"))
+ (global-set-key (kbd "M-o") 'sd/hydra-window/body)
+
+ (defun triggle-windows-max-size ()
+ (interactive)
+ (if (> (length (window-list)) 1)
+ (delete-other-windows)
+ (winner-undo)))
+
+#+END_SRC
+
+** Line Number
+
+Enable linum mode on programming modes
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (add-hook 'prog-mode-hook 'linum-mode)
+
+#+END_SRC
+
+Fix the font size of line number
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (defun fix-linum-size ()
+ (interactive)
+ (set-face-attribute 'linum nil :height 110))
+
+ (add-hook 'linum-mode-hook 'fix-linum-size)
+
+#+END_SRC
+
+I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package linum-relative
+ :ensure t
+ :config
+ (defun linum-new-mode ()
+ "If line numbers aren't displayed, then display them.
+ Otherwise, toggle between absolute and relative numbers."
+ (interactive)
+ (if linum-mode
+ (linum-relative-toggle)
+ (linum-mode 1)))
+
+ :bind
+ ("A-k" . linum-new-mode))
+
+ ;; auto enable linum-new-mode in programming modes
+ (add-hook 'prog-mode-hook 'linum-relative-mode)
+
+#+END_SRC
+
+** Save File Position
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (require 'saveplace)
+ (setq-default save-place t)
+ (setq save-place-forget-unreadable-files t)
+ (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
+
+#+END_SRC
+
+** Multi-term
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package multi-term
+ :ensure t)
+
+#+END_SRC
+
+** ace-link
+
+[[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
+Type =o= to go to the link
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package ace-link
+ :ensure t
+ :init
+ (ace-link-setup-default))
+
+#+END_SRC
+
+** Emux
+
+[[https://github.com/re5et/emux][emux]] is
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (el-get-bundle re5et/emux)
+
+#+END_SRC
+
+** Smart Parens
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package smartparens
+ :ensure t
+ :config
+ (progn
+ (require 'smartparens-config)
+ (add-hook 'prog-mode-hook 'smartparens-mode)))
+
+#+END_SRC
+
+** Ace-Windows
+
+[[https://github.com/abo-abo/ace-window][ace-window]]
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package ace-window
+ :ensure t
+ :defer t
+ ; :init
+ ; (global-set-key (kbd "M-o") 'ace-window)
+ :config
+ (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
+
+#+END_SRC
+
+** Projectile
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package projectile
+ :ensure t
+ :init
+ (setq projectile-enable-caching t)
+ :config
+ (projectile-global-mode t))
+
+ (use-package persp-projectile
+ :ensure t
+ :config
+ (persp-mode)
+ :bind
+ (:map projectile-mode-map
+ ("s-t" . projectile-persp-switch-project)))
+
+ ;; projectile-find-file
+ ;; projectile-switch-buffer
+ ;; projectile-find-file-other-window
+#+END_SRC
+
+** Which key
+
+[[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package which-key
+ :ensure t
+ :config
+ (which-key-mode))
+
+#+END_SRC
+
+** Emms
+
+We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package emms
+ :ensure t
+ :init
+ (setq emms-source-file-default-directory "~/Music/emms/")
+ :config
+ (emms-standard)
+ (emms-default-players)
+ (define-emms-simple-player mplayer '(file url)
+ (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
+ ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
+ "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
+ ".m4a" ".flv" ".ogv" ".pls"))
+ "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
+ (emms-history-load))
+
+#+END_SRC
+
+** GnoGo
+
+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
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package gnugo
+ :ensure t
+ :defer t
+ :init
+ (require 'gnugo-imgen)
+ (setq gnugo-xpms 'gnugo-imgen-create-xpms)
+ (add-hook 'gnugo-start-game-hook '(lambda ()
+ (gnugo-image-display-mode)
+ (gnugo-grid-mode)))
+ :config
+ (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
+
+#+END_SRC
+
+** undo-tree
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package undo-tree
+ :ensure t
+ :config
+ (global-undo-tree-mode 1))
+
+#+END_SRC
+
+** swiper
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package swiper
+ :ensure t)
+
+
+ (ivy-mode 1)
+ (setq ivy-use-virtual-buffers t)
+ (global-set-key "\C-s" 'swiper)
+ (global-set-key (kbd "C-c C-r") 'ivy-resume)
+ (global-set-key (kbd "<f6>") 'ivy-resume)
+ ;; (global-set-key (kbd "M-x") 'counsel-M-x)
+ ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
+ (global-set-key (kbd "<f1> f") 'counsel-describe-function)
+ (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
+ (global-set-key (kbd "<f1> l") 'counsel-load-library)
+ (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
+ (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
+ (global-set-key (kbd "C-c g") 'counsel-git)
+ (global-set-key (kbd "C-c j") 'counsel-git-grep)
+ (global-set-key (kbd "C-c k") 'counsel-ag)
+ (global-set-key (kbd "C-x l") 'counsel-locate)
+ (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
+ ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
+
+#+END_SRC
+
+** Tabbar
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ ;; (use-package tabbar-ruler
+ ;; :ensure t
+ ;; :init
+ ;; (setq tabbar-ruler-global-tabbar t)
+ ;; (setq tabbar-ruler-global-ruler t)
+ ;; (setq tabbar-ruler-popu-menu t)
+ ;; (setq tabbar-ruler-popu-toolbar t)
+ ;; (setq tabbar-use-images t)
+ ;; :config
+ ;; (tabbar-ruler-group-by-projectile-project)
+ ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
+ ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
+
+#+END_SRC
+
+* Programming
+
+** Languages
+
+*** Emacs Lisp
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package color-identifiers-mode
+ :ensure t
+ :init
+ (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
+
+ :diminish color-identifiers-mode)
+
+ (global-prettify-symbols-mode t)
+
+#+END_SRC
+
+**** Lispy Mode
+
+In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
+bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package lispy
+ :ensure t
+ :init
+ (eval-after-load 'lispy
+ '(progn
+ (define-key lispy-mode-map (kbd "M-o") nil)))
+ :config
+ (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
+
+#+END_SRC
+
+*** Perl
+
+[[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (defalias 'perl-mode 'cperl-mode)
+
+ ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
+ (setq cperl-auto-newline t)
+ (setq cperl-highlight-variables-indiscriminately t)
+ ;(setq cperl-indent-level 4)
+ ;(setq cperl-continued-statement-offset 4)
+ (setq cperl-close-paren-offset -4)
+ (setq cperl-indent-parents-as-block t)
+ (setq cperl-tab-always-indent t)
+ ;(setq cperl-brace-offset 0)
+
+ (add-hook 'cperl-mode-hook
+ '(lambda ()
+ (cperl-set-style "C++")))
+
+ ;(require 'template)
+ ;(template-initialize)
+ ;(require 'perlnow)
+
+#+END_SRC
+
+- auto insert
+- run script
+
+Change the compile-command to set the default command run when call =compile=
+Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
+to call =compilation= interactively.
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (defun my-perl-hook ()
+ (progn
+ (setq-local compilation-read-command nil)
+ (set (make-local-variable 'compile-command)
+ (concat "/usr/bin/perl "
+ (if buffer-file-name
+ (shell-quote-argument buffer-file-name))))
+ (local-set-key (kbd "s-r")
+ (lambda ()
+ (interactive)
+ ; (setq current-prefix-arg '(4)) ; C-u
+ (call-interactively 'compile)))))
+
+ (add-hook 'cperl-mode-hook 'my-perl-hook)
+
+
+#+END_SRC
+
+*** C & C++
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (setq c-default-style "stroustrup"
+ c-basic-offset 4)
+
+#+END_SRC
+
+** Compile
+
+Set the environments vairables in compilation mode
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package compile
+ :commands compile
+ :config
+ (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
+
+#+END_SRC
+
+** Auto-Insert
+
+Enable auto-insert mode
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (auto-insert-mode t)
+ (setq auto-insert-query nil)
+
+#+END_SRC
+
+*** C++ Auto Insert
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (eval-after-load 'autoinsert
+ '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
+ '(
+ "Short description:"
+ "/*"
+ "\n * " (file-name-nondirectory (buffer-file-name))
+ "\n */" > \n \n
+ "#include <iostream>" \n
+ "#include \""
+ (file-name-sans-extension
+ (file-name-nondirectory (buffer-file-name)))
+ ".hpp\"" \n \n
+ "using namespace std;" \n \n
+ "int main ()"
+ "\n{" \n
+ > _ \n
+ "return 1;"
+ "\n}" > \n
+ )))
+
+ (eval-after-load 'autoinsert
+ '(define-auto-insert '("\\.c\\'" . "C skeleton")
+ '(
+ "Short description:"
+ "/*\n"
+ " * " (file-name-nondirectory (buffer-file-name)) "\n"
+ " */" > \n \n
+ "#include <stdio.h>" \n
+ "#include \""
+ (file-name-sans-extension
+ (file-name-nondirectory (buffer-file-name)))
+ ".h\"" \n \n
+ "int main ()\n"
+ "{" \n
+ > _ \n
+ "return 1;\n"
+ "}" > \n
+ )))
+
+#+END_SRC
+
+*** Perl Auto Insert
+
+Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (eval-after-load 'autoinsert
+ '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
+ '(
+ "Description: "
+ "#!/usr/bin/perl -w" \n
+ \n
+ "use strict;" \n \n
+ )))
+
+#+END_SRC
+
+** Completion
+
+company mode
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package company
+ :ensure t
+ :diminish company-mode
+ :init (setq company-idle-delay 0.1)
+ :config
+ (global-company-mode))
+
+#+END_SRC
+
+[[https://github.com/company-mode/company-statistics][company-statistics]]
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+ (use-package company-statistics
+ :ensure t
+ :config
+ (company-statistics-mode))
+
+#+END_SRC
+
+* Todo
+
+- change M-o to trigger to delete other windows and restore previous config
+
--- /dev/null
+
+;; Added by Package.el. This must come before configurations of
+;; installed packages. Don't delete this line. If you don't want it,
+;; just comment it out by adding a semicolon to the start of the line.
+;; You may delete these explanatory comments.
+(package-initialize)
+
+(org-babel-load-file "~/.emacs.d/config.org")
+++ /dev/null
-.*
-elpa/*
-\#*
-config.el
-ido.last
-*~
-recentf
-el-get/*
-custom.el
-projectile.cache
-projectile-bookmarks.eld
-semanticdb/*
-config.html
-company-statistics-cache.el
-emms/*
+++ /dev/null
-#+TITLE: Emacs Configuration file
-#+AUTHOR: Peng Li
-#+EMAIL: seudut@gmail.com
-
-* Introduction
-
-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
-
-* Basic Settings
-
-** Setting loading Path
-
-Set system PATH and emacs exec path
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (setenv "PATH" (concat (getenv "PATH")
- ":" "/usr/local/bin"
- ":" "/Library/TeX/texbin"))
- (setq exec-path (append exec-path '("/usr/local/bin")))
- (setq exec-path (append exec-path '("/Library/TeX/texbin/")))
-
-#+END_SRC
-
-Set the emacs load path
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (add-to-list 'load-path "~/.emacs.d/elisp")
-
-#+END_SRC
-
-** Package Initialization
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (require 'package)
-
- (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
- ("gnu" . "http://elpa.gnu.org/packages/")
- ("org" . "http://orgmode.org/elpa/")))
-
- (package-initialize)
-
-#+END_SRC
-
-** General Setting
-
-Disable scroll bar, tool-bar and menu-bar
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (scroll-bar-mode 0)
- (tool-bar-mode 0)
- (menu-bar-mode 1)
-
- (setq debug-on-error t)
- (setq inhibit-startup-message t)
-
- (defalias 'yes-or-no-p 'y-or-n-p)
- (show-paren-mode 1)
-
-
-
-#+END_SRC
-
-set custom file
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (setq custom-file "~/.emacs.d/custom.el")
- (load custom-file)
-
-#+END_SRC
-
-Switch the focus to help window when it appears
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (setq help-window-select t)
-
-#+END_SRC
-
-* Package Management Tools
-
-** Use-package
-
-Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (unless (package-installed-p 'use-package)
- (package-refresh-contents)
- (package-install 'use-package))
-
- (require 'use-package)
-
-#+END_SRC
-
-** El-get
-
-[[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.
-Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package el-get
- :ensure t
- :init
- (add-to-list 'load-path "~/.emacs.d/el-get"))
-
-#+END_SRC
-
-* Color and Fonts Settings
-
-** highlight current line
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (global-hl-line-mode)
-
-#+END_SRC
-
-** Smart Comments
-
-[[https://github.com/paldepind/smart-comment][smart-comments]]
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package smart-comment
- :ensure t
- :bind ("M-;" . smart-conmment))
-
-#+END_SRC
-
-** Font Setting
-
-syntax highlighting
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (global-font-lock-mode 1)
-
-#+END_SRC
-
-[[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (if window-system
- (defvar sd/fixed-font-family
- (cond ((x-list-fonts "Hasklig") "Hasklig")
- ((x-list-fonts "Source Code Pro") "Source Code Pro")
- ((x-list-fonts "Anonymous Pro") "Anonymous Pro")
- ((x-list-fonts "M+ 1mn") "M+ 1mn"))
- "The fixed width font based on what is installed, `nil' if not defined."))
-
-#+END_SRC
-
-Setting the fonts
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (if window-system
- (when sd/fixed-font-family
- (set-frame-font sd/fixed-font-family)
- (set-face-attribute 'default nil :font sd/fixed-font-family :height 120)
- (set-face-font 'default sd/fixed-font-family)))
-
-#+END_SRC
-
-** Color Theme
-
-Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (setq vc-follow-symlinks t)
-
- (use-package color-theme
- :ensure t
- :init (require 'color-theme)
- :config (use-package color-theme-sanityinc-tomorrow
- :ensure t
- :no-require t
- :config
- (load-theme 'sanityinc-tomorrow-bright t)))
-
- ;(eval-after-load 'color-theme
- ; (load-theme 'sanityinc-tomorrow-bright t))
-
-#+END_SRC
-
-Change the Org-mode colors
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (defun org-src-color-blocks-light ()
- "Colors the block headers and footers to make them stand out more for lighter themes"
- (interactive)
- (custom-set-faces
- '(org-block-begin-line
- ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
- '(org-block-background
- ((t (:background "#FFFFEA"))))
- '(org-block
- ((t (:background "#FFFFEA"))))
- '(org-block-end-line
- ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
-
- '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
- '(which-func ((t (:foreground "#008000"))))))
-
- (defun org-src-color-blocks-dark ()
- "Colors the block headers and footers to make them stand out more for dark themes"
- (interactive)
- (custom-set-faces
- '(org-block-begin-line
- ((t (:foreground "#008ED1" :background "#002E41"))))
- '(org-block-background
- ((t (:background "#000000"))))
- '(org-block
- ((t (:background "#000000"))))
- '(org-block-end-line
- ((t (:foreground "#008ED1" :background "#002E41"))))
-
- '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
- '(which-func ((t (:foreground "green"))))))
-
- (org-src-color-blocks-dark)
-
-#+END_SRC
-
-improve color for org-mode
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
- (deftheme ha/org-theme "Sub-theme to beautify org mode")
-
- (if window-system
- (defvar sd/variable-font-tuple
- (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
- ((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
- ((x-list-fonts "Verdana") '(:font "Verdana"))
- ((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
- (nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro.")))
- "My variable width font available to org-mode files and whatnot."))
-
- (defun sd/org-color ()
- (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
- (base-font-color (face-foreground 'default nil 'default))
- (background-color (face-background 'default nil 'default))
- (primary-color (face-foreground 'mode-line nil))
- (secondary-color (face-background 'secondary-selection nil 'region))
- (base-height (face-attribute 'default :height))
- (headline `(:inherit default :weight bold :foreground ,base-font-color)))
- (custom-theme-set-faces 'ha/org-theme
- `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
- `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
- `(org-table ((t (:inherit 'fixed-pitched))))
- `(org-block ((t (:inherit 'fixed-pitched))))
- `(org-block-background ((t (:inherit 'fixed-pitched))))
- `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
- `(org-block-end-line ((t (:inherit 'fixed-pitched))))
- `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
- `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
- `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
- `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
- `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
- :height ,(round (* 1.1 base-height))))))
- `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
- :height ,(round (* 1.25 base-height))))))
- `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
- :height ,(round (* 1.5 base-height))))))
- `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
- :height ,(round (* 1.75 base-height))))))
- `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
-
-
-#+END_SRC
-
-** Rainbow-delimiter
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package rainbow-delimiters
- :ensure t
- :init
- (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
-
-#+END_SRC
-
-** page-break-lines
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package page-break-lines
- :ensure t
- :config
- (turn-on-page-break-lines-mode))
-
-#+END_SRC
-
-* Org-mode Settings
-
-** Org-mode Basic setting
-
-Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package org
- :ensure t
- :init
- (setq org-startup-indented t)
- (setq org-hide-leading-starts t)
- (setq org-src-fontify-natively t)
- (setq org-src-tab-acts-natively t)
- (setq org-confirm-babel-evaluate nil)
- (setq org-use-speed-commands t)
- (setq org-completion-use-ido t))
-
- (org-babel-do-load-languages
- 'org-babel-load-languages
- '((python . t)
- (C . t)
- (perl . t)
- (calc . t)
- (latex . t)
- (java . t)
- (ruby . t)
- (lisp . t)
- (scheme . t)
- (sh . t)
- (sqlite . t)
- (js . t)))
-
- ;; use current window for org source buffer editting
- (setq org-src-window-setup 'current-window )
-
-#+END_SRC
-
-** Org-bullets
-
-use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package org-bullets
- :ensure t
- :init
- (add-hook 'org-mode-hook
- (lambda ()
- (org-bullets-mode t))))
-
-#+END_SRC
-
-** Worf Mode
-
-[[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
-In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
-cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
-=M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package worf
- :ensure t
- :commands worf-mode
- :init (add-hook 'org-mode-hook 'worf-mode)
- ;; :config
- ;; (define-key worf-mode-map "[" nil)
- ;; (define-key worf-mode-map "]" nil)
- ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
- ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
- )
-
-#+END_SRC
-
-** Task Management
-
-** Capture
-
-** Export PDF
-
-Install MacTex-basic and some tex packages
-
-#+BEGIN_SRC bash
-
- sudo tlmgr update --self
-
- 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
-
-#+END_SRC
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
- ;; ;; allow for export=>beamer by placing
-
- ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
- ;; #+LaTeX_CLASS: beamer in org files
- (unless (boundp 'org-export-latex-classes)
- (setq org-export-latex-classes nil))
- (add-to-list 'org-export-latex-classes
- ;; beamer class, for presentations
- '("beamer"
- "\\documentclass[11pt]{beamer}\n
- \\mode<{{{beamermode}}}>\n
- \\usetheme{{{{beamertheme}}}}\n
- \\usecolortheme{{{{beamercolortheme}}}}\n
- \\beamertemplateballitem\n
- \\setbeameroption{show notes}
- \\usepackage[utf8]{inputenc}\n
- \\usepackage[T1]{fontenc}\n
- \\usepackage{hyperref}\n
- \\usepackage{color}
- \\usepackage{listings}
- \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
- frame=single,
- basicstyle=\\small,
- showspaces=false,showstringspaces=false,
- showtabs=false,
- keywordstyle=\\color{blue}\\bfseries,
- commentstyle=\\color{red},
- }\n
- \\usepackage{verbatim}\n
- \\institute{{{{beamerinstitute}}}}\n
- \\subject{{{{beamersubject}}}}\n"
-
- ("\\section{%s}" . "\\section*{%s}")
-
- ("\\begin{frame}[fragile]\\frametitle{%s}"
- "\\end{frame}"
- "\\begin{frame}[fragile]\\frametitle{%s}"
- "\\end{frame}")))
-
- ;; letter class, for formal letters
-
- (add-to-list 'org-export-latex-classes
-
- '("letter"
- "\\documentclass[11pt]{letter}\n
- \\usepackage[utf8]{inputenc}\n
- \\usepackage[T1]{fontenc}\n
- \\usepackage{color}"
-
- ("\\section{%s}" . "\\section*{%s}")
- ("\\subsection{%s}" . "\\subsection*{%s}")
- ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
- ("\\paragraph{%s}" . "\\paragraph*{%s}")
- ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
-
-
- (require 'ox-md)
- (require 'ox-beamer)
-
- (setq org-latex-pdf-process
- '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
- "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
- "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
-
- (setq TeX-parse-self t)
-
- (setq TeX-PDF-mode t)
- (add-hook 'LaTeX-mode-hook
- (lambda ()
- (LaTeX-math-mode)
- (setq TeX-master t)))
-
-#+END_SRC
-
-** others
-
-refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]]
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (setq org-todo-keywords '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
- (sequence "⚑ WAITING(w)" "|")
- (sequence "|" "✘ CANCELED(c)")))
-
-#+END_SRC
-
-extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (add-to-list 'org-structure-template-alist
- '("E" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"))
- (add-to-list 'org-structure-template-alist
- '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
- (add-to-list 'org-structure-template-alist
- '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
-
-#+END_SRC
-
-* Magit
-
-[[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package magit
- :ensure t
- :commands magit-status magit-blame)
-
-
-#+END_SRC
-
-* IDO & SMEX
-
-** IDO
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package ido
- :ensure t
- :init (setq ido-enable-flex-matching t
- ido-ignore-extensions t
- ido-use-virtual-buffers t
- ido-everywhere t)
- :config
- (ido-mode 1)
- (ido-everywhere 1)
- (add-to-list 'completion-ignored-extensions ".pyc"))
-
- (icomplete-mode t)
-
-#+END_SRC
-
-** FLX
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package flx-ido
- :ensure t
- :init (setq ido-enable-flex-matching t
- ido-use-faces nil)
- :config (flx-ido-mode 1))
-
-#+END_SRC
-
-** IDO-vertically
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package ido-vertical-mode
- :ensure t
- :init
- (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
- :config
- (ido-vertical-mode 1))
-
-#+END_SRC
-
-** SMEX
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package smex
- :ensure t
- :init (smex-initialize)
- :bind
- ("M-x" . smex)
- ("M-X" . smex-major-mode-commands))
-
-#+END_SRC
-
-** Ido-ubiquitous
-
-Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package ido-ubiquitous
- :ensure t
- :init
- (setq magit-completing-read-function 'magit-ido-completing-read)
- (setq gnus-completing-read-function 'gnus-ido-completing-read)
- :config
- (ido-ubiquitous-mode 1))
-
-#+END_SRC
-
-** Ido-exit-target
-
-[[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package ido-exit-target
- :ensure t
- :init
- (define-key ido-common-completion-map (kbd "C-j") #'ido-exit-target-split-window-right)
- (define-key ido-common-completion-map (kbd "C-l") #'ido-exit-target-split-window-below))
-
-#+END_SRC
-
-* Key bindings
-
-** Remove prefix =ESC=, refer [[http://emacs.stackexchange.com/questions/14755/how-to-remove-bindings-to-the-esc-prefix-key][here]]
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- ;; (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
-
-#+END_SRC
-
-** Esc on Minibuffer
-
-Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
- (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
- (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
- (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
- (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
- (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
- (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
- (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
- (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
-
- ;; Also map s-h same as C-g
- (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
-
-#+END_SRC
-
-** =Ctrl= key bindings
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
- ;;
-
- ;; C-h help
- ;; C-j newline and indent
- ;; C-k kill line
- ;; C-l recenter-top-bottom
- ;; (global-set-key (kbd "C-;") 'ido-switch-buffer)
- ;; C-;
- ;; C-'
- ;; C-ret
-
- ;; C-n next-line
- ;; C-m
- ;; C-,
- ;; C-.
- ;; C-/
-
- ;; C-y
- ;; C-u
- ;; C-i
- ;; C-o
- ;; C-p
- ;; C-[
- ;; C-]
- ;; C-\
-
- ;; C-=
- ;; C--
- ;; C-0
- ;; C-9
- ;; C-8
- ;; C-7
-
- ;; C-Space
-
-
-
-
-
-
-
-#+END_SRC
-
-** =Super= bindings for file, buffer and windows
-
-Some global bindings on =Super=, on Mac, it is =Command=
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (global-set-key (kbd "s-h") 'keyboard-quit)
- (global-set-key (kbd "s-j") 'ido-switch-buffer)
- (global-set-key (kbd "s-k") 'ido-find-file)
- ;; s-k --> kill-this-buffer
- (global-set-key (kbd "s-l") (lambda ()
- (interactive)
- (if (> (length (window-list)) 1)
- (delete-window)
- (message "Only one Windows now!"))))
- ;; s-l --> goto-line
- (global-set-key (kbd "s-;") 'swiper)
- ;; s-; -->
- ;; s-' --> 'next-multiframe-window
- (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
-
- ;; (global-set-key (kbd "s-y") 'projectile-find-file)
- (global-set-key (kbd "s-f") 'projectile-find-file)
- (global-set-key (kbd "s-[") 'persp-next)
- (global-set-key (kbd "s-]") 'persp-prev)
-
- (global-set-key (kbd "s-`") 'mode-line-other-buffer)
-
- (global-set-key (kbd "s-n") 'persp-next)
- (global-set-key (kbd "s-p") 'persp-prev)
-
-
-
- ;; someothers default mapping on super (command) key
- ;; s-s save-buffer
- ;; s-k kill-this-buffer
-
-
- ;; s-h --> ns-do-hide-emacs
- ;; s-j --> ido-switch-buffer +
- ;; s-k --> kill-this-buffer
- ;; s-l --> goto-line
- ;; s-; --> undefined
- ;; s-' --> next-multiframe-window
- ;; s-ret --> toggle-frame-fullscreen +
-
- ;; s-y --> ns-paste-secondary
- ;; s-u --> revert-buffer
- ;; s-i --> undefined - but used for iterm globally
- ;; s-o --> used for emacs globally
- ;; s-p --> projectile-persp-switch-project +
- ;; s-[ --> next-buffer +
- ;; s-] --> previous-buffer +
-
- ;; s-0 --> undefined
- ;; s-9 --> undefined
- ;; s-8 --> undefined
- ;; s-7 --> undefined
- ;; s-6 --> undefined
- ;; s-- --> center-line
- ;; s-= --> undefined
-
- ;; s-n --> make-frame
- ;; s-m --> iconify-frame
- ;; s-b --> undefined
- ;; s-, --> customize
- ;; s-. --> undefined
- ;; s-/ --> undefined
-
- ;; s-g --> isearch-repeat-forward
- ;; s-f --> projectile-find-file +
- ;; s-d --> isearch-repeat-background
- ;; s-s --> save-buffer
- ;; s-a --> make-whole-buffer
-
- ;; s-b --> undefined
- ;; s-v --> yank
- ;; s-c --> ns-copy-including-secondary
-
- ;; s-t --> ns-popup-font-panel
- ;; s-r --> undefined
- ;; s-e --> isearch-yanqk-kill
- ;; s-w --> delete-frame
- ;; s-q --> same-buffers-kill-emacs
-
- ;; s-` --> other-frame
-#+END_SRC
-
-** =M-s= bindings for searching
-
-I use the prefix =M-s= for searching in buffers
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (defun pl-make-keymap (key bindings)
- (setq keymap (make-sparse-keymap))
- (dolist (binding bindings)
- (define-key keymap (car binding) (cdr binding)))
- (global-set-key key keymap))
-
- (define-key minibuffer-local-map "\M-s" nil)
-
- (global-set-key (kbd "M-s s") 'isearch-forward-regexp)
- (define-key isearch-mode-map "\M-s" 'isearch-repeat-forward)
- (global-set-key (kbd "M-s r") 'isearch-backward-regexp)
- (define-key isearch-mode-map "\M-r" 'isearch-repeat-backward)
-
- (global-set-key (kbd "s-/") 'isearch-forward-regexp)
- (define-key isearch-mode-map (kbd "s-/") 'isearch-repeat-forward)
- (define-key isearch-mode-map (kbd "C-n") 'isearch-repeat-forward)
-
-
- (set-face-background 'ido-first-match "white")
-
- ;; M-s o --> occur
- ;; M-s s --> isearch-forward-regexp
- ;; M-s r --> isearch-backward-regexp
- ;; M-s w --> isearch-forward-word
- ;; M-s . --> isearch-forward-symbol-at-point
- ;; M-s _ --> isearch-forward-symbol
-
- ;; highlight bindings
- ;; M-s h . --> highlight-symbol-at-point
- ;; M-s h r --> highlight-regexp
- ;; M-s h u --> unhighlight-regexp
- ;; M-s h l --> highlight-lines-match-regexp
- ;; M-s h p --> highlight-phrase
- ;; M-s h f --> hi-lock-find-patterns
-
- ;;
- ;; (global-set-key (kbd "M-s M-r") 'isearch-backward-regexp)
- ;;
-
- ;; M-c
- ;; M-r
- ;; M-t
- ;; M-u,
-#+END_SRC
-
-Occur search key bindings
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (define-key occur-mode-map (kbd "C-n")
- (lambda ()
- (interactive)
- (occur-next)
- (occur-mode-goto-occurrence-other-window)
- (recenter)
- (other-window 1)))
-
- (define-key occur-mode-map (kbd "C-p")
- (lambda ()
- (interactive)
- (occur-prev)
- (occur-mode-goto-occurrence-other-window)
- (recenter)
- (other-window 1)))
-
-#+END_SRC
-
-
-** =M-o= as prefix key for windows
-
-** =M-g= as prefix key for launcher
-
-** others
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
-
- ;; C-' undefined
- ;; C-. undefined
-#+END_SRC
-
-* Eshell
-
-Eshell alias
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (defalias 'e 'ido-find-file)
- (defalias 'ff 'ido-find-file)
- (defalias 'ee 'ido-find-file-other-window)
-
-#+END_SRC
-
-Quickly start eshll in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (defun eshell-x ()
- (insert "exit")
- (eshell-send-input)
- (delete-window))
-
- (defun eshell-here ()
- "Opens up a new shell in the directory associated with the
- current buffer's file. The eshell is renamed to match that
- directory to make multiple eshell windows easier."
- (interactive)
- (let* ((parent (if (buffer-file-name)
- (file-name-directory (buffer-file-name))
- default-directory))
- (height (/ (window-total-height) 3))
- (name (car (last (split-string parent "/" t))))
- (eshell-name (concat "*eshell: " name "*")))
- (split-window-vertically (- height))
- (other-window 1)
- (if (get-buffer eshell-name)
- (progn
- (message "buffer exist")
- (switch-to-buffer eshell-name))
- (progn
- (eshell "new")
- (rename-buffer eshell-name)
-
- (insert (concat "ls"))
- (eshell-send-input)))))
-
- ;; (global-set-key (kbd "M-`") (lambda ()
- ;; (interactive)
- ;; (if (buffer-name))))
-
-#+END_SRC
-
-* Misc Settings
-
-** [[https://github.com/abo-abo/hydra][Hydra]]
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package hydra
- :ensure t)
-
-#+END_SRC
-
-*** Font Zoom
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (defhydra sd/font-zoom (global-map "<f2>")
- "zoom"
- ("g" text-scale-increase "in")
- ("l" text-scale-decrease "out"))
-
-#+END_SRC
-
-*** Windmove Splitter
-
-Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (defun hydra-move-splitter-left (arg)
- "Move window splitter left."
- (interactive "p")
- (if (let ((windmove-wrap-around))
- (windmove-find-other-window 'right))
- (shrink-window-horizontally arg)
- (enlarge-window-horizontally arg)))
-
- (defun hydra-move-splitter-right (arg)
- "Move window splitter right."
- (interactive "p")
- (if (let ((windmove-wrap-around))
- (windmove-find-other-window 'right))
- (enlarge-window-horizontally arg)
- (shrink-window-horizontally arg)))
-
- (defun hydra-move-splitter-up (arg)
- "Move window splitter up."
- (interactive "p")
- (if (let ((windmove-wrap-around))
- (windmove-find-other-window 'up))
- (enlarge-window arg)
- (shrink-window arg)))
-
- (defun hydra-move-splitter-down (arg)
- "Move window splitter down."
- (interactive "p")
- (if (let ((windmove-wrap-around))
- (windmove-find-other-window 'up))
- (shrink-window arg)
- (enlarge-window arg)))
-
-#+END_SRC
-
-*** hydra-window
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (winner-mode 1)
-
- (defhydra sd/hydra-window (:color red :columns nil)
- "window"
- ("h" windmove-left nil)
- ("j" windmove-down nil)
- ("k" windmove-up nil)
- ("l" windmove-right nil)
- ("H" hydra-move-splitter-left nil)
- ("J" hydra-move-splitter-down nil)
- ("K" hydra-move-splitter-up nil)
- ("L" hydra-move-splitter-right nil)
- ("v" (lambda ()
- (interactive)
- (split-window-right)
- (windmove-right))
- "vert")
- ("x" (lambda ()
- (interactive)
- (split-window-below)
- (windmove-down))
- "horz")
- ("o" delete-other-windows "one" :exit t)
- ("a" ace-window "ace")
- ("s" ace-swap-window "swap")
- ("d" ace-delete-window "ace-one" :exit t)
- ("i" ace-maximize-window "ace-one" :exit t)
- ("b" ido-switch-buffer "buf")
- ("m" headlong-bookmark-jump "bmk")
- ("q" nil "cancel")
- ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
- ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
- ("f" nil))
-
- (global-unset-key (kbd "M-o"))
- (global-set-key (kbd "M-o") 'sd/hydra-window/body)
-
- (defun triggle-windows-max-size ()
- (interactive)
- (if (> (length (window-list)) 1)
- (delete-other-windows)
- (winner-undo)))
-
-#+END_SRC
-
-** Line Number
-
-Enable linum mode on programming modes
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (add-hook 'prog-mode-hook 'linum-mode)
-
-#+END_SRC
-
-Fix the font size of line number
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (defun fix-linum-size ()
- (interactive)
- (set-face-attribute 'linum nil :height 110))
-
- (add-hook 'linum-mode-hook 'fix-linum-size)
-
-#+END_SRC
-
-I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package linum-relative
- :ensure t
- :config
- (defun linum-new-mode ()
- "If line numbers aren't displayed, then display them.
- Otherwise, toggle between absolute and relative numbers."
- (interactive)
- (if linum-mode
- (linum-relative-toggle)
- (linum-mode 1)))
-
- :bind
- ("A-k" . linum-new-mode))
-
- ;; auto enable linum-new-mode in programming modes
- (add-hook 'prog-mode-hook 'linum-relative-mode)
-
-#+END_SRC
-
-** Save File Position
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (require 'saveplace)
- (setq-default save-place t)
- (setq save-place-forget-unreadable-files t)
- (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
-
-#+END_SRC
-
-** Multi-term
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package multi-term
- :ensure t)
-
-#+END_SRC
-
-** ace-link
-
-[[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
-Type =o= to go to the link
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package ace-link
- :ensure t
- :init
- (ace-link-setup-default))
-
-#+END_SRC
-
-** Emux
-
-[[https://github.com/re5et/emux][emux]] is
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (el-get-bundle re5et/emux)
-
-#+END_SRC
-
-** Smart Parens
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package smartparens
- :ensure t
- :config
- (progn
- (require 'smartparens-config)
- (add-hook 'prog-mode-hook 'smartparens-mode)))
-
-#+END_SRC
-
-** Ace-Windows
-
-[[https://github.com/abo-abo/ace-window][ace-window]]
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package ace-window
- :ensure t
- :defer t
- ; :init
- ; (global-set-key (kbd "M-o") 'ace-window)
- :config
- (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
-
-#+END_SRC
-
-** Projectile
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package projectile
- :ensure t
- :init
- (setq projectile-enable-caching t)
- :config
- (projectile-global-mode t))
-
- (use-package persp-projectile
- :ensure t
- :config
- (persp-mode)
- :bind
- (:map projectile-mode-map
- ("s-t" . projectile-persp-switch-project)))
-
- ;; projectile-find-file
- ;; projectile-switch-buffer
- ;; projectile-find-file-other-window
-#+END_SRC
-
-** Which key
-
-[[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package which-key
- :ensure t
- :config
- (which-key-mode))
-
-#+END_SRC
-
-** Emms
-
-We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package emms
- :ensure t
- :init
- (setq emms-source-file-default-directory "~/Music/emms/")
- :config
- (emms-standard)
- (emms-default-players)
- (define-emms-simple-player mplayer '(file url)
- (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
- ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
- "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
- ".m4a" ".flv" ".ogv" ".pls"))
- "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
- (emms-history-load))
-
-#+END_SRC
-
-** GnoGo
-
-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
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package gnugo
- :ensure t
- :defer t
- :init
- (require 'gnugo-imgen)
- (setq gnugo-xpms 'gnugo-imgen-create-xpms)
- (add-hook 'gnugo-start-game-hook '(lambda ()
- (gnugo-image-display-mode)
- (gnugo-grid-mode)))
- :config
- (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
-
-#+END_SRC
-
-** undo-tree
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package undo-tree
- :ensure t
- :config
- (global-undo-tree-mode 1))
-
-#+END_SRC
-
-** swiper
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package swiper
- :ensure t)
-
-
- (ivy-mode 1)
- (setq ivy-use-virtual-buffers t)
- (global-set-key "\C-s" 'swiper)
- (global-set-key (kbd "C-c C-r") 'ivy-resume)
- (global-set-key (kbd "<f6>") 'ivy-resume)
- ;; (global-set-key (kbd "M-x") 'counsel-M-x)
- ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
- (global-set-key (kbd "<f1> f") 'counsel-describe-function)
- (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
- (global-set-key (kbd "<f1> l") 'counsel-load-library)
- (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
- (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
- (global-set-key (kbd "C-c g") 'counsel-git)
- (global-set-key (kbd "C-c j") 'counsel-git-grep)
- (global-set-key (kbd "C-c k") 'counsel-ag)
- (global-set-key (kbd "C-x l") 'counsel-locate)
- (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
- ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
-
-#+END_SRC
-
-** Tabbar
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- ;; (use-package tabbar-ruler
- ;; :ensure t
- ;; :init
- ;; (setq tabbar-ruler-global-tabbar t)
- ;; (setq tabbar-ruler-global-ruler t)
- ;; (setq tabbar-ruler-popu-menu t)
- ;; (setq tabbar-ruler-popu-toolbar t)
- ;; (setq tabbar-use-images t)
- ;; :config
- ;; (tabbar-ruler-group-by-projectile-project)
- ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
- ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
-
-#+END_SRC
-
-* Programming
-
-** Languages
-
-*** Emacs Lisp
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package color-identifiers-mode
- :ensure t
- :init
- (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
-
- :diminish color-identifiers-mode)
-
- (global-prettify-symbols-mode t)
-
-#+END_SRC
-
-**** Lispy Mode
-
-In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
-bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package lispy
- :ensure t
- :init
- (eval-after-load 'lispy
- '(progn
- (define-key lispy-mode-map (kbd "M-o") nil)))
- :config
- (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
-
-#+END_SRC
-
-*** Perl
-
-[[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (defalias 'perl-mode 'cperl-mode)
-
- ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
- (setq cperl-auto-newline t)
- (setq cperl-highlight-variables-indiscriminately t)
- ;(setq cperl-indent-level 4)
- ;(setq cperl-continued-statement-offset 4)
- (setq cperl-close-paren-offset -4)
- (setq cperl-indent-parents-as-block t)
- (setq cperl-tab-always-indent t)
- ;(setq cperl-brace-offset 0)
-
- (add-hook 'cperl-mode-hook
- '(lambda ()
- (cperl-set-style "C++")))
-
- ;(require 'template)
- ;(template-initialize)
- ;(require 'perlnow)
-
-#+END_SRC
-
-- auto insert
-- run script
-
-Change the compile-command to set the default command run when call =compile=
-Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
-to call =compilation= interactively.
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (defun my-perl-hook ()
- (progn
- (setq-local compilation-read-command nil)
- (set (make-local-variable 'compile-command)
- (concat "/usr/bin/perl "
- (if buffer-file-name
- (shell-quote-argument buffer-file-name))))
- (local-set-key (kbd "s-r")
- (lambda ()
- (interactive)
- ; (setq current-prefix-arg '(4)) ; C-u
- (call-interactively 'compile)))))
-
- (add-hook 'cperl-mode-hook 'my-perl-hook)
-
-
-#+END_SRC
-
-*** C & C++
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (setq c-default-style "stroustrup"
- c-basic-offset 4)
-
-#+END_SRC
-
-** Compile
-
-Set the environments vairables in compilation mode
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package compile
- :commands compile
- :config
- (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
-
-#+END_SRC
-
-** Auto-Insert
-
-Enable auto-insert mode
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (auto-insert-mode t)
- (setq auto-insert-query nil)
-
-#+END_SRC
-
-*** C++ Auto Insert
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (eval-after-load 'autoinsert
- '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
- '(
- "Short description:"
- "/*"
- "\n * " (file-name-nondirectory (buffer-file-name))
- "\n */" > \n \n
- "#include <iostream>" \n
- "#include \""
- (file-name-sans-extension
- (file-name-nondirectory (buffer-file-name)))
- ".hpp\"" \n \n
- "using namespace std;" \n \n
- "int main ()"
- "\n{" \n
- > _ \n
- "return 1;"
- "\n}" > \n
- )))
-
- (eval-after-load 'autoinsert
- '(define-auto-insert '("\\.c\\'" . "C skeleton")
- '(
- "Short description:"
- "/*\n"
- " * " (file-name-nondirectory (buffer-file-name)) "\n"
- " */" > \n \n
- "#include <stdio.h>" \n
- "#include \""
- (file-name-sans-extension
- (file-name-nondirectory (buffer-file-name)))
- ".h\"" \n \n
- "int main ()\n"
- "{" \n
- > _ \n
- "return 1;\n"
- "}" > \n
- )))
-
-#+END_SRC
-
-*** Perl Auto Insert
-
-Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (eval-after-load 'autoinsert
- '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
- '(
- "Description: "
- "#!/usr/bin/perl -w" \n
- \n
- "use strict;" \n \n
- )))
-
-#+END_SRC
-
-** Completion
-
-company mode
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package company
- :ensure t
- :diminish company-mode
- :init (setq company-idle-delay 0.1)
- :config
- (global-company-mode))
-
-#+END_SRC
-
-[[https://github.com/company-mode/company-statistics][company-statistics]]
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-
- (use-package company-statistics
- :ensure t
- :config
- (company-statistics-mode))
-
-#+END_SRC
-
-* Todo
-
-- change M-o to trigger to delete other windows and restore previous config
-
+++ /dev/null
-
-;; Added by Package.el. This must come before configurations of
-;; installed packages. Don't delete this line. If you don't want it,
-;; just comment it out by adding a semicolon to the start of the line.
-;; You may delete these explanatory comments.
-(package-initialize)
-
-(org-babel-load-file "~/.emacs.d/config.org")