rename old emacs folder
[dotfiles.git] / emacs.d_2 / config.org
index 6c8ff38..b087ec4 100644 (file)
@@ -10,6 +10,18 @@ Most config are just copied from [[https://github.com/howardabrams/dot-files][ho
 
 ** 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
@@ -20,16 +32,17 @@ Set the emacs load path
 
 ** Package Initialization
 
-#+BEGIN_SRC emacs-lisp :tangle yes
+#+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
+#+END_SRC       
 
 ** General Setting
 
@@ -51,6 +64,15 @@ Disable scroll bar, tool-bar and menu-bar
 
 #+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
@@ -255,6 +277,28 @@ improve color for org-mode
 
 #+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
@@ -335,6 +379,118 @@ cause we cannot input =[= and =]=, so here I unset this mappings. And redifined
 
 ** 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.
@@ -423,7 +579,29 @@ Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for
 
 #+END_SRC
 
-* File and Buffer Operation
+** 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
 
@@ -446,6 +624,52 @@ Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
 
 #+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=
@@ -454,19 +678,29 @@ Some global bindings on =Super=, on Mac, it is =Command=
 
   (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-[") 'next-buffer)
-  (global-set-key (kbd "s-]") 'previous-buffer)
+  (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
@@ -536,14 +770,133 @@ I use the prefix =M-s= for searching in buffers
       (define-key keymap (car binding) (cdr binding)))
     (global-set-key key keymap))
 
-  (global-set-key (kbd "M-s M-s") 'isearch-forward-regexp)
-  (global-set-key (kbd "M-s M-r") 'isearch-forward-regexp)
+  (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
 
-  (define-key isearch-mode-map (kbd "M-s") 'isearch-forward-regexp)
+  ;; 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
-* Misc Settings
 
+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]]
 
@@ -646,6 +999,12 @@ Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-ex
   (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
@@ -783,9 +1142,128 @@ Type =o= to go to the link
     (persp-mode)
     :bind
     (:map projectile-mode-map
-          ("s-p" . projectile-persp-switch-project)))
+          ("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
@@ -801,6 +1279,8 @@ Type =o= to go to the link
 
     :diminish color-identifiers-mode)
 
+  (global-prettify-symbols-mode t)
+
 #+END_SRC
 
 **** Lispy Mode
@@ -986,7 +1466,18 @@ 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
-- 
+