emacs - add temp directory for chace and history files
[dotfiles.git] / emacs.d / config.org
1 #+TITLE: Emacs Configuration file
2 #+AUTHOR: Peng Li
3 #+EMAIL: seudut@gmail.com
4
5 * Introduction
6
7 Most config are just copied from [[https://github.com/howardabrams/dot-files][howardabrams]]'s and [[https://github.com/abo-abo/oremacs][abo-abo's]] dotfiles
8
9 * Basic Settings
10 ** Setting loading Path
11
12 Set system PATH and emacs exec path
13
14 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
15
16   (setenv "PATH" (concat (getenv "PATH")
17                          ":" "/usr/local/bin"
18                          ":" "/Library/TeX/texbin"))
19   (setq exec-path (append exec-path '("/usr/local/bin")))
20   (setq exec-path (append exec-path '("/Library/TeX/texbin/")))
21
22 #+END_SRC
23
24 Set the emacs load path
25
26 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
27   ;; (add-to-list 'load-path "~/.emacs.d/elisp")
28 #+END_SRC
29
30 ** Package Initialization
31
32 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
33
34   (require 'package)
35
36   (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
37                            ("gnu" . "http://elpa.gnu.org/packages/")
38                            ("org" . "http://orgmode.org/elpa/")))
39
40   (package-initialize)
41
42 #+END_SRC       
43
44 ** General Setting
45 *** scroll bar, tool-bar and menu-bar
46 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
47   (scroll-bar-mode 0)
48   (tool-bar-mode 0)
49   (menu-bar-mode 1)
50
51   ;; (setq debug-on-error t)
52   (setq inhibit-startup-message t)
53
54   (defalias 'yes-or-no-p 'y-or-n-p)
55   (show-paren-mode 1)
56   ;; don't backupf
57   (setq make-backup-files nil)
58 #+END_SRC
59
60 *** Custom file 
61 #+BEGIN_SRC emacs-lisp :tangle yes :results silent 
62   (setq custom-file "~/.emacs.d/custom.el")
63   (if (file-exists-p custom-file)
64       (load custom-file))
65 #+END_SRC
66
67 *** Switch the focus to help window when it appears
68 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
69   (setq help-window-select t)
70 #+END_SRC
71
72 *** Set default window size
73 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
74   (setq initial-frame-alist
75         '((width . 120)
76           (height . 50)))
77 #+END_SRC
78
79 *** Stop auto save
80 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
81   (setq auto-save-default nil)
82
83   ;; restore last session
84   ;; (desktop-save-mode t)
85 #+END_SRC
86
87 *** Save minibuffer history
88 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
89   (savehist-mode 1)
90   (setq history-length 1000)
91 #+END_SRC
92
93 *** temp folder
94 Make a temp directory for all cache/history files
95 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
96   (defconst sd-temp-directory
97     (file-name-as-directory "~/.emacs.d/temp"))
98
99   (unless (file-exists-p sd-temp-directory)
100     (mkdir sd-temp-directory))
101 #+END_SRC
102
103 * Package Management Tools
104
105 ** Use-package
106
107 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
108
109 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
110
111   (unless (package-installed-p 'use-package)
112     (package-refresh-contents)
113     (package-install 'use-package))
114
115   (require 'use-package)
116
117 #+END_SRC
118
119 ** El-get
120
121 [[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. 
122 Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
123
124 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
125
126   (use-package el-get
127     :ensure t
128     :init
129     (add-to-list 'load-path "~/.emacs.d/el-get"))
130
131 #+END_SRC
132
133 * Color and Fonts Settings
134
135 ** highlight current line
136
137 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
138
139   (global-hl-line-mode)
140
141 #+END_SRC
142
143 ** Smart Comments
144
145 [[https://github.com/paldepind/smart-comment][smart-comments]]
146
147 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
148
149   (use-package smart-comment
150     :ensure t
151     :bind ("M-;" . smart-conmment))
152
153 #+END_SRC
154
155 ** Font Setting
156
157 syntax highlighting
158
159 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
160
161   (global-font-lock-mode 1)
162
163 #+END_SRC
164
165 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
166
167 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
168
169   (if window-system
170       (defvar sd/fixed-font-family
171         (cond ((x-list-fonts "Hasklig")         "Hasklig")
172               ((x-list-fonts "Source Code Pro") "Source Code Pro:weight:light")
173               ((x-list-fonts "Anonymous Pro")   "Anonymous Pro")
174               ((x-list-fonts "M+ 1mn")          "M+ 1mn"))
175         "The fixed width font based on what is installed, `nil' if not defined."))
176
177 #+END_SRC
178
179 Setting the fonts 
180
181 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
182
183   (if window-system
184       (when sd/fixed-font-family
185         (set-frame-font sd/fixed-font-family)
186         (set-face-attribute 'default nil :font sd/fixed-font-family :height 130)
187         (set-face-font 'default sd/fixed-font-family)))
188
189 #+END_SRC
190
191 ** Color Theme
192
193 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
194
195 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
196
197   (setq vc-follow-symlinks t)
198
199   (use-package color-theme
200     :ensure t
201     :init (require 'color-theme)
202     :config (use-package color-theme-sanityinc-tomorrow
203               :ensure t
204               :no-require t
205               :config
206               (load-theme 'sanityinc-tomorrow-bright t)))
207
208   ;(eval-after-load 'color-theme
209   ;  (load-theme 'sanityinc-tomorrow-bright t))
210
211 #+END_SRC
212
213 Change the Org-mode colors 
214
215 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
216
217   (defun org-src-color-blocks-light ()
218     "Colors the block headers and footers to make them stand out more for lighter themes"
219     (interactive)
220     (custom-set-faces
221      '(org-block-begin-line
222       ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
223      '(org-block-background
224        ((t (:background "#FFFFEA"))))
225      '(org-block
226        ((t (:background "#FFFFEA"))))
227      '(org-block-end-line
228        ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
229
230      '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
231      '(which-func ((t (:foreground "#008000"))))))
232
233   (defun org-src-color-blocks-dark ()
234     "Colors the block headers and footers to make them stand out more for dark themes"
235     (interactive)
236     (custom-set-faces
237      '(org-block-begin-line
238        ((t (:foreground "#008ED1" :background "#002E41"))))
239      '(org-block-background
240        ((t (:background "#000000"))))
241      '(org-block
242        ((t (:background "#000000"))))
243      '(org-block-end-line
244        ((t (:foreground "#008ED1" :background "#002E41"))))
245
246      '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
247      '(which-func ((t (:foreground "green"))))))
248
249   (org-src-color-blocks-dark)
250
251 #+END_SRC
252
253 improve color for org-mode
254 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
255   (deftheme ha/org-theme "Sub-theme to beautify org mode")
256
257   (if window-system
258       (defvar sd/variable-font-tuple
259         (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
260               ((x-list-fonts "Lucida Grande")   '(:font "Lucida Grande"))
261               ((x-list-fonts "Verdana")         '(:font "Verdana"))
262               ((x-family-fonts "Sans Serif")    '(:family "Sans Serif"))
263               (nil (warn "Cannot find a Sans Serif Font.  Install Source Sans Pro.")))
264         "My variable width font available to org-mode files and whatnot."))
265
266   (defun sd/org-color ()
267     (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
268            (base-font-color     (face-foreground 'default nil 'default))
269            (background-color    (face-background 'default nil 'default))
270            (primary-color       (face-foreground 'mode-line nil))
271            (secondary-color     (face-background 'secondary-selection nil 'region))
272            (base-height         (face-attribute 'default :height))
273            (headline           `(:inherit default :weight bold :foreground ,base-font-color)))
274       (custom-theme-set-faces 'ha/org-theme
275                               `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
276                               `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
277                               `(org-table ((t (:inherit 'fixed-pitched))))
278                               `(org-block ((t (:inherit 'fixed-pitched))))
279                               `(org-block-background ((t (:inherit 'fixed-pitched))))
280                               `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
281                               `(org-block-end-line ((t (:inherit 'fixed-pitched))))
282                               `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
283                               `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
284                               `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
285                               `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
286                               `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
287                                                             :height ,(round (* 1.1 base-height))))))
288                               `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
289                                                             :height ,(round (* 1.25 base-height))))))
290                               `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
291                                                             :height ,(round (* 1.5 base-height))))))
292                               `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
293                                                             :height ,(round (* 1.75 base-height))))))
294                               `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
295
296
297 #+END_SRC
298
299 ** Rainbow-delimiter
300
301 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
302
303   (use-package rainbow-delimiters
304     :ensure t
305     :init
306     (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
307
308 #+END_SRC
309
310 ** page-break-lines
311
312 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
313
314   (use-package page-break-lines
315     :ensure t
316     :config
317     (turn-on-page-break-lines-mode))
318
319 #+END_SRC
320
321 ** rainbow-mode
322
323 Enable rainbow mode in emacs lisp mode
324
325 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
326   (use-package rainbow-mode
327     :ensure t
328   ;  :init
329   ;  (add-hook emacs-lisp-mode-hook 'rainbow-mode)
330     )
331
332 #+END_SRC
333
334 * Mode-line
335
336 ** clean mode line
337
338 clean mode line, Refer to [[https://www.masteringemacs.org/article/hiding-replacing-modeline-strings][Marstering Emacs]]
339
340 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
341   (defvar mode-line-cleaner-alist
342     `((auto-complete-mode . " Î±")
343       (yas/minor-mode . " Ï…")
344       (paredit-mode . " Ï€")
345       (eldoc-mode . "")
346       (abbrev-mode . "")
347       (projectile-mode . "")
348       (ivy-mode . "")
349       (undo-tree-mode . "")
350       ;; default is WK
351       (which-key-mode . "")
352       ;; default is SP
353       (smartparens-mode . "")
354       ;; default is LR
355       (linum-relative-mode . "")
356       ;; default is ARev
357       (auto-revert-mode . "")
358       ;; default is Ind
359       (org-indent-mode . "")
360       ;; default is  Fly
361       (flyspell-mode . "")
362       ;; Major modes
363       (lisp-interaction-mode . "λ")
364       (hi-lock-mode . "")
365       (python-mode . "Py")
366       (emacs-lisp-mode . "EL")
367       (eshell-mode . "ε")
368       (nxhtml-mode . "nx"))
369     "Alist for `clean-mode-line'.
370
371   When you add a new element to the alist, keep in mind that you
372   must pass the correct minor/major mode symbol and a string you
373   want to use in the modeline *in lieu of* the original.")
374
375
376   (defun clean-mode-line ()
377     (interactive)
378     (loop for cleaner in mode-line-cleaner-alist
379           do (let* ((mode (car cleaner))
380                    (mode-str (cdr cleaner))
381                    (old-mode-str (cdr (assq mode minor-mode-alist))))
382                (when old-mode-str
383                    (setcar old-mode-str mode-str))
384                  ;; major mode
385                (when (eq mode major-mode)
386                  (setq mode-name mode-str)))))
387
388
389   (add-hook 'after-change-major-mode-hook 'clean-mode-line)
390 #+END_SRC
391
392 ** Powerline mode
393
394 Install powerline mode [[https://github.com/milkypostman/powerline][powerline]]
395
396 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
397   (use-package powerline
398     :ensure t
399     :config
400     ;; (powerline-center-theme)
401     )
402
403   ;; (use-package smart-mode-line
404   ;;   :ensure t)
405   ;; (use-package smart-mode-line-powerline-theme
406   ;;   :ensure t)
407 #+END_SRC
408
409 Revised powerline-center-theme
410 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
411   (defun sd/powerline-simpler-vc (s)
412     (if s
413         (replace-regexp-in-string "Git[:-]" "" s)
414       s))
415
416   (defface sd/powerline-active1 '((t (:background "yellow" :foreground "black" :inherit mode-line)))
417     "My Powerline face 1 based on powerline-active1."
418     :group 'powerline)
419
420   (defface sd/buffer-modified-active1 '((t (:background "red" :foreground "black" :inherit mode-line)))
421     "My Powerline face 1 based on powerline-active1."
422     :group 'powerline)
423
424   (defface sd/buffer-view-active1 '((t (:background "green" :foreground "black" :inherit mode-line)))
425     "My Powerline face 1 based on powerline-active1."
426     :group 'powerline)
427
428   (defface sd/mode-line-buffer-id
429     '((t (:background "yellow" :foreground "black" :inherit mode-line-buffer-id)))
430     "My powerline mode-line face, based on mode-line-buffer-id"
431     :group 'powerline)
432
433   ;; Don't show buffer modified for scratch and eshell mode
434   (defun sd/buffer-show-modified ()
435     "Dot not show modified indicator for buffers"
436     (interactive)
437     (unless (or (string-match "*scratch*" (buffer-name))
438                 (equal major-mode 'eshell-mode))
439       t))
440
441   (defun sd/powerline-center-theme_revised ()
442     "Setup a mode-line with major and minor modes centered."
443     (interactive)
444     (setq-default mode-line-format
445                   '("%e"
446                     (:eval
447                      (let* ((active (powerline-selected-window-active))
448                             (mode-line-buffer-id (if active 'sd/mode-line-buffer-id 'mode-line-buffer-id-inactive))
449                             (mode-line (if active 'mode-line 'mode-line-inactive))
450                             (my-face1 (if active 'sd/powerline-active1 'powerline-inactive1))
451                             (my-face-buffer-modified (if (and (sd/buffer-show-modified) (buffer-modified-p)) 
452                                                          'sd/buffer-modified-active1
453                                                        (if buffer-read-only 'sd/buffer-view-active1
454                                                          my-face1)))
455                             (face1 (if active 'powerline-active1 'powerline-inactive1))
456                             (face2 (if active 'powerline-active2 'powerline-inactive2))
457                             (separator-left (intern (format "powerline-%s-%s"
458                                                             (powerline-current-separator)
459                                                             (car powerline-default-separator-dir))))
460                             (separator-right (intern (format "powerline-%s-%s"
461                                                              (powerline-current-separator)
462                                                              (cdr powerline-default-separator-dir))))
463                             (lhs (list (powerline-raw "%* " my-face-buffer-modified 'l)
464                                        ;; (powerline-buffer-size mode-line 'l)
465                                        (powerline-buffer-id mode-line-buffer-id 'l)
466                                        (powerline-raw " " my-face1)
467                                        (funcall separator-left my-face1 face1)
468                                        (powerline-narrow face1 'l)
469                                        ;; (powerline-vc face1)
470                                        (sd/powerline-simpler-vc (powerline-vc face1))))
471                             (rhs (list (powerline-raw global-mode-string face1 'r)
472                                        (powerline-raw "%4l" face1 'r)
473                                        (powerline-raw ":" face1)     
474                                        (powerline-raw "%3c" face1 'r)
475                                        (funcall separator-right face1 my-face1)
476                                        ;; (powerline-raw " " my-face1)
477                                        (powerline-raw (format-time-string " %I:%M %p  ") my-face1 'r)
478                                        ;; (powerline-raw "%6p" my-face1 'r)
479                                        ;; (powerline-hud my-face1 face1 )
480                                        ))
481                             (center (list (powerline-raw " " face1)
482                                           (funcall separator-left face1 face2)
483                                           (when (and (boundp 'erc-track-minor-mode) erc-track-minor-mode)
484                                             (powerline-raw erc-modified-channels-object face2 'l))
485                                           (powerline-major-mode face2 'l)
486                                           (powerline-process face2)
487                                           (powerline-raw " :" face2)
488                                           (powerline-minor-modes face2 'l)
489                                           (powerline-raw " " face2)
490                                           (funcall separator-right face2 face1))))
491                        (concat (powerline-render lhs)
492                                (powerline-fill-center face1 (/ (powerline-width center) 2.0))
493                                (powerline-render center)
494                                (powerline-fill face1 (powerline-width rhs))
495                                (powerline-render rhs)))))))
496
497   (sd/powerline-center-theme_revised)
498 #+END_SRC
499
500 Fix the issue in mode line when showing triangle 
501 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
502   (setq ns-use-srgb-colorspace nil)
503 #+END_SRC
504
505 set height in mode line
506 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
507   (set-variable 'powerline-height 14)
508   (set-variable 'powerline-text-scale-factor (/ (float 100) 140))
509   ;; (custom-set-variables
510   ;;  '(powerline-height 14)
511   ;;  '(powerline-text-scale-factor (/ (float 100) 140)))
512   ;; 100/140;0.8
513   (set-face-attribute 'mode-line nil :height 100)
514 #+END_SRC
515
516 * IDO & SMEX
517
518 ** IDO
519
520 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
521
522   (use-package ido
523     :ensure t
524     :init (setq ido-enable-flex-matching t
525                 ido-ignore-extensions t
526                 ido-use-virtual-buffers t
527                 ido-everywhere t)
528     :config
529     (ido-mode 1)
530     (ido-everywhere 1)
531     (add-to-list 'completion-ignored-extensions ".pyc"))
532
533   (icomplete-mode t)
534
535 #+END_SRC
536
537 ** FLX
538
539 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
540
541   (use-package flx-ido
542     :ensure t
543     :init (setq ido-enable-flex-matching t
544                 ido-use-faces nil)
545     :config (flx-ido-mode 1))
546
547 #+END_SRC
548
549 ** IDO-vertically
550 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
551   (use-package ido-vertical-mode
552     :ensure t
553     :init
554     (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
555     :config
556     (ido-vertical-mode 1))
557 #+END_SRC
558
559 ** SMEX
560
561 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
562
563   (use-package smex
564     :ensure t
565     :init (smex-initialize)
566     :bind
567     ("M-x" . smex)
568     ("M-X" . smex-major-mode-commands))
569
570 #+END_SRC
571
572 ** Ido-ubiquitous
573
574 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
575
576 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
577
578   (use-package ido-ubiquitous
579     :ensure t
580     :init
581     (setq magit-completing-read-function 'magit-ido-completing-read)
582     (setq gnus-completing-read-function 'gnus-ido-completing-read)
583     :config
584     (ido-ubiquitous-mode 1))
585
586 #+END_SRC
587
588 ** Ido-exit-target
589 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
590 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
591   (use-package ido-exit-target
592     :ensure t
593     :init
594     (mapcar (lambda (map)
595               (define-key map (kbd "C-j") #'ido-exit-target-split-window-right)
596               (define-key map (kbd "C-k") #'ido-exit-target-split-window-below))
597             (list ido-buffer-completion-map
598                   ;; ido-common-completion-map
599                   ido-file-completion-map
600                   ido-file-dir-completion-map)))
601 #+END_SRC
602
603 * Normal Text Operation
604 ** Edit
605 *** undo-tree
606 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
607   (use-package undo-tree
608     :ensure t
609     :config
610     (define-key undo-tree-visualizer-mode-map "j" 'undo-tree-visualize-redo)
611     (define-key undo-tree-visualizer-mode-map "k" 'undo-tree-visualize-undo)
612     (define-key undo-tree-visualizer-mode-map "h" 'undo-tree-visualize-switch-branch-left)
613     (define-key undo-tree-visualizer-mode-map "l" 'undo-tree-visualize-switch-branch-right)
614     (global-undo-tree-mode 1))
615
616   (global-set-key (kbd "s-u") 'undo-tree-visualize)
617 #+END_SRC
618
619 *** flyspell
620 Stolen from [[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-spelling.el][here]], hunspell will search dictionary in =DICPATH=
621 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
622   (setenv "DICPATH" "/usr/local/share/hunspell")
623
624   (when (executable-find "hunspell")
625     (setq-default ispell-program-name "hunspell")
626     (setq ispell-really-hunspell t))
627
628   ;; (defun text-mode-hook-setup ()
629   ;;   ;; Turn off RUN-TOGETHER option when spell check text-mode
630   ;;   (setq-local ispell-extra-args (flyspell-detect-ispell-args)))
631   ;; (add-hook 'text-mode-hook 'text-mode-hook-setup)
632   ;; (add-hook 'text-mode-hook 'flyspell-mode)
633
634   ;; enable flyspell check on comments and strings in progmamming modes
635   ;; (add-hook 'prog-mode-hook 'flyspell-prog-mode)
636
637   ;; I don't use the default mappings
638   (with-eval-after-load 'flyspell
639     (define-key flyspell-mode-map (kbd "C-;") nil)
640     (define-key flyspell-mode-map (kbd "C-,") nil)
641     (define-key flyspell-mode-map (kbd "C-.") nil))
642 #+END_SRC
643
644 Make flyspell enabled for org-mode, see [[http://emacs.stackexchange.com/questions/9333/how-does-one-use-flyspell-in-org-buffers-without-flyspell-triggering-on-tangled][here]]
645 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
646   ;; NO spell check for embedded snippets
647   (defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
648     (let ((rlt ad-return-value)
649           (begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\)")
650           (end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\)")
651           old-flag
652           b e)
653       (when ad-return-value
654         (save-excursion
655           (setq old-flag case-fold-search)
656           (setq case-fold-search t)
657           (setq b (re-search-backward begin-regexp nil t))
658           (if b (setq e (re-search-forward end-regexp nil t)))
659           (setq case-fold-search old-flag))
660         (if (and b e (< (point) e)) (setq rlt nil)))
661       (setq ad-return-value rlt)))
662 #+END_SRC
663
664 *** Expand-region
665 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
666   (use-package expand-region
667     :ensure t
668     :config
669     (global-set-key (kbd "C-=") 'er/expand-region))
670 #+END_SRC
671
672 * Key bindings
673
674 ** Esc on Minibuffer
675
676 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
677
678 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
679
680   (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
681   (define-key minibuffer-local-map [escape]  'keyboard-escape-quit)
682   (define-key minibuffer-local-ns-map [escape]  'keyboard-escape-quit)
683   (define-key minibuffer-local-isearch-map [escape]  'keyboard-escape-quit)
684   (define-key minibuffer-local-completion-map [escape]  'keyboard-escape-quit)
685   (define-key minibuffer-local-must-match-map [escape]  'keyboard-escape-quit)
686   (define-key minibuffer-local-must-match-filename-map [escape]  'keyboard-escape-quit)
687   (define-key minibuffer-local-filename-completion-map [escape]  'keyboard-escape-quit)
688   (define-key minibuffer-local-filename-must-match-map [escape]  'keyboard-escape-quit)
689
690   ;; Also map s-h same as C-g
691   (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
692
693 #+END_SRC
694
695 ** =Super= bindings for file, buffer and windows
696
697 Some global bindings on =Super=, on Mac, it is =Command=
698
699 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
700   (defun sd/delete-current-window ()
701     (interactive)
702     (if (> (length (window-list)) 1)
703         (delete-window)
704       (message "Only one Windows now!")))
705
706   (global-set-key (kbd "s-h") 'keyboard-quit)
707   (global-set-key (kbd "s-j") 'ido-switch-buffer)
708   (global-set-key (kbd "s-k") 'ido-find-file)
709   (global-set-key (kbd "s-l") 'sd/delete-current-window)
710   ;; s-l  -->  goto-line
711   ;; (global-set-key (kbd "s-/") 'swiper)
712   ;; s-;  -->
713   ;; s-'  -->  'next-multiframe-window
714   (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
715
716   (global-set-key (kbd "s-f") 'projectile-find-file)
717
718   (global-set-key (kbd "s-`") 'mode-line-other-buffer)
719
720   (global-set-key (kbd "s-n") 'persp-next)
721   (global-set-key (kbd "s-p") 'persp-prev)
722
723   (global-set-key (kbd "s-=") 'text-scale-increase)
724   (global-set-key (kbd "s--") 'text-scale-decrease)
725
726   ;; (global-set-key (kbd "s-u") 'undo-tree-visualize)
727
728
729   ;; someothers default mapping on super (command) key
730   ;; s-s save-buffer
731   ;; s-k kill-this-buffer
732
733
734   ;; s-h  -->  ns-do-hide-emacs
735   ;; s-j  -->  ido-switch-buffer  +
736   ;; s-k  -->  kill-this-buffer
737   ;; s-l  -->  goto-line
738   ;; s-;  -->  undefined
739   ;; s-'  -->  next-multiframe-window
740   ;; s-ret --> toggle-frame-fullscreen +
741
742   ;; s-y  -->  ns-paste-secondary
743   ;; s-u  -->  revert-buffer
744   ;; s-i  -->  undefined - but used for iterm globally
745   ;; s-o  -->  used for emacs globally
746   ;; s-p  -->  projectile-persp-switch-project  +  
747   ;; s-[  -->  next-buffer  +    
748   ;; s-]  -->  previous-buffer +
749
750   ;; s-0  -->  undefined
751   ;; s-9  -->  undefined
752   ;; s-8  -->  undefined
753   ;; s-7  -->  undefined
754   ;; s-6  -->  undefined
755   ;; s--  -->  center-line
756   ;; s-=  -->  undefined
757
758   ;; s-n  -->  make-frame
759   ;; s-m  -->  iconify-frame
760   ;; s-b  -->  undefined
761   ;; s-,  -->  customize
762   ;; s-.  -->  undefined
763   ;; s-/  -->  undefined
764
765   ;; s-g  -->  isearch-repeat-forward
766   ;; s-f  -->  projectile-find-file   +
767   ;; s-d  -->  isearch-repeat-background
768   ;; s-s  -->  save-buffer
769   ;; s-a  -->  make-whole-buffer
770
771   ;; s-b  -->  undefined
772   ;; s-v  -->  yank
773   ;; s-c  -->  ns-copy-including-secondary
774
775   ;; s-t  -->  ns-popup-font-panel
776   ;; s-r  -->  undefined
777   ;; s-e  -->  isearch-yanqk-kill
778   ;; s-w  -->  delete-frame
779   ;; s-q  -->  same-buffers-kill-emacs
780
781   ;; s-`  -->  other-frame
782 #+END_SRC
783
784 ** Search Replace and highlight
785 *** swiper
786 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
787   ;; (use-package swiper
788   ;;   :ensure t)
789
790   ;; (ivy-mode 1)
791   ;; (setq ivy-use-virtual-buffers t)
792   ;; (global-set-key (kbd "s-/") 'swiper)
793
794   (use-package counsel
795     :ensure t
796     :defer t)
797   ;;* 
798   ;; (global-set-key "\C-s" 'swiper)
799   ;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
800   ;; (global-set-key (kbd "<f6>") 'ivy-resume)
801   (global-set-key (kbd "M-x") 'counsel-M-x)
802   ;; ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
803   (global-set-key (kbd "C-h f") 'counsel-describe-function)
804   (global-set-key (kbd "C-h v") 'counsel-describe-variable)
805   ;; (global-set-key (kbd "<f1> l") 'counsel-load-library)
806   ;; (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
807   ;; (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
808   ;; (global-set-key (kbd "C-c g") 'counsel-git)
809   ;; (global-set-key (kbd "C-c j") 'counsel-git-grep)
810   ;; (global-set-key (kbd "C-c k") 'counsel-ag)
811   ;; (global-set-key (kbd "C-x l") 'counsel-locate)
812   ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
813   ;; ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
814
815   ;; (set-face-attribute
816   ;;  'ivy-current-match nil
817   ;;  :background "Orange"
818   ;;  :foreground "black")
819
820   ;; ivy-resume
821   ;; (define-key swiper-map (kbd "M-%") 'swiper-aa-replace)
822 #+END_SRC
823
824 *** =M-s= prefix
825 use the prefix =M-s= for searching in buffers
826 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
827   (defun sd/make-keymap (key bindings)
828     (setq keymap (make-sparse-keymap))
829     (dolist (binding bindings)
830       (define-key keymap (car binding) (cdr binding)))
831     (global-set-key key keymap))
832
833   (use-package highlight-symbol
834     :ensure t)
835
836   (sd/make-keymap "\M-s"
837                   '(("w" . save-buffer)
838                     ;; ("\M-w" . save-buffer)
839                     ("e" . revert-buffer)
840                     ("s" . isearch-forward-regexp)
841                     ("\M-s" . isearch-forward-regexp)
842                     ("r" . isearch-backward-regexp)
843                     ("." . isearch-forward-symbol-at-point)
844                     ("o" . occur)
845                     ;; ("h" . highlight-symbol-at-point)
846                     ("h" . highlight-symbol)
847                     ("m" . highlight-regexp)
848                     ("l" . highlight-lines-matching-regexp)
849                     ("M" . unhighlight-regexp)
850                     ("f" . keyboard-quit)
851                     ("q" . keyboard-quit)))
852
853   ;; search and replace and highlight
854   (define-key isearch-mode-map (kbd "M-s") 'isearch-repeat-forward)
855   (define-key isearch-mode-map (kbd "M-r") 'isearch-repeat-backward)
856   (global-set-key (kbd "s-[") 'highlight-symbol-next)
857   (global-set-key (kbd "s-]") 'highlight-symbol-prev)
858   (global-set-key (kbd "s-\\") 'highlight-symbol-query-replace)
859
860
861   (define-key minibuffer-local-map "\M-s" nil)
862
863   (set-face-background 'ido-first-match "yellow")
864
865   ;; M-s M-w              eww-search-words
866
867   ;; M-c
868   ;; M-r
869   ;; M-t
870   ;; M-u, 
871 #+END_SRC
872
873 * Org-mode Settings
874
875 ** Org-mode Basic setting
876
877 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent= 
878
879 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
880   (use-package org
881     :ensure t
882     :init
883     (setq org-startup-indented t)
884     (setq org-hide-leading-starts t)
885     (setq org-src-fontify-natively t)
886     (setq org-src-tab-acts-natively t)
887     (setq org-confirm-babel-evaluate nil)
888     (setq org-use-speed-commands t)
889     (setq org-completion-use-ido t))
890
891   (org-babel-do-load-languages
892    'org-babel-load-languages
893    '((python . t)
894      (C . t)
895      (perl . t)
896      (calc . t)
897      (latex . t)
898      (java . t)
899      (ruby . t)
900      (lisp . t)
901      (scheme . t)
902      (sh . t)
903      (sqlite . t)
904      (js . t)
905      (gnuplot . t)
906      (ditaa . t)))
907
908   ;; use current window for org source buffer editting
909   (setq org-src-window-setup 'current-window )
910
911   (define-key org-mode-map (kbd "C-'") nil)
912   ;; C-M-i is mapped to imenu globally
913   (define-key org-mode-map (kbd "C-M-i") nil)
914
915   ;; set the ditta.jar path
916   (setq org-ditaa-jar-path "/usr/local/Cellar/ditaa/0.9/libexec/ditaa0_9.jar")
917   (unless 
918       (file-exists-p org-ditaa-jar-path)
919     (error "seudut: ditaa.jar not found at %s " org-ditaa-jar-path))
920 #+END_SRC
921
922 ** Org-bullets
923
924 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
925
926 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
927   (use-package org-bullets
928     :ensure t
929     :init
930     (add-hook 'org-mode-hook
931               (lambda ()
932                 (org-bullets-mode t))))
933
934   (setq org-bullets-bullet-list '("⦿" "✪" "â—‰" "â—‹" "â–º" "â—†"))
935
936   ;; increase font size when enter org-src-mode
937   (add-hook 'org-src-mode-hook (lambda () (text-scale-increase 2)))
938 #+END_SRC
939
940 ** Worf Mode
941
942 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode. 
943 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
944 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
945 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
946
947 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
948
949   (use-package worf
950     :ensure t
951     :commands worf-mode
952     :init (add-hook 'org-mode-hook 'worf-mode)
953     ;; :config
954     ;; (define-key worf-mode-map "[" nil)
955     ;; (define-key worf-mode-map "]" nil)
956     ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
957     ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
958     )
959
960 #+END_SRC
961
962 ** Get Things Done
963
964 Refer to [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
965 *** basic setup
966
967 standard key binding
968
969 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
970   (global-set-key "\C-cl" 'org-store-link)
971   (global-set-key "\C-ca" 'org-agenda)
972   (global-set-key "\C-cb" 'org-iswitchb)
973 #+END_SRC
974
975 *** Plain List 
976
977 Replace the list bullet =-=, =+=,  with =•=, a litter change based [[https://github.com/howardabrams/dot-files/blob/master/emacs-org.org][here]]
978
979 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
980   ;; (use-package org-mode
981   ;;   :init
982   ;;   (font-lock-add-keywords 'org-mode
983   ;;    '(("^ *\\([-+]\\) "
984   ;;           (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•")))))))
985 #+END_SRC
986  
987 *** Todo Keywords
988
989 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]], 
990
991 To track TODO state changes, the =!= is to insert a timetamp, =@= is to insert a note with
992 timestamp for the state change.
993
994 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
995     ;; (setq org-todo-keywords
996     ;;        '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
997     ;;          (sequence "âš‘ WAITING(w)" "|")
998     ;;          (sequence "|" "✘ CANCELLED(c)")))
999   ; (setq org-todo-keyword-faces
1000   ;        (quote ("TODO" .  (:foreground "red" :weight bold))
1001   ;               ("NEXT" .  (:foreground "blue" :weight bold))
1002   ;               ("WAITING" . (:foreground "forest green" :weight bold))
1003   ;               ("DONE" .  (:foreground "magenta" :weight bold))
1004   ;               ("CANCELLED" . (:foreground "forest green" :weight bold))))
1005
1006
1007   (setq org-todo-keywords
1008         (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!)")
1009                 ;; (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING")
1010                 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" ))))
1011
1012   (setq org-todo-keyword-faces
1013         (quote (("TODO" :foreground "red" :weight bold)
1014                 ("NEXT" :foreground "blue" :weight bold)
1015                 ("DONE" :foreground "forest green" :weight bold)
1016                 ("WAITING" :foreground "orange" :weight bold)
1017                 ("HOLD" :foreground "magenta" :weight bold)
1018                 ("CANCELLED" :foreground "forest green" :weight bold)
1019                 ;; ("MEETING" :foreground "forest green" :weight bold)
1020                 ;; ("PHONE" :foreground "forest green" :weight bold)
1021                 )))
1022 #+END_SRC
1023
1024 Fast todo selections
1025
1026 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1027   (setq org-use-fast-todo-selection t)
1028   (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1029 #+END_SRC
1030
1031 TODO state triggers and tags, [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
1032
1033 - Moving a task to =CANCELLED=, adds a =CANCELLED= tag
1034 - Moving a task to =WAITING=, adds a =WAITING= tag
1035 - Moving a task to =HOLD=, add =HOLD= tags
1036 - Moving a task to =DONE=, remove =WAITING=, =HOLD= tag
1037 - Moving a task to =NEXT=, remove all waiting/hold/cancelled tags
1038
1039 This tags are used to filter tasks in agenda views
1040 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1041   (setq org-todo-state-tags-triggers
1042         (quote (("CANCELLED" ("CANCELLED" . t))
1043                 ("WAITING" ("WAITING" . t))
1044                 ("HOLD" ("WAITING") ("HOLD" . t))
1045                 (done ("WAITING") ("HOLD"))
1046                 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1047                 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1048                 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1049 #+END_SRC
1050
1051 Logging Stuff 
1052 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1053   ;; log time when task done
1054   ;; (setq org-log-done (quote time))
1055   ;; save clocking into to LOGBOOK
1056   (setq org-clock-into-drawer t)
1057   ;; save state change notes and time stamp into LOGBOOK drawer
1058   (setq org-log-into-drawer t)
1059   (setq org-clock-into-drawer "CLOCK")
1060 #+END_SRC
1061
1062 *** Tags
1063 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1064   (setq org-tag-alist (quote ((:startgroup)
1065                               ("@office" . ?e)
1066                               ("@home" . ?h)
1067                               (:endgroup)
1068                               ("WAITING" . ?w)
1069                               ("HOLD" . ?h)
1070                               ("CANCELLED" . ?c))))
1071
1072   ;; Allow setting single tags without the menu
1073   (setq org-fast-tag-selection-single-key (quote expert))
1074 #+END_SRC
1075
1076 *** Capture - Refile - Archive
1077
1078 Capture lets you quickly store notes with little interruption of your work flow.
1079
1080 **** Capture Templates
1081
1082 When a new taks needs to be added, categorize it as 
1083
1084 All captured file which need next actions are stored in =refile.org=, 
1085 - A new task / note (t) =refile.org=
1086 - A work task in office =office.org=
1087 - A jourenl =diary.org=
1088 - A new habit (h) =refile.org=
1089
1090 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1091   (setq org-directory "~/org")
1092   (setq org-default-notes-file "~/org/refile.org")
1093   (setq sd/org-diary-file "~/org/diary.org")
1094
1095   (global-set-key (kbd "C-c c") 'org-capture)
1096
1097   (setq org-capture-templates
1098         (quote (("t" "Todo" entry (file org-default-notes-file)
1099                  "* TODO %?\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1100                 ("n" "Note" entry (file org-default-notes-file)
1101                  "* %? :NOTE:\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1102                 ("j" "Journal" entry (file+datetree sd/org-diary-file)
1103                  "* %?\n:LOGBOOK:\n:END:" :clock-in t :clock-resume t)
1104                 ("h" "Habit" entry (file org-default-notes-file)
1105                  "* NEXT %?\n:LOGBOOK:\n%a\nSCHEDULED: %(format-time-string \"%<<%Y-%m-%d %a .+1d/3d>>\")\n:END:\n:PROPERTIES:\n:STYLE: habit\n:REPEAT_TO_STATE: NEXT\n:END:\n "))))
1106 #+END_SRC
1107
1108 **** Refiling Tasks
1109
1110 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1111   (setq org-refile-targets (quote (;; (nil :maxlevel . 9)
1112                                    (org-agenda-files :maxlevel . 9))))
1113
1114   (setq org-refile-use-outline-path t)
1115
1116   (setq org-refile-allow-creating-parent-nodes (quote confirm))
1117 #+END_SRC
1118
1119 *** Agenda Setup
1120 Setting agenda files and the agenda view
1121 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1122   (setq org-agenda-files (quote ("~/org/gtd.org"
1123                                  "~/org/work.org")))
1124
1125   ;; only show today's tasks in agenda view
1126   (setq org-agenda-span 'day)
1127   ;; Use current windows for agenda view
1128   (setq org-agenda-window-setup 'current-window)
1129
1130   ;; show all feature entries for repeating tasks,
1131   ;; this is already setting by default
1132   (setq org-agenda-repeating-timestamp-show-all t)
1133
1134   ;; Show all agenda dates - even if they are empty
1135   (setq org-agenda-show-all-dates t)
1136 #+END_SRC
1137
1138 ** Export PDF
1139
1140 Install MacTex-basic and some tex packages
1141
1142 #+BEGIN_SRC bash 
1143
1144   sudo tlmgr update --self
1145
1146   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
1147
1148 #+END_SRC
1149
1150 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1151   ;; ;; allow for export=>beamer by placing
1152
1153   ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
1154   ;; #+LaTeX_CLASS: beamer in org files
1155   (unless (boundp 'org-export-latex-classes)
1156     (setq org-export-latex-classes nil))
1157   (add-to-list 'org-export-latex-classes
1158     ;; beamer class, for presentations
1159     '("beamer"
1160        "\\documentclass[11pt]{beamer}\n
1161         \\mode<{{{beamermode}}}>\n
1162         \\usetheme{{{{beamertheme}}}}\n
1163         \\usecolortheme{{{{beamercolortheme}}}}\n
1164         \\beamertemplateballitem\n
1165         \\setbeameroption{show notes}
1166         \\usepackage[utf8]{inputenc}\n
1167         \\usepackage[T1]{fontenc}\n
1168         \\usepackage{hyperref}\n
1169         \\usepackage{color}
1170         \\usepackage{listings}
1171         \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
1172     frame=single,
1173     basicstyle=\\small,
1174     showspaces=false,showstringspaces=false,
1175     showtabs=false,
1176     keywordstyle=\\color{blue}\\bfseries,
1177     commentstyle=\\color{red},
1178     }\n
1179         \\usepackage{verbatim}\n
1180         \\institute{{{{beamerinstitute}}}}\n          
1181          \\subject{{{{beamersubject}}}}\n"
1182
1183        ("\\section{%s}" . "\\section*{%s}")
1184  
1185        ("\\begin{frame}[fragile]\\frametitle{%s}"
1186          "\\end{frame}"
1187          "\\begin{frame}[fragile]\\frametitle{%s}"
1188          "\\end{frame}")))
1189
1190     ;; letter class, for formal letters
1191
1192     (add-to-list 'org-export-latex-classes
1193
1194     '("letter"
1195        "\\documentclass[11pt]{letter}\n
1196         \\usepackage[utf8]{inputenc}\n
1197         \\usepackage[T1]{fontenc}\n
1198         \\usepackage{color}"
1199  
1200        ("\\section{%s}" . "\\section*{%s}")
1201        ("\\subsection{%s}" . "\\subsection*{%s}")
1202        ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1203        ("\\paragraph{%s}" . "\\paragraph*{%s}")
1204        ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1205
1206
1207   (require 'ox-md)
1208   (require 'ox-beamer)
1209
1210   (setq org-latex-pdf-process
1211         '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1212           "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1213           "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
1214
1215   (setq TeX-parse-self t)
1216
1217   (setq TeX-PDF-mode t)
1218   (add-hook 'LaTeX-mode-hook
1219             (lambda ()
1220               (LaTeX-math-mode)
1221               (setq TeX-master t)))
1222
1223 #+END_SRC
1224
1225 ** others
1226
1227 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
1228
1229 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1230
1231   (add-to-list 'org-structure-template-alist
1232                '("E" "#+BEGIN_SRC emacs-lisp :tangle yes :results silent\n?\n#+END_SRC"))
1233   (add-to-list 'org-structure-template-alist
1234                '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
1235   (add-to-list 'org-structure-template-alist
1236                '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
1237
1238 #+END_SRC
1239
1240 * Magit
1241 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
1242 and Defined keys, using vi keybindings, Refer abo-abo's setting [[https://github.com/abo-abo/oremacs/blob/c5cafdcebc88afe9e73cc8bd40c49b70675509c7/modes/ora-nextmagit.el][here]]
1243 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1244   (use-package magit
1245     :ensure t
1246     :init
1247     ;; don't ask me to confirm the unsaved change 
1248     (setq magit-save-repository-buffers nil)
1249     :commands magit-status magit-blame
1250     :config
1251     (dolist (map (list magit-status-mode-map
1252                        magit-log-mode-map
1253                        magit-diff-mode-map
1254                        magit-staged-section-map))
1255       (define-key map "j" 'magit-section-forward)
1256       (define-key map "k" 'magit-section-backward)
1257       (define-key map "D" 'magit-discard)
1258       (define-key map "O" 'magit-discard-file)
1259       (define-key map "n" nil)
1260       (define-key map "p" nil)
1261       (define-key map "v" 'recenter-top-bottom)
1262       (define-key map "i" 'magit-section-toggle)))
1263 #+END_SRC
1264
1265 * Eshell
1266 *** Eshell alias
1267 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1268   (defalias 'e 'find-file)
1269   (defalias 'ff 'find-file)
1270   (defalias 'ee 'find-files)
1271 #+END_SRC
1272
1273 *** eshell temp directory
1274 set default eshell history folder
1275 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1276   (setq eshell-directory-name (concat  sd-temp-directory "eshell"))
1277 #+END_SRC
1278
1279 *** Eshell erase buffer
1280 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1281   (defun sd/eshell-clear-buffer ()
1282     "Clear eshell buffer"
1283     (interactive)
1284     (let ((inhibit-read-only t))
1285       (erase-buffer)
1286       (eshell-send-input)))
1287
1288    (add-hook 'eshell-mode-hook (lambda ()
1289                                 (local-set-key (kbd "C-l") 'sd/eshell-clear-buffer)))
1290 #+END_SRC
1291
1292 *** Toggle Eshell
1293 Toggle an eshell in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
1294 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1295   (defun sd/window-has-eshell ()
1296     "Check if current windows list has a eshell buffer, and return the window"
1297     (interactive)
1298     (let ((ret nil))
1299       (walk-windows (lambda (window)
1300                       (if (equal (with-current-buffer (window-buffer window) major-mode)
1301                                  'eshell-mode)
1302                           (setq ret window)))
1303                     nil nil)
1304       ret))
1305
1306   (defun sd/toggle-eshell-here ()
1307     "Toggle a eshell buffer vertically"
1308     (interactive)
1309     (if (sd/window-has-eshell)
1310         (if (equal major-mode 'eshell-mode)
1311             (progn
1312               (if (equal (length (window-list)) 1)
1313                   (mode-line-other-buffer)
1314                 (delete-window)))
1315           (select-window (sd/window-has-eshell)))
1316       (progn
1317         (let ((dir default-directory))
1318           
1319           (split-window-vertically (- (/ (window-total-height) 3)))
1320           (other-window 1)
1321           (unless (and (boundp 'eshell-buffer-name) (get-buffer eshell-buffer-name))
1322             (eshell))
1323           (switch-to-buffer eshell-buffer-name)
1324           (goto-char (point-max))
1325           (eshell-kill-input)
1326           (insert (format "cd %s" dir))
1327           (eshell-send-input)))))
1328
1329   (global-unset-key (kbd "M-`"))
1330   (global-set-key (kbd "M-`") 'sd/toggle-eshell-here)
1331 #+END_SRC
1332
1333 *** TODO smart display
1334 * Misc Settings
1335
1336 ** [[https://github.com/abo-abo/hydra][Hydra]]
1337 *** hydra install
1338 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1339   (use-package hydra
1340     :ensure t)
1341   ;; disable new line in minibuffer when hint hydra
1342   (setq hydra-lv nil)
1343 #+END_SRC
1344
1345 *** Font Zoom
1346 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1347   (defhydra sd/font-zoom (global-map "<f2>")
1348     "zoom"
1349     ("g" text-scale-increase "in")
1350     ("l" text-scale-decrease "out"))
1351 #+END_SRC
1352
1353 *** Windmove Splitter
1354
1355 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1356
1357 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1358
1359   (defun hydra-move-splitter-left (arg)
1360     "Move window splitter left."
1361     (interactive "p")
1362     (if (let ((windmove-wrap-around))
1363           (windmove-find-other-window 'right))
1364         (shrink-window-horizontally arg)
1365       (enlarge-window-horizontally arg)))
1366
1367   (defun hydra-move-splitter-right (arg)
1368     "Move window splitter right."
1369     (interactive "p")
1370     (if (let ((windmove-wrap-around))
1371           (windmove-find-other-window 'right))
1372         (enlarge-window-horizontally arg)
1373       (shrink-window-horizontally arg)))
1374
1375   (defun hydra-move-splitter-up (arg)
1376     "Move window splitter up."
1377     (interactive "p")
1378     (if (let ((windmove-wrap-around))
1379           (windmove-find-other-window 'up))
1380         (enlarge-window arg)
1381       (shrink-window arg)))
1382
1383   (defun hydra-move-splitter-down (arg)
1384     "Move window splitter down."
1385     (interactive "p")
1386     (if (let ((windmove-wrap-around))
1387           (windmove-find-other-window 'up))
1388         (shrink-window arg)
1389       (enlarge-window arg)))
1390
1391 #+END_SRC
1392
1393 *** hydra misc
1394 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1395   (defhydra sd/hydra-misc (:color red :columns nil)
1396     "Miscellaneous Commands"
1397     ("e" eshell "eshell" :exit t)
1398     ("p" (lambda ()
1399            (interactive)
1400            (if (not (eq nil (get-buffer "*Packages*")))
1401                (switch-to-buffer "*Packages*")
1402              (package-list-packages)))
1403      "list-package" :exit t)
1404     ("g" magit-status "git-status" :exit t)
1405     ("'" mode-line-other-buffer "last buffer" :exit t)
1406     ("C-'" mode-line-other-buffer "last buffer" :exit t)
1407     ("m" man "man" :exit t)
1408     ("d" dired-jump "dired" :exit t)
1409     ("b" ibuffer "ibuffer" :exit t)
1410     ("q" nil "quit")
1411     ("f" nil "quit"))
1412
1413   (global-set-key (kbd "C-'") 'sd/hydra-misc/body)
1414 #+END_SRC
1415
1416 *** hydra launcher
1417 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1418   (defhydra sd/hydra-launcher (:color blue :columns 2)
1419     "Launch"
1420     ("e" emms "emms" :exit t)
1421     ("q" nil "cancel"))
1422 #+END_SRC
1423
1424 ** Line Number
1425
1426 Enable linum mode on programming modes
1427
1428 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1429   (add-hook 'prog-mode-hook 'linum-mode)
1430   ;; (add-hook 'prog-mode-hook (lambda ()
1431   ;;                             (setq-default indicate-empty-lines t)))
1432 #+END_SRC
1433
1434 Fix the font size of line number
1435
1436 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1437
1438   (defun fix-linum-size ()
1439        (interactive)
1440        (set-face-attribute 'linum nil :height 110))
1441
1442   (add-hook 'linum-mode-hook 'fix-linum-size)
1443
1444 #+END_SRC
1445
1446 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1447
1448 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1449
1450   (use-package linum-relative
1451     :ensure t
1452     :config
1453     (defun linum-new-mode ()
1454       "If line numbers aren't displayed, then display them.
1455   Otherwise, toggle between absolute and relative numbers."
1456       (interactive)
1457       (if linum-mode
1458           (linum-relative-toggle)
1459         (linum-mode 1)))
1460
1461     :bind
1462     ("A-k" . linum-new-mode))
1463
1464   ;; auto enable linum-new-mode in programming modes
1465   (add-hook 'prog-mode-hook 'linum-relative-mode)
1466
1467 #+END_SRC
1468
1469 ** Save File Position
1470
1471 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1472
1473   (require 'saveplace)
1474   (setq-default save-place t)
1475   (setq save-place-forget-unreadable-files t)
1476   (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1477
1478 #+END_SRC
1479
1480 ** Multi-term
1481
1482 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1483
1484   (use-package multi-term
1485     :ensure t)
1486
1487 #+END_SRC
1488
1489 ** ace-link
1490
1491 [[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
1492 Type =o= to go to the link
1493
1494 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1495
1496   (use-package ace-link
1497     :ensure t
1498     :init
1499     (ace-link-setup-default))
1500
1501 #+END_SRC
1502
1503 ** Emux
1504
1505 [[https://github.com/re5et/emux][emux]] is 
1506
1507 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1508
1509   (el-get-bundle re5et/emux)
1510
1511 #+END_SRC
1512
1513 ** Smart Parens
1514
1515 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1516
1517   (use-package smartparens
1518     :ensure t
1519     :config
1520     (progn
1521       (require 'smartparens-config)
1522       (add-hook 'prog-mode-hook 'smartparens-mode)))
1523
1524 #+END_SRC
1525
1526 ** Ace-Windows
1527
1528 [[https://github.com/abo-abo/ace-window][ace-window]] 
1529
1530 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1531
1532   (use-package ace-window
1533     :ensure t
1534     :defer t
1535   ;  :init
1536   ;  (global-set-key (kbd "M-o") 'ace-window)
1537     :config
1538     (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1539
1540 #+END_SRC
1541
1542 ** Projectile
1543
1544 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1545
1546   (use-package projectile
1547     :ensure t
1548     :init
1549     (setq projectile-enable-caching t)
1550     :config
1551     (projectile-global-mode t))
1552
1553   (use-package persp-projectile
1554     :ensure t
1555     :config
1556     (persp-mode)
1557     :bind
1558     (:map projectile-mode-map
1559           ("s-t" . projectile-persp-switch-project)))
1560
1561   ;; projectile-find-file
1562   ;; projectile-switch-buffer
1563   ;; projectile-find-file-other-window
1564 #+END_SRC
1565
1566 ** Which key
1567
1568 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings 
1569
1570 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1571
1572   (use-package which-key
1573     :ensure t
1574     :config
1575     (which-key-mode))
1576
1577 #+END_SRC
1578
1579 ** Emms
1580
1581 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1582
1583 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1584   (use-package emms
1585     :ensure t
1586     :init
1587     (setq emms-source-file-default-directory "~/Music/")
1588     :config
1589     (emms-standard)
1590     (emms-default-players)
1591     (define-emms-simple-player mplayer '(file url)
1592       (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1593                     ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1594                     "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1595                     ".m4a" ".flv" ".ogv" ".pls"))
1596       "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1597     (emms-history-load))
1598
1599 #+END_SRC
1600
1601 ** GnoGo
1602
1603 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
1604
1605 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1606
1607   (use-package gnugo
1608     :ensure t
1609     :defer t
1610     :init
1611     (require 'gnugo-imgen)
1612     (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1613     (add-hook 'gnugo-start-game-hook '(lambda ()
1614                                         (gnugo-image-display-mode)
1615                                         (gnugo-grid-mode)))
1616       :config
1617     (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1618
1619 #+END_SRC
1620
1621 ** Tabbar
1622
1623 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1624
1625   ;; (use-package tabbar-ruler
1626   ;;   :ensure t
1627   ;;   :init
1628   ;;   (setq tabbar-ruler-global-tabbar t)
1629   ;;   (setq tabbar-ruler-global-ruler t)
1630   ;;   (setq tabbar-ruler-popu-menu t)
1631   ;;   (setq tabbar-ruler-popu-toolbar t)
1632   ;;   (setq tabbar-use-images t)
1633   ;;   :config
1634   ;;   (tabbar-ruler-group-by-projectile-project)
1635   ;;   (global-set-key (kbd "s-1") 'tabbar-forward-group)
1636   ;;   (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1637
1638 #+END_SRC
1639
1640 ** View only for some directory
1641 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]]
1642 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1643   (dir-locals-set-class-variables
1644    'emacs
1645    '((nil . ((buffer-read-only . t)
1646              (show-trailing-whitespace . nil)
1647              (tab-width . 8)
1648              (eval . (whitespace-mode -1))))))
1649
1650   ;; (dir-locals-set-directory-class (expand-file-name "/usr/local/share/emacs") 'emacs)
1651   (dir-locals-set-directory-class "/usr/local/Cellar/emacs" 'emacs)
1652   ;; (dir-locals-set-directory-class "~/.emacs.d/elpa" 'emacs)
1653   (dir-locals-set-directory-class "~/dotfiles/emacs.d/elpa" 'emacs)
1654   (dir-locals-set-directory-class "~/dotfiles/emacs.d/el-get" 'emacs)
1655 #+END_SRC
1656
1657 ** Info plus
1658 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1659   (el-get-bundle info+
1660     :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/info+.el"
1661     (require 'info+))
1662 #+END_SRC
1663
1664 ** TODO bookmark
1665
1666 ** TODO Calendar
1667 ** advice info
1668 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1669   (defun sd/info-mode ()
1670     (interactive)
1671     (unless (equal major-mode 'Info-mode)
1672       (unless (> (length (window-list)) 1)
1673         (split-window-right))
1674       (other-window 1)
1675       ;; (info)
1676       ))
1677
1678   ;; (global-set-key (kbd "C-h i") 'sd/info-mode)
1679
1680   ;; open Info buffer in other window instead of current window
1681   (defadvice info (before my-info (&optional file buf) activate)
1682     (sd/info-mode))
1683
1684   (defadvice Info-exit (after my-info-exit activate)
1685     (sd/delete-current-window))
1686 #+END_SRC
1687
1688 ** TODO Man mode
1689 Color for Man-mode
1690
1691 ** TODO swiper to occur
1692
1693 ** TODO UTF8
1694 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1695   ;; (set-language-environment "UTF-8")
1696   ;; (set-default-coding-systems 'utf-8)
1697 #+END_SRC
1698
1699 ** Demo It
1700 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1701   ;; (el-get-bundle howardabrams/demo-it)
1702
1703   (use-package org-tree-slide
1704     :ensure t)
1705
1706   ;; (use-package yasnippet
1707   ;;   :ensure t)
1708 #+END_SRC
1709
1710 ** Presentation
1711 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1712   (use-package org-tree-slide
1713     :ensure
1714     :config
1715     ;; (define-key org-mode-map "\C-ccp" 'org-tree-slide-mode)
1716     (define-key org-tree-slide-mode-map (kbd "<ESC>") 'org-tree-slide-content)
1717     (define-key org-tree-slide-mode-map (kbd "<SPACE>") 'org-tree-slide-move-next-tree)
1718     (define-key org-tree-slide-mode-map [escape] 'org-tree-slide-move-previous-tree))
1719 #+END_SRC
1720
1721 * dired
1722 =C-o= is defined as a global key for window operation, here unset it in dired mode
1723 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1724   (use-package dired
1725     :config
1726     (require 'dired-x)
1727     (setq dired-omit-mode t)
1728     (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
1729     (add-hook 'dired-mode-hook (lambda ()
1730                                  (define-key dired-mode-map (kbd "C-o") nil)
1731                                  (define-key dired-mode-map (kbd "H") 'dired-omit-mode)
1732                                  (define-key dired-mode-map (kbd "DEL") (lambda () (interactive) (find-alternate-file "..")))
1733                                  (dired-omit-mode))))
1734 #+END_SRC
1735
1736 Dired+
1737 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1738   (use-package dired+
1739     :ensure t
1740     :init
1741     (setq diredp-hide-details-initially-flag nil)
1742     :config
1743     (define-key dired-mode-map (kbd "j") 'diredp-next-line)
1744     (define-key dired-mode-map (kbd "k") 'diredp-previous-line)
1745     (define-key dired-mode-map (kbd "g") 'dired-goto-file))
1746 #+END_SRC
1747
1748 * Completion
1749 company mode and company-statistics
1750 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1751   (use-package company
1752     :ensure t
1753     :diminish company-mode
1754     :init (setq company-idle-delay 0.1)
1755     :config
1756     (global-company-mode))
1757
1758   (use-package company-statistics
1759     :ensure t
1760     :config
1761     (company-statistics-mode))
1762 #+END_SRC
1763
1764 * Programming Language
1765 ** Emacs Lisp
1766 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1767   (use-package color-identifiers-mode
1768     :ensure t
1769     :init
1770     (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1771
1772     :diminish color-identifiers-mode)
1773
1774   (global-prettify-symbols-mode t)
1775 #+END_SRC
1776
1777 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1778 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1779 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1780   (use-package lispy
1781     :ensure t
1782     :init
1783     (eval-after-load "lispy"
1784       `(progn
1785          (define-key lispy-mode-map (kbd "M-o") nil)))
1786     :config
1787     (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1788 #+END_SRC
1789
1790 ** Perl
1791 *** CPerl mode
1792 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1793 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1794   (defalias 'perl-mode 'cperl-mode)
1795
1796   ;; (setq cperl-hairy t)
1797   ;; Turns on most of the CPerlMode options
1798   (setq cperl-auto-newline t)
1799   (setq cperl-highlight-variables-indiscriminately t)
1800   ;(setq cperl-indent-level 4)
1801   ;(setq cperl-continued-statement-offset 4)
1802   (setq cperl-close-paren-offset -4)
1803   (setq cperl-indent-parents-as-block t)
1804   (setq cperl-tab-always-indent t)
1805   ;(setq cperl-brace-offset  0)
1806
1807   (add-hook 'cperl-mode-hook
1808             '(lambda ()
1809                (cperl-set-style "C++")))
1810
1811   (defalias 'perldoc 'cperl-perldoc)
1812 #+END_SRC
1813
1814 *** Perl template
1815 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1816 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1817   (eval-after-load 'autoinsert
1818     '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1819        '(
1820          "Empty"
1821          "#!/usr/bin/perl -w" \n
1822          \n
1823          "use strict;" >  \n \n
1824          > _
1825          )))
1826 #+END_SRC
1827
1828 *** Perl Keywords
1829 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1830   (font-lock-add-keywords 'cperl-mode
1831                           '(("\\(say\\)" . cperl-nonoverridable-face)
1832                             ("\\([0-9.]\\)*" . font-lock-constant-face)
1833                             ("\".*\\(\\\n\\).*\"" . font-lock-constant-face)
1834                             ("\n" . font-lock-constant-face)
1835                             ("\\(^#!.*\\)$" .  cperl-nonoverridable-face)))
1836
1837     ;; (font-lock-add-keywords 'Man-mode
1838     ;;                         '(("\\(NAME\\)" . font-lock-function-name-face)))
1839
1840 #+END_SRC
1841
1842 *** Run Perl
1843 Change the compile-command to set the default command run when call =compile=
1844 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1845 to call =compilation=  interactively.
1846 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1847   (defun my-perl-hook ()
1848     (progn
1849       (setq-local compilation-read-command nil)
1850       (set (make-local-variable 'compile-command)
1851            (concat "/usr/bin/perl "
1852                    (if buffer-file-name
1853                        (shell-quote-argument buffer-file-name))))
1854       (local-set-key (kbd "s-r")
1855                      (lambda ()
1856                        (interactive)
1857                                           ;                       (setq current-prefix-arg '(4)) ; C-u
1858                        (call-interactively 'compile)))))
1859
1860   (add-hook 'cperl-mode-hook 'my-perl-hook)
1861 #+END_SRC
1862
1863 ** C & C++
1864 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1865   (setq c-default-style "stroustrup"
1866         c-basic-offset 4)
1867 #+END_SRC
1868
1869 * Compile
1870 Set the environments vairables in compilation mode
1871 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1872   (use-package compile
1873     :commands compile
1874     :config
1875     (setq compilation-environment (cons "LC_ALL=C" compilation-environment))
1876     (setq compilation-auto-jump-to-first-error t)
1877     (setq compilation-auto-jump-to-next t)
1878     (setq compilation-scroll-output 'first-error))
1879
1880   ;; super-r to compile
1881   (with-eval-after-load "compile"
1882     (define-key compilation-mode-map (kbd "C-o") nil)
1883     (define-key compilation-mode-map (kbd "n") 'compilation-next-error)
1884     (define-key compilation-mode-map (kbd "p") 'compilation-previous-error)
1885     (define-key compilation-mode-map (kbd "r") #'recompile))
1886 #+END_SRC
1887
1888 * Auto-Insert
1889 ** Enable auto-insert mode
1890 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1891   (auto-insert-mode t)
1892   (setq auto-insert-query nil)
1893 #+END_SRC
1894
1895 ** C++ Auto Insert
1896 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1897   (eval-after-load 'autoinsert
1898     '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1899        '(
1900          "Short description:"
1901          "/*"
1902          "\n * " (file-name-nondirectory (buffer-file-name))
1903          "\n */" > \n \n
1904          "#include <iostream>" \n
1905          "#include \""
1906          (file-name-sans-extension
1907           (file-name-nondirectory (buffer-file-name)))
1908          ".hpp\"" \n \n
1909          "using namespace std;" \n \n
1910          "int main ()"
1911          "\n{" \n 
1912          > _ \n
1913          "return 1;"
1914          "\n}" > \n
1915          )))
1916
1917   (eval-after-load 'autoinsert
1918     '(define-auto-insert '("\\.c\\'" . "C skeleton")
1919        '(
1920          "Short description:"
1921          "/*\n"
1922          " * " (file-name-nondirectory (buffer-file-name)) "\n"
1923          " */" > \n \n
1924          "#include <stdio.h>" \n
1925          "#include \""
1926          (file-name-sans-extension
1927           (file-name-nondirectory (buffer-file-name)))
1928          ".h\"" \n \n
1929          "int main ()\n"
1930          "{" \n
1931          > _ \n
1932          "return 1;\n"
1933          "}" > \n
1934          )))
1935 #+END_SRC
1936
1937 ** Python template
1938 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1939   (eval-after-load 'autoinsert
1940     '(define-auto-insert '("\\.\\(py\\)\\'" . "Python skeleton")
1941        '(
1942          "Empty"
1943          "#import os,sys" \n
1944          \n \n
1945          )))
1946 #+END_SRC
1947
1948 ** Elisp 
1949 Emacs lisp auto-insert, based on the default module in =autoinsert.el=, but replace =completing-read= as 
1950 =completing-read-ido-ubiquitous= to fix the edge case of that =ido= cannot handle.
1951 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1952   (eval-after-load 'autoinsert
1953     '(define-auto-insert '("\\.el\\'" . "my Emacs Lisp header")
1954        '(
1955          "Short description: "
1956          ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str
1957          (make-string (max 2 (- 80 (current-column) 27)) ?\s)
1958          "-*- lexical-binding: t; -*-" '(setq lexical-binding t)
1959          "\n
1960   ;; Copyright (C) " (format-time-string "%Y") "  "
1961          (getenv "ORGANIZATION") | (progn user-full-name) "
1962
1963   ;; Author: " (user-full-name)
1964          '(if (search-backward "&" (line-beginning-position) t)
1965               (replace-match (capitalize (user-login-name)) t t))
1966          '(end-of-line 1) " <" (progn user-mail-address) ">
1967   ;; Keywords: "
1968          '(require 'finder)
1969          ;;'(setq v1 (apply 'vector (mapcar 'car finder-known-keywords)))
1970          '(setq v1 (mapcar (lambda (x) (list (symbol-name (car x))))
1971                            finder-known-keywords)
1972                 v2 (mapconcat (lambda (x) (format "%12s:  %s" (car x) (cdr x)))
1973                               finder-known-keywords
1974                               "\n"))
1975          ((let ((minibuffer-help-form v2))
1976             (completing-read-ido-ubiquitous "Keyword, C-h: " v1 nil t))
1977           str ", ") & -2 "
1978
1979   \;; This program is free software; you can redistribute it and/or modify
1980   \;; it under the terms of the GNU General Public License as published by
1981   \;; the Free Software Foundation, either version 3 of the License, or
1982   \;; (at your option) any later version.
1983
1984   \;; This program is distributed in the hope that it will be useful,
1985   \;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1986   \;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1987   \;; GNU General Public License for more details.
1988
1989   \;; You should have received a copy of the GNU General Public License
1990   \;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
1991
1992   \;;; Commentary:
1993
1994   \;; " _ "
1995
1996   \;;; Code:
1997
1998
1999   \(provide '"
2000          (file-name-base)
2001          ")
2002   \;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")))
2003 #+END_SRC
2004
2005 ** Org file template
2006 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2007   (eval-after-load 'autoinsert
2008     '(define-auto-insert '("\\.\\(org\\)\\'" . "Org-mode skeleton")
2009        '(
2010          "title: "
2011          "#+TITLE: " str (make-string 30 ?\s) > \n
2012          "#+AUTHOR: Peng Li\n"
2013          "#+EMAIL: seudut@gmail.com\n"
2014          "#+DATE: " (shell-command-to-string "echo -n $(date +%Y-%m-%d)") > \n
2015          > \n
2016          > _)))
2017 #+END_SRC
2018
2019 * Markdown mode
2020 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2021   (use-package markdown-mode
2022     :ensure t
2023     :commands (markdown-mode gfm-mode)
2024     :mode (("README\\.md\\'" . gfm-mode)
2025            ("\\.md\\'" . markdown-mode)
2026            ("\\.markdown\\'" . markdown-mode))
2027     :init (setq markdown-command "multimarkdown"))
2028 #+END_SRC
2029
2030 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2031   (use-package markdown-preview-eww
2032     :ensure t)
2033 #+END_SRC
2034
2035 * Gnus
2036 ** Gmail setting 
2037 Refer [[https://www.emacswiki.org/emacs/GnusGmail][GnusGmail]]
2038 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2039   (setq user-mail-address "seudut@gmail.com"
2040         user-full-name "Peng Li")
2041
2042   (setq gnus-select-method
2043         '(nnimap "gmail"
2044                  (nnimap-address "imap.gmail.com")
2045                  (nnimap-server-port "imaps")
2046                  (nnimap-stream ssl)))
2047
2048   (setq smtpmail-smtp-service 587
2049         gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
2050
2051   ;; Use gmail sending mail
2052   (setq message-send-mail-function 'smtpmail-send-it
2053         smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
2054         smtpmail-auth-credentials '(("smtp.gmail.com" 587 "seudut@gmail.com" nil))
2055         smtpmail-default-smtp-server "smtp.gmail.com"
2056         smtpmail-smtp-server "smtp.gmail.com"
2057         smtpmail-smtp-service 587
2058         starttls-use-gnutls t)
2059 #+END_SRC
2060
2061 And put the following in =~/.authinfo= file, replacing =<USE>= with your email address
2062 and =<PASSWORD>= with the password
2063 #+BEGIN_EXAMPLE
2064   machine imap.gmail.com login <USER> password <PASSWORD> port imaps
2065   machine smtp.gmail.com login <USER> password <PASSWORD> port 587
2066 #+END_EXAMPLE
2067
2068 Then Run =M-x gnus=
2069
2070 ** Group buffer
2071 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2072   (use-package gnus
2073     :init
2074     (setq gnus-permanently-visible-groups "\.*")
2075     :config
2076     (cond (window-system
2077            (setq custom-background-mode 'light)
2078            (defface my-group-face-1
2079              '((t (:foreground "Red" :bold t))) "First group face")
2080            (defface my-group-face-2
2081              '((t (:foreground "DarkSeaGreen4" :bold t)))
2082              "Second group face")
2083            (defface my-group-face-3
2084              '((t (:foreground "Green4" :bold t))) "Third group face")
2085            (defface my-group-face-4
2086              '((t (:foreground "SteelBlue" :bold t))) "Fourth group face")
2087            (defface my-group-face-5
2088              '((t (:foreground "Blue" :bold t))) "Fifth group face")))
2089     (setq gnus-group-highlight
2090           '(((> unread 200) . my-group-face-1)
2091             ((and (< level 3) (zerop unread)) . my-group-face-2)
2092             ((< level 3) . my-group-face-3)
2093             ((zerop unread) . my-group-face-4)
2094             (t . my-group-face-5))))
2095
2096
2097   ;; key-
2098   (add-hook 'gnus-group-mode-hook (lambda ()
2099                                     (define-key gnus-group-mode-map "k" 'gnus-group-prev-group)
2100                                     (define-key gnus-group-mode-map "j" 'gnus-group-next-group)
2101                                     (define-key gnus-group-mode-map "g" 'gnus-group-jump-to-group)
2102                                     (define-key gnus-group-mode-map "v" (lambda () (interactive) (gnus-group-select-group t)))))
2103 #+END_SRC
2104
2105 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2106   (setq gnus-fetch-old-headers 't)
2107
2108
2109
2110   (setq gnus-extract-address-components
2111         'mail-extract-address-components)
2112   ;; summary buffer 
2113   (setq gnus-summary-line-format "%U%R%z%I%(%[%-20,20f%]%)  %s%-80=   %11&user-date;\n")
2114   (setq gnus-user-date-format-alist '(((gnus-seconds-today) . "%H:%M")
2115                                       ((+ 86400 (gnus-seconds-today)) . "%a %H:%M")
2116                                       (604800 . "%a, %b %-d")
2117                                       (15778476 . "%b %-d")
2118                                       (t . "%Y-%m-%d")))
2119
2120   (setq gnus-thread-sort-functions '((not gnus-thread-sort-by-number)))
2121   (setq gnus-unread-mark ?\.)
2122   (setq gnus-use-correct-string-widths t)
2123
2124   ;; thread
2125   (setq gnus-thread-hide-subtree t)
2126
2127   ;; (with-eval-after-load 'gnus-summary-mode
2128   ;;   (define-key gnus-summary-mode-map (kbd "C-o") 'sd/hydra-window/body))
2129
2130   (add-hook 'gnus-summary-mode-hook (lambda ()
2131                                       (define-key gnus-summary-mode-map (kbd "C-o") nil)))
2132
2133
2134 #+END_SRC
2135
2136 ** Windows layout
2137 See [[https://www.emacswiki.org/emacs/GnusWindowLayout][GnusWindowLayout]]
2138 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2139   (gnus-add-configuration
2140    '(summary
2141      (horizontal 1.0
2142                  (vertical 35
2143                            (group 1.0))
2144                  (vertical 1.0
2145                            (summary 1.0 poine)))))
2146
2147   (gnus-add-configuration
2148    '(article
2149      (horizontal 1.0
2150                  (vertical 35
2151                            (group 1.0))
2152                  (vertical 1.0
2153                            (summary 0.50 point)
2154                            (article 1.0)))))
2155
2156   (with-eval-after-load 'gnus-group-mode
2157     (gnus-group-select-group "INBOX"))
2158   ;; (add-hook 'gnus-group-mode-map (lambda ()
2159   ;;                               (gnus-group-select-group "INBOX")))
2160 #+END_SRC
2161
2162 * Gnu Plot
2163 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=
2164 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2165   (use-package gnuplot
2166     :ensure
2167     :init
2168     (setq gnuplot-help-xpm nil)
2169     (setq gnuplot-line-xpm nil)
2170     (setq gnuplot-region-xpm nil)
2171     (setq gnuplot-buffer-xpm nil)
2172     (setq gnuplot-doc-xpm nil))
2173 #+END_SRC
2174
2175 Use =gnuplot= on =Org-mode= file, see [[http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-gnuplot.html][ob-doc-gnuplot]]
2176 #+BEGIN_SRC gnuplot :exports code :file ./temp/file.png
2177   reset
2178
2179   set title "Putting it All Together"
2180
2181   set xlabel "X"
2182   set xrange [-8:8]
2183   set xtics -8,2,8
2184
2185
2186   set ylabel "Y"
2187   set yrange [-20:70]
2188   set ytics -20,10,70
2189
2190   f(x) = x**2
2191   g(x) = x**3
2192   h(x) = 10*sqrt(abs(x))
2193
2194   plot f(x) w lp lw 1, g(x) w p lw 2, h(x) w l lw 3
2195 #+END_SRC
2196
2197 #+RESULTS:
2198 [[file:./temp/file.png]]
2199
2200 * Blog
2201 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2202
2203 #+END_SRC
2204
2205 * key
2206 - passion
2207 - vision
2208 - mission
2209 * Ediff
2210 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2211   (with-eval-after-load 'ediff
2212     (setq ediff-split-window-function 'split-window-horizontally)
2213     (setq ediff-window-setup-function 'ediff-setup-windows-plain)
2214     (add-hook 'ediff-startup-hook 'ediff-toggle-wide-display)
2215     (add-hook 'ediff-cleanup-hook 'ediff-toggle-wide-display)
2216     (add-hook 'ediff-suspend-hook 'ediff-toggle-wide-display))
2217 #+END_SRC
2218
2219 * TODO Convert ASCII to key
2220 ** map =function-key-map= [[http://academic.evergreen.edu/projects/biophysics/technotes/program/ascii_ctrl.htm][ascii_ctrl]]
2221 new file =C-x C-f C-f=
2222
2223 ** write color syntax for =Man-mode=
2224
2225 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2226   (font-lock-add-keywords 'perl-mode '(("\\(|\\w+?\\(,\\w+?\\)?|\\)" 1 'py-builtins-face)))
2227 #+END_SRC
2228
2229 * TODO set fly-spell binding
2230
2231 * TODO imenu bindings
2232
2233 * DONE modified indicator
2234 :LOGBOOK:
2235 - State "DONE"       from "TODO"       [2016-07-18 Mon 23:35]
2236 :END:
2237 * DONE highlight selected ido candicate
2238 :LOGBOOK:
2239 - State "DONE"       from "TODO"       [2016-07-19 Tue 01:49]
2240 :END:
2241 * DONE show time in right of mode-line
2242 :LOGBOOK:
2243 - State "DONE"       from "TODO"       [2016-07-19 Tue 01:11]
2244 :END:
2245 * DONE ediff mode
2246 :LOGBOOK:
2247 - State "DONE"       from "TODO"       [2016-07-19 Tue 01:11]
2248 :END:
2249 * TODO jump last change point
2250 * TODO emms mode-line
2251
2252 * NEXT Key Bindings
2253 Here are some global key bindings for basic editting
2254 ** Project operations - =super=
2255 =projectile= settins
2256 ** Windown & Buffer - =C-o=
2257 Defind a =hydra= function for windows, buffer & bookmark operations. And map it to =C-o= globally.
2258 Most use =C-o C-o= to switch buffers; =C-o x, v= to split window; =C-o o= to delete other windows
2259 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2260   (winner-mode 1)
2261
2262   (defhydra sd/hydra-window (:color red :columns nil)
2263     "window"
2264     ("h" windmove-left nil :exit t)
2265     ("j" windmove-down nil :exit t)
2266     ("k" windmove-up nil :exit t)
2267     ("l" windmove-right nil :exit t)
2268     ("H" hydra-move-splitter-left nil)
2269     ("J" hydra-move-splitter-down nil)
2270     ("K" hydra-move-splitter-up nil)
2271     ("L" hydra-move-splitter-right nil)
2272     ("v" (lambda ()
2273            (interactive)
2274            (split-window-right)
2275            (windmove-right))
2276      "vert" :exit t)
2277     ("x" (lambda ()
2278            (interactive)
2279            (split-window-below)
2280            (windmove-down))
2281      "horz" :exit t)
2282     ("o" delete-other-windows "one" :exit t)
2283     ("C-o" ido-switch-buffer "buf" :exit t)
2284     ("C-k" sd/delete-current-window "del" :exit t)
2285     ("'" other-window "other" :exit t)
2286     ("a" ace-window "ace")
2287     ("s" ace-swap-window "swap")
2288     ("d" ace-delete-window "ace-one" :exit t)
2289     ("i" ace-maximize-window "ace-one" :exit t)
2290     ("b" ido-switch-buffer "buf" :exit t)
2291     ("C-b" ido-switch-buffer "buf" :exit t)
2292     ("m" bookmark-jump-other-window "open bmk" :exit t)
2293     ("M" bookmark-set "set bmk" :exit t)
2294     ("q" nil "cancel")
2295     ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
2296     ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
2297     ("C-h" nil nil :exit t)
2298     ("C-j" nil nil :exit t)
2299     ;; ("C-k" nil :exit t)
2300     ("C-l" nil nil :exit t)
2301     ("C-;" nil nil :exit t)
2302     ("p" nil nil :exit t)
2303     ("n" nil nil :exit t)
2304     ("[" nil nil :exit t)
2305     ("]" nil nil :exit t)
2306     ("f" nil))
2307
2308   (global-unset-key (kbd "C-o"))
2309   (global-set-key (kbd "C-o") 'sd/hydra-window/body)
2310 #+END_SRC
2311
2312 ** Edit
2313 - cut, yank, =C-w=, =C-y=
2314 - save, revert
2315 - undo, redo - undo-tree
2316 - select, expand-region
2317 - spell check, flyspell
2318
2319 ** Motion - =C-M-=
2320 Use =Avy= for motion
2321 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2322   (use-package avy
2323     :ensure t
2324     :config
2325     (avy-setup-default))
2326
2327   (global-set-key (kbd "C-M-j") 'avy-goto-line-below)
2328   (global-set-key (kbd "C-M-n") 'avy-goto-line-below)
2329   (global-set-key (kbd "C-M-k") 'avy-goto-line-above)
2330   (global-set-key (kbd "C-M-p") 'avy-goto-line-above)
2331
2332   (global-set-key (kbd "C-M-f") 'avy-goto-word-1-below)
2333   (global-set-key (kbd "C-M-b") 'avy-goto-word-1-above)
2334
2335   ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
2336   (global-set-key (kbd "C-M-w") 'avy-goto-char-timer)
2337   (global-set-key (kbd "C-M-l") 'avy-goto-char-in-line)
2338
2339   ;; will delete above 
2340   (global-set-key (kbd "M-g j") 'avy-goto-line-below)
2341   (global-set-key (kbd "M-g k") 'avy-goto-line-above)
2342   (global-set-key (kbd "M-g w") 'avy-goto-word-1-below)
2343   (global-set-key (kbd "M-g b") 'avy-goto-word-1-above)
2344   (global-set-key (kbd "M-g e") 'avy-goto-word-0)
2345   (global-set-key (kbd "M-g f") 'avy-goto-char-timer)
2346   (global-set-key (kbd "M-g c") 'avy-goto-char-in-line)
2347
2348   ;; M-g TAB              move-to-column
2349   ;; M-g ESC              Prefix Command
2350   ;; M-g c                goto-char
2351   ;; M-g g                goto-line
2352   ;; M-g n                next-error
2353   ;; M-g p                previous-error
2354
2355   ;; M-g M-g              goto-line
2356   ;; M-g M-n              next-error
2357   ;; M-g M-p              previous-error
2358 #+END_SRC
2359
2360 =imenu=, mapping =C-M-i= to =counsel-imenu=
2361 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2362   (global-unset-key (kbd "C-M-i"))
2363   (global-set-key (kbd "C-M-i") #'counsel-imenu)
2364 #+END_SRC
2365
2366 ** Search & Replace / hightlight =M-s=
2367 *** search
2368 *** replace
2369 *** hightlight
2370 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2371
2372   ;; (defhydra sd/search-highlight (:color red :columns nil)
2373   ;;   "search"
2374   ;;   ("M-s" . isearch-forward-regexp "search-forward" :exit t)
2375   ;;   ("s" . isearch-forward-regexp "search-forward" :exit t)
2376   ;;   ("r" . isearch-backward-regexp "search-backward" :exit t)
2377   ;;   )
2378
2379   ;; (setq-default indicate-empty-lines t)
2380 #+END_SRC
2381
2382 *** Occur
2383 Occur search key bindings
2384 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2385   (defun sd/occur-keys ()
2386     "My key bindings in occur-mode"
2387     (interactive)
2388     (switch-to-buffer-other-window "*Occur*")
2389     (define-key occur-mode-map (kbd "C-o") nil)
2390     (define-key occur-mode-map (kbd "C-n") (lambda ()
2391                                              (interactive)
2392                                              (occur-next)
2393                                              (occur-mode-goto-occurrence-other-window)
2394                                              (recenter)
2395                                              (other-window 1)))
2396     (define-key occur-mode-map (kbd "C-p") (lambda ()
2397                                              (interactive)
2398                                              (occur-prev)
2399                                              (occur-mode-goto-occurrence-other-window)
2400                                              (recenter)
2401                                              (other-window 1))))
2402
2403   (add-hook 'occur-hook #'sd/occur-keys)
2404
2405   (use-package color-moccur
2406     :ensure t
2407     :commands (isearch-moccur isearch-all)
2408     :init
2409     (setq isearch-lazy-highlight t)
2410     :config
2411     (use-package moccur-edit))
2412 #+END_SRC
2413
2414 *** Swiper
2415 stolen from [[https://github.com/mariolong/emacs.d/blob/f6a061594ef1b5d1f4750e9dad9dc97d6e122840/emacs-init.org][here]]
2416 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2417   (use-package swiper
2418     :ensure t
2419     :init
2420     (setq ivy-use-virtual-buffers t)
2421     :config
2422     (ivy-mode)
2423     (global-set-key (kbd "s-/") 'swiper)
2424     (define-key swiper-map (kbd "M-r") 'swiper-query-replace))
2425
2426   (set-face-attribute
2427    'ivy-current-match nil
2428    :background "Orange"
2429    :foreground "black")
2430
2431   (eval-after-load 'swiper
2432     '(progn
2433        (define-key swiper-map (kbd "C-.")
2434          (lambda () 
2435            (interactive)
2436            (insert (format "%s" (with-ivy-window (thing-at-point 'word))))))
2437        (define-key swiper-map (kbd "M-.")
2438          (lambda ()
2439            (interactive)
2440            (insert (format "%s" (with-ivy-window (thing-at-point 'symbol))))))
2441        ))
2442 #+END_SRC
2443
2444 * TODO Temp directory for cached/history/temp files
2445 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2446   (use-package recentf
2447     :config
2448     (setq recentf-save-file (concat sd-temp-directory "recentf")))
2449
2450   (use-package projectile
2451     :config
2452     (setq projectile-cache-file (concat sd-temp-directory "projectile.cache")))
2453
2454   (use-package ido
2455     :config
2456     (setq ido-save-directory-list-file (concat sd-temp-directory "ido.last")))
2457
2458   (use-package savehist
2459     :config
2460     (setq savehist-file (concat sd-temp-directory "history")))
2461
2462   (use-package emms
2463     :config
2464     (setq emms-directory (concat sd-temp-directory "emms")))
2465
2466   (setq auto-save-list-file-prefix (concat sd-temp-directory "auto-save-list/.saves-")) 
2467
2468   (use-package smex
2469     :config
2470     (setq smex-save-file (concat sd-temp-directory "smex-items")))
2471 #+END_SRC
2472
2473 * test
2474 #+BEGIN_SRC ditaa :file temp/hello-world.png :cmdline -r
2475 +--------------+
2476 |              |
2477 | Hello World! |
2478 |              |
2479 +--------------+
2480 #+END_SRC
2481
2482 #+RESULTS:
2483 [[file:temp/hello-world.png]]
2484
2485
2486 * =C-u C-h a= search funtions 
2487 =apropos-command=