+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
+
+** 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
+
+** 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
+
+** View only for some directory
+When see function by =C-h f=, and visit the source code, I would like the buffer is read only. See [[http://emacs.stackexchange.com/questions/3676/how-to-enter-view-only-mode-when-browsing-emacs-source-code-from-help/3681#3681][here]]
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (dir-locals-set-class-variables
+ 'emacs
+ '((nil . ((buffer-read-only . t)
+ (show-trailing-whitespace . nil)
+ (tab-width . 8)
+ (eval . (whitespace-mode -1))
+ (eval . (when buffer-file-name
+ (setq-local view-no-disable-on-exit t)
+ (view-mode-enter)))))))
+
+ ;; (dir-locals-set-directory-class (expand-file-name "/usr/local/share/emacs") 'emacs)
+ (dir-locals-set-directory-class "/usr/local/Cellar/emacs" 'emacs)
+ ;; (dir-locals-set-directory-class "~/.emacs.d/elpa" 'emacs)
+ (dir-locals-set-directory-class "~/dotfiles/emacs.d/elpa" 'emacs)
+ (dir-locals-set-directory-class "~/dotfiles/emacs.d/el-get" 'emacs)
+#+END_SRC
+
+** Info plus
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (el-get-bundle info+
+ :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/info+.el"
+ ;; (require 'info+)
+ )
+
+ (with-eval-after-load 'info
+ (require 'info+))
+#+END_SRC
+
+** TODO bookmark
+
+** TODO Calendar
+** advice info
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (defun sd/info-mode ()
+ (interactive)
+ (unless (equal major-mode 'Info-mode)
+ (unless (> (length (window-list)) 1)
+ (split-window-right))
+ (other-window 1)
+ ;; (info)
+ ))
+
+ ;; (global-set-key (kbd "C-h i") 'sd/info-mode)
+
+ ;; open Info buffer in other window instead of current window
+ (defadvice info (before my-info (&optional file buf) activate)
+ (sd/info-mode))
+
+ (defadvice Info-exit (after my-info-exit activate)
+ (sd/delete-current-window))
+#+END_SRC
+
+** TODO Man mode
+Color for Man-mode
+
+** TODO UTF8
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ ;; (set-language-environment "UTF-8")
+ ;; (set-default-coding-systems 'utf-8)
+#+END_SRC
+
+** Demo It
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ ;; (el-get-bundle howardabrams/demo-it)
+
+ (use-package org-tree-slide
+ :ensure t)
+
+ ;; (use-package yasnippet
+ ;; :ensure t)
+#+END_SRC
+
+** Presentation
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package org-tree-slide
+ :ensure
+ :config
+ ;; (define-key org-mode-map "\C-ccp" 'org-tree-slide-mode)
+ (define-key org-tree-slide-mode-map (kbd "<ESC>") 'org-tree-slide-content)
+ (define-key org-tree-slide-mode-map (kbd "<SPACE>") 'org-tree-slide-move-next-tree)
+ (define-key org-tree-slide-mode-map [escape] 'org-tree-slide-move-previous-tree))
+#+END_SRC
+
+** pdf-tools
+#+BEGIN_SRC sh
+ brew install poppler
+#+END_SRC
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package pdf-tools
+ :ensure t
+ :init
+ ;; run to complete the installation
+ (pdf-tools-install)
+ :config
+ (add-to-list 'auto-mode-alist '("\.pdf$" . pdf-view-mode))
+ (add-hook 'pdf-outline-buffer-mode-hook #'sd/pdf-outline-map))
+
+ (defun sd/pdf-outline-map ()
+ "My keybindings in pdf-outline-map"
+ (interactive)
+ (define-key pdf-outline-buffer-mode-map (kbd "C-o") nil)
+ (define-key pdf-outline-buffer-mode-map (kbd "i") 'outline-toggle-children)
+ (define-key pdf-outline-buffer-mode-map (kbd "j") 'next-line)
+ (define-key pdf-outline-buffer-mode-map (kbd "k") 'previous-line))
+#+END_SRC
+
+* Dired
+** Dired bindings
+=C-o= is defined as a global key for window operation, here unset it in dired mode
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (defun sd/dired-key-map ()
+ "My keybindings for dired"
+ (interactive)
+ ;; these two prefix are used globally
+ (define-key dired-mode-map (kbd "C-o") nil)
+ (define-key dired-mode-map (kbd "M-s") nil)
+ ;; toggle hidden files
+ (define-key dired-mode-map (kbd "H") 'dired-omit-mode)
+ ;; scroll
+ (define-key dired-mode-map (kbd "SPC") 'scroll-up-command)
+ (define-key dired-mode-map (kbd "DEL") 'scroll-down-command)
+ (define-key dired-mode-map (kbd "j") 'diredp-next-line)
+ (define-key dired-mode-map (kbd "k") 'diredp-previous-line)
+ (define-key dired-mode-map (kbd "g") 'dired-goto-file)
+ ;; (define-key dired-mode-map (kbd "S-SPC") 'scroll-down-command)
+ ;; jump to fil/dirs
+ (define-key dired-mode-map (kbd "f") 'dired-isearch-filenames)
+ ;; subdir
+ ;; i dired-maybe-insert-subdir
+ ;; o dired-find-file-other-window (switch to other window)
+ ;; O dired-display-file
+ (define-key dired-mode-map (kbd "G") 'ido-dired)
+ (define-key dired-mode-map (kbd "c") 'sd/dired-new-file)
+ (define-key dired-mode-map (kbd "h") 'dired-summary)
+ (define-key dired-mode-map (kbd "r") 'revert-buffer)
+ (define-key dired-mode-map (kbd "l") 'dired-display-file)
+ (define-key dired-mode-map [C-backspace] 'dired-up-directory)
+ (define-key dired-mode-map (kbd "?") 'describe-mode)
+ (define-key dired-mode-map (kbd "z") #'sd/dired-get-size)
+ (define-key dired-mode-map (kbd "C-d") 'dired-kill-subdir)
+ (define-key dired-mode-map (kbd "M-d") 'dired-kill-subdir)
+ (define-key dired-mode-map (kbd "J") 'diredp-next-subdir)
+ (define-key dired-mode-map (kbd "TAB") 'diredp-next-subdir)
+ (define-key dired-mode-map (kbd "K") 'diredp-prev-subdir)
+ (define-key dired-mode-map (kbd "O") 'dired-display-file)
+ (define-key dired-mode-map (kbd "I") 'other-window))
+
+ (use-package dired
+ :config
+ (require 'dired-x)
+ ;; also load dired+
+ (use-package dired+
+ :ensure t
+ :init (setq diredp-hide-details-initially-flag nil))
+
+ (setq dired-omit-mode t)
+ (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
+ (add-hook 'dired-mode-hook (lambda ()
+ (sd/dired-key-map)
+ (dired-omit-mode))))
+
+ (defadvice dired-summary (around sd/dired-summary activate)
+ "Revisied dired summary."
+ (interactive)
+ (dired-why)
+ (message
+ "Δ: d-delete, u-ndelete, x-punge, f-ind, o-ther window, R-ename, C-opy, c-create, +new dir, r-evert, /-filter, h-summary, ?-help"))
+
+ (defun sd/dired-high-level-dir ()
+ "Go to higher level directory"
+ (interactive)
+ (find-alternate-file ".."))
+#+END_SRC
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (defun sd/dired-new-file ()
+ "Create a new file in dired mode"
+ (interactive)
+ (call-interactively 'find-file))
+
+ ;; copied from abo-abo's config
+ (defun sd/dired-get-size ()
+ (interactive)
+ (let ((files (dired-get-marked-files)))
+ (with-temp-buffer
+ (apply 'call-process "/usr/bin/du" nil t nil "-sch" files)
+ (message
+ "Size of all marked files: %s"
+ (progn
+ (re-search-backward "\\(^[ 0-9.,]+[A-Za-z]+\\).*total$")
+ (match-string 1))))))
+#+END_SRC
+
+** disable ido when dired new file
+When create a new directory, I want to disalbe =ido= completion. see [[http://stackoverflow.com/questions/7479565/emacs-ido-mode-and-creating-new-files-in-directories-it-keeps-changing-the-dire][here]]. Thhis code snippets copied
+from [[https://emacs.stackexchange.com/questions/13713/how-to-disable-ido-in-dired-create-directory/13795#13795?newreg%3Ddb17c20f7af3490fb11cf15f1d888e9e][How to disable IDO in ‘dired-create-directory’]]
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (defun mk-anti-ido-advice (func &rest args)
+ "Temporarily disable IDO and call function FUNC with arguments ARGS."
+ (interactive)
+ (let ((read-file-name-function #'read-file-name-default))
+ (if (called-interactively-p 'any)
+ (call-interactively func)
+ (apply func args))))
+
+ (defun mk-disable-ido (command)
+ "Disable IDO when command COMMAND is called."
+ (advice-add command :around #'mk-anti-ido-advice))
+#+END_SRC
+
+Disalble =ido= when new a directory or file in =dired= mode
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ ;; call the function which you want to disable ido
+ (mk-disable-ido 'dired-create-directory)
+ (mk-disable-ido 'sd/dired-new-file)
+#+END_SRC
+
+** Dired open with
+=!= =dired-do-shell-command=
+=&= =dired-do-async-shell-command=
+here on Mac, just use "open" commands to pen =.pdf=, =.html= and image files
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (setq dired-guess-shell-alist-user
+ '(("\\.pdf\\'" "open" "okular")
+ ("\\.\\(?:djvu\\|eps\\)\\'" "evince")
+ ("\\.\\(?:jpg\\|jpeg\\|png\\|gif\\|xpm\\)\\'" "open")
+ ("\\.\\(?:xcf\\)\\'" "gimp")
+ ("\\.csv\\'" "libreoffice")
+ ("\\.tex\\'" "pdflatex" "latex")
+ ("\\.\\(?:mp4\\|mkv\\|avi\\|flv\\|ogv\\)\\(?:\\.part\\)?\\'" "mplayer")
+ ("\\.\\(?:mp3\\|flac\\)\\'" "rhythmbox")
+ ("\\.html?\\'" "open")
+ ("\\.dmg\\'" "open")
+ ("\\.cue?\\'" "audacious")))
+
+
+ (defun sd/dired-start-process (cmd &optional file-list)
+ (interactive
+ (let ((files (dired-get-marked-files
+ t current-prefix-arg)))
+ (list
+ (unless (eq system-type 'windows-nt)
+ (dired-read-shell-command "& on %s: "
+ current-prefix-arg files))
+ files)))
+
+ (if (eq system-type 'windows-nt)
+ (dolist (file file-list)
+ (w32-shell-execute "open" (expand-file-name file)))
+ (let (list-switch)
+ (start-process
+ cmd nil shell-file-name
+ shell-command-switch
+ (format
+ "nohup 1>/dev/null 2>/dev/null %s \"%s\""
+ cmd
+ ;; (if (and (> (length file-list) 1)
+ ;; (setq list-switch
+ ;; (cadr (assoc cmd ora-dired-filelist-cmd))))
+ ;; (format "%s %s" cmd list-switch)
+ ;; cmd)
+ (mapconcat #'expand-file-name file-list "\" \""))))))
+#+END_SRC
+
+** dired-hacks
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package dired-hacks-utils
+ :ensure t
+ :defer t)
+#+END_SRC
+
+** dired-narrow
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ ;;narrow dired to match filter
+ (use-package dired-narrow
+ :ensure t
+ :commands (dired-narrow)
+ :bind (:map dired-mode-map
+ ("/" . dired-narrow)))
+#+END_SRC
+
+* Ibuffer
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (global-set-key (kbd "s-b") 'ibuffer)
+
+ (with-eval-after-load 'ibuffer
+ (define-key ibuffer-mode-map (kbd "C-o") nil)
+ (define-key ibuffer-mode-map (kbd "j") 'ibuffer-forward-line)
+ (define-key ibuffer-mode-map (kbd "k") 'ibuffer-backward-line)
+ (define-key ibuffer-mode-map (kbd "r") 'ibuffer-update)
+ (define-key ibuffer-mode-map (kbd "g") 'ibuffer-jump-to-buffer)
+ (define-key ibuffer-mode-map (kbd "h") 'sd/ibuffer-summary))
+
+ (defun sd/ibuffer-summary ()
+ "Show summary of keybindings in ibuffer mode"
+ (interactive)
+ (message
+ "Β: m|u - (un)mark, /-filter, //-remove filter, t, RET, g, k, S, D, Q; q to quit; h for help"))
+#+END_SRC
+
+* Completion
+company mode and company-statistics
+#+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))
+
+ (use-package company-statistics
+ :ensure t
+ :config
+ (company-statistics-mode))
+#+END_SRC
+
+* Programming Language
+** 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
+
+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
+*** CPerl mode
+[[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++")))
+
+ (defalias 'perldoc 'cperl-perldoc)
+#+END_SRC
+
+*** Perl template
+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")
+ '(
+ "Empty"
+ "#!/usr/bin/perl -w" \n
+ \n
+ "use strict;" > \n \n
+ > _
+ )))
+#+END_SRC
+
+*** Perl Keywords
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (font-lock-add-keywords 'cperl-mode
+ '(("\\(say\\)" . cperl-nonoverridable-face)
+ ("\\([0-9.]\\)*" . font-lock-constant-face)
+ ("\".*\\(\\\n\\).*\"" . font-lock-constant-face)
+ ("\n" . font-lock-constant-face)
+ ("\\(^#!.*\\)$" . cperl-nonoverridable-face)))
+
+ ;; (font-lock-add-keywords 'Man-mode
+ ;; '(("\\(NAME\\)" . font-lock-function-name-face)))
+
+#+END_SRC
+
+*** Run Perl
+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++
+*** c/c++ style
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (setq c-default-style "stroustrup"
+ c-basic-offset 4)
+#+END_SRC
+
+*** flycheck
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package flycheck
+ :ensure t)
+#+END_SRC
+
+*** irony
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package irony
+ :ensure t
+ :config
+ (add-hook 'c++-mode-hook 'irony-mode)
+ (add-hook 'c-mode-hook 'irony-mode)
+ (add-hook 'objc-mode-hook 'irony-mode))
+#+END_SRC
+
+Install clang, on mac, it has =libclang.dylib=, but no develop headers. Install by =brew=
+#+BEGIN_SRC sh
+ brew install llvm --with-clang
+#+END_SRC
+
+then install irony searver, and =LIBCLANG_LIBRARY= and =LIBCLANG_INCLUDE_DIR= accordingly
+#+BEGIN_SRC emacs-lisp :tangle no :results silent
+ (irony-install-server)
+#+END_SRC
+
+#+BEGIN_SRC sh
+ cmake -DLIBCLANG_LIBRARY\=/usr/local/Cellar/llvm/3.6.2/lib/libclang.dylib \
+ -DLIBCLANG_INCLUDE_DIR=/usr/local/Cellar/llvm/3.6.2/include \
+ -DCMAKE_INSTALL_PREFIX\=/Users/peli3/.emacs.d/irony/ \
+ /Users/peli3/.emacs.d/elpa/irony-20160713.1245/server && cmake --build . --use-stderr --config Release --target install
+#+END_SRC
+
+irony-mode-hook, copied from [[https://github.com/Sarcasm/irony-mode][irony-mode]] github
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ ;; replace the `completion-at-point' and `complete-symbol' bindings in
+ ;; irony-mode's buffers by irony-mode's function
+ (defun my-irony-mode-hook ()
+ (define-key irony-mode-map [remap completion-at-point]
+ 'irony-completion-at-point-async)
+ (define-key irony-mode-map [remap complete-symbol]
+ 'irony-completion-at-point-async))
+ (add-hook 'irony-mode-hook 'my-irony-mode-hook)
+ (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
+#+END_SRC
+
+irony-company
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package company-irony
+ :ensure t)
+
+ (eval-after-load 'company
+ '(add-to-list 'company-backends 'company-irony))
+
+ (use-package flycheck-irony
+ :ensure t)
+
+ (eval-after-load 'flycheck
+ '(add-hook 'flycheck-mode-hook #'flycheck-irony-setup))
+#+END_SRC
+
+*** yasnippet
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package yasnippet
+ :ensure t)
+#+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))
+ (setq compilation-auto-jump-to-first-error t)
+ (setq compilation-auto-jump-to-next t)
+ (setq compilation-scroll-output 'first-error))
+
+ ;; super-r to compile
+ (with-eval-after-load "compile"
+ (define-key compilation-mode-map (kbd "C-o") nil)
+ (define-key compilation-mode-map (kbd "n") 'compilation-next-error)
+ (define-key compilation-mode-map (kbd "p") 'compilation-previous-error)
+ (define-key compilation-mode-map (kbd "r") #'recompile))
+#+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
+
+** Python template
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (eval-after-load 'autoinsert
+ '(define-auto-insert '("\\.\\(py\\)\\'" . "Python skeleton")
+ '(
+ "Empty"
+ "#import os,sys" \n
+ \n \n
+ )))
+#+END_SRC
+
+** Elisp
+Emacs lisp auto-insert, based on the default module in =autoinsert.el=, but replace =completing-read= as
+=completing-read-ido-ubiquitous= to fix the edge case of that =ido= cannot handle.
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (eval-after-load 'autoinsert
+ '(define-auto-insert '("\\.el\\'" . "my Emacs Lisp header")
+ '(
+ "Short description: "
+ ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str
+ (make-string (max 2 (- 80 (current-column) 27)) ?\s)
+ "-*- lexical-binding: t; -*-" '(setq lexical-binding t)
+ "\n
+ ;; Copyright (C) " (format-time-string "%Y") " "
+ (getenv "ORGANIZATION") | (progn user-full-name) "
+
+ ;; Author: " (user-full-name)
+ '(if (search-backward "&" (line-beginning-position) t)
+ (replace-match (capitalize (user-login-name)) t t))
+ '(end-of-line 1) " <" (progn user-mail-address) ">
+ ;; Keywords: "
+ '(require 'finder)
+ ;;'(setq v1 (apply 'vector (mapcar 'car finder-known-keywords)))
+ '(setq v1 (mapcar (lambda (x) (list (symbol-name (car x))))
+ finder-known-keywords)
+ v2 (mapconcat (lambda (x) (format "%12s: %s" (car x) (cdr x)))
+ finder-known-keywords
+ "\n"))
+ ((let ((minibuffer-help-form v2))
+ (completing-read-ido-ubiquitous "Keyword, C-h: " v1 nil t))
+ str ", ") & -2 "
+
+ \;; This program is free software; you can redistribute it and/or modify
+ \;; it under the terms of the GNU General Public License as published by
+ \;; the Free Software Foundation, either version 3 of the License, or
+ \;; (at your option) any later version.
+
+ \;; This program is distributed in the hope that it will be useful,
+ \;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+ \;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ \;; GNU General Public License for more details.
+
+ \;; You should have received a copy of the GNU General Public License
+ \;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ \;;; Commentary:
+
+ \;; " _ "
+
+ \;;; Code:
+
+
+ \(provide '"
+ (file-name-base)
+ ")
+ \;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")))
+#+END_SRC
+
+** Org file template
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (eval-after-load 'autoinsert
+ '(define-auto-insert '("\\.\\(org\\)\\'" . "Org-mode skeleton")
+ '(
+ "title: "
+ "#+TITLE: " str (make-string 30 ?\s) > \n
+ "#+AUTHOR: Peng Li\n"
+ "#+EMAIL: seudut@gmail.com\n"
+ "#+DATE: " (shell-command-to-string "echo -n $(date +%Y-%m-%d)") > \n
+ > \n
+ > _)))
+#+END_SRC
+
+* Markdown mode
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package markdown-mode
+ :ensure t
+ :commands (markdown-mode gfm-mode)
+ :mode (("README\\.md\\'" . gfm-mode)
+ ("\\.md\\'" . markdown-mode)
+ ("\\.markdown\\'" . markdown-mode))
+ :init (setq markdown-command "multimarkdown"))
+#+END_SRC
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package markdown-preview-eww
+ :ensure t)
+#+END_SRC
+
+* Gnus
+** Gmail setting
+Refer [[https://www.emacswiki.org/emacs/GnusGmail][GnusGmail]]
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (setq user-mail-address "seudut@gmail.com"
+ user-full-name "Peng Li")
+
+ (setq gnus-select-method
+ '(nnimap "gmail"
+ (nnimap-address "imap.gmail.com")
+ (nnimap-server-port "imaps")
+ (nnimap-stream ssl)))
+
+ (setq smtpmail-smtp-service 587
+ gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
+
+ ;; Use gmail sending mail
+ (setq message-send-mail-function 'smtpmail-send-it
+ smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
+ smtpmail-auth-credentials '(("smtp.gmail.com" 587 "seudut@gmail.com" nil))
+ smtpmail-default-smtp-server "smtp.gmail.com"
+ smtpmail-smtp-server "smtp.gmail.com"
+ smtpmail-smtp-service 587
+ starttls-use-gnutls t)
+#+END_SRC
+
+And put the following in =~/.authinfo= file, replacing =<USE>= with your email address
+and =<PASSWORD>= with the password
+#+BEGIN_EXAMPLE
+ machine imap.gmail.com login <USER> password <PASSWORD> port imaps
+ machine smtp.gmail.com login <USER> password <PASSWORD> port 587
+#+END_EXAMPLE
+
+Then Run =M-x gnus=
+
+** Group buffer
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package gnus
+ :init
+ (setq gnus-permanently-visible-groups "\.*")
+ :config
+ (cond (window-system
+ (setq custom-background-mode 'light)
+ (defface my-group-face-1
+ '((t (:foreground "Red" :bold t))) "First group face")
+ (defface my-group-face-2
+ '((t (:foreground "DarkSeaGreen4" :bold t)))
+ "Second group face")
+ (defface my-group-face-3
+ '((t (:foreground "Green4" :bold t))) "Third group face")
+ (defface my-group-face-4
+ '((t (:foreground "SteelBlue" :bold t))) "Fourth group face")
+ (defface my-group-face-5
+ '((t (:foreground "Blue" :bold t))) "Fifth group face")))
+ (setq gnus-group-highlight
+ '(((> unread 200) . my-group-face-1)
+ ((and (< level 3) (zerop unread)) . my-group-face-2)
+ ((< level 3) . my-group-face-3)
+ ((zerop unread) . my-group-face-4)
+ (t . my-group-face-5))))
+
+
+ ;; key-
+ (add-hook 'gnus-group-mode-hook (lambda ()
+ (define-key gnus-group-mode-map "k" 'gnus-group-prev-group)
+ (define-key gnus-group-mode-map "j" 'gnus-group-next-group)
+ (define-key gnus-group-mode-map "g" 'gnus-group-jump-to-group)
+ (define-key gnus-group-mode-map "v" (lambda () (interactive) (gnus-group-select-group t)))))
+#+END_SRC
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (setq gnus-fetch-old-headers 't)
+
+
+
+ (setq gnus-extract-address-components
+ 'mail-extract-address-components)
+ ;; summary buffer
+ (setq gnus-summary-line-format "%U%R%z%I%(%[%-20,20f%]%) %s%-80= %11&user-date;\n")
+ (setq gnus-user-date-format-alist '(((gnus-seconds-today) . "%H:%M")
+ ((+ 86400 (gnus-seconds-today)) . "%a %H:%M")
+ (604800 . "%a, %b %-d")
+ (15778476 . "%b %-d")
+ (t . "%Y-%m-%d")))
+
+ (setq gnus-thread-sort-functions '((not gnus-thread-sort-by-number)))
+ (setq gnus-unread-mark ?\.)
+ (setq gnus-use-correct-string-widths t)
+
+ ;; thread
+ (setq gnus-thread-hide-subtree t)
+
+ ;; (with-eval-after-load 'gnus-summary-mode
+ ;; (define-key gnus-summary-mode-map (kbd "C-o") 'sd/hydra-window/body))
+
+ (add-hook 'gnus-summary-mode-hook (lambda ()
+ (define-key gnus-summary-mode-map (kbd "C-o") nil)))
+
+
+#+END_SRC
+
+** Windows layout
+See [[https://www.emacswiki.org/emacs/GnusWindowLayout][GnusWindowLayout]]
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (gnus-add-configuration
+ '(summary
+ (horizontal 1.0
+ (vertical 35
+ (group 1.0))
+ (vertical 1.0
+ (summary 1.0 poine)))))
+
+ (gnus-add-configuration
+ '(article
+ (horizontal 1.0
+ (vertical 35
+ (group 1.0))
+ (vertical 1.0
+ (summary 0.50 point)
+ (article 1.0)))))
+
+ (with-eval-after-load 'gnus-group-mode
+ (gnus-group-select-group "INBOX"))
+ ;; (add-hook 'gnus-group-mode-map (lambda ()
+ ;; (gnus-group-select-group "INBOX")))
+#+END_SRC
+
+* Gnu Plot
+To fix some issue that =toolbar-make-button-list= is void, see the [[https://github.com/bruceravel/gnuplot-mode/issues/31][issue]], here I set some variable as =nil=
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package gnuplot
+ :ensure
+ :init
+ (setq gnuplot-help-xpm nil)
+ (setq gnuplot-line-xpm nil)
+ (setq gnuplot-region-xpm nil)
+ (setq gnuplot-buffer-xpm nil)
+ (setq gnuplot-doc-xpm nil))
+#+END_SRC
+
+Use =gnuplot= on =Org-mode= file, see [[http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-gnuplot.html][ob-doc-gnuplot]]
+#+BEGIN_SRC gnuplot :exports code :file ./temp/file.png
+ reset
+
+ set title "Putting it All Together"
+
+ set xlabel "X"
+ set xrange [-8:8]
+ set xtics -8,2,8
+
+
+ set ylabel "Y"
+ set yrange [-20:70]
+ set ytics -20,10,70
+
+ f(x) = x**2
+ g(x) = x**3
+ h(x) = 10*sqrt(abs(x))
+
+ plot f(x) w lp lw 1, g(x) w p lw 2, h(x) w l lw 3
+#+END_SRC
+
+#+RESULTS:
+[[file:./temp/file.png]]
+* Ediff
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (with-eval-after-load 'ediff
+ (setq ediff-split-window-function 'split-window-horizontally)
+ (setq ediff-window-setup-function 'ediff-setup-windows-plain)
+ (add-hook 'ediff-startup-hook 'ediff-toggle-wide-display)
+ (add-hook 'ediff-cleanup-hook 'ediff-toggle-wide-display)
+ (add-hook 'ediff-suspend-hook 'ediff-toggle-wide-display))
+#+END_SRC
+
+* Entertainment
+** 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
+
+** 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-directory (concat sd-temp-directory "emms"))
+ (setq emms-source-file-default-directory "~/Music/")
+ :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
+
+* Dictionary
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package bing-dict
+ :ensure t
+ :init
+ (global-set-key (kbd "s-d") 'bing-dict-brief)
+ :commands (bing-dict-brief))
+#+END_SRC
+
+* Key Bindings
+Here are some global key bindings for basic editting
+** Esc in minibuffer
+Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent