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
29 (add-to-list 'load-path "~/.emacs.d/elisp")
33 ** Package Initialization
35 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
39 (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
40 ("gnu" . "http://elpa.gnu.org/packages/")
41 ("org" . "http://orgmode.org/elpa/")))
49 Disable scroll bar, tool-bar and menu-bar
51 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
56 (setq debug-on-error t)
57 (setq inhibit-startup-message t)
59 (defalias 'yes-or-no-p 'y-or-n-p)
62 (setq make-backup-files nil)
67 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
69 (setq custom-file "~/.emacs.d/custom.el")
70 (if (file-exists-p custom-file)
75 Switch the focus to help window when it appears
77 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
79 (setq help-window-select t)
83 Setting scroll right/left
84 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
85 ; (global-set-key (kbd "C-,") 'scoll-left)
86 ; (global-set-key (kbd "C-.") 'scoll-right)
89 * Package Management Tools
93 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
95 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
97 (unless (package-installed-p 'use-package)
98 (package-refresh-contents)
99 (package-install 'use-package))
101 (require 'use-package)
107 [[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.
108 Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
110 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
115 (add-to-list 'load-path "~/.emacs.d/el-get"))
119 * Color and Fonts Settings
121 ** highlight current line
123 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
125 (global-hl-line-mode)
131 [[https://github.com/paldepind/smart-comment][smart-comments]]
133 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
135 (use-package smart-comment
137 :bind ("M-;" . smart-conmment))
145 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
147 (global-font-lock-mode 1)
151 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
153 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
156 (defvar sd/fixed-font-family
157 (cond ((x-list-fonts "Hasklig") "Hasklig")
158 ((x-list-fonts "Source Code Pro") "Source Code Pro:weight:light")
159 ((x-list-fonts "Anonymous Pro") "Anonymous Pro")
160 ((x-list-fonts "M+ 1mn") "M+ 1mn"))
161 "The fixed width font based on what is installed, `nil' if not defined."))
167 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
170 (when sd/fixed-font-family
171 (set-frame-font sd/fixed-font-family)
172 (set-face-attribute 'default nil :font sd/fixed-font-family :height 130)
173 (set-face-font 'default sd/fixed-font-family)))
179 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
181 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
183 (setq vc-follow-symlinks t)
185 (use-package color-theme
187 :init (require 'color-theme)
188 :config (use-package color-theme-sanityinc-tomorrow
192 (load-theme 'sanityinc-tomorrow-bright t)))
194 ;(eval-after-load 'color-theme
195 ; (load-theme 'sanityinc-tomorrow-bright t))
199 Change the Org-mode colors
201 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
203 (defun org-src-color-blocks-light ()
204 "Colors the block headers and footers to make them stand out more for lighter themes"
207 '(org-block-begin-line
208 ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
209 '(org-block-background
210 ((t (:background "#FFFFEA"))))
212 ((t (:background "#FFFFEA"))))
214 ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
216 '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
217 '(which-func ((t (:foreground "#008000"))))))
219 (defun org-src-color-blocks-dark ()
220 "Colors the block headers and footers to make them stand out more for dark themes"
223 '(org-block-begin-line
224 ((t (:foreground "#008ED1" :background "#002E41"))))
225 '(org-block-background
226 ((t (:background "#000000"))))
228 ((t (:background "#000000"))))
230 ((t (:foreground "#008ED1" :background "#002E41"))))
232 '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
233 '(which-func ((t (:foreground "green"))))))
235 (org-src-color-blocks-dark)
239 improve color for org-mode
240 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
241 (deftheme ha/org-theme "Sub-theme to beautify org mode")
244 (defvar sd/variable-font-tuple
245 (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
246 ((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
247 ((x-list-fonts "Verdana") '(:font "Verdana"))
248 ((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
249 (nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro.")))
250 "My variable width font available to org-mode files and whatnot."))
252 (defun sd/org-color ()
253 (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
254 (base-font-color (face-foreground 'default nil 'default))
255 (background-color (face-background 'default nil 'default))
256 (primary-color (face-foreground 'mode-line nil))
257 (secondary-color (face-background 'secondary-selection nil 'region))
258 (base-height (face-attribute 'default :height))
259 (headline `(:inherit default :weight bold :foreground ,base-font-color)))
260 (custom-theme-set-faces 'ha/org-theme
261 `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
262 `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
263 `(org-table ((t (:inherit 'fixed-pitched))))
264 `(org-block ((t (:inherit 'fixed-pitched))))
265 `(org-block-background ((t (:inherit 'fixed-pitched))))
266 `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
267 `(org-block-end-line ((t (:inherit 'fixed-pitched))))
268 `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
269 `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
270 `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
271 `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
272 `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
273 :height ,(round (* 1.1 base-height))))))
274 `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
275 :height ,(round (* 1.25 base-height))))))
276 `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
277 :height ,(round (* 1.5 base-height))))))
278 `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
279 :height ,(round (* 1.75 base-height))))))
280 `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
287 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
289 (use-package rainbow-delimiters
292 (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
298 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
300 (use-package page-break-lines
303 (turn-on-page-break-lines-mode))
309 Enable rainbow mode in emacs lisp mode
311 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
312 (use-package rainbow-mode
315 ; (add-hook emacs-lisp-mode-hook 'rainbow-mode)
324 clean mode line, Refer to [[https://www.masteringemacs.org/article/hiding-replacing-modeline-strings][Marstering Emacs]]
326 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
327 (defvar mode-line-cleaner-alist
328 `((auto-complete-mode . " α")
329 (yas/minor-mode . " Ï…")
330 (paredit-mode . " π")
333 (projectile-mode . "")
335 (undo-tree-mode . "")
337 (which-key-mode . "")
339 (smartparens-mode . "")
341 (linum-relative-mode . "")
343 (auto-revert-mode . "")
345 (org-indent-mode . "")
347 (lisp-interaction-mode . "λ")
350 (emacs-lisp-mode . "EL")
352 (nxhtml-mode . "nx"))
353 "Alist for `clean-mode-line'.
355 When you add a new element to the alist, keep in mind that you
356 must pass the correct minor/major mode symbol and a string you
357 want to use in the modeline *in lieu of* the original.")
360 (defun clean-mode-line ()
362 (loop for cleaner in mode-line-cleaner-alist
363 do (let* ((mode (car cleaner))
364 (mode-str (cdr cleaner))
365 (old-mode-str (cdr (assq mode minor-mode-alist))))
367 (setcar old-mode-str mode-str))
369 (when (eq mode major-mode)
370 (setq mode-name mode-str)))))
373 (add-hook 'after-change-major-mode-hook 'clean-mode-line)
378 Install powerline mode [[https://github.com/milkypostman/powerline][powerline]]
380 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
381 (use-package powerline
384 ;; (powerline-center-theme)
387 ;; (use-package smart-mode-line
389 ;; (use-package smart-mode-line-powerline-theme
393 Revised powerline-center-theme
395 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
396 (defun sd/powerline-simpler-vc (s)
398 (replace-regexp-in-string "Git[:-]" "" s)
401 (defun sd/powerline-center-theme_revised ()
402 "Setup a mode-line with major and minor modes centered."
404 (setq-default mode-line-format
407 (let* ((active (powerline-selected-window-active))
408 (mode-line-buffer-id (if active 'mode-line-buffer-id 'mode-line-buffer-id-inactive))
409 (mode-line (if active 'mode-line 'mode-line-inactive))
410 (face1 (if active 'powerline-active1 'powerline-inactive1))
411 (face2 (if active 'powerline-active2 'powerline-inactive2))
412 (separator-left (intern (format "powerline-%s-%s"
413 (powerline-current-separator)
414 (car powerline-default-separator-dir))))
415 (separator-right (intern (format "powerline-%s-%s"
416 (powerline-current-separator)
417 (cdr powerline-default-separator-dir))))
418 (lhs (list (powerline-raw "%*" mode-line 'l)
419 ;; (powerline-buffer-size mode-line 'l)
420 (powerline-buffer-id mode-line-buffer-id 'l)
422 (funcall separator-left mode-line face1)
423 (powerline-narrow face1 'l)
424 ;; (powerline-vc face1)
425 (sd/powerline-simpler-vc (powerline-vc face1))
427 (rhs (list (powerline-raw global-mode-string face1 'r)
428 (powerline-raw "%4l" face1 'r)
429 (powerline-raw ":" face1)
430 (powerline-raw "%3c" face1 'r)
431 (funcall separator-right face1 mode-line)
433 (powerline-raw "%6p" mode-line 'r)
434 (powerline-hud face2 face1)))
435 (center (list (powerline-raw " " face1)
436 (funcall separator-left face1 face2)
437 (when (and (boundp 'erc-track-minor-mode) erc-track-minor-mode)
438 (powerline-raw erc-modified-channels-object face2 'l))
439 (powerline-major-mode face2 'l)
440 (powerline-process face2)
441 (powerline-raw " :" face2)
442 (powerline-minor-modes face2 'l)
443 (powerline-raw " " face2)
444 (funcall separator-right face2 face1))))
445 (concat (powerline-render lhs)
446 (powerline-fill-center face1 (/ (powerline-width center) 2.0))
447 (powerline-render center)
448 (powerline-fill face1 (powerline-width rhs))
449 (powerline-render rhs)))))))
451 (sd/powerline-center-theme_revised)
454 Fix the issue in mode line when showing triangle
456 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
457 (setq ns-use-srgb-colorspace nil)
460 set height in mode line
462 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
464 (custom-set-variables
465 '(powerline-height 14)
466 '(powerline-text-scale-factor 0.8))
468 (set-face-attribute 'mode-line nil :height 100)
476 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
480 :init (setq ido-enable-flex-matching t
481 ido-ignore-extensions t
482 ido-use-virtual-buffers t
487 (add-to-list 'completion-ignored-extensions ".pyc"))
495 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
499 :init (setq ido-enable-flex-matching t
501 :config (flx-ido-mode 1))
507 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
509 (use-package ido-vertical-mode
512 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
514 (ido-vertical-mode 1))
520 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
524 :init (smex-initialize)
527 ("M-X" . smex-major-mode-commands))
533 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
535 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
537 (use-package ido-ubiquitous
540 (setq magit-completing-read-function 'magit-ido-completing-read)
541 (setq gnus-completing-read-function 'gnus-ido-completing-read)
543 (ido-ubiquitous-mode 1))
549 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
551 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
553 (use-package ido-exit-target
556 (define-key ido-common-completion-map (kbd "C-j") #'ido-exit-target-split-window-right)
557 (define-key ido-common-completion-map (kbd "C-l") #'ido-exit-target-split-window-below))
563 ** Remove prefix =ESC=, refer [[http://emacs.stackexchange.com/questions/14755/how-to-remove-bindings-to-the-esc-prefix-key][here]]
565 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
567 ;; (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
573 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
575 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
577 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
578 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
579 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
580 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
581 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
582 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
583 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
584 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
585 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
587 ;; Also map s-h same as C-g
588 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
592 ** =Ctrl= key bindings
594 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
598 ;; C-j newline and indent
600 ;; C-l recenter-top-bottom
601 ;; (global-set-key (kbd "C-;") 'ido-switch-buffer)
638 ** =Super= bindings for file, buffer and windows
640 Some global bindings on =Super=, on Mac, it is =Command=
642 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
643 (defun sd/delete-current-window ()
645 (if (> (length (window-list)) 1)
647 (message "Only one Windows now!")))
649 (global-set-key (kbd "s-h") 'keyboard-quit)
650 (global-set-key (kbd "s-j") 'ido-switch-buffer)
651 (global-set-key (kbd "s-k") 'ido-find-file)
652 ;; s-k --> kill-this-buffer
653 (global-set-key (kbd "s-l") 'sd/delete-current-window)
655 (global-set-key (kbd "s-;") 'swiper)
657 ;; s-' --> 'next-multiframe-window
658 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
660 ;; (global-set-key (kbd "s-y") 'projectile-find-file)
661 (global-set-key (kbd "s-f") 'projectile-find-file)
662 ;; (global-set-key (kbd "s-[") 'persp-next)
663 ;; (global-set-key (kbd "s-]") 'persp-prev)
665 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
667 (global-set-key (kbd "s-n") 'persp-next)
668 (global-set-key (kbd "s-p") 'persp-prev)
670 (global-set-key (kbd "s-=") 'text-scale-increase)
671 (global-set-key (kbd "s--") 'text-scale-decrease)
674 ;; someothers default mapping on super (command) key
676 ;; s-k kill-this-buffer
679 ;; s-h --> ns-do-hide-emacs
680 ;; s-j --> ido-switch-buffer +
681 ;; s-k --> kill-this-buffer
684 ;; s-' --> next-multiframe-window
685 ;; s-ret --> toggle-frame-fullscreen +
687 ;; s-y --> ns-paste-secondary
688 ;; s-u --> revert-buffer
689 ;; s-i --> undefined - but used for iterm globally
690 ;; s-o --> used for emacs globally
691 ;; s-p --> projectile-persp-switch-project +
692 ;; s-[ --> next-buffer +
693 ;; s-] --> previous-buffer +
700 ;; s-- --> center-line
703 ;; s-n --> make-frame
704 ;; s-m --> iconify-frame
710 ;; s-g --> isearch-repeat-forward
711 ;; s-f --> projectile-find-file +
712 ;; s-d --> isearch-repeat-background
713 ;; s-s --> save-buffer
714 ;; s-a --> make-whole-buffer
718 ;; s-c --> ns-copy-including-secondary
720 ;; s-t --> ns-popup-font-panel
722 ;; s-e --> isearch-yanqk-kill
723 ;; s-w --> delete-frame
724 ;; s-q --> same-buffers-kill-emacs
726 ;; s-` --> other-frame
729 ** =M-s= bindings for searching
731 I use the prefix =M-s= for searching in buffers
733 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
735 (defun pl-make-keymap (key bindings)
736 (setq keymap (make-sparse-keymap))
737 (dolist (binding bindings)
738 (define-key keymap (car binding) (cdr binding)))
739 (global-set-key key keymap))
741 (define-key minibuffer-local-map "\M-s" nil)
743 (global-set-key (kbd "M-s s") 'isearch-forward-regexp)
744 (define-key isearch-mode-map "\M-s" 'isearch-repeat-forward)
745 (global-set-key (kbd "M-s r") 'isearch-backward-regexp)
746 (define-key isearch-mode-map "\M-r" 'isearch-repeat-backward)
748 (global-set-key (kbd "s-/") 'isearch-forward-regexp)
749 (define-key isearch-mode-map (kbd "s-/") 'isearch-repeat-forward)
750 (define-key isearch-mode-map (kbd "C-n") 'isearch-repeat-forward)
753 (set-face-background 'ido-first-match "white")
756 ;; M-s s --> isearch-forward-regexp
757 ;; M-s r --> isearch-backward-regexp
758 ;; M-s w --> isearch-forward-word
759 ;; M-s . --> isearch-forward-symbol-at-point
760 ;; M-s _ --> isearch-forward-symbol
762 ;; highlight bindings
763 ;; M-s h . --> highlight-symbol-at-point
764 ;; M-s h r --> highlight-regexp
765 ;; M-s h u --> unhighlight-regexp
766 ;; M-s h l --> highlight-lines-match-regexp
767 ;; M-s h p --> highlight-phrase
768 ;; M-s h f --> hi-lock-find-patterns
771 ;; (global-set-key (kbd "M-s M-r") 'isearch-backward-regexp)
780 Occur search key bindings
782 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
784 (define-key occur-mode-map (kbd "C-n")
788 (occur-mode-goto-occurrence-other-window)
792 (define-key occur-mode-map (kbd "C-p")
796 (occur-mode-goto-occurrence-other-window)
803 ** =M-o= as prefix key for windows
805 ** =M-g= as prefix key for launcher
809 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
818 ** Org-mode Basic setting
820 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
822 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
827 (setq org-startup-indented t)
828 (setq org-hide-leading-starts t)
829 (setq org-src-fontify-natively t)
830 (setq org-src-tab-acts-natively t)
831 (setq org-confirm-babel-evaluate nil)
832 (setq org-use-speed-commands t)
833 (setq org-completion-use-ido t))
835 (org-babel-do-load-languages
836 'org-babel-load-languages
850 ;; use current window for org source buffer editting
851 (setq org-src-window-setup 'current-window )
857 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
859 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
860 (use-package org-bullets
863 (add-hook 'org-mode-hook
865 (org-bullets-mode t))))
867 (setq org-bullets-bullet-list '("⦿" "✪" "◉" "○" "►" "◆"))
872 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
873 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
874 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
875 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
877 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
882 :init (add-hook 'org-mode-hook 'worf-mode)
884 ;; (define-key worf-mode-map "[" nil)
885 ;; (define-key worf-mode-map "]" nil)
886 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
887 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
894 Refer to [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
899 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
900 (global-set-key "\C-cl" 'org-store-link)
901 (global-set-key "\C-ca" 'org-agenda)
902 (global-set-key "\C-cb" 'org-iswitchb)
907 Replace the list bullet =-=, =+=, with =•=, a litter change based [[https://github.com/howardabrams/dot-files/blob/master/emacs-org.org][here]]
909 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
910 ;; (use-package org-mode
912 ;; (font-lock-add-keywords 'org-mode
913 ;; '(("^ *\\([-+]\\) "
914 ;; (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•")))))))
919 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]],
921 To track TODO state changes, the =!= is to insert a timetamp, =@= is to insert a note with
922 timestamp for the state change.
924 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
925 ;; (setq org-todo-keywords
926 ;; '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
927 ;; (sequence "âš‘ WAITING(w)" "|")
928 ;; (sequence "|" "✘ CANCELLED(c)")))
929 ; (setq org-todo-keyword-faces
930 ; (quote ("TODO" . (:foreground "red" :weight bold))
931 ; ("NEXT" . (:foreground "blue" :weight bold))
932 ; ("WAITING" . (:foreground "forest green" :weight bold))
933 ; ("DONE" . (:foreground "magenta" :weight bold))
934 ; ("CANCELLED" . (:foreground "forest green" :weight bold))))
937 (setq org-todo-keywords
938 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!)")
939 ;; (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING")
940 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" ))))
942 (setq org-todo-keyword-faces
943 (quote (("TODO" :foreground "red" :weight bold)
944 ("NEXT" :foreground "blue" :weight bold)
945 ("DONE" :foreground "forest green" :weight bold)
946 ("WAITING" :foreground "orange" :weight bold)
947 ("HOLD" :foreground "magenta" :weight bold)
948 ("CANCELLED" :foreground "forest green" :weight bold)
949 ;; ("MEETING" :foreground "forest green" :weight bold)
950 ;; ("PHONE" :foreground "forest green" :weight bold)
956 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
957 (setq org-use-fast-todo-selection t)
958 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
961 TODO state triggers and tags, [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
963 - Moving a task to =CANCELLED=, adds a =CANCELLED= tag
964 - Moving a task to =WAITING=, adds a =WAITING= tag
965 - Moving a task to =HOLD=, add =HOLD= tags
966 - Moving a task to =DONE=, remove =WAITING=, =HOLD= tag
967 - Moving a task to =NEXT=, remove all waiting/hold/cancelled tags
969 This tags are used to filter tasks in agenda views
970 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
971 (setq org-todo-state-tags-triggers
972 (quote (("CANCELLED" ("CANCELLED" . t))
973 ("WAITING" ("WAITING" . t))
974 ("HOLD" ("WAITING") ("HOLD" . t))
975 (done ("WAITING") ("HOLD"))
976 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
977 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
978 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
982 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
983 ;; log time when task done
984 ;; (setq org-log-done (quote time))
985 ;; save clocking into to LOGBOOK
986 (setq org-clock-into-drawer t)
987 ;; save state change notes and time stamp into LOGBOOK drawer
988 (setq org-log-into-drawer t)
989 (setq org-clock-into-drawer "CLOCK")
993 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
994 (setq org-tag-alist (quote ((:startgroup)
1000 ("CANCELLED" . ?c))))
1002 ;; Allow setting single tags without the menu
1003 (setq org-fast-tag-selection-single-key (quote expert))
1006 *** Capture - Refile - Archive
1008 Capture lets you quickly store notes with little interruption of your work flow.
1010 **** Capture Templates
1012 When a new taks needs to be added, categorize it as
1014 All captured file which need next actions are stored in =refile.org=,
1015 - A new task / note (t) =refile.org=
1016 - A work task in office =office.org=
1017 - A jourenl =diary.org=
1018 - A new habit (h) =refile.org=
1020 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1021 (setq org-directory "~/org")
1022 (setq org-default-notes-file "~/org/refile.org")
1023 (setq sd/org-diary-file "~/org/diary.org")
1025 (global-set-key (kbd "C-c c") 'org-capture)
1027 (setq org-capture-templates
1028 (quote (("t" "Todo" entry (file org-default-notes-file)
1029 "* TODO %?\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1030 ("n" "Note" entry (file org-default-notes-file)
1031 "* %? :NOTE:\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1032 ("j" "Journal" entry (file+datetree sd/org-diary-file)
1033 "* %?\n:LOGBOOK:\n:END:" :clock-in t :clock-resume t)
1034 ("h" "Habit" entry (file org-default-notes-file)
1035 "* 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 "))))
1040 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1041 (setq org-refile-targets (quote (;; (nil :maxlevel . 9)
1042 (org-agenda-files :maxlevel . 9))))
1044 (setq org-refile-use-outline-path t)
1046 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1050 Setting agenda files and the agenda view
1051 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1052 (setq org-agenda-files (quote ("~/org/gtd.org"
1055 ;; only show today's tasks in agenda view
1056 (setq org-agenda-span 'day)
1057 ;; Use current windows for agenda view
1058 (setq org-agenda-window-setup 'current-window)
1060 ;; show all feature entries for repeating tasks,
1061 ;; this is already setting by default
1062 (setq org-agenda-repeating-timestamp-show-all t)
1064 ;; Show all agenda dates - even if they are empty
1065 (setq org-agenda-show-all-dates t)
1070 Install MacTex-basic and some tex packages
1074 sudo tlmgr update --self
1076 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
1080 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1081 ;; ;; allow for export=>beamer by placing
1083 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
1084 ;; #+LaTeX_CLASS: beamer in org files
1085 (unless (boundp 'org-export-latex-classes)
1086 (setq org-export-latex-classes nil))
1087 (add-to-list 'org-export-latex-classes
1088 ;; beamer class, for presentations
1090 "\\documentclass[11pt]{beamer}\n
1091 \\mode<{{{beamermode}}}>\n
1092 \\usetheme{{{{beamertheme}}}}\n
1093 \\usecolortheme{{{{beamercolortheme}}}}\n
1094 \\beamertemplateballitem\n
1095 \\setbeameroption{show notes}
1096 \\usepackage[utf8]{inputenc}\n
1097 \\usepackage[T1]{fontenc}\n
1098 \\usepackage{hyperref}\n
1100 \\usepackage{listings}
1101 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
1104 showspaces=false,showstringspaces=false,
1106 keywordstyle=\\color{blue}\\bfseries,
1107 commentstyle=\\color{red},
1109 \\usepackage{verbatim}\n
1110 \\institute{{{{beamerinstitute}}}}\n
1111 \\subject{{{{beamersubject}}}}\n"
1113 ("\\section{%s}" . "\\section*{%s}")
1115 ("\\begin{frame}[fragile]\\frametitle{%s}"
1117 "\\begin{frame}[fragile]\\frametitle{%s}"
1120 ;; letter class, for formal letters
1122 (add-to-list 'org-export-latex-classes
1125 "\\documentclass[11pt]{letter}\n
1126 \\usepackage[utf8]{inputenc}\n
1127 \\usepackage[T1]{fontenc}\n
1128 \\usepackage{color}"
1130 ("\\section{%s}" . "\\section*{%s}")
1131 ("\\subsection{%s}" . "\\subsection*{%s}")
1132 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1133 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1134 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1138 (require 'ox-beamer)
1140 (setq org-latex-pdf-process
1141 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1142 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1143 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
1145 (setq TeX-parse-self t)
1147 (setq TeX-PDF-mode t)
1148 (add-hook 'LaTeX-mode-hook
1151 (setq TeX-master t)))
1157 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
1159 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1161 (add-to-list 'org-structure-template-alist
1162 '("E" "#+BEGIN_SRC emacs-lisp :tangle yes :results silent\n?\n#+END_SRC"))
1163 (add-to-list 'org-structure-template-alist
1164 '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
1165 (add-to-list 'org-structure-template-alist
1166 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
1171 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
1172 and Defined keys, using vi keybindings, Refer abo-abo's setting [[https://github.com/abo-abo/oremacs/blob/c5cafdcebc88afe9e73cc8bd40c49b70675509c7/modes/ora-nextmagit.el][here]]
1173 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1176 :commands magit-status magit-blame
1178 (dolist (map (list magit-status-mode-map
1181 magit-staged-section-map))
1182 (define-key map "j" 'magit-section-forward)
1183 (define-key map "k" 'magit-section-backward)
1184 (define-key map "D" 'magit-discard-file)
1185 (define-key map "n" nil)
1186 (define-key map "p" nil)
1187 (define-key map "v" 'recenter-top-bottom)
1188 (define-key map "i" 'magit-section-toggle)))
1193 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1194 (defalias 'e 'find-file)
1195 (defalias 'ff 'find-file)
1196 (defalias 'ee 'find-files)
1199 *** Eshell erase buffer
1200 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1201 (defun sd/eshell-clear-buffer ()
1202 "Clear eshell buffer"
1204 (let ((inhibit-read-only t))
1206 (eshell-send-input)))
1208 (add-hook 'eshell-mode-hook (lambda ()
1209 (local-set-key (kbd "C-l") 'sd/eshell-clear-buffer)))
1213 Toggle an eshell in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
1214 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1215 (defun sd/window-has-eshell ()
1216 "Check if current windows list has a eshell buffer, and return the window"
1219 (walk-windows (lambda (window)
1220 (if (equal (with-current-buffer (window-buffer window) major-mode)
1226 (defun sd/toggle-eshell-here ()
1227 "Toggle a eshell buffer vertically"
1229 (if (sd/window-has-eshell)
1230 (if (equal major-mode 'eshell-mode)
1232 (if (equal (length (window-list)) 1)
1233 (mode-line-other-buffer)
1235 (select-window (sd/window-has-eshell)))
1237 (let ((dir default-directory))
1239 (split-window-vertically (- (/ (window-total-height) 3)))
1241 (unless (and (boundp 'eshell-buffer-name) (get-buffer eshell-buffer-name))
1243 (switch-to-buffer eshell-buffer-name)
1244 (goto-char (point-max))
1246 (insert (format "cd %s" dir))
1247 (eshell-send-input)))))
1249 (global-unset-key (kbd "M-`"))
1250 (global-set-key (kbd "M-`") 'sd/toggle-eshell-here)
1253 *** TODO smart display
1256 ** [[https://github.com/abo-abo/hydra][Hydra]]
1258 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1261 ;; disable new line in minibuffer when hint hydra
1267 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1268 (defhydra sd/font-zoom (global-map "<f2>")
1271 ("g" text-scale-increase "in")
1272 ("l" text-scale-decrease "out"))
1275 *** Windmove Splitter
1277 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1279 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1281 (defun hydra-move-splitter-left (arg)
1282 "Move window splitter left."
1284 (if (let ((windmove-wrap-around))
1285 (windmove-find-other-window 'right))
1286 (shrink-window-horizontally arg)
1287 (enlarge-window-horizontally arg)))
1289 (defun hydra-move-splitter-right (arg)
1290 "Move window splitter right."
1292 (if (let ((windmove-wrap-around))
1293 (windmove-find-other-window 'right))
1294 (enlarge-window-horizontally arg)
1295 (shrink-window-horizontally arg)))
1297 (defun hydra-move-splitter-up (arg)
1298 "Move window splitter up."
1300 (if (let ((windmove-wrap-around))
1301 (windmove-find-other-window 'up))
1302 (enlarge-window arg)
1303 (shrink-window arg)))
1305 (defun hydra-move-splitter-down (arg)
1306 "Move window splitter down."
1308 (if (let ((windmove-wrap-around))
1309 (windmove-find-other-window 'up))
1311 (enlarge-window arg)))
1316 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1319 (defhydra sd/hydra-window (:color red :columns nil)
1321 ("h" windmove-left nil :exit t)
1322 ("j" windmove-down nil :exit t)
1323 ("k" windmove-up nil :exit t)
1324 ("l" windmove-right nil :exit t)
1325 ("H" hydra-move-splitter-left nil)
1326 ("J" hydra-move-splitter-down nil)
1327 ("K" hydra-move-splitter-up nil)
1328 ("L" hydra-move-splitter-right nil)
1331 (split-window-right)
1336 (split-window-below)
1339 ("o" delete-other-windows "one" :exit t)
1340 ("C-o" ido-switch-buffer "buf" :exit t)
1341 ("C-k" sd/delete-current-window "del" :exit t)
1342 ("a" ace-window "ace")
1343 ("s" ace-swap-window "swap")
1344 ("d" ace-delete-window "ace-one" :exit t)
1345 ("i" ace-maximize-window "ace-one" :exit t)
1346 ("b" ido-switch-buffer "buf" :exit t)
1347 ("C-b" ido-switch-buffer "buf" :exit t)
1348 ;; ("m" headlong-bookmark-jump "bmk")
1350 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
1351 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
1354 (global-unset-key (kbd "C-o"))
1355 (global-set-key (kbd "C-o") 'sd/hydra-window/body)
1359 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1360 (defhydra sd/hydra-misc ()
1361 "Miscellaneous Commands"
1362 ("e" eshell "eshell" :color red :exit t)
1365 (if (sd/buffer-exist "*Packages*")
1366 (switch-to-buffer "*Packages*")
1367 (package-list-packages)))
1368 "list-package" :color red :exit t)
1369 ("g" magit-status "git-status" :color red :exit t))
1373 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1374 (defhydra hydra-launcher (:color blue :columns 2)
1377 ("s" eshell "eshell")
1378 ("p" package-list-packages "Package")
1384 Enable linum mode on programming modes
1386 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1388 (add-hook 'prog-mode-hook 'linum-mode)
1392 Fix the font size of line number
1394 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1396 (defun fix-linum-size ()
1398 (set-face-attribute 'linum nil :height 110))
1400 (add-hook 'linum-mode-hook 'fix-linum-size)
1404 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1406 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1408 (use-package linum-relative
1411 (defun linum-new-mode ()
1412 "If line numbers aren't displayed, then display them.
1413 Otherwise, toggle between absolute and relative numbers."
1416 (linum-relative-toggle)
1420 ("A-k" . linum-new-mode))
1422 ;; auto enable linum-new-mode in programming modes
1423 (add-hook 'prog-mode-hook 'linum-relative-mode)
1427 ** Save File Position
1429 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1431 (require 'saveplace)
1432 (setq-default save-place t)
1433 (setq save-place-forget-unreadable-files t)
1434 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1440 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1442 (use-package multi-term
1449 [[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
1450 Type =o= to go to the link
1452 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1454 (use-package ace-link
1457 (ace-link-setup-default))
1463 [[https://github.com/re5et/emux][emux]] is
1465 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1467 (el-get-bundle re5et/emux)
1473 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1475 (use-package smartparens
1479 (require 'smartparens-config)
1480 (add-hook 'prog-mode-hook 'smartparens-mode)))
1486 [[https://github.com/abo-abo/ace-window][ace-window]]
1488 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1490 (use-package ace-window
1494 ; (global-set-key (kbd "M-o") 'ace-window)
1496 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1502 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1504 (use-package projectile
1507 (setq projectile-enable-caching t)
1509 (projectile-global-mode t))
1511 (use-package persp-projectile
1516 (:map projectile-mode-map
1517 ("s-t" . projectile-persp-switch-project)))
1519 ;; projectile-find-file
1520 ;; projectile-switch-buffer
1521 ;; projectile-find-file-other-window
1526 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1528 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1530 (use-package which-key
1539 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1541 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1545 (setq emms-source-file-default-directory "~/Music/")
1548 (emms-default-players)
1549 (define-emms-simple-player mplayer '(file url)
1550 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1551 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1552 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1553 ".m4a" ".flv" ".ogv" ".pls"))
1554 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1555 (emms-history-load))
1561 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
1563 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1569 (require 'gnugo-imgen)
1570 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1571 (add-hook 'gnugo-start-game-hook '(lambda ()
1572 (gnugo-image-display-mode)
1575 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1580 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1581 (use-package undo-tree
1584 (define-key undo-tree-visualizer-mode-map "j" 'undo-tree-visualize-redo)
1585 (define-key undo-tree-visualizer-mode-map "k" 'undo-tree-visualize-undo)
1586 (define-key undo-tree-visualizer-mode-map "h" 'undo-tree-visualize-switch-branch-left)
1587 (define-key undo-tree-visualizer-mode-map "l" 'undo-tree-visualize-switch-branch-right)
1588 (global-undo-tree-mode 1))
1593 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1600 (setq ivy-use-virtual-buffers t)
1601 ;; (global-set-key "\C-s" 'swiper)
1602 ;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
1603 ;; (global-set-key (kbd "<f6>") 'ivy-resume)
1604 ;; ;; (global-set-key (kbd "M-x") 'counsel-M-x)
1605 ;; ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
1606 ;; (global-set-key (kbd "<f1> f") 'counsel-describe-function)
1607 ;; (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
1608 ;; (global-set-key (kbd "<f1> l") 'counsel-load-library)
1609 ;; (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
1610 ;; (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
1611 ;; (global-set-key (kbd "C-c g") 'counsel-git)
1612 ;; (global-set-key (kbd "C-c j") 'counsel-git-grep)
1613 ;; (global-set-key (kbd "C-c k") 'counsel-ag)
1614 ;; (global-set-key (kbd "C-x l") 'counsel-locate)
1615 ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
1616 ;; ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
1622 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1624 ;; (use-package tabbar-ruler
1627 ;; (setq tabbar-ruler-global-tabbar t)
1628 ;; (setq tabbar-ruler-global-ruler t)
1629 ;; (setq tabbar-ruler-popu-menu t)
1630 ;; (setq tabbar-ruler-popu-toolbar t)
1631 ;; (setq tabbar-use-images t)
1633 ;; (tabbar-ruler-group-by-projectile-project)
1634 ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
1635 ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1640 =C-o= is defined as a global key for window operation, here unset it in dired mode
1641 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1642 (add-hook 'dired-mode-hook (lambda ()
1643 (local-unset-key (kbd "C-o"))
1644 (local-set-key (kbd "o") 'dired-display-file)))
1648 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1649 (el-get-bundle info+
1650 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/info+.el"
1664 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1666 (use-package color-identifiers-mode
1669 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1671 :diminish color-identifiers-mode)
1673 (global-prettify-symbols-mode t)
1679 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1680 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1682 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1686 (eval-after-load "lispy"
1688 (define-key lispy-mode-map (kbd "M-o") nil)))
1690 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1695 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1697 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1699 (defalias 'perl-mode 'cperl-mode)
1701 ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
1702 (setq cperl-auto-newline t)
1703 (setq cperl-highlight-variables-indiscriminately t)
1704 ;(setq cperl-indent-level 4)
1705 ;(setq cperl-continued-statement-offset 4)
1706 (setq cperl-close-paren-offset -4)
1707 (setq cperl-indent-parents-as-block t)
1708 (setq cperl-tab-always-indent t)
1709 ;(setq cperl-brace-offset 0)
1711 (add-hook 'cperl-mode-hook
1713 (cperl-set-style "C++")))
1715 ;(require 'template)
1716 ;(template-initialize)
1724 Change the compile-command to set the default command run when call =compile=
1725 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1726 to call =compilation= interactively.
1728 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1730 (defun my-perl-hook ()
1732 (setq-local compilation-read-command nil)
1733 (set (make-local-variable 'compile-command)
1734 (concat "/usr/bin/perl "
1735 (if buffer-file-name
1736 (shell-quote-argument buffer-file-name))))
1737 (local-set-key (kbd "s-r")
1740 ; (setq current-prefix-arg '(4)) ; C-u
1741 (call-interactively 'compile)))))
1743 (add-hook 'cperl-mode-hook 'my-perl-hook)
1750 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1752 (setq c-default-style "stroustrup"
1759 Set the environments vairables in compilation mode
1761 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1763 (use-package compile
1766 (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
1772 Enable auto-insert mode
1774 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1776 (auto-insert-mode t)
1777 (setq auto-insert-query nil)
1783 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1785 (eval-after-load 'autoinsert
1786 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1788 "Short description:"
1790 "\n * " (file-name-nondirectory (buffer-file-name))
1792 "#include <iostream>" \n
1794 (file-name-sans-extension
1795 (file-name-nondirectory (buffer-file-name)))
1797 "using namespace std;" \n \n
1805 (eval-after-load 'autoinsert
1806 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1808 "Short description:"
1810 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1812 "#include <stdio.h>" \n
1814 (file-name-sans-extension
1815 (file-name-nondirectory (buffer-file-name)))
1826 *** Perl Auto Insert
1828 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1830 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1832 (eval-after-load 'autoinsert
1833 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1836 "#!/usr/bin/perl -w" \n
1847 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1849 (use-package company
1851 :diminish company-mode
1852 :init (setq company-idle-delay 0.1)
1854 (global-company-mode))
1858 [[https://github.com/company-mode/company-statistics][company-statistics]]
1860 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1862 (use-package company-statistics
1865 (company-statistics-mode))
1870 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1871 (use-package markdown-mode
1873 :commands (markdown-mode gfm-mode)
1874 :mode (("README\\.md\\'" . gfm-mode)
1875 ("\\.md\\'" . markdown-mode)
1876 ("\\.markdown\\'" . markdown-mode))
1877 :init (setq markdown-command "multimarkdown"))
1880 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1881 (use-package markdown-preview-eww
1887 Refer [[https://www.emacswiki.org/emacs/GnusGmail][GnusGmail]]
1888 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1889 (setq user-mail-address "seudut@gmail.com"
1890 user-full-name "Peng Li")
1892 (setq gnus-select-method
1894 (nnimap-address "imap.gmail.com")
1895 (nnimap-server-port "imaps")
1896 (nnimap-stream ssl)))
1898 (setq smtpmail-smtp-service 587
1899 gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
1901 ;; Use gmail sending mail
1902 (setq message-send-mail-function 'smtpmail-send-it
1903 smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
1904 smtpmail-auth-credentials '(("smtp.gmail.com" 587 "seudut@gmail.com" nil))
1905 smtpmail-default-smtp-server "smtp.gmail.com"
1906 smtpmail-smtp-server "smtp.gmail.com"
1907 smtpmail-smtp-service 587
1908 starttls-use-gnutls t)
1911 And put the following in =~/.authinfo= file, replacing =<USE>= with your email address
1912 and =<PASSWORD>= with the password
1914 machine imap.gmail.com login <USER> password <PASSWORD> port imaps
1915 machine smtp.gmail.com login <USER> password <PASSWORD> port 587
1921 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1924 (setq gnus-permanently-visible-groups "\.*")
1926 (cond (window-system
1927 (setq custom-background-mode 'light)
1928 (defface my-group-face-1
1929 '((t (:foreground "Red" :bold t))) "First group face")
1930 (defface my-group-face-2
1931 '((t (:foreground "DarkSeaGreen4" :bold t)))
1932 "Second group face")
1933 (defface my-group-face-3
1934 '((t (:foreground "Green4" :bold t))) "Third group face")
1935 (defface my-group-face-4
1936 '((t (:foreground "SteelBlue" :bold t))) "Fourth group face")
1937 (defface my-group-face-5
1938 '((t (:foreground "Blue" :bold t))) "Fifth group face")))
1939 (setq gnus-group-highlight
1940 '(((> unread 200) . my-group-face-1)
1941 ((and (< level 3) (zerop unread)) . my-group-face-2)
1942 ((< level 3) . my-group-face-3)
1943 ((zerop unread) . my-group-face-4)
1944 (t . my-group-face-5))))
1948 (add-hook 'gnus-group-mode-hook (lambda ()
1949 (define-key gnus-group-mode-map "k" 'gnus-group-prev-group)
1950 (define-key gnus-group-mode-map "j" 'gnus-group-next-group)
1951 (define-key gnus-group-mode-map "g" 'gnus-group-jump-to-group)
1952 (define-key gnus-group-mode-map "v" (lambda () (interactive) (gnus-group-select-group t)))))
1955 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1956 (setq gnus-fetch-old-headers 't)
1960 (setq gnus-extract-address-components
1961 'mail-extract-address-components)
1963 (setq gnus-summary-line-format "%U%R%z%I%(%[%-20,20f%]%) %s%-80= %11&user-date;\n")
1964 (setq gnus-user-date-format-alist '(((gnus-seconds-today) . "%H:%M")
1965 ((+ 86400 (gnus-seconds-today)) . "%a %H:%M")
1966 (604800 . "%a, %b %-d")
1967 (15778476 . "%b %-d")
1970 (setq gnus-thread-sort-functions '((not gnus-thread-sort-by-number)))
1971 (setq gnus-unread-mark ?\.)
1972 (setq gnus-use-correct-string-widths t)
1975 (setq gnus-thread-hide-subtree t)
1977 ;; (with-eval-after-load 'gnus-summary-mode
1978 ;; (define-key gnus-summary-mode-map (kbd "C-o") 'sd/hydra-window/body))
1980 (add-hook 'gnus-summary-mode-hook (lambda ()
1981 (define-key gnus-summary-mode-map (kbd "C-o") nil)))
1987 See [[https://www.emacswiki.org/emacs/GnusWindowLayout][GnusWindowLayout]]
1988 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1989 (gnus-add-configuration
1995 (summary 1.0 poine)))))
1997 (gnus-add-configuration
2003 (summary 0.50 point)
2006 (with-eval-after-load 'gnus-group-mode
2007 (gnus-group-select-group "INBOX"))
2008 ;; (add-hook 'gnus-group-mode-map (lambda ()
2009 ;; (gnus-group-select-group "INBOX")))