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