1 #+TITLE: Emacs Configuration file
3 #+EMAIL: seudut@gmail.com
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
11 ** Setting loading Path
13 Set system PATH and emacs exec path
15 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
17 (setenv "PATH" (concat (getenv "PATH")
19 ":" "/Library/TeX/texbin"))
20 (setq exec-path (append exec-path '("/usr/local/bin")))
21 (setq exec-path (append exec-path '("/Library/TeX/texbin/")))
25 Set the emacs load path
27 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
28 ;; (add-to-list 'load-path "~/.emacs.d/elisp")
31 ** Package Initialization
33 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
37 (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
38 ("gnu" . "http://elpa.gnu.org/packages/")
39 ("org" . "http://orgmode.org/elpa/")))
47 Disable scroll bar, tool-bar and menu-bar
49 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
54 ;; (setq debug-on-error t)
55 (setq inhibit-startup-message t)
57 (defalias 'yes-or-no-p 'y-or-n-p)
60 (setq make-backup-files nil)
65 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
67 (setq custom-file "~/.emacs.d/custom.el")
68 (if (file-exists-p custom-file)
73 Switch the focus to help window when it appears
75 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
77 (setq help-window-select t)
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)
87 Set default window size
88 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
89 (setq initial-frame-alist
95 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
96 (setq auto-save-default nil)
98 ;; restore last session
102 * Package Management Tools
106 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
108 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
110 (unless (package-installed-p 'use-package)
111 (package-refresh-contents)
112 (package-install 'use-package))
114 (require 'use-package)
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]].
123 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
128 (add-to-list 'load-path "~/.emacs.d/el-get"))
132 * Color and Fonts Settings
134 ** highlight current line
136 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
138 (global-hl-line-mode)
144 [[https://github.com/paldepind/smart-comment][smart-comments]]
146 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
148 (use-package smart-comment
150 :bind ("M-;" . smart-conmment))
158 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
160 (global-font-lock-mode 1)
164 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
166 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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."))
180 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
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)))
192 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
194 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
196 (setq vc-follow-symlinks t)
198 (use-package color-theme
200 :init (require 'color-theme)
201 :config (use-package color-theme-sanityinc-tomorrow
205 (load-theme 'sanityinc-tomorrow-bright t)))
207 ;(eval-after-load 'color-theme
208 ; (load-theme 'sanityinc-tomorrow-bright t))
212 Change the Org-mode colors
214 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
216 (defun org-src-color-blocks-light ()
217 "Colors the block headers and footers to make them stand out more for lighter themes"
220 '(org-block-begin-line
221 ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
222 '(org-block-background
223 ((t (:background "#FFFFEA"))))
225 ((t (:background "#FFFFEA"))))
227 ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
229 '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
230 '(which-func ((t (:foreground "#008000"))))))
232 (defun org-src-color-blocks-dark ()
233 "Colors the block headers and footers to make them stand out more for dark themes"
236 '(org-block-begin-line
237 ((t (:foreground "#008ED1" :background "#002E41"))))
238 '(org-block-background
239 ((t (:background "#000000"))))
241 ((t (:background "#000000"))))
243 ((t (:foreground "#008ED1" :background "#002E41"))))
245 '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
246 '(which-func ((t (:foreground "green"))))))
248 (org-src-color-blocks-dark)
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")
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."))
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)))))))
300 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
302 (use-package rainbow-delimiters
305 (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
311 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
313 (use-package page-break-lines
316 (turn-on-page-break-lines-mode))
322 Enable rainbow mode in emacs lisp mode
324 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
325 (use-package rainbow-mode
328 ; (add-hook emacs-lisp-mode-hook 'rainbow-mode)
337 clean mode line, Refer to [[https://www.masteringemacs.org/article/hiding-replacing-modeline-strings][Marstering Emacs]]
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 . " π")
346 (projectile-mode . "")
348 (undo-tree-mode . "")
350 (which-key-mode . "")
352 (smartparens-mode . "")
354 (linum-relative-mode . "")
356 (auto-revert-mode . "")
358 (org-indent-mode . "")
362 (lisp-interaction-mode . "λ")
365 (emacs-lisp-mode . "EL")
367 (nxhtml-mode . "nx"))
368 "Alist for `clean-mode-line'.
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.")
375 (defun clean-mode-line ()
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))))
382 (setcar old-mode-str mode-str))
384 (when (eq mode major-mode)
385 (setq mode-name mode-str)))))
388 (add-hook 'after-change-major-mode-hook 'clean-mode-line)
393 Install powerline mode [[https://github.com/milkypostman/powerline][powerline]]
395 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
396 (use-package powerline
399 ;; (powerline-center-theme)
402 ;; (use-package smart-mode-line
404 ;; (use-package smart-mode-line-powerline-theme
408 Revised powerline-center-theme
410 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
411 (defun sd/powerline-simpler-vc (s)
413 (replace-regexp-in-string "Git[:-]" "" s)
416 (defun sd/powerline-center-theme_revised ()
417 "Setup a mode-line with major and minor modes centered."
419 (setq-default mode-line-format
422 (let* ((active (powerline-selected-window-active))
423 (mode-line-buffer-id (if active 'mode-line-buffer-id 'mode-line-buffer-id-inactive))
424 (mode-line (if active 'mode-line 'mode-line-inactive))
425 (face1 (if active 'powerline-active1 'powerline-inactive1))
426 (face2 (if active 'powerline-active2 'powerline-inactive2))
427 (separator-left (intern (format "powerline-%s-%s"
428 (powerline-current-separator)
429 (car powerline-default-separator-dir))))
430 (separator-right (intern (format "powerline-%s-%s"
431 (powerline-current-separator)
432 (cdr powerline-default-separator-dir))))
433 (lhs (list (powerline-raw "%*" mode-line 'l)
434 ;; (powerline-buffer-size mode-line 'l)
435 (powerline-buffer-id mode-line-buffer-id 'l)
437 (funcall separator-left mode-line face1)
438 (powerline-narrow face1 'l)
439 ;; (powerline-vc face1)
440 (sd/powerline-simpler-vc (powerline-vc face1))
442 (rhs (list (powerline-raw global-mode-string face1 'r)
443 (powerline-raw "%4l" face1 'r)
444 (powerline-raw ":" face1)
445 (powerline-raw "%3c" face1 'r)
446 (funcall separator-right face1 mode-line)
448 (powerline-raw "%6p" mode-line 'r)
449 (powerline-hud face2 face1)))
450 (center (list (powerline-raw " " face1)
451 (funcall separator-left face1 face2)
452 (when (and (boundp 'erc-track-minor-mode) erc-track-minor-mode)
453 (powerline-raw erc-modified-channels-object face2 'l))
454 (powerline-major-mode face2 'l)
455 (powerline-process face2)
456 (powerline-raw " :" face2)
457 (powerline-minor-modes face2 'l)
458 (powerline-raw " " face2)
459 (funcall separator-right face2 face1))))
460 (concat (powerline-render lhs)
461 (powerline-fill-center face1 (/ (powerline-width center) 2.0))
462 (powerline-render center)
463 (powerline-fill face1 (powerline-width rhs))
464 (powerline-render rhs)))))))
466 (sd/powerline-center-theme_revised)
469 Fix the issue in mode line when showing triangle
471 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
472 (setq ns-use-srgb-colorspace nil)
475 set height in mode line
477 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
479 (custom-set-variables
480 '(powerline-height 14)
481 '(powerline-text-scale-factor 0.8))
483 (set-face-attribute 'mode-line nil :height 100)
491 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
495 :init (setq ido-enable-flex-matching t
496 ido-ignore-extensions t
497 ido-use-virtual-buffers t
502 (add-to-list 'completion-ignored-extensions ".pyc"))
510 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
514 :init (setq ido-enable-flex-matching t
516 :config (flx-ido-mode 1))
522 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
524 (use-package ido-vertical-mode
527 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
529 (ido-vertical-mode 1))
535 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
539 :init (smex-initialize)
542 ("M-X" . smex-major-mode-commands))
548 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
550 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
552 (use-package ido-ubiquitous
555 (setq magit-completing-read-function 'magit-ido-completing-read)
556 (setq gnus-completing-read-function 'gnus-ido-completing-read)
558 (ido-ubiquitous-mode 1))
564 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
566 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
568 (use-package ido-exit-target
571 (define-key ido-common-completion-map (kbd "C-j") #'ido-exit-target-split-window-right)
572 (define-key ido-common-completion-map (kbd "C-l") #'ido-exit-target-split-window-below))
576 * Normal Text Operation
579 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
580 (use-package undo-tree
583 (define-key undo-tree-visualizer-mode-map "j" 'undo-tree-visualize-redo)
584 (define-key undo-tree-visualizer-mode-map "k" 'undo-tree-visualize-undo)
585 (define-key undo-tree-visualizer-mode-map "h" 'undo-tree-visualize-switch-branch-left)
586 (define-key undo-tree-visualizer-mode-map "l" 'undo-tree-visualize-switch-branch-right)
587 (global-undo-tree-mode 1))
589 (global-set-key (kbd "s-u") 'undo-tree-visualize)
593 Stolen from [[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-spelling.el][here]], hunspell will search dictionary in =DICPATH=
594 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
595 (setenv "DICPATH" "/usr/local/share/hunspell")
597 (when (executable-find "hunspell")
598 (setq-default ispell-program-name "hunspell")
599 (setq ispell-really-hunspell t))
601 ;; (defun text-mode-hook-setup ()
602 ;; ;; Turn off RUN-TOGETHER option when spell check text-mode
603 ;; (setq-local ispell-extra-args (flyspell-detect-ispell-args)))
604 ;; (add-hook 'text-mode-hook 'text-mode-hook-setup)
605 (add-hook 'text-mode-hook 'flyspell-mode)
607 ;; enable flyspell check on comments and strings in progmamming modes
608 (add-hook 'prog-mode-hook 'flyspell-prog-mode)
610 ;; I don't use the default mappings
611 (with-eval-after-load 'flyspell
612 (define-key flyspell-mode-map (kbd "C-;") nil)
613 (define-key flyspell-mode-map (kbd "C-,") nil)
614 (define-key flyspell-mode-map (kbd "C-.") nil))
617 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]]
618 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
619 ;; NO spell check for embedded snippets
620 (defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
621 (let ((rlt ad-return-value)
622 (begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\)")
623 (end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\)")
626 (when ad-return-value
628 (setq old-flag case-fold-search)
629 (setq case-fold-search t)
630 (setq b (re-search-backward begin-regexp nil t))
631 (if b (setq e (re-search-forward end-regexp nil t)))
632 (setq case-fold-search old-flag))
633 (if (and b e (< (point) e)) (setq rlt nil)))
634 (setq ad-return-value rlt)))
638 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
639 (use-package expand-region
642 (global-set-key (kbd "C-=") 'er/expand-region))
647 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
655 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
656 (global-set-key (kbd "M-g j") 'avy-goto-line-below)
657 (global-set-key (kbd "M-g k") 'avy-goto-line-above)
658 (global-set-key (kbd "M-g w") 'avy-goto-word-1-below)
659 (global-set-key (kbd "M-g b") 'avy-goto-word-1-above)
660 (global-set-key (kbd "M-g e") 'avy-goto-word-0)
661 (global-set-key (kbd "M-g f") 'avy-goto-char-timer)
662 (global-set-key (kbd "M-g c") 'avy-goto-char-in-line)
664 ;; M-g TAB move-to-column
665 ;; M-g ESC Prefix Command
669 ;; M-g p previous-error
672 ;; M-g M-n next-error
673 ;; M-g M-p previous-error
677 ** Search & highlight
682 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
684 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
686 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
687 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
688 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
689 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
690 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
691 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
692 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
693 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
694 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
696 ;; Also map s-h same as C-g
697 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
701 ** =Ctrl= key bindings
703 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
707 ;; C-j newline and indent
709 ;; C-l recenter-top-bottom
710 ;; (global-set-key (kbd "C-;") 'ido-switch-buffer)
740 ** =Super= bindings for file, buffer and windows
742 Some global bindings on =Super=, on Mac, it is =Command=
744 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
745 (defun sd/delete-current-window ()
747 (if (> (length (window-list)) 1)
749 (message "Only one Windows now!")))
751 (global-set-key (kbd "s-h") 'keyboard-quit)
752 (global-set-key (kbd "s-j") 'ido-switch-buffer)
753 (global-set-key (kbd "s-k") 'ido-find-file)
754 (global-set-key (kbd "s-l") 'sd/delete-current-window)
756 ;; (global-set-key (kbd "s-/") 'swiper)
758 ;; s-' --> 'next-multiframe-window
759 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
761 (global-set-key (kbd "s-f") 'projectile-find-file)
763 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
765 (global-set-key (kbd "s-n") 'persp-next)
766 (global-set-key (kbd "s-p") 'persp-prev)
768 (global-set-key (kbd "s-=") 'text-scale-increase)
769 (global-set-key (kbd "s--") 'text-scale-decrease)
771 ;; (global-set-key (kbd "s-u") 'undo-tree-visualize)
774 ;; someothers default mapping on super (command) key
776 ;; s-k kill-this-buffer
779 ;; s-h --> ns-do-hide-emacs
780 ;; s-j --> ido-switch-buffer +
781 ;; s-k --> kill-this-buffer
784 ;; s-' --> next-multiframe-window
785 ;; s-ret --> toggle-frame-fullscreen +
787 ;; s-y --> ns-paste-secondary
788 ;; s-u --> revert-buffer
789 ;; s-i --> undefined - but used for iterm globally
790 ;; s-o --> used for emacs globally
791 ;; s-p --> projectile-persp-switch-project +
792 ;; s-[ --> next-buffer +
793 ;; s-] --> previous-buffer +
800 ;; s-- --> center-line
803 ;; s-n --> make-frame
804 ;; s-m --> iconify-frame
810 ;; s-g --> isearch-repeat-forward
811 ;; s-f --> projectile-find-file +
812 ;; s-d --> isearch-repeat-background
813 ;; s-s --> save-buffer
814 ;; s-a --> make-whole-buffer
818 ;; s-c --> ns-copy-including-secondary
820 ;; s-t --> ns-popup-font-panel
822 ;; s-e --> isearch-yanqk-kill
823 ;; s-w --> delete-frame
824 ;; s-q --> same-buffers-kill-emacs
826 ;; s-` --> other-frame
829 ** Search Replace and highlight
831 Occur search key bindings
832 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
833 (add-hook 'occur-hook (lambda ()
834 (switch-to-buffer-other-window "*Occur*")
835 (define-key occur-mode-map (kbd "C-o") nil)))
836 ;; auto select occur window
838 (define-key occur-mode-map (kbd "C-n")
842 (occur-mode-goto-occurrence-other-window)
846 (define-key occur-mode-map (kbd "C-p")
850 (occur-mode-goto-occurrence-other-window)
854 (use-package color-moccur
856 :commands (isearch-moccur isearch-all)
858 (setq isearch-lazy-highlight t)
860 (use-package moccur-edit))
864 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
869 (setq ivy-use-virtual-buffers t)
870 (global-set-key (kbd "s-/") 'swiper)
872 ;; (global-set-key "\C-s" 'swiper)
873 ;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
874 ;; (global-set-key (kbd "<f6>") 'ivy-resume)
875 ;; ;; (global-set-key (kbd "M-x") 'counsel-M-x)
876 ;; ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
877 ;; (global-set-key (kbd "<f1> f") 'counsel-describe-function)
878 ;; (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
879 ;; (global-set-key (kbd "<f1> l") 'counsel-load-library)
880 ;; (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
881 ;; (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
882 ;; (global-set-key (kbd "C-c g") 'counsel-git)
883 ;; (global-set-key (kbd "C-c j") 'counsel-git-grep)
884 ;; (global-set-key (kbd "C-c k") 'counsel-ag)
885 ;; (global-set-key (kbd "C-x l") 'counsel-locate)
886 ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
887 ;; ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
892 use the prefix =M-s= for searching in buffers
893 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
894 (defun sd/make-keymap (key bindings)
895 (setq keymap (make-sparse-keymap))
896 (dolist (binding bindings)
897 (define-key keymap (car binding) (cdr binding)))
898 (global-set-key key keymap))
900 (use-package highlight-symbol
903 (sd/make-keymap "\M-s"
904 '(("w" . save-buffer)
905 ;; ("\M-w" . save-buffer)
906 ("e" . revert-buffer)
907 ("s" . isearch-forward-regexp)
908 ("r" . isearch-backward-regexp)
909 ("." . isearch-forward-symbol-at-point)
911 ;; ("h" . highlight-symbol-at-point)
912 ("h" . highlight-symbol)
913 ("m" . highlight-regexp)
914 ("l" . highlight-lines-matching-regexp)
915 ("M" . unhighlight-regexp)
916 ("f" . keyboard-quit)
917 ("q" . keyboard-quit)))
919 ;; search and replace and highlight
920 (define-key isearch-mode-map (kbd "M-s") 'isearch-repeat-forward)
921 (define-key isearch-mode-map (kbd "M-r") 'isearch-repeat-backward)
922 (global-set-key (kbd "s-[") 'highlight-symbol-next)
923 (global-set-key (kbd "s-]") 'highlight-symbol-prev)
924 (global-set-key (kbd "s-\\") 'highlight-symbol-query-replace)
927 (define-key minibuffer-local-map "\M-s" nil)
929 (set-face-background 'ido-first-match "yellow")
931 ;; M-s M-w eww-search-words
939 ** =M-o= as prefix key for windows
941 ** =M-g= as prefix key for launcher
945 ** Org-mode Basic setting
947 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
949 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
953 (setq org-startup-indented t)
954 (setq org-hide-leading-starts t)
955 (setq org-src-fontify-natively t)
956 (setq org-src-tab-acts-natively t)
957 (setq org-confirm-babel-evaluate nil)
958 (setq org-use-speed-commands t)
959 (setq org-completion-use-ido t))
961 (org-babel-do-load-languages
962 'org-babel-load-languages
976 ;; use current window for org source buffer editting
977 (setq org-src-window-setup 'current-window )
979 (define-key org-mode-map (kbd "C-'") nil)
984 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
986 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
987 (use-package org-bullets
990 (add-hook 'org-mode-hook
992 (org-bullets-mode t))))
994 (setq org-bullets-bullet-list '("⦿" "✪" "◉" "○" "►" "◆"))
996 ;; increase font size when enter org-src-mode
997 (add-hook 'org-src-mode-hook (lambda () (text-scale-increase 2)))
1002 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
1003 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
1004 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
1005 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
1007 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1012 :init (add-hook 'org-mode-hook 'worf-mode)
1014 ;; (define-key worf-mode-map "[" nil)
1015 ;; (define-key worf-mode-map "]" nil)
1016 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
1017 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
1024 Refer to [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
1027 standard key binding
1029 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1030 (global-set-key "\C-cl" 'org-store-link)
1031 (global-set-key "\C-ca" 'org-agenda)
1032 (global-set-key "\C-cb" 'org-iswitchb)
1037 Replace the list bullet =-=, =+=, with =•=, a litter change based [[https://github.com/howardabrams/dot-files/blob/master/emacs-org.org][here]]
1039 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1040 ;; (use-package org-mode
1042 ;; (font-lock-add-keywords 'org-mode
1043 ;; '(("^ *\\([-+]\\) "
1044 ;; (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•")))))))
1049 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]],
1051 To track TODO state changes, the =!= is to insert a timetamp, =@= is to insert a note with
1052 timestamp for the state change.
1054 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1055 ;; (setq org-todo-keywords
1056 ;; '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
1057 ;; (sequence "âš‘ WAITING(w)" "|")
1058 ;; (sequence "|" "✘ CANCELLED(c)")))
1059 ; (setq org-todo-keyword-faces
1060 ; (quote ("TODO" . (:foreground "red" :weight bold))
1061 ; ("NEXT" . (:foreground "blue" :weight bold))
1062 ; ("WAITING" . (:foreground "forest green" :weight bold))
1063 ; ("DONE" . (:foreground "magenta" :weight bold))
1064 ; ("CANCELLED" . (:foreground "forest green" :weight bold))))
1067 (setq org-todo-keywords
1068 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!)")
1069 ;; (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING")
1070 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" ))))
1072 (setq org-todo-keyword-faces
1073 (quote (("TODO" :foreground "red" :weight bold)
1074 ("NEXT" :foreground "blue" :weight bold)
1075 ("DONE" :foreground "forest green" :weight bold)
1076 ("WAITING" :foreground "orange" :weight bold)
1077 ("HOLD" :foreground "magenta" :weight bold)
1078 ("CANCELLED" :foreground "forest green" :weight bold)
1079 ;; ("MEETING" :foreground "forest green" :weight bold)
1080 ;; ("PHONE" :foreground "forest green" :weight bold)
1084 Fast todo selections
1086 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1087 (setq org-use-fast-todo-selection t)
1088 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1091 TODO state triggers and tags, [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
1093 - Moving a task to =CANCELLED=, adds a =CANCELLED= tag
1094 - Moving a task to =WAITING=, adds a =WAITING= tag
1095 - Moving a task to =HOLD=, add =HOLD= tags
1096 - Moving a task to =DONE=, remove =WAITING=, =HOLD= tag
1097 - Moving a task to =NEXT=, remove all waiting/hold/cancelled tags
1099 This tags are used to filter tasks in agenda views
1100 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1101 (setq org-todo-state-tags-triggers
1102 (quote (("CANCELLED" ("CANCELLED" . t))
1103 ("WAITING" ("WAITING" . t))
1104 ("HOLD" ("WAITING") ("HOLD" . t))
1105 (done ("WAITING") ("HOLD"))
1106 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1107 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1108 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1112 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1113 ;; log time when task done
1114 ;; (setq org-log-done (quote time))
1115 ;; save clocking into to LOGBOOK
1116 (setq org-clock-into-drawer t)
1117 ;; save state change notes and time stamp into LOGBOOK drawer
1118 (setq org-log-into-drawer t)
1119 (setq org-clock-into-drawer "CLOCK")
1123 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1124 (setq org-tag-alist (quote ((:startgroup)
1130 ("CANCELLED" . ?c))))
1132 ;; Allow setting single tags without the menu
1133 (setq org-fast-tag-selection-single-key (quote expert))
1136 *** Capture - Refile - Archive
1138 Capture lets you quickly store notes with little interruption of your work flow.
1140 **** Capture Templates
1142 When a new taks needs to be added, categorize it as
1144 All captured file which need next actions are stored in =refile.org=,
1145 - A new task / note (t) =refile.org=
1146 - A work task in office =office.org=
1147 - A jourenl =diary.org=
1148 - A new habit (h) =refile.org=
1150 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1151 (setq org-directory "~/org")
1152 (setq org-default-notes-file "~/org/refile.org")
1153 (setq sd/org-diary-file "~/org/diary.org")
1155 (global-set-key (kbd "C-c c") 'org-capture)
1157 (setq org-capture-templates
1158 (quote (("t" "Todo" entry (file org-default-notes-file)
1159 "* TODO %?\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1160 ("n" "Note" entry (file org-default-notes-file)
1161 "* %? :NOTE:\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1162 ("j" "Journal" entry (file+datetree sd/org-diary-file)
1163 "* %?\n:LOGBOOK:\n:END:" :clock-in t :clock-resume t)
1164 ("h" "Habit" entry (file org-default-notes-file)
1165 "* 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 "))))
1170 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1171 (setq org-refile-targets (quote (;; (nil :maxlevel . 9)
1172 (org-agenda-files :maxlevel . 9))))
1174 (setq org-refile-use-outline-path t)
1176 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1180 Setting agenda files and the agenda view
1181 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1182 (setq org-agenda-files (quote ("~/org/gtd.org"
1185 ;; only show today's tasks in agenda view
1186 (setq org-agenda-span 'day)
1187 ;; Use current windows for agenda view
1188 (setq org-agenda-window-setup 'current-window)
1190 ;; show all feature entries for repeating tasks,
1191 ;; this is already setting by default
1192 (setq org-agenda-repeating-timestamp-show-all t)
1194 ;; Show all agenda dates - even if they are empty
1195 (setq org-agenda-show-all-dates t)
1200 Install MacTex-basic and some tex packages
1204 sudo tlmgr update --self
1206 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
1210 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1211 ;; ;; allow for export=>beamer by placing
1213 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
1214 ;; #+LaTeX_CLASS: beamer in org files
1215 (unless (boundp 'org-export-latex-classes)
1216 (setq org-export-latex-classes nil))
1217 (add-to-list 'org-export-latex-classes
1218 ;; beamer class, for presentations
1220 "\\documentclass[11pt]{beamer}\n
1221 \\mode<{{{beamermode}}}>\n
1222 \\usetheme{{{{beamertheme}}}}\n
1223 \\usecolortheme{{{{beamercolortheme}}}}\n
1224 \\beamertemplateballitem\n
1225 \\setbeameroption{show notes}
1226 \\usepackage[utf8]{inputenc}\n
1227 \\usepackage[T1]{fontenc}\n
1228 \\usepackage{hyperref}\n
1230 \\usepackage{listings}
1231 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
1234 showspaces=false,showstringspaces=false,
1236 keywordstyle=\\color{blue}\\bfseries,
1237 commentstyle=\\color{red},
1239 \\usepackage{verbatim}\n
1240 \\institute{{{{beamerinstitute}}}}\n
1241 \\subject{{{{beamersubject}}}}\n"
1243 ("\\section{%s}" . "\\section*{%s}")
1245 ("\\begin{frame}[fragile]\\frametitle{%s}"
1247 "\\begin{frame}[fragile]\\frametitle{%s}"
1250 ;; letter class, for formal letters
1252 (add-to-list 'org-export-latex-classes
1255 "\\documentclass[11pt]{letter}\n
1256 \\usepackage[utf8]{inputenc}\n
1257 \\usepackage[T1]{fontenc}\n
1258 \\usepackage{color}"
1260 ("\\section{%s}" . "\\section*{%s}")
1261 ("\\subsection{%s}" . "\\subsection*{%s}")
1262 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1263 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1264 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1268 (require 'ox-beamer)
1270 (setq org-latex-pdf-process
1271 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1272 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1273 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
1275 (setq TeX-parse-self t)
1277 (setq TeX-PDF-mode t)
1278 (add-hook 'LaTeX-mode-hook
1281 (setq TeX-master t)))
1287 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
1289 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1291 (add-to-list 'org-structure-template-alist
1292 '("E" "#+BEGIN_SRC emacs-lisp :tangle yes :results silent\n?\n#+END_SRC"))
1293 (add-to-list 'org-structure-template-alist
1294 '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
1295 (add-to-list 'org-structure-template-alist
1296 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
1301 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
1302 and Defined keys, using vi keybindings, Refer abo-abo's setting [[https://github.com/abo-abo/oremacs/blob/c5cafdcebc88afe9e73cc8bd40c49b70675509c7/modes/ora-nextmagit.el][here]]
1303 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1307 ;; don't ask me to confirm the unsaved change
1308 (setq magit-save-repository-buffers nil)
1309 :commands magit-status magit-blame
1311 (dolist (map (list magit-status-mode-map
1314 magit-staged-section-map))
1315 (define-key map "j" 'magit-section-forward)
1316 (define-key map "k" 'magit-section-backward)
1317 (define-key map "D" 'magit-discard)
1318 (define-key map "O" 'magit-discard-file)
1319 (define-key map "n" nil)
1320 (define-key map "p" nil)
1321 (define-key map "v" 'recenter-top-bottom)
1322 (define-key map "i" 'magit-section-toggle)))
1327 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1328 (defalias 'e 'find-file)
1329 (defalias 'ff 'find-file)
1330 (defalias 'ee 'find-files)
1333 *** Eshell erase buffer
1334 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1335 (defun sd/eshell-clear-buffer ()
1336 "Clear eshell buffer"
1338 (let ((inhibit-read-only t))
1340 (eshell-send-input)))
1342 (add-hook 'eshell-mode-hook (lambda ()
1343 (local-set-key (kbd "C-l") 'sd/eshell-clear-buffer)))
1347 Toggle an eshell in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
1348 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1349 (defun sd/window-has-eshell ()
1350 "Check if current windows list has a eshell buffer, and return the window"
1353 (walk-windows (lambda (window)
1354 (if (equal (with-current-buffer (window-buffer window) major-mode)
1360 (defun sd/toggle-eshell-here ()
1361 "Toggle a eshell buffer vertically"
1363 (if (sd/window-has-eshell)
1364 (if (equal major-mode 'eshell-mode)
1366 (if (equal (length (window-list)) 1)
1367 (mode-line-other-buffer)
1369 (select-window (sd/window-has-eshell)))
1371 (let ((dir default-directory))
1373 (split-window-vertically (- (/ (window-total-height) 3)))
1375 (unless (and (boundp 'eshell-buffer-name) (get-buffer eshell-buffer-name))
1377 (switch-to-buffer eshell-buffer-name)
1378 (goto-char (point-max))
1380 (insert (format "cd %s" dir))
1381 (eshell-send-input)))))
1383 (global-unset-key (kbd "M-`"))
1384 (global-set-key (kbd "M-`") 'sd/toggle-eshell-here)
1387 *** TODO smart display
1390 ** [[https://github.com/abo-abo/hydra][Hydra]]
1392 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1395 ;; disable new line in minibuffer when hint hydra
1400 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1401 (defhydra sd/font-zoom (global-map "<f2>")
1403 ("g" text-scale-increase "in")
1404 ("l" text-scale-decrease "out"))
1407 *** Windmove Splitter
1409 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1411 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1413 (defun hydra-move-splitter-left (arg)
1414 "Move window splitter left."
1416 (if (let ((windmove-wrap-around))
1417 (windmove-find-other-window 'right))
1418 (shrink-window-horizontally arg)
1419 (enlarge-window-horizontally arg)))
1421 (defun hydra-move-splitter-right (arg)
1422 "Move window splitter right."
1424 (if (let ((windmove-wrap-around))
1425 (windmove-find-other-window 'right))
1426 (enlarge-window-horizontally arg)
1427 (shrink-window-horizontally arg)))
1429 (defun hydra-move-splitter-up (arg)
1430 "Move window splitter up."
1432 (if (let ((windmove-wrap-around))
1433 (windmove-find-other-window 'up))
1434 (enlarge-window arg)
1435 (shrink-window arg)))
1437 (defun hydra-move-splitter-down (arg)
1438 "Move window splitter down."
1440 (if (let ((windmove-wrap-around))
1441 (windmove-find-other-window 'up))
1443 (enlarge-window arg)))
1448 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1451 (defhydra sd/hydra-window (:color red :columns nil)
1453 ("h" windmove-left nil :exit t)
1454 ("j" windmove-down nil :exit t)
1455 ("k" windmove-up nil :exit t)
1456 ("l" windmove-right nil :exit t)
1457 ("H" hydra-move-splitter-left nil)
1458 ("J" hydra-move-splitter-down nil)
1459 ("K" hydra-move-splitter-up nil)
1460 ("L" hydra-move-splitter-right nil)
1463 (split-window-right)
1468 (split-window-below)
1471 ("o" delete-other-windows "one" :exit t)
1472 ("C-o" ido-switch-buffer "buf" :exit t)
1473 ("C-k" sd/delete-current-window "del" :exit t)
1474 ("'" other-window "other" :exit t)
1475 ("a" ace-window "ace")
1476 ("s" ace-swap-window "swap")
1477 ("d" ace-delete-window "ace-one" :exit t)
1478 ("i" ace-maximize-window "ace-one" :exit t)
1479 ("b" ido-switch-buffer "buf" :exit t)
1480 ("C-b" ido-switch-buffer "buf" :exit t)
1481 ;; ("m" headlong-bookmark-jump "bmk")
1483 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
1484 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
1487 (global-unset-key (kbd "C-o"))
1488 (global-set-key (kbd "C-o") 'sd/hydra-window/body)
1492 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1493 (defhydra sd/hydra-misc (:color red :columns nil)
1494 "Miscellaneous Commands"
1495 ("e" eshell "eshell" :exit t)
1498 (if (not (eq nil (get-buffer "*Packages*")))
1499 (switch-to-buffer "*Packages*")
1500 (package-list-packages)))
1501 "list-package" :exit t)
1502 ("g" magit-status "git-status" :exit t)
1503 ("'" mode-line-other-buffer "last buffer" :exit t)
1504 ("C-'" mode-line-other-buffer "last buffer" :exit t)
1505 ("m" man "man" :exit t)
1506 ("d" dired-jump "dired" :exit t)
1510 (global-set-key (kbd "C-'") 'sd/hydra-misc/body)
1514 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1515 (defhydra sd/hydra-launcher (:color blue :columns 2)
1517 ("e" emms "emms" :exit t)
1523 Enable linum mode on programming modes
1525 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1527 (add-hook 'prog-mode-hook 'linum-mode)
1531 Fix the font size of line number
1533 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1535 (defun fix-linum-size ()
1537 (set-face-attribute 'linum nil :height 110))
1539 (add-hook 'linum-mode-hook 'fix-linum-size)
1543 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1545 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1547 (use-package linum-relative
1550 (defun linum-new-mode ()
1551 "If line numbers aren't displayed, then display them.
1552 Otherwise, toggle between absolute and relative numbers."
1555 (linum-relative-toggle)
1559 ("A-k" . linum-new-mode))
1561 ;; auto enable linum-new-mode in programming modes
1562 (add-hook 'prog-mode-hook 'linum-relative-mode)
1566 ** Save File Position
1568 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1570 (require 'saveplace)
1571 (setq-default save-place t)
1572 (setq save-place-forget-unreadable-files t)
1573 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1579 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1581 (use-package multi-term
1588 [[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
1589 Type =o= to go to the link
1591 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1593 (use-package ace-link
1596 (ace-link-setup-default))
1602 [[https://github.com/re5et/emux][emux]] is
1604 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1606 (el-get-bundle re5et/emux)
1612 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1614 (use-package smartparens
1618 (require 'smartparens-config)
1619 (add-hook 'prog-mode-hook 'smartparens-mode)))
1625 [[https://github.com/abo-abo/ace-window][ace-window]]
1627 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1629 (use-package ace-window
1633 ; (global-set-key (kbd "M-o") 'ace-window)
1635 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1641 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1643 (use-package projectile
1646 (setq projectile-enable-caching t)
1648 (projectile-global-mode t))
1650 (use-package persp-projectile
1655 (:map projectile-mode-map
1656 ("s-t" . projectile-persp-switch-project)))
1658 ;; projectile-find-file
1659 ;; projectile-switch-buffer
1660 ;; projectile-find-file-other-window
1665 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1667 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1669 (use-package which-key
1678 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1680 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1684 (setq emms-source-file-default-directory "~/Music/")
1687 (emms-default-players)
1688 (define-emms-simple-player mplayer '(file url)
1689 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1690 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1691 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1692 ".m4a" ".flv" ".ogv" ".pls"))
1693 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1694 (emms-history-load))
1700 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
1702 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1708 (require 'gnugo-imgen)
1709 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1710 (add-hook 'gnugo-start-game-hook '(lambda ()
1711 (gnugo-image-display-mode)
1714 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1720 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1722 ;; (use-package tabbar-ruler
1725 ;; (setq tabbar-ruler-global-tabbar t)
1726 ;; (setq tabbar-ruler-global-ruler t)
1727 ;; (setq tabbar-ruler-popu-menu t)
1728 ;; (setq tabbar-ruler-popu-toolbar t)
1729 ;; (setq tabbar-use-images t)
1731 ;; (tabbar-ruler-group-by-projectile-project)
1732 ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
1733 ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1738 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1739 (el-get-bundle info+
1740 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/info+.el"
1748 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1749 (defun sd/info-mode ()
1751 (unless (equal major-mode 'Info-mode)
1752 (unless (> (length (window-list)) 1)
1753 (split-window-right))
1758 ;; (global-set-key (kbd "C-h i") 'sd/info-mode)
1760 ;; open Info buffer in other window instead of current window
1761 (defadvice info (before my-info (&optional file buf) activate)
1764 (defadvice Info-exit (after my-info-exit activate)
1765 (sd/delete-current-window))
1770 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1771 ;; (add-hook 'Man-mode-hook (lambda ()
1773 ;; (setenv "GROFF_NO_SRG")))
1776 ** TODO swiper to occur
1779 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1780 ;; (set-language-environment "UTF-8")
1781 ;; (set-default-coding-systems 'utf-8)
1785 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1786 ;; (el-get-bundle howardabrams/demo-it)
1788 ;; (use-package org-tree-slide
1791 ;; (use-package yasnippet
1796 =C-o= is defined as a global key for window operation, here unset it in dired mode
1797 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1798 (add-hook 'dired-mode-hook (lambda ()
1799 (local-unset-key (kbd "C-o"))
1800 (local-set-key (kbd "o") 'dired-display-file)))
1802 (define-key dired-mode-map (kbd "DEL") (lambda () (interactive) (find-alternate-file "..")))
1806 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1810 (setq diredp-hide-details-initially-flag nil)
1812 (define-key dired-mode-map (kbd "j") 'diredp-next-line)
1813 (define-key dired-mode-map (kbd "k") 'diredp-previous-line)
1814 (define-key dired-mode-map (kbd "g") 'dired-goto-file))
1823 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1825 (use-package color-identifiers-mode
1828 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1830 :diminish color-identifiers-mode)
1832 (global-prettify-symbols-mode t)
1838 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1839 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1841 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1845 (eval-after-load "lispy"
1847 (define-key lispy-mode-map (kbd "M-o") nil)))
1849 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1854 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1856 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1858 (defalias 'perl-mode 'cperl-mode)
1860 ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
1861 (setq cperl-auto-newline t)
1862 (setq cperl-highlight-variables-indiscriminately t)
1863 ;(setq cperl-indent-level 4)
1864 ;(setq cperl-continued-statement-offset 4)
1865 (setq cperl-close-paren-offset -4)
1866 (setq cperl-indent-parents-as-block t)
1867 (setq cperl-tab-always-indent t)
1868 ;(setq cperl-brace-offset 0)
1870 (add-hook 'cperl-mode-hook
1872 (cperl-set-style "C++")))
1874 ;(require 'template)
1875 ;(template-initialize)
1883 Change the compile-command to set the default command run when call =compile=
1884 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1885 to call =compilation= interactively.
1887 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1889 (defun my-perl-hook ()
1891 (setq-local compilation-read-command nil)
1892 (set (make-local-variable 'compile-command)
1893 (concat "/usr/bin/perl "
1894 (if buffer-file-name
1895 (shell-quote-argument buffer-file-name))))
1896 (local-set-key (kbd "s-r")
1899 ; (setq current-prefix-arg '(4)) ; C-u
1900 (call-interactively 'compile)))))
1902 (add-hook 'cperl-mode-hook 'my-perl-hook)
1909 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1911 (setq c-default-style "stroustrup"
1918 Set the environments vairables in compilation mode
1920 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1922 (use-package compile
1925 (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
1931 Enable auto-insert mode
1933 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1935 (auto-insert-mode t)
1936 (setq auto-insert-query nil)
1942 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1944 (eval-after-load 'autoinsert
1945 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1947 "Short description:"
1949 "\n * " (file-name-nondirectory (buffer-file-name))
1951 "#include <iostream>" \n
1953 (file-name-sans-extension
1954 (file-name-nondirectory (buffer-file-name)))
1956 "using namespace std;" \n \n
1964 (eval-after-load 'autoinsert
1965 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1967 "Short description:"
1969 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1971 "#include <stdio.h>" \n
1973 (file-name-sans-extension
1974 (file-name-nondirectory (buffer-file-name)))
1985 *** Perl Auto Insert
1987 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1989 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1991 (eval-after-load 'autoinsert
1992 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1995 "#!/usr/bin/perl -w" \n
2006 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2008 (use-package company
2010 :diminish company-mode
2011 :init (setq company-idle-delay 0.1)
2013 (global-company-mode))
2017 [[https://github.com/company-mode/company-statistics][company-statistics]]
2019 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2021 (use-package company-statistics
2024 (company-statistics-mode))
2029 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2030 (use-package markdown-mode
2032 :commands (markdown-mode gfm-mode)
2033 :mode (("README\\.md\\'" . gfm-mode)
2034 ("\\.md\\'" . markdown-mode)
2035 ("\\.markdown\\'" . markdown-mode))
2036 :init (setq markdown-command "multimarkdown"))
2039 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2040 (use-package markdown-preview-eww
2046 Refer [[https://www.emacswiki.org/emacs/GnusGmail][GnusGmail]]
2047 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2048 (setq user-mail-address "seudut@gmail.com"
2049 user-full-name "Peng Li")
2051 (setq gnus-select-method
2053 (nnimap-address "imap.gmail.com")
2054 (nnimap-server-port "imaps")
2055 (nnimap-stream ssl)))
2057 (setq smtpmail-smtp-service 587
2058 gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
2060 ;; Use gmail sending mail
2061 (setq message-send-mail-function 'smtpmail-send-it
2062 smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
2063 smtpmail-auth-credentials '(("smtp.gmail.com" 587 "seudut@gmail.com" nil))
2064 smtpmail-default-smtp-server "smtp.gmail.com"
2065 smtpmail-smtp-server "smtp.gmail.com"
2066 smtpmail-smtp-service 587
2067 starttls-use-gnutls t)
2070 And put the following in =~/.authinfo= file, replacing =<USE>= with your email address
2071 and =<PASSWORD>= with the password
2073 machine imap.gmail.com login <USER> password <PASSWORD> port imaps
2074 machine smtp.gmail.com login <USER> password <PASSWORD> port 587
2080 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2083 (setq gnus-permanently-visible-groups "\.*")
2085 (cond (window-system
2086 (setq custom-background-mode 'light)
2087 (defface my-group-face-1
2088 '((t (:foreground "Red" :bold t))) "First group face")
2089 (defface my-group-face-2
2090 '((t (:foreground "DarkSeaGreen4" :bold t)))
2091 "Second group face")
2092 (defface my-group-face-3
2093 '((t (:foreground "Green4" :bold t))) "Third group face")
2094 (defface my-group-face-4
2095 '((t (:foreground "SteelBlue" :bold t))) "Fourth group face")
2096 (defface my-group-face-5
2097 '((t (:foreground "Blue" :bold t))) "Fifth group face")))
2098 (setq gnus-group-highlight
2099 '(((> unread 200) . my-group-face-1)
2100 ((and (< level 3) (zerop unread)) . my-group-face-2)
2101 ((< level 3) . my-group-face-3)
2102 ((zerop unread) . my-group-face-4)
2103 (t . my-group-face-5))))
2107 (add-hook 'gnus-group-mode-hook (lambda ()
2108 (define-key gnus-group-mode-map "k" 'gnus-group-prev-group)
2109 (define-key gnus-group-mode-map "j" 'gnus-group-next-group)
2110 (define-key gnus-group-mode-map "g" 'gnus-group-jump-to-group)
2111 (define-key gnus-group-mode-map "v" (lambda () (interactive) (gnus-group-select-group t)))))
2114 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2115 (setq gnus-fetch-old-headers 't)
2119 (setq gnus-extract-address-components
2120 'mail-extract-address-components)
2122 (setq gnus-summary-line-format "%U%R%z%I%(%[%-20,20f%]%) %s%-80= %11&user-date;\n")
2123 (setq gnus-user-date-format-alist '(((gnus-seconds-today) . "%H:%M")
2124 ((+ 86400 (gnus-seconds-today)) . "%a %H:%M")
2125 (604800 . "%a, %b %-d")
2126 (15778476 . "%b %-d")
2129 (setq gnus-thread-sort-functions '((not gnus-thread-sort-by-number)))
2130 (setq gnus-unread-mark ?\.)
2131 (setq gnus-use-correct-string-widths t)
2134 (setq gnus-thread-hide-subtree t)
2136 ;; (with-eval-after-load 'gnus-summary-mode
2137 ;; (define-key gnus-summary-mode-map (kbd "C-o") 'sd/hydra-window/body))
2139 (add-hook 'gnus-summary-mode-hook (lambda ()
2140 (define-key gnus-summary-mode-map (kbd "C-o") nil)))
2146 See [[https://www.emacswiki.org/emacs/GnusWindowLayout][GnusWindowLayout]]
2147 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2148 (gnus-add-configuration
2154 (summary 1.0 poine)))))
2156 (gnus-add-configuration
2162 (summary 0.50 point)
2165 (with-eval-after-load 'gnus-group-mode
2166 (gnus-group-select-group "INBOX"))
2167 ;; (add-hook 'gnus-group-mode-map (lambda ()
2168 ;; (gnus-group-select-group "INBOX")))
2172 #+BEGIN_SRC emacs-lisp :tangle yes :results silent