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
10 ** Setting loading Path
12 Set system PATH and emacs exec path
14 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
16 (setenv "PATH" (concat (getenv "PATH")
18 ":" "/Library/TeX/texbin"))
19 (setq exec-path (append exec-path '("/usr/local/bin")))
20 (setq exec-path (append exec-path '("/Library/TeX/texbin/")))
24 Set the emacs load path
26 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
27 ;; (add-to-list 'load-path "~/.emacs.d/elisp")
30 ** Package Initialization
32 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
36 (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
37 ("gnu" . "http://elpa.gnu.org/packages/")
38 ("org" . "http://orgmode.org/elpa/")))
45 *** scroll bar, tool-bar and menu-bar
46 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
51 ;; (setq debug-on-error t)
52 (setq inhibit-startup-message t)
54 (defalias 'yes-or-no-p 'y-or-n-p)
57 (setq make-backup-files nil)
61 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
62 (setq custom-file "~/.emacs.d/custom.el")
63 (if (file-exists-p custom-file)
67 *** Switch the focus to help window when it appears
68 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
69 (setq help-window-select t)
72 *** Set default window size
73 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
74 (setq initial-frame-alist
80 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
81 (setq auto-save-default nil)
83 ;; restore last session
84 ;; (desktop-save-mode t)
87 *** Save minibuffer history
88 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
90 (setq history-length 1000)
94 Make a temp directory for all cache/history files
95 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
96 (defconst sd-temp-directory
97 (file-name-as-directory "~/.emacs.d/temp"))
99 (unless (file-exists-p sd-temp-directory)
100 (mkdir sd-temp-directory))
103 * Package Management Tools
107 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
109 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
111 (unless (package-installed-p 'use-package)
112 (package-refresh-contents)
113 (package-install 'use-package))
115 (require 'use-package)
121 [[https://github.com/dimitri/el-get][El-get]] is package management tool, whicl allows to install external elisp package from any git repository not in mepla.
122 Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
124 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
129 (add-to-list 'load-path "~/.emacs.d/el-get"))
133 * Color and Fonts Settings
135 ** highlight current line
137 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
139 (global-hl-line-mode)
145 [[https://github.com/paldepind/smart-comment][smart-comments]]
147 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
149 (use-package smart-comment
151 :bind ("M-;" . smart-conmment))
159 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
161 (global-font-lock-mode 1)
165 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
167 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
170 (defvar sd/fixed-font-family
171 (cond ((x-list-fonts "Hasklig") "Hasklig")
172 ((x-list-fonts "Source Code Pro") "Source Code Pro:weight:light")
173 ((x-list-fonts "Anonymous Pro") "Anonymous Pro")
174 ((x-list-fonts "M+ 1mn") "M+ 1mn"))
175 "The fixed width font based on what is installed, `nil' if not defined."))
181 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
184 (when sd/fixed-font-family
185 (set-frame-font sd/fixed-font-family)
186 (set-face-attribute 'default nil :font sd/fixed-font-family :height 130)
187 (set-face-font 'default sd/fixed-font-family)))
193 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
195 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
197 (setq vc-follow-symlinks t)
199 (use-package color-theme
201 :init (require 'color-theme)
202 :config (use-package color-theme-sanityinc-tomorrow
206 (load-theme 'sanityinc-tomorrow-bright t)))
208 ;(eval-after-load 'color-theme
209 ; (load-theme 'sanityinc-tomorrow-bright t))
213 Change the Org-mode colors
215 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
217 (defun org-src-color-blocks-light ()
218 "Colors the block headers and footers to make them stand out more for lighter themes"
221 '(org-block-begin-line
222 ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
223 '(org-block-background
224 ((t (:background "#FFFFEA"))))
226 ((t (:background "#FFFFEA"))))
228 ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
230 '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
231 '(which-func ((t (:foreground "#008000"))))))
233 (defun org-src-color-blocks-dark ()
234 "Colors the block headers and footers to make them stand out more for dark themes"
237 '(org-block-begin-line
238 ((t (:foreground "#008ED1" :background "#002E41"))))
239 '(org-block-background
240 ((t (:background "#000000"))))
242 ((t (:background "#000000"))))
244 ((t (:foreground "#008ED1" :background "#002E41"))))
246 '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
247 '(which-func ((t (:foreground "green"))))))
249 (org-src-color-blocks-dark)
253 improve color for org-mode
254 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
255 (deftheme ha/org-theme "Sub-theme to beautify org mode")
258 (defvar sd/variable-font-tuple
259 (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
260 ((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
261 ((x-list-fonts "Verdana") '(:font "Verdana"))
262 ((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
263 (nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro.")))
264 "My variable width font available to org-mode files and whatnot."))
266 (defun sd/org-color ()
267 (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
268 (base-font-color (face-foreground 'default nil 'default))
269 (background-color (face-background 'default nil 'default))
270 (primary-color (face-foreground 'mode-line nil))
271 (secondary-color (face-background 'secondary-selection nil 'region))
272 (base-height (face-attribute 'default :height))
273 (headline `(:inherit default :weight bold :foreground ,base-font-color)))
274 (custom-theme-set-faces 'ha/org-theme
275 `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
276 `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
277 `(org-table ((t (:inherit 'fixed-pitched))))
278 `(org-block ((t (:inherit 'fixed-pitched))))
279 `(org-block-background ((t (:inherit 'fixed-pitched))))
280 `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
281 `(org-block-end-line ((t (:inherit 'fixed-pitched))))
282 `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
283 `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
284 `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
285 `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
286 `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
287 :height ,(round (* 1.1 base-height))))))
288 `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
289 :height ,(round (* 1.25 base-height))))))
290 `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
291 :height ,(round (* 1.5 base-height))))))
292 `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
293 :height ,(round (* 1.75 base-height))))))
294 `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
301 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
303 (use-package rainbow-delimiters
306 (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
312 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
314 (use-package page-break-lines
317 (turn-on-page-break-lines-mode))
323 Enable rainbow mode in emacs lisp mode
325 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
326 (use-package rainbow-mode
329 ; (add-hook emacs-lisp-mode-hook 'rainbow-mode)
338 clean mode line, Refer to [[https://www.masteringemacs.org/article/hiding-replacing-modeline-strings][Marstering Emacs]]
340 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
341 (defvar mode-line-cleaner-alist
342 `((auto-complete-mode . " α")
343 (yas/minor-mode . " Ï…")
344 (paredit-mode . " π")
347 (projectile-mode . "")
349 (undo-tree-mode . "")
351 (which-key-mode . "")
353 (smartparens-mode . "")
355 (linum-relative-mode . "")
357 (auto-revert-mode . "")
359 (org-indent-mode . "")
363 (lisp-interaction-mode . "λ")
366 (emacs-lisp-mode . "EL")
368 (nxhtml-mode . "nx"))
369 "Alist for `clean-mode-line'.
371 When you add a new element to the alist, keep in mind that you
372 must pass the correct minor/major mode symbol and a string you
373 want to use in the modeline *in lieu of* the original.")
376 (defun clean-mode-line ()
378 (loop for cleaner in mode-line-cleaner-alist
379 do (let* ((mode (car cleaner))
380 (mode-str (cdr cleaner))
381 (old-mode-str (cdr (assq mode minor-mode-alist))))
383 (setcar old-mode-str mode-str))
385 (when (eq mode major-mode)
386 (setq mode-name mode-str)))))
389 (add-hook 'after-change-major-mode-hook 'clean-mode-line)
394 Install powerline mode [[https://github.com/milkypostman/powerline][powerline]]
396 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
397 (use-package powerline
400 ;; (powerline-center-theme)
403 ;; (use-package smart-mode-line
405 ;; (use-package smart-mode-line-powerline-theme
409 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 (defface sd/powerline-active1 '((t (:background "yellow" :foreground "black" :inherit mode-line)))
417 "My Powerline face 1 based on powerline-active1."
420 (defface sd/buffer-modified-active1 '((t (:background "red" :foreground "black" :inherit mode-line)))
421 "My Powerline face 1 based on powerline-active1."
424 (defface sd/buffer-view-active1 '((t (:background "green" :foreground "black" :inherit mode-line)))
425 "My Powerline face 1 based on powerline-active1."
428 (defface sd/mode-line-buffer-id
429 '((t (:background "yellow" :foreground "black" :inherit mode-line-buffer-id)))
430 "My powerline mode-line face, based on mode-line-buffer-id"
433 ;; Don't show buffer modified for scratch and eshell mode
434 (defun sd/buffer-show-modified ()
435 "Dot not show modified indicator for buffers"
437 (unless (or (string-match "*scratch*" (buffer-name))
438 (equal major-mode 'eshell-mode))
441 (defun sd/powerline-center-theme_revised ()
442 "Setup a mode-line with major and minor modes centered."
444 (setq-default mode-line-format
447 (let* ((active (powerline-selected-window-active))
448 (mode-line-buffer-id (if active 'sd/mode-line-buffer-id 'mode-line-buffer-id-inactive))
449 (mode-line (if active 'mode-line 'mode-line-inactive))
450 (my-face1 (if active 'sd/powerline-active1 'powerline-inactive1))
451 (my-face-buffer-modified (if (and (sd/buffer-show-modified) (buffer-modified-p))
452 'sd/buffer-modified-active1
453 (if buffer-read-only 'sd/buffer-view-active1
455 (face1 (if active 'powerline-active1 'powerline-inactive1))
456 (face2 (if active 'powerline-active2 'powerline-inactive2))
457 (separator-left (intern (format "powerline-%s-%s"
458 (powerline-current-separator)
459 (car powerline-default-separator-dir))))
460 (separator-right (intern (format "powerline-%s-%s"
461 (powerline-current-separator)
462 (cdr powerline-default-separator-dir))))
463 (lhs (list (powerline-raw "%* " my-face-buffer-modified 'l)
464 ;; (powerline-buffer-size mode-line 'l)
465 (powerline-buffer-id mode-line-buffer-id 'l)
466 (powerline-raw " " my-face1)
467 (funcall separator-left my-face1 face1)
468 (powerline-narrow face1 'l)
469 ;; (powerline-vc face1)
470 (sd/powerline-simpler-vc (powerline-vc face1))))
471 (rhs (list (powerline-raw global-mode-string face1 'r)
472 (powerline-raw "%4l" face1 'r)
473 (powerline-raw ":" face1)
474 (powerline-raw "%3c" face1 'r)
475 (funcall separator-right face1 my-face1)
476 ;; (powerline-raw " " my-face1)
477 (powerline-raw (format-time-string " %I:%M %p ") my-face1 'r)
478 ;; (powerline-raw "%6p" my-face1 'r)
479 ;; (powerline-hud my-face1 face1 )
481 (center (list (powerline-raw " " face1)
482 (funcall separator-left face1 face2)
483 (when (and (boundp 'erc-track-minor-mode) erc-track-minor-mode)
484 (powerline-raw erc-modified-channels-object face2 'l))
485 (powerline-major-mode face2 'l)
486 (powerline-process face2)
487 (powerline-raw " :" face2)
488 (powerline-minor-modes face2 'l)
489 (powerline-raw " " face2)
490 (funcall separator-right face2 face1))))
491 (concat (powerline-render lhs)
492 (powerline-fill-center face1 (/ (powerline-width center) 2.0))
493 (powerline-render center)
494 (powerline-fill face1 (powerline-width rhs))
495 (powerline-render rhs)))))))
497 (sd/powerline-center-theme_revised)
500 Fix the issue in mode line when showing triangle
501 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
502 (setq ns-use-srgb-colorspace nil)
505 set height in mode line
506 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
507 (set-variable 'powerline-height 14)
508 (set-variable 'powerline-text-scale-factor (/ (float 100) 140))
509 ;; (custom-set-variables
510 ;; '(powerline-height 14)
511 ;; '(powerline-text-scale-factor (/ (float 100) 140)))
513 (set-face-attribute 'mode-line nil :height 100)
520 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
524 :init (setq ido-enable-flex-matching t
525 ido-ignore-extensions t
526 ido-use-virtual-buffers t
531 (add-to-list 'completion-ignored-extensions ".pyc"))
539 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
543 :init (setq ido-enable-flex-matching t
545 :config (flx-ido-mode 1))
550 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
551 (use-package ido-vertical-mode
554 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
556 (ido-vertical-mode 1))
561 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
565 :init (smex-initialize)
568 ("M-X" . smex-major-mode-commands))
574 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
576 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
578 (use-package ido-ubiquitous
581 (setq magit-completing-read-function 'magit-ido-completing-read)
582 (setq gnus-completing-read-function 'gnus-ido-completing-read)
584 (ido-ubiquitous-mode 1))
589 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
590 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
591 (use-package ido-exit-target
594 (mapcar (lambda (map)
595 (define-key map (kbd "C-j") #'ido-exit-target-split-window-right)
596 (define-key map (kbd "C-k") #'ido-exit-target-split-window-below))
597 (list ido-buffer-completion-map
598 ;; ido-common-completion-map
599 ido-file-completion-map
600 ido-file-dir-completion-map)))
603 * Normal Text Operation
606 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
607 (use-package undo-tree
610 (define-key undo-tree-visualizer-mode-map "j" 'undo-tree-visualize-redo)
611 (define-key undo-tree-visualizer-mode-map "k" 'undo-tree-visualize-undo)
612 (define-key undo-tree-visualizer-mode-map "h" 'undo-tree-visualize-switch-branch-left)
613 (define-key undo-tree-visualizer-mode-map "l" 'undo-tree-visualize-switch-branch-right)
614 (global-undo-tree-mode 1))
616 (global-set-key (kbd "s-u") 'undo-tree-visualize)
620 Stolen from [[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-spelling.el][here]], hunspell will search dictionary in =DICPATH=
621 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
622 (setenv "DICPATH" "/usr/local/share/hunspell")
624 (when (executable-find "hunspell")
625 (setq-default ispell-program-name "hunspell")
626 (setq ispell-really-hunspell t))
628 ;; (defun text-mode-hook-setup ()
629 ;; ;; Turn off RUN-TOGETHER option when spell check text-mode
630 ;; (setq-local ispell-extra-args (flyspell-detect-ispell-args)))
631 ;; (add-hook 'text-mode-hook 'text-mode-hook-setup)
632 ;; (add-hook 'text-mode-hook 'flyspell-mode)
634 ;; enable flyspell check on comments and strings in progmamming modes
635 ;; (add-hook 'prog-mode-hook 'flyspell-prog-mode)
637 ;; I don't use the default mappings
638 (with-eval-after-load 'flyspell
639 (define-key flyspell-mode-map (kbd "C-;") nil)
640 (define-key flyspell-mode-map (kbd "C-,") nil)
641 (define-key flyspell-mode-map (kbd "C-.") nil))
644 Make flyspell enabled for org-mode, see [[http://emacs.stackexchange.com/questions/9333/how-does-one-use-flyspell-in-org-buffers-without-flyspell-triggering-on-tangled][here]]
645 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
646 ;; NO spell check for embedded snippets
647 (defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
648 (let ((rlt ad-return-value)
649 (begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\)")
650 (end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\)")
653 (when ad-return-value
655 (setq old-flag case-fold-search)
656 (setq case-fold-search t)
657 (setq b (re-search-backward begin-regexp nil t))
658 (if b (setq e (re-search-forward end-regexp nil t)))
659 (setq case-fold-search old-flag))
660 (if (and b e (< (point) e)) (setq rlt nil)))
661 (setq ad-return-value rlt)))
665 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
666 (use-package expand-region
669 (global-set-key (kbd "C-=") 'er/expand-region))
676 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
678 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
680 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
681 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
682 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
683 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
684 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
685 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
686 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
687 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
688 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
690 ;; Also map s-h same as C-g
691 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
695 ** =Super= bindings for file, buffer and windows
697 Some global bindings on =Super=, on Mac, it is =Command=
699 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
700 (defun sd/delete-current-window ()
702 (if (> (length (window-list)) 1)
704 (message "Only one Windows now!")))
706 ;; (global-set-key (kbd "s-h") 'keyboard-quit)
707 ;; (global-set-key (kbd "s-j") 'ido-switch-buffer)
708 ;; (global-set-key (kbd "s-k") 'ido-find-file)
709 ;; (global-set-key (kbd "s-l") 'sd/delete-current-window)
711 ;; (global-set-key (kbd "s-/") 'swiper)
713 ;; s-' --> 'next-multiframe-window
714 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
716 (global-set-key (kbd "s-f") 'projectile-find-file)
718 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
720 (global-set-key (kbd "s-n") 'persp-next)
721 (global-set-key (kbd "s-p") 'persp-prev)
723 (global-set-key (kbd "s-=") 'text-scale-increase)
724 (global-set-key (kbd "s--") 'text-scale-decrease)
726 ;; (global-set-key (kbd "s-u") 'undo-tree-visualize)
729 ;; someothers default mapping on super (command) key
731 ;; s-k kill-this-buffer
734 ;; s-h --> ns-do-hide-emacs
735 ;; s-j --> ido-switch-buffer +
736 ;; s-k --> kill-this-buffer
739 ;; s-' --> next-multiframe-window
740 ;; s-ret --> toggle-frame-fullscreen +
742 ;; s-y --> ns-paste-secondary
743 ;; s-u --> revert-buffer
744 ;; s-i --> undefined - but used for iterm globally
745 ;; s-o --> used for emacs globally
746 ;; s-p --> projectile-persp-switch-project +
747 ;; s-[ --> next-buffer +
748 ;; s-] --> previous-buffer +
755 ;; s-- --> center-line
758 ;; s-n --> make-frame
759 ;; s-m --> iconify-frame
765 ;; s-g --> isearch-repeat-forward
766 ;; s-f --> projectile-find-file +
767 ;; s-d --> isearch-repeat-background
768 ;; s-s --> save-buffer
769 ;; s-a --> make-whole-buffer
773 ;; s-c --> ns-copy-including-secondary
775 ;; s-t --> ns-popup-font-panel
777 ;; s-e --> isearch-yanqk-kill
778 ;; s-w --> delete-frame
779 ;; s-q --> same-buffers-kill-emacs
781 ;; s-` --> other-frame
784 ** Search Replace and highlight
786 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
787 ;; (use-package swiper
791 ;; (setq ivy-use-virtual-buffers t)
792 ;; (global-set-key (kbd "s-/") 'swiper)
798 ;; (global-set-key "\C-s" 'swiper)
799 ;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
800 ;; (global-set-key (kbd "<f6>") 'ivy-resume)
801 (global-set-key (kbd "M-x") 'counsel-M-x)
802 ;; ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
803 (global-set-key (kbd "C-h f") 'counsel-describe-function)
804 (global-set-key (kbd "C-h v") 'counsel-describe-variable)
805 ;; (global-set-key (kbd "<f1> l") 'counsel-load-library)
806 ;; (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
807 ;; (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
808 ;; (global-set-key (kbd "C-c g") 'counsel-git)
809 ;; (global-set-key (kbd "C-c j") 'counsel-git-grep)
810 ;; (global-set-key (kbd "C-c k") 'counsel-ag)
811 ;; (global-set-key (kbd "C-x l") 'counsel-locate)
812 ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
813 ;; ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
815 ;; (set-face-attribute
816 ;; 'ivy-current-match nil
817 ;; :background "Orange"
818 ;; :foreground "black")
821 ;; (define-key swiper-map (kbd "M-%") 'swiper-aa-replace)
825 use the prefix =M-s= for searching in buffers
826 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
827 (defun sd/make-keymap (key bindings)
828 (setq keymap (make-sparse-keymap))
829 (dolist (binding bindings)
830 (define-key keymap (car binding) (cdr binding)))
831 (global-set-key key keymap))
833 (use-package highlight-symbol
836 (sd/make-keymap "\M-s"
837 '(("w" . save-buffer)
838 ;; ("\M-w" . save-buffer)
839 ("e" . revert-buffer)
840 ("s" . isearch-forward-regexp)
841 ("\M-s" . isearch-forward-regexp)
842 ("r" . isearch-backward-regexp)
843 ("." . isearch-forward-symbol-at-point)
845 ;; ("h" . highlight-symbol-at-point)
846 ("h" . highlight-symbol)
847 ("m" . highlight-regexp)
848 ("l" . highlight-lines-matching-regexp)
849 ("M" . unhighlight-regexp)
850 ("f" . keyboard-quit)
851 ("q" . keyboard-quit)))
853 ;; search and replace and highlight
854 (define-key isearch-mode-map (kbd "M-s") 'isearch-repeat-forward)
855 (define-key isearch-mode-map (kbd "M-r") 'isearch-repeat-backward)
856 (global-set-key (kbd "s-[") 'highlight-symbol-next)
857 (global-set-key (kbd "s-]") 'highlight-symbol-prev)
858 (global-set-key (kbd "s-\\") 'highlight-symbol-query-replace)
861 (define-key minibuffer-local-map "\M-s" nil)
863 (set-face-background 'ido-first-match "yellow")
865 ;; M-s M-w eww-search-words
875 ** Org-mode Basic setting
877 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
879 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
883 (setq org-startup-indented t)
884 (setq org-hide-leading-starts t)
885 (setq org-src-fontify-natively t)
886 (setq org-src-tab-acts-natively t)
887 (setq org-confirm-babel-evaluate nil)
888 (setq org-use-speed-commands t)
889 (setq org-completion-use-ido t))
891 (org-babel-do-load-languages
892 'org-babel-load-languages
908 ;; use current window for org source buffer editting
909 (setq org-src-window-setup 'current-window )
911 (define-key org-mode-map (kbd "C-'") nil)
912 ;; C-M-i is mapped to imenu globally
913 (define-key org-mode-map (kbd "C-M-i") nil)
915 ;; set the ditta.jar path
916 (setq org-ditaa-jar-path "/usr/local/Cellar/ditaa/0.9/libexec/ditaa0_9.jar")
918 (file-exists-p org-ditaa-jar-path)
919 (error "seudut: ditaa.jar not found at %s " org-ditaa-jar-path))
924 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
926 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
927 (use-package org-bullets
930 (add-hook 'org-mode-hook
932 (org-bullets-mode t))))
934 (setq org-bullets-bullet-list '("⦿" "✪" "◉" "○" "►" "◆"))
936 ;; increase font size when enter org-src-mode
937 (add-hook 'org-src-mode-hook (lambda () (text-scale-increase 2)))
942 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
943 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
944 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
945 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
947 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
952 :init (add-hook 'org-mode-hook 'worf-mode)
954 ;; (define-key worf-mode-map "[" nil)
955 ;; (define-key worf-mode-map "]" nil)
956 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
957 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
964 Refer to [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
969 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
970 (global-set-key "\C-cl" 'org-store-link)
971 (global-set-key "\C-ca" 'org-agenda)
972 (global-set-key "\C-cb" 'org-iswitchb)
977 Replace the list bullet =-=, =+=, with =•=, a litter change based [[https://github.com/howardabrams/dot-files/blob/master/emacs-org.org][here]]
979 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
980 ;; (use-package org-mode
982 ;; (font-lock-add-keywords 'org-mode
983 ;; '(("^ *\\([-+]\\) "
984 ;; (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•")))))))
989 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]],
991 To track TODO state changes, the =!= is to insert a timetamp, =@= is to insert a note with
992 timestamp for the state change.
994 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
995 ;; (setq org-todo-keywords
996 ;; '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
997 ;; (sequence "âš‘ WAITING(w)" "|")
998 ;; (sequence "|" "✘ CANCELLED(c)")))
999 ; (setq org-todo-keyword-faces
1000 ; (quote ("TODO" . (:foreground "red" :weight bold))
1001 ; ("NEXT" . (:foreground "blue" :weight bold))
1002 ; ("WAITING" . (:foreground "forest green" :weight bold))
1003 ; ("DONE" . (:foreground "magenta" :weight bold))
1004 ; ("CANCELLED" . (:foreground "forest green" :weight bold))))
1007 (setq org-todo-keywords
1008 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!)")
1009 ;; (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING")
1010 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" ))))
1012 (setq org-todo-keyword-faces
1013 (quote (("TODO" :foreground "red" :weight bold)
1014 ("NEXT" :foreground "blue" :weight bold)
1015 ("DONE" :foreground "forest green" :weight bold)
1016 ("WAITING" :foreground "orange" :weight bold)
1017 ("HOLD" :foreground "magenta" :weight bold)
1018 ("CANCELLED" :foreground "forest green" :weight bold)
1019 ;; ("MEETING" :foreground "forest green" :weight bold)
1020 ;; ("PHONE" :foreground "forest green" :weight bold)
1024 Fast todo selections
1026 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1027 (setq org-use-fast-todo-selection t)
1028 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1031 TODO state triggers and tags, [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
1033 - Moving a task to =CANCELLED=, adds a =CANCELLED= tag
1034 - Moving a task to =WAITING=, adds a =WAITING= tag
1035 - Moving a task to =HOLD=, add =HOLD= tags
1036 - Moving a task to =DONE=, remove =WAITING=, =HOLD= tag
1037 - Moving a task to =NEXT=, remove all waiting/hold/cancelled tags
1039 This tags are used to filter tasks in agenda views
1040 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1041 (setq org-todo-state-tags-triggers
1042 (quote (("CANCELLED" ("CANCELLED" . t))
1043 ("WAITING" ("WAITING" . t))
1044 ("HOLD" ("WAITING") ("HOLD" . t))
1045 (done ("WAITING") ("HOLD"))
1046 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1047 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1048 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1052 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1053 ;; log time when task done
1054 ;; (setq org-log-done (quote time))
1055 ;; save clocking into to LOGBOOK
1056 (setq org-clock-into-drawer t)
1057 ;; save state change notes and time stamp into LOGBOOK drawer
1058 (setq org-log-into-drawer t)
1059 (setq org-clock-into-drawer "CLOCK")
1063 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1064 (setq org-tag-alist (quote ((:startgroup)
1070 ("CANCELLED" . ?c))))
1072 ;; Allow setting single tags without the menu
1073 (setq org-fast-tag-selection-single-key (quote expert))
1076 *** Capture - Refile - Archive
1078 Capture lets you quickly store notes with little interruption of your work flow.
1080 **** Capture Templates
1082 When a new taks needs to be added, categorize it as
1084 All captured file which need next actions are stored in =refile.org=,
1085 - A new task / note (t) =refile.org=
1086 - A work task in office =office.org=
1087 - A jourenl =diary.org=
1088 - A new habit (h) =refile.org=
1090 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1091 (setq org-directory "~/org")
1092 (setq org-default-notes-file "~/org/refile.org")
1093 (setq sd/org-diary-file "~/org/diary.org")
1095 (global-set-key (kbd "C-c c") 'org-capture)
1097 (setq org-capture-templates
1098 (quote (("t" "Todo" entry (file org-default-notes-file)
1099 "* TODO %?\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1100 ("n" "Note" entry (file org-default-notes-file)
1101 "* %? :NOTE:\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1102 ("j" "Journal" entry (file+datetree sd/org-diary-file)
1103 "* %?\n:LOGBOOK:\n:END:" :clock-in t :clock-resume t)
1104 ("h" "Habit" entry (file org-default-notes-file)
1105 "* NEXT %?\n:LOGBOOK:\n%a\nSCHEDULED: %(format-time-string \"%<<%Y-%m-%d %a .+1d/3d>>\")\n:END:\n:PROPERTIES:\n:STYLE: habit\n:REPEAT_TO_STATE: NEXT\n:END:\n "))))
1110 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1111 (setq org-refile-targets (quote (;; (nil :maxlevel . 9)
1112 (org-agenda-files :maxlevel . 9))))
1114 (setq org-refile-use-outline-path t)
1116 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1120 Setting agenda files and the agenda view
1121 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1122 (setq org-agenda-files (quote ("~/org/gtd.org"
1125 ;; only show today's tasks in agenda view
1126 (setq org-agenda-span 'day)
1127 ;; Use current windows for agenda view
1128 (setq org-agenda-window-setup 'current-window)
1130 ;; show all feature entries for repeating tasks,
1131 ;; this is already setting by default
1132 (setq org-agenda-repeating-timestamp-show-all t)
1134 ;; Show all agenda dates - even if they are empty
1135 (setq org-agenda-show-all-dates t)
1140 Install MacTex-basic and some tex packages
1144 sudo tlmgr update --self
1146 sudo tlmgr install titlesec framed threeparttable wrapfig multirow enumitem bbding titling tabu mdframed tcolorbox textpos import varwidth needspace tocloft ntheorem environ trimspaces collection-fontsrecommended capt-of
1150 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1151 ;; ;; allow for export=>beamer by placing
1153 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
1154 ;; #+LaTeX_CLASS: beamer in org files
1155 (unless (boundp 'org-export-latex-classes)
1156 (setq org-export-latex-classes nil))
1157 (add-to-list 'org-export-latex-classes
1158 ;; beamer class, for presentations
1160 "\\documentclass[11pt]{beamer}\n
1161 \\mode<{{{beamermode}}}>\n
1162 \\usetheme{{{{beamertheme}}}}\n
1163 \\usecolortheme{{{{beamercolortheme}}}}\n
1164 \\beamertemplateballitem\n
1165 \\setbeameroption{show notes}
1166 \\usepackage[utf8]{inputenc}\n
1167 \\usepackage[T1]{fontenc}\n
1168 \\usepackage{hyperref}\n
1170 \\usepackage{listings}
1171 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
1174 showspaces=false,showstringspaces=false,
1176 keywordstyle=\\color{blue}\\bfseries,
1177 commentstyle=\\color{red},
1179 \\usepackage{verbatim}\n
1180 \\institute{{{{beamerinstitute}}}}\n
1181 \\subject{{{{beamersubject}}}}\n"
1183 ("\\section{%s}" . "\\section*{%s}")
1185 ("\\begin{frame}[fragile]\\frametitle{%s}"
1187 "\\begin{frame}[fragile]\\frametitle{%s}"
1190 ;; letter class, for formal letters
1192 (add-to-list 'org-export-latex-classes
1195 "\\documentclass[11pt]{letter}\n
1196 \\usepackage[utf8]{inputenc}\n
1197 \\usepackage[T1]{fontenc}\n
1198 \\usepackage{color}"
1200 ("\\section{%s}" . "\\section*{%s}")
1201 ("\\subsection{%s}" . "\\subsection*{%s}")
1202 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1203 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1204 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1208 (require 'ox-beamer)
1210 (setq org-latex-pdf-process
1211 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1212 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1213 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
1215 (setq TeX-parse-self t)
1217 (setq TeX-PDF-mode t)
1218 (add-hook 'LaTeX-mode-hook
1221 (setq TeX-master t)))
1227 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
1229 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1231 (add-to-list 'org-structure-template-alist
1232 '("E" "#+BEGIN_SRC emacs-lisp :tangle yes :results silent\n?\n#+END_SRC"))
1233 (add-to-list 'org-structure-template-alist
1234 '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
1235 (add-to-list 'org-structure-template-alist
1236 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
1241 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
1242 and Defined keys, using vi keybindings, Refer abo-abo's setting [[https://github.com/abo-abo/oremacs/blob/c5cafdcebc88afe9e73cc8bd40c49b70675509c7/modes/ora-nextmagit.el][here]]
1243 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1247 ;; don't ask me to confirm the unsaved change
1248 (setq magit-save-repository-buffers nil)
1249 :commands magit-status magit-blame
1251 (dolist (map (list magit-status-mode-map
1254 magit-staged-section-map))
1255 (define-key map "j" 'magit-section-forward)
1256 (define-key map "k" 'magit-section-backward)
1257 (define-key map "D" 'magit-discard)
1258 (define-key map "O" 'magit-discard-file)
1259 (define-key map "n" nil)
1260 (define-key map "p" nil)
1261 (define-key map "v" 'recenter-top-bottom)
1262 (define-key map "i" 'magit-section-toggle)))
1267 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1268 (defalias 'e 'find-file)
1269 (defalias 'ff 'find-file)
1270 (defalias 'ee 'find-files)
1273 *** eshell temp directory
1274 set default eshell history folder
1275 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1276 (setq eshell-directory-name (concat sd-temp-directory "eshell"))
1279 *** Eshell erase buffer
1280 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1281 (defun sd/eshell-clear-buffer ()
1282 "Clear eshell buffer"
1284 (let ((inhibit-read-only t))
1286 (eshell-send-input)))
1288 (add-hook 'eshell-mode-hook (lambda ()
1289 (local-set-key (kbd "C-l") 'sd/eshell-clear-buffer)))
1293 Toggle an eshell in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
1294 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1295 (defun sd/window-has-eshell ()
1296 "Check if current windows list has a eshell buffer, and return the window"
1299 (walk-windows (lambda (window)
1300 (if (equal (with-current-buffer (window-buffer window) major-mode)
1306 (defun sd/toggle-eshell-here ()
1307 "Toggle a eshell buffer vertically"
1309 (if (sd/window-has-eshell)
1310 (if (equal major-mode 'eshell-mode)
1312 (if (equal (length (window-list)) 1)
1313 (mode-line-other-buffer)
1315 (select-window (sd/window-has-eshell)))
1317 (let ((dir default-directory))
1319 (split-window-vertically (- (/ (window-total-height) 3)))
1321 (unless (and (boundp 'eshell-buffer-name) (get-buffer eshell-buffer-name))
1323 (switch-to-buffer eshell-buffer-name)
1324 (goto-char (point-max))
1326 (insert (format "cd %s" dir))
1327 (eshell-send-input)))))
1329 (global-unset-key (kbd "M-`"))
1330 (global-set-key (kbd "M-`") 'sd/toggle-eshell-here)
1333 *** TODO smart display
1336 ** [[https://github.com/abo-abo/hydra][Hydra]]
1338 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1341 ;; disable new line in minibuffer when hint hydra
1346 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1347 (defhydra sd/font-zoom (global-map "<f2>")
1349 ("g" text-scale-increase "in")
1350 ("l" text-scale-decrease "out"))
1353 *** Windmove Splitter
1355 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1357 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1359 (defun hydra-move-splitter-left (arg)
1360 "Move window splitter left."
1362 (if (let ((windmove-wrap-around))
1363 (windmove-find-other-window 'right))
1364 (shrink-window-horizontally arg)
1365 (enlarge-window-horizontally arg)))
1367 (defun hydra-move-splitter-right (arg)
1368 "Move window splitter right."
1370 (if (let ((windmove-wrap-around))
1371 (windmove-find-other-window 'right))
1372 (enlarge-window-horizontally arg)
1373 (shrink-window-horizontally arg)))
1375 (defun hydra-move-splitter-up (arg)
1376 "Move window splitter up."
1378 (if (let ((windmove-wrap-around))
1379 (windmove-find-other-window 'up))
1380 (enlarge-window arg)
1381 (shrink-window arg)))
1383 (defun hydra-move-splitter-down (arg)
1384 "Move window splitter down."
1386 (if (let ((windmove-wrap-around))
1387 (windmove-find-other-window 'up))
1389 (enlarge-window arg)))
1394 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1395 (defhydra sd/hydra-misc (:color red :columns nil)
1396 "Miscellaneous Commands"
1397 ("e" eshell "eshell" :exit t)
1400 (if (not (eq nil (get-buffer "*Packages*")))
1401 (switch-to-buffer "*Packages*")
1402 (package-list-packages)))
1403 "list-package" :exit t)
1404 ("g" magit-status "git-status" :exit t)
1405 ("'" mode-line-other-buffer "last buffer" :exit t)
1406 ("C-'" mode-line-other-buffer "last buffer" :exit t)
1407 ("m" man "man" :exit t)
1408 ("d" dired-jump "dired" :exit t)
1409 ("b" ibuffer "ibuffer" :exit t)
1413 (global-set-key (kbd "C-'") 'sd/hydra-misc/body)
1417 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1418 (defhydra sd/hydra-launcher (:color blue :columns 2)
1420 ("e" emms "emms" :exit t)
1426 Enable linum mode on programming modes
1428 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1429 (add-hook 'prog-mode-hook 'linum-mode)
1430 ;; (add-hook 'prog-mode-hook (lambda ()
1431 ;; (setq-default indicate-empty-lines t)))
1434 Fix the font size of line number
1436 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1438 (defun fix-linum-size ()
1440 (set-face-attribute 'linum nil :height 110))
1442 (add-hook 'linum-mode-hook 'fix-linum-size)
1446 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1448 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1450 (use-package linum-relative
1453 (defun linum-new-mode ()
1454 "If line numbers aren't displayed, then display them.
1455 Otherwise, toggle between absolute and relative numbers."
1458 (linum-relative-toggle)
1462 ("A-k" . linum-new-mode))
1464 ;; auto enable linum-new-mode in programming modes
1465 (add-hook 'prog-mode-hook 'linum-relative-mode)
1469 ** Save File Position
1471 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1473 (require 'saveplace)
1474 (setq-default save-place t)
1475 (setq save-place-forget-unreadable-files t)
1476 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1482 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1484 (use-package multi-term
1491 [[https://github.com/abo-abo/ace-link][ace-link]] is a package written by [[https://github.com/abo-abo][Oleh Krehel]]. It is convenient to jump to link in help mode, info-mode, etc
1492 Type =o= to go to the link
1494 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1496 (use-package ace-link
1499 (ace-link-setup-default))
1505 [[https://github.com/re5et/emux][emux]] is
1507 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1509 (el-get-bundle re5et/emux)
1515 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1517 (use-package smartparens
1521 (require 'smartparens-config)
1522 (add-hook 'prog-mode-hook 'smartparens-mode)))
1528 [[https://github.com/abo-abo/ace-window][ace-window]]
1530 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1532 (use-package ace-window
1536 ; (global-set-key (kbd "M-o") 'ace-window)
1538 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1544 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1546 (use-package projectile
1549 (setq projectile-enable-caching t)
1551 (projectile-global-mode t))
1553 (use-package persp-projectile
1558 (:map projectile-mode-map
1559 ("s-t" . projectile-persp-switch-project)))
1561 ;; projectile-find-file
1562 ;; projectile-switch-buffer
1563 ;; projectile-find-file-other-window
1568 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1570 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1572 (use-package which-key
1581 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1583 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1587 (setq emms-source-file-default-directory "~/Music/")
1590 (emms-default-players)
1591 (define-emms-simple-player mplayer '(file url)
1592 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1593 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1594 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1595 ".m4a" ".flv" ".ogv" ".pls"))
1596 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1597 (emms-history-load))
1603 Play Go in Emacs, gnugo xpm refert [[https://github.com/okanotor/dotemacs/blob/f95b774cb292d1169748bc0a62ba647bbd8c0652/etc/my-inits/my-inits-gnugo.el][to here]]. start at image display mode and grid mode
1605 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1611 (require 'gnugo-imgen)
1612 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1613 (add-hook 'gnugo-start-game-hook '(lambda ()
1614 (gnugo-image-display-mode)
1617 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1623 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1625 ;; (use-package tabbar-ruler
1628 ;; (setq tabbar-ruler-global-tabbar t)
1629 ;; (setq tabbar-ruler-global-ruler t)
1630 ;; (setq tabbar-ruler-popu-menu t)
1631 ;; (setq tabbar-ruler-popu-toolbar t)
1632 ;; (setq tabbar-use-images t)
1634 ;; (tabbar-ruler-group-by-projectile-project)
1635 ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
1636 ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1640 ** View only for some directory
1641 When see function by =C-h f=, and visit the source code, I would like the buffer is read only. See [[http://emacs.stackexchange.com/questions/3676/how-to-enter-view-only-mode-when-browsing-emacs-source-code-from-help/3681#3681][here]]
1642 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1643 (dir-locals-set-class-variables
1645 '((nil . ((buffer-read-only . t)
1646 (show-trailing-whitespace . nil)
1648 (eval . (whitespace-mode -1))))))
1650 ;; (dir-locals-set-directory-class (expand-file-name "/usr/local/share/emacs") 'emacs)
1651 (dir-locals-set-directory-class "/usr/local/Cellar/emacs" 'emacs)
1652 ;; (dir-locals-set-directory-class "~/.emacs.d/elpa" 'emacs)
1653 (dir-locals-set-directory-class "~/dotfiles/emacs.d/elpa" 'emacs)
1654 (dir-locals-set-directory-class "~/dotfiles/emacs.d/el-get" 'emacs)
1658 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1659 (el-get-bundle info+
1660 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/info+.el"
1668 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1669 (defun sd/info-mode ()
1671 (unless (equal major-mode 'Info-mode)
1672 (unless (> (length (window-list)) 1)
1673 (split-window-right))
1678 ;; (global-set-key (kbd "C-h i") 'sd/info-mode)
1680 ;; open Info buffer in other window instead of current window
1681 (defadvice info (before my-info (&optional file buf) activate)
1684 (defadvice Info-exit (after my-info-exit activate)
1685 (sd/delete-current-window))
1691 ** TODO swiper to occur
1694 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1695 ;; (set-language-environment "UTF-8")
1696 ;; (set-default-coding-systems 'utf-8)
1700 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1701 ;; (el-get-bundle howardabrams/demo-it)
1703 (use-package org-tree-slide
1706 ;; (use-package yasnippet
1711 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1712 (use-package org-tree-slide
1715 ;; (define-key org-mode-map "\C-ccp" 'org-tree-slide-mode)
1716 (define-key org-tree-slide-mode-map (kbd "<ESC>") 'org-tree-slide-content)
1717 (define-key org-tree-slide-mode-map (kbd "<SPACE>") 'org-tree-slide-move-next-tree)
1718 (define-key org-tree-slide-mode-map [escape] 'org-tree-slide-move-previous-tree))
1722 =C-o= is defined as a global key for window operation, here unset it in dired mode
1723 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1727 (setq dired-omit-mode t)
1728 (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
1729 (add-hook 'dired-mode-hook (lambda ()
1730 (define-key dired-mode-map (kbd "C-o") nil)
1731 (define-key dired-mode-map (kbd "H") 'dired-omit-mode)
1732 (define-key dired-mode-map (kbd "DEL") (lambda () (interactive) (find-alternate-file "..")))
1733 (dired-omit-mode))))
1737 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1741 (setq diredp-hide-details-initially-flag nil)
1743 (define-key dired-mode-map (kbd "j") 'diredp-next-line)
1744 (define-key dired-mode-map (kbd "k") 'diredp-previous-line)
1745 (define-key dired-mode-map (kbd "g") 'dired-goto-file))
1749 company mode and company-statistics
1750 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1751 (use-package company
1753 :diminish company-mode
1754 :init (setq company-idle-delay 0.1)
1756 (global-company-mode))
1758 (use-package company-statistics
1761 (company-statistics-mode))
1764 * Programming Language
1766 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1767 (use-package color-identifiers-mode
1770 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1772 :diminish color-identifiers-mode)
1774 (global-prettify-symbols-mode t)
1777 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1778 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1779 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1783 (eval-after-load "lispy"
1785 (define-key lispy-mode-map (kbd "M-o") nil)))
1787 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1792 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1793 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1794 (defalias 'perl-mode 'cperl-mode)
1796 ;; (setq cperl-hairy t)
1797 ;; Turns on most of the CPerlMode options
1798 (setq cperl-auto-newline t)
1799 (setq cperl-highlight-variables-indiscriminately t)
1800 ;(setq cperl-indent-level 4)
1801 ;(setq cperl-continued-statement-offset 4)
1802 (setq cperl-close-paren-offset -4)
1803 (setq cperl-indent-parents-as-block t)
1804 (setq cperl-tab-always-indent t)
1805 ;(setq cperl-brace-offset 0)
1807 (add-hook 'cperl-mode-hook
1809 (cperl-set-style "C++")))
1811 (defalias 'perldoc 'cperl-perldoc)
1815 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1816 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1817 (eval-after-load 'autoinsert
1818 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1821 "#!/usr/bin/perl -w" \n
1823 "use strict;" > \n \n
1829 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1830 (font-lock-add-keywords 'cperl-mode
1831 '(("\\(say\\)" . cperl-nonoverridable-face)
1832 ("\\([0-9.]\\)*" . font-lock-constant-face)
1833 ("\".*\\(\\\n\\).*\"" . font-lock-constant-face)
1834 ("\n" . font-lock-constant-face)
1835 ("\\(^#!.*\\)$" . cperl-nonoverridable-face)))
1837 ;; (font-lock-add-keywords 'Man-mode
1838 ;; '(("\\(NAME\\)" . font-lock-function-name-face)))
1843 Change the compile-command to set the default command run when call =compile=
1844 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1845 to call =compilation= interactively.
1846 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1847 (defun my-perl-hook ()
1849 (setq-local compilation-read-command nil)
1850 (set (make-local-variable 'compile-command)
1851 (concat "/usr/bin/perl "
1852 (if buffer-file-name
1853 (shell-quote-argument buffer-file-name))))
1854 (local-set-key (kbd "s-r")
1857 ; (setq current-prefix-arg '(4)) ; C-u
1858 (call-interactively 'compile)))))
1860 (add-hook 'cperl-mode-hook 'my-perl-hook)
1864 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1865 (setq c-default-style "stroustrup"
1870 Set the environments vairables in compilation mode
1871 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1872 (use-package compile
1875 (setq compilation-environment (cons "LC_ALL=C" compilation-environment))
1876 (setq compilation-auto-jump-to-first-error t)
1877 (setq compilation-auto-jump-to-next t)
1878 (setq compilation-scroll-output 'first-error))
1880 ;; super-r to compile
1881 (with-eval-after-load "compile"
1882 (define-key compilation-mode-map (kbd "C-o") nil)
1883 (define-key compilation-mode-map (kbd "n") 'compilation-next-error)
1884 (define-key compilation-mode-map (kbd "p") 'compilation-previous-error)
1885 (define-key compilation-mode-map (kbd "r") #'recompile))
1889 ** Enable auto-insert mode
1890 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1891 (auto-insert-mode t)
1892 (setq auto-insert-query nil)
1896 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1897 (eval-after-load 'autoinsert
1898 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1900 "Short description:"
1902 "\n * " (file-name-nondirectory (buffer-file-name))
1904 "#include <iostream>" \n
1906 (file-name-sans-extension
1907 (file-name-nondirectory (buffer-file-name)))
1909 "using namespace std;" \n \n
1917 (eval-after-load 'autoinsert
1918 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1920 "Short description:"
1922 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1924 "#include <stdio.h>" \n
1926 (file-name-sans-extension
1927 (file-name-nondirectory (buffer-file-name)))
1938 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1939 (eval-after-load 'autoinsert
1940 '(define-auto-insert '("\\.\\(py\\)\\'" . "Python skeleton")
1949 Emacs lisp auto-insert, based on the default module in =autoinsert.el=, but replace =completing-read= as
1950 =completing-read-ido-ubiquitous= to fix the edge case of that =ido= cannot handle.
1951 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1952 (eval-after-load 'autoinsert
1953 '(define-auto-insert '("\\.el\\'" . "my Emacs Lisp header")
1955 "Short description: "
1956 ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str
1957 (make-string (max 2 (- 80 (current-column) 27)) ?\s)
1958 "-*- lexical-binding: t; -*-" '(setq lexical-binding t)
1960 ;; Copyright (C) " (format-time-string "%Y") " "
1961 (getenv "ORGANIZATION") | (progn user-full-name) "
1963 ;; Author: " (user-full-name)
1964 '(if (search-backward "&" (line-beginning-position) t)
1965 (replace-match (capitalize (user-login-name)) t t))
1966 '(end-of-line 1) " <" (progn user-mail-address) ">
1969 ;;'(setq v1 (apply 'vector (mapcar 'car finder-known-keywords)))
1970 '(setq v1 (mapcar (lambda (x) (list (symbol-name (car x))))
1971 finder-known-keywords)
1972 v2 (mapconcat (lambda (x) (format "%12s: %s" (car x) (cdr x)))
1973 finder-known-keywords
1975 ((let ((minibuffer-help-form v2))
1976 (completing-read-ido-ubiquitous "Keyword, C-h: " v1 nil t))
1979 \;; This program is free software; you can redistribute it and/or modify
1980 \;; it under the terms of the GNU General Public License as published by
1981 \;; the Free Software Foundation, either version 3 of the License, or
1982 \;; (at your option) any later version.
1984 \;; This program is distributed in the hope that it will be useful,
1985 \;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1986 \;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1987 \;; GNU General Public License for more details.
1989 \;; You should have received a copy of the GNU General Public License
1990 \;; along with this program. If not, see <http://www.gnu.org/licenses/>.
2002 \;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")))
2005 ** Org file template
2006 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2007 (eval-after-load 'autoinsert
2008 '(define-auto-insert '("\\.\\(org\\)\\'" . "Org-mode skeleton")
2011 "#+TITLE: " str (make-string 30 ?\s) > \n
2012 "#+AUTHOR: Peng Li\n"
2013 "#+EMAIL: seudut@gmail.com\n"
2014 "#+DATE: " (shell-command-to-string "echo -n $(date +%Y-%m-%d)") > \n
2020 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2021 (use-package markdown-mode
2023 :commands (markdown-mode gfm-mode)
2024 :mode (("README\\.md\\'" . gfm-mode)
2025 ("\\.md\\'" . markdown-mode)
2026 ("\\.markdown\\'" . markdown-mode))
2027 :init (setq markdown-command "multimarkdown"))
2030 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2031 (use-package markdown-preview-eww
2037 Refer [[https://www.emacswiki.org/emacs/GnusGmail][GnusGmail]]
2038 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2039 (setq user-mail-address "seudut@gmail.com"
2040 user-full-name "Peng Li")
2042 (setq gnus-select-method
2044 (nnimap-address "imap.gmail.com")
2045 (nnimap-server-port "imaps")
2046 (nnimap-stream ssl)))
2048 (setq smtpmail-smtp-service 587
2049 gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
2051 ;; Use gmail sending mail
2052 (setq message-send-mail-function 'smtpmail-send-it
2053 smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
2054 smtpmail-auth-credentials '(("smtp.gmail.com" 587 "seudut@gmail.com" nil))
2055 smtpmail-default-smtp-server "smtp.gmail.com"
2056 smtpmail-smtp-server "smtp.gmail.com"
2057 smtpmail-smtp-service 587
2058 starttls-use-gnutls t)
2061 And put the following in =~/.authinfo= file, replacing =<USE>= with your email address
2062 and =<PASSWORD>= with the password
2064 machine imap.gmail.com login <USER> password <PASSWORD> port imaps
2065 machine smtp.gmail.com login <USER> password <PASSWORD> port 587
2071 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2074 (setq gnus-permanently-visible-groups "\.*")
2076 (cond (window-system
2077 (setq custom-background-mode 'light)
2078 (defface my-group-face-1
2079 '((t (:foreground "Red" :bold t))) "First group face")
2080 (defface my-group-face-2
2081 '((t (:foreground "DarkSeaGreen4" :bold t)))
2082 "Second group face")
2083 (defface my-group-face-3
2084 '((t (:foreground "Green4" :bold t))) "Third group face")
2085 (defface my-group-face-4
2086 '((t (:foreground "SteelBlue" :bold t))) "Fourth group face")
2087 (defface my-group-face-5
2088 '((t (:foreground "Blue" :bold t))) "Fifth group face")))
2089 (setq gnus-group-highlight
2090 '(((> unread 200) . my-group-face-1)
2091 ((and (< level 3) (zerop unread)) . my-group-face-2)
2092 ((< level 3) . my-group-face-3)
2093 ((zerop unread) . my-group-face-4)
2094 (t . my-group-face-5))))
2098 (add-hook 'gnus-group-mode-hook (lambda ()
2099 (define-key gnus-group-mode-map "k" 'gnus-group-prev-group)
2100 (define-key gnus-group-mode-map "j" 'gnus-group-next-group)
2101 (define-key gnus-group-mode-map "g" 'gnus-group-jump-to-group)
2102 (define-key gnus-group-mode-map "v" (lambda () (interactive) (gnus-group-select-group t)))))
2105 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2106 (setq gnus-fetch-old-headers 't)
2110 (setq gnus-extract-address-components
2111 'mail-extract-address-components)
2113 (setq gnus-summary-line-format "%U%R%z%I%(%[%-20,20f%]%) %s%-80= %11&user-date;\n")
2114 (setq gnus-user-date-format-alist '(((gnus-seconds-today) . "%H:%M")
2115 ((+ 86400 (gnus-seconds-today)) . "%a %H:%M")
2116 (604800 . "%a, %b %-d")
2117 (15778476 . "%b %-d")
2120 (setq gnus-thread-sort-functions '((not gnus-thread-sort-by-number)))
2121 (setq gnus-unread-mark ?\.)
2122 (setq gnus-use-correct-string-widths t)
2125 (setq gnus-thread-hide-subtree t)
2127 ;; (with-eval-after-load 'gnus-summary-mode
2128 ;; (define-key gnus-summary-mode-map (kbd "C-o") 'sd/hydra-window/body))
2130 (add-hook 'gnus-summary-mode-hook (lambda ()
2131 (define-key gnus-summary-mode-map (kbd "C-o") nil)))
2137 See [[https://www.emacswiki.org/emacs/GnusWindowLayout][GnusWindowLayout]]
2138 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2139 (gnus-add-configuration
2145 (summary 1.0 poine)))))
2147 (gnus-add-configuration
2153 (summary 0.50 point)
2156 (with-eval-after-load 'gnus-group-mode
2157 (gnus-group-select-group "INBOX"))
2158 ;; (add-hook 'gnus-group-mode-map (lambda ()
2159 ;; (gnus-group-select-group "INBOX")))
2163 To fix some issue that =toolbar-make-button-list= is void, see the [[https://github.com/bruceravel/gnuplot-mode/issues/31][issue]], here I set some variable as =nil=
2164 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2165 (use-package gnuplot
2168 (setq gnuplot-help-xpm nil)
2169 (setq gnuplot-line-xpm nil)
2170 (setq gnuplot-region-xpm nil)
2171 (setq gnuplot-buffer-xpm nil)
2172 (setq gnuplot-doc-xpm nil))
2175 Use =gnuplot= on =Org-mode= file, see [[http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-gnuplot.html][ob-doc-gnuplot]]
2176 #+BEGIN_SRC gnuplot :exports code :file ./temp/file.png
2179 set title "Putting it All Together"
2192 h(x) = 10*sqrt(abs(x))
2194 plot f(x) w lp lw 1, g(x) w p lw 2, h(x) w l lw 3
2198 [[file:./temp/file.png]]
2201 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2210 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2211 (with-eval-after-load 'ediff
2212 (setq ediff-split-window-function 'split-window-horizontally)
2213 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
2214 (add-hook 'ediff-startup-hook 'ediff-toggle-wide-display)
2215 (add-hook 'ediff-cleanup-hook 'ediff-toggle-wide-display)
2216 (add-hook 'ediff-suspend-hook 'ediff-toggle-wide-display))
2219 * TODO Convert ASCII to key
2220 ** map =function-key-map= [[http://academic.evergreen.edu/projects/biophysics/technotes/program/ascii_ctrl.htm][ascii_ctrl]]
2221 new file =C-x C-f C-f=
2223 ** write color syntax for =Man-mode=
2225 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2226 (font-lock-add-keywords 'perl-mode '(("\\(|\\w+?\\(,\\w+?\\)?|\\)" 1 'py-builtins-face)))
2229 * TODO set fly-spell binding
2231 * TODO imenu bindings
2233 * DONE modified indicator
2235 - State "DONE" from "TODO" [2016-07-18 Mon 23:35]
2237 * DONE highlight selected ido candicate
2239 - State "DONE" from "TODO" [2016-07-19 Tue 01:49]
2241 * DONE show time in right of mode-line
2243 - State "DONE" from "TODO" [2016-07-19 Tue 01:11]
2247 - State "DONE" from "TODO" [2016-07-19 Tue 01:11]
2249 * TODO jump last change point
2250 * TODO emms mode-line
2253 Here are some global key bindings for basic editting
2254 ** Project operations - =super=
2255 =projectile= settins
2256 ** Windown & Buffer - =C-o=
2257 Defind a =hydra= function for windows, buffer & bookmark operations. And map it to =C-o= globally.
2258 Most use =C-o C-o= to switch buffers; =C-o x, v= to split window; =C-o o= to delete other windows
2259 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2262 (defhydra sd/hydra-window (:color red :columns nil)
2264 ("h" windmove-left nil :exit t)
2265 ("j" windmove-down nil :exit t)
2266 ("k" windmove-up nil :exit t)
2267 ("l" windmove-right nil :exit t)
2268 ("H" hydra-move-splitter-left nil)
2269 ("J" hydra-move-splitter-down nil)
2270 ("K" hydra-move-splitter-up nil)
2271 ("L" hydra-move-splitter-right nil)
2274 (split-window-right)
2279 (split-window-below)
2282 ("o" delete-other-windows "one" :exit t)
2283 ("C-o" ido-switch-buffer "buf" :exit t)
2284 ("C-k" sd/delete-current-window "del" :exit t)
2285 ("'" other-window "other" :exit t)
2286 ("a" ace-window "ace")
2287 ("s" ace-swap-window "swap")
2288 ("d" ace-delete-window "ace-one" :exit t)
2289 ("i" ace-maximize-window "ace-one" :exit t)
2290 ("b" ido-switch-buffer "buf" :exit t)
2291 ("C-b" ido-switch-buffer "buf" :exit t)
2292 ("m" bookmark-jump-other-window "open bmk" :exit t)
2293 ("M" bookmark-set "set bmk" :exit t)
2295 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
2296 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
2297 ("C-h" nil nil :exit t)
2298 ("C-j" nil nil :exit t)
2299 ;; ("C-k" nil :exit t)
2300 ("C-l" nil nil :exit t)
2301 ("C-;" nil nil :exit t)
2302 ("p" nil nil :exit t)
2303 ("n" nil nil :exit t)
2304 ("[" nil nil :exit t)
2305 ("]" nil nil :exit t)
2308 (global-unset-key (kbd "C-o"))
2309 (global-set-key (kbd "C-o") 'sd/hydra-window/body)
2313 - cut, yank, =C-w=, =C-y=
2315 - undo, redo - undo-tree
2316 - select, expand-region
2317 - spell check, flyspell
2321 *** Use =Avy= for motion
2322 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2326 (avy-setup-default))
2328 (global-set-key (kbd "C-M-j") 'avy-goto-line-below)
2329 (global-set-key (kbd "C-M-n") 'avy-goto-line-below)
2330 (global-set-key (kbd "C-M-k") 'avy-goto-line-above)
2331 (global-set-key (kbd "C-M-p") 'avy-goto-line-above)
2333 (global-set-key (kbd "C-M-f") 'avy-goto-word-1-below)
2334 (global-set-key (kbd "C-M-b") 'avy-goto-word-1-above)
2336 ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
2337 (global-set-key (kbd "C-M-w") 'avy-goto-char-timer)
2338 (global-set-key (kbd "C-M-l") 'avy-goto-char-in-line)
2340 ;; will delete above
2341 (global-set-key (kbd "M-g j") 'avy-goto-line-below)
2342 (global-set-key (kbd "M-g k") 'avy-goto-line-above)
2343 (global-set-key (kbd "M-g w") 'avy-goto-word-1-below)
2344 (global-set-key (kbd "M-g b") 'avy-goto-word-1-above)
2345 (global-set-key (kbd "M-g e") 'avy-goto-word-0)
2346 (global-set-key (kbd "M-g f") 'avy-goto-char-timer)
2347 (global-set-key (kbd "M-g c") 'avy-goto-char-in-line)
2349 ;; M-g TAB move-to-column
2350 ;; M-g ESC Prefix Command
2354 ;; M-g p previous-error
2356 ;; M-g M-g goto-line
2357 ;; M-g M-n next-error
2358 ;; M-g M-p previous-error
2362 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2363 ;; (global-unset-key (kbd "C-M-i"))
2364 ;; (global-set-key (kbd "C-M-i") #'counsel-imenu)
2365 (global-set-key (kbd "M-i") #'counsel-imenu)
2367 (global-set-key (kbd "M-l") 'goto-line)
2370 *** Movement effective
2371 [[https://www.masteringemacs.org/article/effective-editing-movement][effective-editing-movement]]
2372 **** Command arguments, numeric argument
2373 =C-u 4= same as =C-4=, =M-4=
2374 **** movement by word
2376 **** movement by paragraph/sentence
2380 **** Move to begin/end buffer
2382 **** Advanced movement
2383 ***** movement by s-expression
2386 =C-w=, put the word into search minibuffer, =M-y=
2387 =M-c=, toggle case sensitivity
2388 =M-n=, =M-p=, history
2389 ***** back to indentation
2391 ***** Registers/Bookmarks
2392 Register, =C-x r SPC=, =C-x r j=
2393 Bookmarks, =C-x r m=, =C-x r b=, =C-x r l=
2395 Stolen [[https://www.masteringemacs.org/article/fixing-mark-commands-transient-mark-mode][fixing-mark-commands-transient-mark-mode]]
2396 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2397 (defun push-mark-no-activate ()
2398 "Pushes `point' to `mark-ring' and does not activate the region
2399 Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
2401 (push-mark (point) t nil)
2402 (message "Pushed mark to ring"))
2404 (global-set-key (kbd "C-`") 'push-mark-no-activate)
2406 (defun jump-to-mark ()
2407 "Jumps to the local mark, respecting the `mark-ring' order.
2408 This is the same as using \\[set-mark-command] with the prefix argument."
2410 (set-mark-command 1))
2412 (global-set-key (kbd "M-`") 'jump-to-mark)
2414 (defun exchange-point-and-mark-no-activate ()
2415 "Identical to \\[exchange-point-and-mark] but will not activate the region."
2417 (exchange-point-and-mark)
2418 (deactivate-mark nil))
2420 (define-key global-map [remap exchange-point-and-mark] 'exchange-point-and-mark-no-activate)
2422 ***** Repositioning Point
2428 ***** Next/Prev error
2429 ***** begin/end of defun
2430 ** Search & Replace / hightlight =M-s=
2434 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2436 ;; (defhydra sd/search-highlight (:color red :columns nil)
2438 ;; ("M-s" . isearch-forward-regexp "search-forward" :exit t)
2439 ;; ("s" . isearch-forward-regexp "search-forward" :exit t)
2440 ;; ("r" . isearch-backward-regexp "search-backward" :exit t)
2443 ;; (setq-default indicate-empty-lines t)
2447 Occur search key bindings
2448 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2449 (defun sd/occur-keys ()
2450 "My key bindings in occur-mode"
2452 (switch-to-buffer-other-window "*Occur*")
2453 (define-key occur-mode-map (kbd "C-o") nil)
2454 (define-key occur-mode-map (kbd "C-n") (lambda ()
2457 (occur-mode-goto-occurrence-other-window)
2460 (define-key occur-mode-map (kbd "C-p") (lambda ()
2463 (occur-mode-goto-occurrence-other-window)
2467 (add-hook 'occur-hook #'sd/occur-keys)
2469 (use-package color-moccur
2471 :commands (isearch-moccur isearch-all)
2473 (setq isearch-lazy-highlight t)
2475 (use-package moccur-edit))
2479 stolen from [[https://github.com/mariolong/emacs.d/blob/f6a061594ef1b5d1f4750e9dad9dc97d6e122840/emacs-init.org][here]]
2480 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2484 (setq ivy-use-virtual-buffers t)
2485 (set-face-attribute 'ivy-current-match nil :background "Orange" :foreground "black")
2488 (global-set-key (kbd "s-/") 'swiper)
2489 (define-key swiper-map (kbd "M-r") 'swiper-query-replace)
2490 (define-key swiper-map (kbd "C-.") (lambda ()
2492 (insert (format "%s" (with-ivy-window (thing-at-point 'word))))))
2493 (define-key swiper-map (kbd "M-.") (lambda ()
2495 (insert (format "%s" (with-ivy-window (thing-at-point 'symbol)))))))
2498 * TODO Temp directory for cached/history/temp files
2499 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2500 (use-package recentf
2502 (setq recentf-save-file (concat sd-temp-directory "recentf")))
2504 (use-package projectile
2506 (setq projectile-cache-file (concat sd-temp-directory "projectile.cache")))
2510 (setq ido-save-directory-list-file (concat sd-temp-directory "ido.last")))
2512 (use-package savehist
2514 (setq savehist-file (concat sd-temp-directory "history")))
2518 (setq emms-directory (concat sd-temp-directory "emms")))
2520 (setq auto-save-list-file-prefix (concat sd-temp-directory "auto-save-list/.saves-"))
2524 (setq smex-save-file (concat sd-temp-directory "smex-items")))
2528 #+BEGIN_SRC ditaa :file temp/hello-world.png :cmdline -r
2537 [[file:temp/hello-world.png]]
2539 #+BEGIN_SRC ditaa :file temp/hello.png
2550 [[file:temp/hello.png]]
2552 * =C-u C-h a= search funtions
2556 - interactive for anonymous function
2557 When define a key to a anonymous function, the lambda function should be interactive
2559 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2560 ;; (require 'saveplace)
2561 ;; (setq-default save-place t)
2562 ;; (delete-selection-mode 1)
2567 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2569 ;; M-h - mark-paragraph
2570 ;; M-j - new line indent
2571 ;; M-k - kill-sentence
2572 ;; M-l - downcase words ====== goto-line
2574 ;; M-'- abbrev-prefix-mark =======
2575 ;; M-RET none ======
2578 ;; M-u - upcase word
2579 ;; M-i - ====== imenu
2580 ;; M-o ====== prefix
2584 ;; M-\ deleter horizontal space =====
2588 ;; M-, --- mark stack====== =
2589 ;; M-. lisp-goto-symboo, find definitation
2597 ;; M-q - lisp fill, fill paragraph
2600 ;; M-r - rePositioning
2601 ;; M-t transpose word
2605 ;; M-c capitalize-word