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