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)
93 * Package Management Tools
97 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
99 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
101 (unless (package-installed-p 'use-package)
102 (package-refresh-contents)
103 (package-install 'use-package))
105 (require 'use-package)
111 [[https://github.com/dimitri/el-get][El-get]] is package management tool, whicl allows to install external elisp package from any git repository not in mepla.
112 Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
114 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
119 (add-to-list 'load-path "~/.emacs.d/el-get"))
123 * Color and Fonts Settings
125 ** highlight current line
127 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
129 (global-hl-line-mode)
135 [[https://github.com/paldepind/smart-comment][smart-comments]]
137 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
139 (use-package smart-comment
141 :bind ("M-;" . smart-conmment))
149 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
151 (global-font-lock-mode 1)
155 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
157 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
160 (defvar sd/fixed-font-family
161 (cond ((x-list-fonts "Hasklig") "Hasklig")
162 ((x-list-fonts "Source Code Pro") "Source Code Pro:weight:light")
163 ((x-list-fonts "Anonymous Pro") "Anonymous Pro")
164 ((x-list-fonts "M+ 1mn") "M+ 1mn"))
165 "The fixed width font based on what is installed, `nil' if not defined."))
171 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
174 (when sd/fixed-font-family
175 (set-frame-font sd/fixed-font-family)
176 (set-face-attribute 'default nil :font sd/fixed-font-family :height 130)
177 (set-face-font 'default sd/fixed-font-family)))
183 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
185 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
187 (setq vc-follow-symlinks t)
189 (use-package color-theme
191 :init (require 'color-theme)
192 :config (use-package color-theme-sanityinc-tomorrow
196 (load-theme 'sanityinc-tomorrow-bright t)))
198 ;(eval-after-load 'color-theme
199 ; (load-theme 'sanityinc-tomorrow-bright t))
203 Change the Org-mode colors
205 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
207 (defun org-src-color-blocks-light ()
208 "Colors the block headers and footers to make them stand out more for lighter themes"
211 '(org-block-begin-line
212 ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
213 '(org-block-background
214 ((t (:background "#FFFFEA"))))
216 ((t (:background "#FFFFEA"))))
218 ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
220 '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
221 '(which-func ((t (:foreground "#008000"))))))
223 (defun org-src-color-blocks-dark ()
224 "Colors the block headers and footers to make them stand out more for dark themes"
227 '(org-block-begin-line
228 ((t (:foreground "#008ED1" :background "#002E41"))))
229 '(org-block-background
230 ((t (:background "#000000"))))
232 ((t (:background "#000000"))))
234 ((t (:foreground "#008ED1" :background "#002E41"))))
236 '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
237 '(which-func ((t (:foreground "green"))))))
239 (org-src-color-blocks-dark)
243 improve color for org-mode
244 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
245 (deftheme ha/org-theme "Sub-theme to beautify org mode")
248 (defvar sd/variable-font-tuple
249 (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
250 ((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
251 ((x-list-fonts "Verdana") '(:font "Verdana"))
252 ((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
253 (nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro.")))
254 "My variable width font available to org-mode files and whatnot."))
256 (defun sd/org-color ()
257 (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
258 (base-font-color (face-foreground 'default nil 'default))
259 (background-color (face-background 'default nil 'default))
260 (primary-color (face-foreground 'mode-line nil))
261 (secondary-color (face-background 'secondary-selection nil 'region))
262 (base-height (face-attribute 'default :height))
263 (headline `(:inherit default :weight bold :foreground ,base-font-color)))
264 (custom-theme-set-faces 'ha/org-theme
265 `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
266 `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
267 `(org-table ((t (:inherit 'fixed-pitched))))
268 `(org-block ((t (:inherit 'fixed-pitched))))
269 `(org-block-background ((t (:inherit 'fixed-pitched))))
270 `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
271 `(org-block-end-line ((t (:inherit 'fixed-pitched))))
272 `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
273 `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
274 `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
275 `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
276 `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
277 :height ,(round (* 1.1 base-height))))))
278 `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
279 :height ,(round (* 1.25 base-height))))))
280 `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
281 :height ,(round (* 1.5 base-height))))))
282 `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
283 :height ,(round (* 1.75 base-height))))))
284 `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
291 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
293 (use-package rainbow-delimiters
296 (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
302 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
304 (use-package page-break-lines
307 (turn-on-page-break-lines-mode))
313 Enable rainbow mode in emacs lisp mode
315 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
316 (use-package rainbow-mode
319 ; (add-hook emacs-lisp-mode-hook 'rainbow-mode)
328 clean mode line, Refer to [[https://www.masteringemacs.org/article/hiding-replacing-modeline-strings][Marstering Emacs]]
330 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
331 (defvar mode-line-cleaner-alist
332 `((auto-complete-mode . " α")
333 (yas/minor-mode . " Ï…")
334 (paredit-mode . " π")
337 (projectile-mode . "")
339 (undo-tree-mode . "")
341 (which-key-mode . "")
343 (smartparens-mode . "")
345 (linum-relative-mode . "")
347 (auto-revert-mode . "")
349 (org-indent-mode . "")
353 (lisp-interaction-mode . "λ")
356 (emacs-lisp-mode . "EL")
358 (nxhtml-mode . "nx"))
359 "Alist for `clean-mode-line'.
361 When you add a new element to the alist, keep in mind that you
362 must pass the correct minor/major mode symbol and a string you
363 want to use in the modeline *in lieu of* the original.")
366 (defun clean-mode-line ()
368 (loop for cleaner in mode-line-cleaner-alist
369 do (let* ((mode (car cleaner))
370 (mode-str (cdr cleaner))
371 (old-mode-str (cdr (assq mode minor-mode-alist))))
373 (setcar old-mode-str mode-str))
375 (when (eq mode major-mode)
376 (setq mode-name mode-str)))))
379 (add-hook 'after-change-major-mode-hook 'clean-mode-line)
384 Install powerline mode [[https://github.com/milkypostman/powerline][powerline]]
386 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
387 (use-package powerline
390 ;; (powerline-center-theme)
393 ;; (use-package smart-mode-line
395 ;; (use-package smart-mode-line-powerline-theme
399 Revised powerline-center-theme
400 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
401 (defun sd/powerline-simpler-vc (s)
403 (replace-regexp-in-string "Git[:-]" "" s)
406 (defface sd/powerline-active1 '((t (:background "yellow" :foreground "black" :inherit mode-line)))
407 "My Powerline face 1 based on powerline-active1."
410 (defface sd/buffer-modified-active1 '((t (:background "red" :foreground "black" :inherit mode-line)))
411 "My Powerline face 1 based on powerline-active1."
414 (defface sd/buffer-view-active1 '((t (:background "green" :foreground "black" :inherit mode-line)))
415 "My Powerline face 1 based on powerline-active1."
418 (defface sd/mode-line-buffer-id
419 '((t (:background "yellow" :foreground "black" :inherit mode-line-buffer-id)))
420 "My powerline mode-line face, based on mode-line-buffer-id"
423 ;; Don't show buffer modified for scratch and eshell mode
424 (defun sd/buffer-show-modified ()
425 "Dot not show modified indicator for buffers"
427 (unless (or (string-match "*scratch*" (buffer-name))
428 (equal major-mode 'eshell-mode))
431 (defun sd/powerline-center-theme_revised ()
432 "Setup a mode-line with major and minor modes centered."
434 (setq-default mode-line-format
437 (let* ((active (powerline-selected-window-active))
438 (mode-line-buffer-id (if active 'sd/mode-line-buffer-id 'mode-line-buffer-id-inactive))
439 (mode-line (if active 'mode-line 'mode-line-inactive))
440 (my-face1 (if active 'sd/powerline-active1 'powerline-inactive1))
441 (my-face-buffer-modified (if (and (sd/buffer-show-modified) (buffer-modified-p))
442 'sd/buffer-modified-active1
443 (if buffer-read-only 'sd/buffer-view-active1
445 (face1 (if active 'powerline-active1 'powerline-inactive1))
446 (face2 (if active 'powerline-active2 'powerline-inactive2))
447 (separator-left (intern (format "powerline-%s-%s"
448 (powerline-current-separator)
449 (car powerline-default-separator-dir))))
450 (separator-right (intern (format "powerline-%s-%s"
451 (powerline-current-separator)
452 (cdr powerline-default-separator-dir))))
453 (lhs (list (powerline-raw "%* " my-face-buffer-modified 'l)
454 ;; (powerline-buffer-size mode-line 'l)
455 (powerline-buffer-id mode-line-buffer-id 'l)
456 (powerline-raw " " my-face1)
457 (funcall separator-left my-face1 face1)
458 (powerline-narrow face1 'l)
459 ;; (powerline-vc face1)
460 (sd/powerline-simpler-vc (powerline-vc face1))))
461 (rhs (list (powerline-raw global-mode-string face1 'r)
462 (powerline-raw "%4l" face1 'r)
463 (powerline-raw ":" face1)
464 (powerline-raw "%3c" face1 'r)
465 (funcall separator-right face1 my-face1)
466 ;; (powerline-raw " " my-face1)
467 (powerline-raw (format-time-string " %I:%M %p ") my-face1 'r)
468 ;; (powerline-raw "%6p" my-face1 'r)
469 ;; (powerline-hud my-face1 face1 )
471 (center (list (powerline-raw " " face1)
472 (funcall separator-left face1 face2)
473 (when (and (boundp 'erc-track-minor-mode) erc-track-minor-mode)
474 (powerline-raw erc-modified-channels-object face2 'l))
475 (powerline-major-mode face2 'l)
476 (powerline-process face2)
477 (powerline-raw " :" face2)
478 (powerline-minor-modes face2 'l)
479 (powerline-raw " " face2)
480 (funcall separator-right face2 face1))))
481 (concat (powerline-render lhs)
482 (powerline-fill-center face1 (/ (powerline-width center) 2.0))
483 (powerline-render center)
484 (powerline-fill face1 (powerline-width rhs))
485 (powerline-render rhs)))))))
487 (sd/powerline-center-theme_revised)
490 Fix the issue in mode line when showing triangle
491 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
492 (setq ns-use-srgb-colorspace nil)
495 set height in mode line
496 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
497 (set-variable 'powerline-height 14)
498 (set-variable 'powerline-text-scale-factor (/ (float 100) 140))
499 ;; (custom-set-variables
500 ;; '(powerline-height 14)
501 ;; '(powerline-text-scale-factor (/ (float 100) 140)))
503 (set-face-attribute 'mode-line nil :height 100)
510 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
514 :init (setq ido-enable-flex-matching t
515 ido-ignore-extensions t
516 ido-use-virtual-buffers t
521 (add-to-list 'completion-ignored-extensions ".pyc"))
529 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
533 :init (setq ido-enable-flex-matching t
535 :config (flx-ido-mode 1))
540 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
541 (use-package ido-vertical-mode
544 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
546 (ido-vertical-mode 1))
551 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
555 :init (smex-initialize)
558 ("M-X" . smex-major-mode-commands))
564 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
566 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
568 (use-package ido-ubiquitous
571 (setq magit-completing-read-function 'magit-ido-completing-read)
572 (setq gnus-completing-read-function 'gnus-ido-completing-read)
574 (ido-ubiquitous-mode 1))
579 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
580 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
581 (use-package ido-exit-target
584 (mapcar (lambda (map)
585 (define-key map (kbd "C-j") #'ido-exit-target-split-window-right)
586 (define-key map (kbd "C-k") #'ido-exit-target-split-window-below))
587 (list ido-buffer-completion-map
588 ;; ido-common-completion-map
589 ido-file-completion-map
590 ido-file-dir-completion-map)))
593 * Normal Text Operation
596 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
597 (use-package undo-tree
600 (define-key undo-tree-visualizer-mode-map "j" 'undo-tree-visualize-redo)
601 (define-key undo-tree-visualizer-mode-map "k" 'undo-tree-visualize-undo)
602 (define-key undo-tree-visualizer-mode-map "h" 'undo-tree-visualize-switch-branch-left)
603 (define-key undo-tree-visualizer-mode-map "l" 'undo-tree-visualize-switch-branch-right)
604 (global-undo-tree-mode 1))
606 (global-set-key (kbd "s-u") 'undo-tree-visualize)
610 Stolen from [[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-spelling.el][here]], hunspell will search dictionary in =DICPATH=
611 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
612 (setenv "DICPATH" "/usr/local/share/hunspell")
614 (when (executable-find "hunspell")
615 (setq-default ispell-program-name "hunspell")
616 (setq ispell-really-hunspell t))
618 ;; (defun text-mode-hook-setup ()
619 ;; ;; Turn off RUN-TOGETHER option when spell check text-mode
620 ;; (setq-local ispell-extra-args (flyspell-detect-ispell-args)))
621 ;; (add-hook 'text-mode-hook 'text-mode-hook-setup)
622 ;; (add-hook 'text-mode-hook 'flyspell-mode)
624 ;; enable flyspell check on comments and strings in progmamming modes
625 ;; (add-hook 'prog-mode-hook 'flyspell-prog-mode)
627 ;; I don't use the default mappings
628 (with-eval-after-load 'flyspell
629 (define-key flyspell-mode-map (kbd "C-;") nil)
630 (define-key flyspell-mode-map (kbd "C-,") nil)
631 (define-key flyspell-mode-map (kbd "C-.") nil))
634 Make flyspell enabled for org-mode, see [[http://emacs.stackexchange.com/questions/9333/how-does-one-use-flyspell-in-org-buffers-without-flyspell-triggering-on-tangled][here]]
635 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
636 ;; NO spell check for embedded snippets
637 (defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
638 (let ((rlt ad-return-value)
639 (begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\)")
640 (end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\)")
643 (when ad-return-value
645 (setq old-flag case-fold-search)
646 (setq case-fold-search t)
647 (setq b (re-search-backward begin-regexp nil t))
648 (if b (setq e (re-search-forward end-regexp nil t)))
649 (setq case-fold-search old-flag))
650 (if (and b e (< (point) e)) (setq rlt nil)))
651 (setq ad-return-value rlt)))
655 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
656 (use-package expand-region
659 (global-set-key (kbd "C-=") 'er/expand-region))
666 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
668 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
670 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
671 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
672 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
673 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
674 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
675 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
676 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
677 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
678 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
680 ;; Also map s-h same as C-g
681 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
685 ** =Super= bindings for file, buffer and windows
687 Some global bindings on =Super=, on Mac, it is =Command=
689 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
690 (defun sd/delete-current-window ()
692 (if (> (length (window-list)) 1)
694 (message "Only one Windows now!")))
696 (global-set-key (kbd "s-h") 'keyboard-quit)
697 (global-set-key (kbd "s-j") 'ido-switch-buffer)
698 (global-set-key (kbd "s-k") 'ido-find-file)
699 (global-set-key (kbd "s-l") 'sd/delete-current-window)
701 ;; (global-set-key (kbd "s-/") 'swiper)
703 ;; s-' --> 'next-multiframe-window
704 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
706 (global-set-key (kbd "s-f") 'projectile-find-file)
708 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
710 (global-set-key (kbd "s-n") 'persp-next)
711 (global-set-key (kbd "s-p") 'persp-prev)
713 (global-set-key (kbd "s-=") 'text-scale-increase)
714 (global-set-key (kbd "s--") 'text-scale-decrease)
716 ;; (global-set-key (kbd "s-u") 'undo-tree-visualize)
719 ;; someothers default mapping on super (command) key
721 ;; s-k kill-this-buffer
724 ;; s-h --> ns-do-hide-emacs
725 ;; s-j --> ido-switch-buffer +
726 ;; s-k --> kill-this-buffer
729 ;; s-' --> next-multiframe-window
730 ;; s-ret --> toggle-frame-fullscreen +
732 ;; s-y --> ns-paste-secondary
733 ;; s-u --> revert-buffer
734 ;; s-i --> undefined - but used for iterm globally
735 ;; s-o --> used for emacs globally
736 ;; s-p --> projectile-persp-switch-project +
737 ;; s-[ --> next-buffer +
738 ;; s-] --> previous-buffer +
745 ;; s-- --> center-line
748 ;; s-n --> make-frame
749 ;; s-m --> iconify-frame
755 ;; s-g --> isearch-repeat-forward
756 ;; s-f --> projectile-find-file +
757 ;; s-d --> isearch-repeat-background
758 ;; s-s --> save-buffer
759 ;; s-a --> make-whole-buffer
763 ;; s-c --> ns-copy-including-secondary
765 ;; s-t --> ns-popup-font-panel
767 ;; s-e --> isearch-yanqk-kill
768 ;; s-w --> delete-frame
769 ;; s-q --> same-buffers-kill-emacs
771 ;; s-` --> other-frame
774 ** Search Replace and highlight
776 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
777 ;; (use-package swiper
781 ;; (setq ivy-use-virtual-buffers t)
782 ;; (global-set-key (kbd "s-/") 'swiper)
788 ;; (global-set-key "\C-s" 'swiper)
789 ;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
790 ;; (global-set-key (kbd "<f6>") 'ivy-resume)
791 (global-set-key (kbd "M-x") 'counsel-M-x)
792 ;; ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
793 (global-set-key (kbd "C-h f") 'counsel-describe-function)
794 (global-set-key (kbd "C-h v") 'counsel-describe-variable)
795 ;; (global-set-key (kbd "<f1> l") 'counsel-load-library)
796 ;; (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
797 ;; (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
798 ;; (global-set-key (kbd "C-c g") 'counsel-git)
799 ;; (global-set-key (kbd "C-c j") 'counsel-git-grep)
800 ;; (global-set-key (kbd "C-c k") 'counsel-ag)
801 ;; (global-set-key (kbd "C-x l") 'counsel-locate)
802 ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
803 ;; ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
805 ;; (set-face-attribute
806 ;; 'ivy-current-match nil
807 ;; :background "Orange"
808 ;; :foreground "black")
811 ;; (define-key swiper-map (kbd "M-%") 'swiper-aa-replace)
815 use the prefix =M-s= for searching in buffers
816 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
817 (defun sd/make-keymap (key bindings)
818 (setq keymap (make-sparse-keymap))
819 (dolist (binding bindings)
820 (define-key keymap (car binding) (cdr binding)))
821 (global-set-key key keymap))
823 (use-package highlight-symbol
826 (sd/make-keymap "\M-s"
827 '(("w" . save-buffer)
828 ;; ("\M-w" . save-buffer)
829 ("e" . revert-buffer)
830 ("s" . isearch-forward-regexp)
831 ("\M-s" . isearch-forward-regexp)
832 ("r" . isearch-backward-regexp)
833 ("." . isearch-forward-symbol-at-point)
835 ;; ("h" . highlight-symbol-at-point)
836 ("h" . highlight-symbol)
837 ("m" . highlight-regexp)
838 ("l" . highlight-lines-matching-regexp)
839 ("M" . unhighlight-regexp)
840 ("f" . keyboard-quit)
841 ("q" . keyboard-quit)))
843 ;; search and replace and highlight
844 (define-key isearch-mode-map (kbd "M-s") 'isearch-repeat-forward)
845 (define-key isearch-mode-map (kbd "M-r") 'isearch-repeat-backward)
846 (global-set-key (kbd "s-[") 'highlight-symbol-next)
847 (global-set-key (kbd "s-]") 'highlight-symbol-prev)
848 (global-set-key (kbd "s-\\") 'highlight-symbol-query-replace)
851 (define-key minibuffer-local-map "\M-s" nil)
853 (set-face-background 'ido-first-match "yellow")
855 ;; M-s M-w eww-search-words
865 ** Org-mode Basic setting
867 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
869 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
873 (setq org-startup-indented t)
874 (setq org-hide-leading-starts t)
875 (setq org-src-fontify-natively t)
876 (setq org-src-tab-acts-natively t)
877 (setq org-confirm-babel-evaluate nil)
878 (setq org-use-speed-commands t)
879 (setq org-completion-use-ido t))
881 (org-babel-do-load-languages
882 'org-babel-load-languages
898 ;; use current window for org source buffer editting
899 (setq org-src-window-setup 'current-window )
901 (define-key org-mode-map (kbd "C-'") nil)
902 ;; C-M-i is mapped to imenu globally
903 (define-key org-mode-map (kbd "C-M-i") nil)
905 ;; set the ditta.jar path
906 (setq org-ditaa-jar-path "/usr/local/Cellar/ditaa/0.9/libexec/ditaa0_9.jar")
908 (file-exists-p org-ditaa-jar-path)
909 (error "seudut: ditaa.jar not found at %s " org-ditaa-jar-path))
914 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
916 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
917 (use-package org-bullets
920 (add-hook 'org-mode-hook
922 (org-bullets-mode t))))
924 (setq org-bullets-bullet-list '("⦿" "✪" "◉" "○" "►" "◆"))
926 ;; increase font size when enter org-src-mode
927 (add-hook 'org-src-mode-hook (lambda () (text-scale-increase 2)))
932 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
933 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
934 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
935 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
937 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
942 :init (add-hook 'org-mode-hook 'worf-mode)
944 ;; (define-key worf-mode-map "[" nil)
945 ;; (define-key worf-mode-map "]" nil)
946 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
947 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
954 Refer to [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
959 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
960 (global-set-key "\C-cl" 'org-store-link)
961 (global-set-key "\C-ca" 'org-agenda)
962 (global-set-key "\C-cb" 'org-iswitchb)
967 Replace the list bullet =-=, =+=, with =•=, a litter change based [[https://github.com/howardabrams/dot-files/blob/master/emacs-org.org][here]]
969 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
970 ;; (use-package org-mode
972 ;; (font-lock-add-keywords 'org-mode
973 ;; '(("^ *\\([-+]\\) "
974 ;; (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•")))))))
979 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]],
981 To track TODO state changes, the =!= is to insert a timetamp, =@= is to insert a note with
982 timestamp for the state change.
984 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
985 ;; (setq org-todo-keywords
986 ;; '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
987 ;; (sequence "âš‘ WAITING(w)" "|")
988 ;; (sequence "|" "✘ CANCELLED(c)")))
989 ; (setq org-todo-keyword-faces
990 ; (quote ("TODO" . (:foreground "red" :weight bold))
991 ; ("NEXT" . (:foreground "blue" :weight bold))
992 ; ("WAITING" . (:foreground "forest green" :weight bold))
993 ; ("DONE" . (:foreground "magenta" :weight bold))
994 ; ("CANCELLED" . (:foreground "forest green" :weight bold))))
997 (setq org-todo-keywords
998 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!)")
999 ;; (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING")
1000 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" ))))
1002 (setq org-todo-keyword-faces
1003 (quote (("TODO" :foreground "red" :weight bold)
1004 ("NEXT" :foreground "blue" :weight bold)
1005 ("DONE" :foreground "forest green" :weight bold)
1006 ("WAITING" :foreground "orange" :weight bold)
1007 ("HOLD" :foreground "magenta" :weight bold)
1008 ("CANCELLED" :foreground "forest green" :weight bold)
1009 ;; ("MEETING" :foreground "forest green" :weight bold)
1010 ;; ("PHONE" :foreground "forest green" :weight bold)
1014 Fast todo selections
1016 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1017 (setq org-use-fast-todo-selection t)
1018 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1021 TODO state triggers and tags, [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
1023 - Moving a task to =CANCELLED=, adds a =CANCELLED= tag
1024 - Moving a task to =WAITING=, adds a =WAITING= tag
1025 - Moving a task to =HOLD=, add =HOLD= tags
1026 - Moving a task to =DONE=, remove =WAITING=, =HOLD= tag
1027 - Moving a task to =NEXT=, remove all waiting/hold/cancelled tags
1029 This tags are used to filter tasks in agenda views
1030 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1031 (setq org-todo-state-tags-triggers
1032 (quote (("CANCELLED" ("CANCELLED" . t))
1033 ("WAITING" ("WAITING" . t))
1034 ("HOLD" ("WAITING") ("HOLD" . t))
1035 (done ("WAITING") ("HOLD"))
1036 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1037 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1038 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1042 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1043 ;; log time when task done
1044 ;; (setq org-log-done (quote time))
1045 ;; save clocking into to LOGBOOK
1046 (setq org-clock-into-drawer t)
1047 ;; save state change notes and time stamp into LOGBOOK drawer
1048 (setq org-log-into-drawer t)
1049 (setq org-clock-into-drawer "CLOCK")
1053 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1054 (setq org-tag-alist (quote ((:startgroup)
1060 ("CANCELLED" . ?c))))
1062 ;; Allow setting single tags without the menu
1063 (setq org-fast-tag-selection-single-key (quote expert))
1066 *** Capture - Refile - Archive
1068 Capture lets you quickly store notes with little interruption of your work flow.
1070 **** Capture Templates
1072 When a new taks needs to be added, categorize it as
1074 All captured file which need next actions are stored in =refile.org=,
1075 - A new task / note (t) =refile.org=
1076 - A work task in office =office.org=
1077 - A jourenl =diary.org=
1078 - A new habit (h) =refile.org=
1080 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1081 (setq org-directory "~/org")
1082 (setq org-default-notes-file "~/org/refile.org")
1083 (setq sd/org-diary-file "~/org/diary.org")
1085 (global-set-key (kbd "C-c c") 'org-capture)
1087 (setq org-capture-templates
1088 (quote (("t" "Todo" entry (file org-default-notes-file)
1089 "* TODO %?\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1090 ("n" "Note" entry (file org-default-notes-file)
1091 "* %? :NOTE:\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1092 ("j" "Journal" entry (file+datetree sd/org-diary-file)
1093 "* %?\n:LOGBOOK:\n:END:" :clock-in t :clock-resume t)
1094 ("h" "Habit" entry (file org-default-notes-file)
1095 "* NEXT %?\n:LOGBOOK:\n%a\nSCHEDULED: %(format-time-string \"%<<%Y-%m-%d %a .+1d/3d>>\")\n:END:\n:PROPERTIES:\n:STYLE: habit\n:REPEAT_TO_STATE: NEXT\n:END:\n "))))
1100 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1101 (setq org-refile-targets (quote (;; (nil :maxlevel . 9)
1102 (org-agenda-files :maxlevel . 9))))
1104 (setq org-refile-use-outline-path t)
1106 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1110 Setting agenda files and the agenda view
1111 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1112 (setq org-agenda-files (quote ("~/org/gtd.org"
1115 ;; only show today's tasks in agenda view
1116 (setq org-agenda-span 'day)
1117 ;; Use current windows for agenda view
1118 (setq org-agenda-window-setup 'current-window)
1120 ;; show all feature entries for repeating tasks,
1121 ;; this is already setting by default
1122 (setq org-agenda-repeating-timestamp-show-all t)
1124 ;; Show all agenda dates - even if they are empty
1125 (setq org-agenda-show-all-dates t)
1130 Install MacTex-basic and some tex packages
1134 sudo tlmgr update --self
1136 sudo tlmgr install titlesec framed threeparttable wrapfig multirow enumitem bbding titling tabu mdframed tcolorbox textpos import varwidth needspace tocloft ntheorem environ trimspaces collection-fontsrecommended capt-of
1140 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1141 ;; ;; allow for export=>beamer by placing
1143 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
1144 ;; #+LaTeX_CLASS: beamer in org files
1145 (unless (boundp 'org-export-latex-classes)
1146 (setq org-export-latex-classes nil))
1147 (add-to-list 'org-export-latex-classes
1148 ;; beamer class, for presentations
1150 "\\documentclass[11pt]{beamer}\n
1151 \\mode<{{{beamermode}}}>\n
1152 \\usetheme{{{{beamertheme}}}}\n
1153 \\usecolortheme{{{{beamercolortheme}}}}\n
1154 \\beamertemplateballitem\n
1155 \\setbeameroption{show notes}
1156 \\usepackage[utf8]{inputenc}\n
1157 \\usepackage[T1]{fontenc}\n
1158 \\usepackage{hyperref}\n
1160 \\usepackage{listings}
1161 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
1164 showspaces=false,showstringspaces=false,
1166 keywordstyle=\\color{blue}\\bfseries,
1167 commentstyle=\\color{red},
1169 \\usepackage{verbatim}\n
1170 \\institute{{{{beamerinstitute}}}}\n
1171 \\subject{{{{beamersubject}}}}\n"
1173 ("\\section{%s}" . "\\section*{%s}")
1175 ("\\begin{frame}[fragile]\\frametitle{%s}"
1177 "\\begin{frame}[fragile]\\frametitle{%s}"
1180 ;; letter class, for formal letters
1182 (add-to-list 'org-export-latex-classes
1185 "\\documentclass[11pt]{letter}\n
1186 \\usepackage[utf8]{inputenc}\n
1187 \\usepackage[T1]{fontenc}\n
1188 \\usepackage{color}"
1190 ("\\section{%s}" . "\\section*{%s}")
1191 ("\\subsection{%s}" . "\\subsection*{%s}")
1192 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1193 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1194 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1198 (require 'ox-beamer)
1200 (setq org-latex-pdf-process
1201 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1202 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1203 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
1205 (setq TeX-parse-self t)
1207 (setq TeX-PDF-mode t)
1208 (add-hook 'LaTeX-mode-hook
1211 (setq TeX-master t)))
1217 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
1219 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1221 (add-to-list 'org-structure-template-alist
1222 '("E" "#+BEGIN_SRC emacs-lisp :tangle yes :results silent\n?\n#+END_SRC"))
1223 (add-to-list 'org-structure-template-alist
1224 '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
1225 (add-to-list 'org-structure-template-alist
1226 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
1231 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
1232 and Defined keys, using vi keybindings, Refer abo-abo's setting [[https://github.com/abo-abo/oremacs/blob/c5cafdcebc88afe9e73cc8bd40c49b70675509c7/modes/ora-nextmagit.el][here]]
1233 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1237 ;; don't ask me to confirm the unsaved change
1238 (setq magit-save-repository-buffers nil)
1239 :commands magit-status magit-blame
1241 (dolist (map (list magit-status-mode-map
1244 magit-staged-section-map))
1245 (define-key map "j" 'magit-section-forward)
1246 (define-key map "k" 'magit-section-backward)
1247 (define-key map "D" 'magit-discard)
1248 (define-key map "O" 'magit-discard-file)
1249 (define-key map "n" nil)
1250 (define-key map "p" nil)
1251 (define-key map "v" 'recenter-top-bottom)
1252 (define-key map "i" 'magit-section-toggle)))
1257 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1258 (defalias 'e 'find-file)
1259 (defalias 'ff 'find-file)
1260 (defalias 'ee 'find-files)
1263 *** Eshell erase buffer
1264 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1265 (defun sd/eshell-clear-buffer ()
1266 "Clear eshell buffer"
1268 (let ((inhibit-read-only t))
1270 (eshell-send-input)))
1272 (add-hook 'eshell-mode-hook (lambda ()
1273 (local-set-key (kbd "C-l") 'sd/eshell-clear-buffer)))
1277 Toggle an eshell in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
1278 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1279 (defun sd/window-has-eshell ()
1280 "Check if current windows list has a eshell buffer, and return the window"
1283 (walk-windows (lambda (window)
1284 (if (equal (with-current-buffer (window-buffer window) major-mode)
1290 (defun sd/toggle-eshell-here ()
1291 "Toggle a eshell buffer vertically"
1293 (if (sd/window-has-eshell)
1294 (if (equal major-mode 'eshell-mode)
1296 (if (equal (length (window-list)) 1)
1297 (mode-line-other-buffer)
1299 (select-window (sd/window-has-eshell)))
1301 (let ((dir default-directory))
1303 (split-window-vertically (- (/ (window-total-height) 3)))
1305 (unless (and (boundp 'eshell-buffer-name) (get-buffer eshell-buffer-name))
1307 (switch-to-buffer eshell-buffer-name)
1308 (goto-char (point-max))
1310 (insert (format "cd %s" dir))
1311 (eshell-send-input)))))
1313 (global-unset-key (kbd "M-`"))
1314 (global-set-key (kbd "M-`") 'sd/toggle-eshell-here)
1317 *** TODO smart display
1320 ** [[https://github.com/abo-abo/hydra][Hydra]]
1322 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1325 ;; disable new line in minibuffer when hint hydra
1330 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1331 (defhydra sd/font-zoom (global-map "<f2>")
1333 ("g" text-scale-increase "in")
1334 ("l" text-scale-decrease "out"))
1337 *** Windmove Splitter
1339 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1341 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1343 (defun hydra-move-splitter-left (arg)
1344 "Move window splitter left."
1346 (if (let ((windmove-wrap-around))
1347 (windmove-find-other-window 'right))
1348 (shrink-window-horizontally arg)
1349 (enlarge-window-horizontally arg)))
1351 (defun hydra-move-splitter-right (arg)
1352 "Move window splitter right."
1354 (if (let ((windmove-wrap-around))
1355 (windmove-find-other-window 'right))
1356 (enlarge-window-horizontally arg)
1357 (shrink-window-horizontally arg)))
1359 (defun hydra-move-splitter-up (arg)
1360 "Move window splitter up."
1362 (if (let ((windmove-wrap-around))
1363 (windmove-find-other-window 'up))
1364 (enlarge-window arg)
1365 (shrink-window arg)))
1367 (defun hydra-move-splitter-down (arg)
1368 "Move window splitter down."
1370 (if (let ((windmove-wrap-around))
1371 (windmove-find-other-window 'up))
1373 (enlarge-window arg)))
1378 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1379 (defhydra sd/hydra-misc (:color red :columns nil)
1380 "Miscellaneous Commands"
1381 ("e" eshell "eshell" :exit t)
1384 (if (not (eq nil (get-buffer "*Packages*")))
1385 (switch-to-buffer "*Packages*")
1386 (package-list-packages)))
1387 "list-package" :exit t)
1388 ("g" magit-status "git-status" :exit t)
1389 ("'" mode-line-other-buffer "last buffer" :exit t)
1390 ("C-'" mode-line-other-buffer "last buffer" :exit t)
1391 ("m" man "man" :exit t)
1392 ("d" dired-jump "dired" :exit t)
1393 ("b" ibuffer "ibuffer" :exit t)
1397 (global-set-key (kbd "C-'") 'sd/hydra-misc/body)
1401 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1402 (defhydra sd/hydra-launcher (:color blue :columns 2)
1404 ("e" emms "emms" :exit t)
1410 Enable linum mode on programming modes
1412 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1413 (add-hook 'prog-mode-hook 'linum-mode)
1414 ;; (add-hook 'prog-mode-hook (lambda ()
1415 ;; (setq-default indicate-empty-lines t)))
1418 Fix the font size of line number
1420 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1422 (defun fix-linum-size ()
1424 (set-face-attribute 'linum nil :height 110))
1426 (add-hook 'linum-mode-hook 'fix-linum-size)
1430 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1432 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1434 (use-package linum-relative
1437 (defun linum-new-mode ()
1438 "If line numbers aren't displayed, then display them.
1439 Otherwise, toggle between absolute and relative numbers."
1442 (linum-relative-toggle)
1446 ("A-k" . linum-new-mode))
1448 ;; auto enable linum-new-mode in programming modes
1449 (add-hook 'prog-mode-hook 'linum-relative-mode)
1453 ** Save File Position
1455 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1457 (require 'saveplace)
1458 (setq-default save-place t)
1459 (setq save-place-forget-unreadable-files t)
1460 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1466 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1468 (use-package multi-term
1475 [[https://github.com/abo-abo/ace-link][ace-link]] is a package written by [[https://github.com/abo-abo][Oleh Krehel]]. It is convenient to jump to link in help mode, info-mode, etc
1476 Type =o= to go to the link
1478 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1480 (use-package ace-link
1483 (ace-link-setup-default))
1489 [[https://github.com/re5et/emux][emux]] is
1491 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1493 (el-get-bundle re5et/emux)
1499 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1501 (use-package smartparens
1505 (require 'smartparens-config)
1506 (add-hook 'prog-mode-hook 'smartparens-mode)))
1512 [[https://github.com/abo-abo/ace-window][ace-window]]
1514 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1516 (use-package ace-window
1520 ; (global-set-key (kbd "M-o") 'ace-window)
1522 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1528 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1530 (use-package projectile
1533 (setq projectile-enable-caching t)
1535 (projectile-global-mode t))
1537 (use-package persp-projectile
1542 (:map projectile-mode-map
1543 ("s-t" . projectile-persp-switch-project)))
1545 ;; projectile-find-file
1546 ;; projectile-switch-buffer
1547 ;; projectile-find-file-other-window
1552 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1554 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1556 (use-package which-key
1565 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1567 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1571 (setq emms-source-file-default-directory "~/Music/")
1574 (emms-default-players)
1575 (define-emms-simple-player mplayer '(file url)
1576 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1577 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1578 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1579 ".m4a" ".flv" ".ogv" ".pls"))
1580 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1581 (emms-history-load))
1587 Play Go in Emacs, gnugo xpm refert [[https://github.com/okanotor/dotemacs/blob/f95b774cb292d1169748bc0a62ba647bbd8c0652/etc/my-inits/my-inits-gnugo.el][to here]]. start at image display mode and grid mode
1589 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1595 (require 'gnugo-imgen)
1596 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1597 (add-hook 'gnugo-start-game-hook '(lambda ()
1598 (gnugo-image-display-mode)
1601 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1607 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1609 ;; (use-package tabbar-ruler
1612 ;; (setq tabbar-ruler-global-tabbar t)
1613 ;; (setq tabbar-ruler-global-ruler t)
1614 ;; (setq tabbar-ruler-popu-menu t)
1615 ;; (setq tabbar-ruler-popu-toolbar t)
1616 ;; (setq tabbar-use-images t)
1618 ;; (tabbar-ruler-group-by-projectile-project)
1619 ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
1620 ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1624 ** View only for some directory
1625 When see function by =C-h f=, and visit the source code, I would like the buffer is read only. See [[http://emacs.stackexchange.com/questions/3676/how-to-enter-view-only-mode-when-browsing-emacs-source-code-from-help/3681#3681][here]]
1626 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1627 (dir-locals-set-class-variables
1629 '((nil . ((buffer-read-only . t)
1630 (show-trailing-whitespace . nil)
1632 (eval . (whitespace-mode -1))))))
1634 ;; (dir-locals-set-directory-class (expand-file-name "/usr/local/share/emacs") 'emacs)
1635 (dir-locals-set-directory-class "/usr/local/Cellar/emacs" 'emacs)
1636 ;; (dir-locals-set-directory-class "~/.emacs.d/elpa" 'emacs)
1637 (dir-locals-set-directory-class "~/dotfiles/emacs.d/elpa" 'emacs)
1638 (dir-locals-set-directory-class "~/dotfiles/emacs.d/el-get" 'emacs)
1642 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1643 (el-get-bundle info+
1644 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/info+.el"
1652 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1653 (defun sd/info-mode ()
1655 (unless (equal major-mode 'Info-mode)
1656 (unless (> (length (window-list)) 1)
1657 (split-window-right))
1662 ;; (global-set-key (kbd "C-h i") 'sd/info-mode)
1664 ;; open Info buffer in other window instead of current window
1665 (defadvice info (before my-info (&optional file buf) activate)
1668 (defadvice Info-exit (after my-info-exit activate)
1669 (sd/delete-current-window))
1675 ** TODO swiper to occur
1678 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1679 ;; (set-language-environment "UTF-8")
1680 ;; (set-default-coding-systems 'utf-8)
1684 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1685 ;; (el-get-bundle howardabrams/demo-it)
1687 (use-package org-tree-slide
1690 ;; (use-package yasnippet
1695 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1696 (use-package org-tree-slide
1699 ;; (define-key org-mode-map "\C-ccp" 'org-tree-slide-mode)
1700 (define-key org-tree-slide-mode-map (kbd "<ESC>") 'org-tree-slide-content)
1701 (define-key org-tree-slide-mode-map (kbd "<SPACE>") 'org-tree-slide-move-next-tree)
1702 (define-key org-tree-slide-mode-map [escape] 'org-tree-slide-move-previous-tree))
1706 =C-o= is defined as a global key for window operation, here unset it in dired mode
1707 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1711 (setq dired-omit-mode t)
1712 (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
1713 (add-hook 'dired-mode-hook (lambda ()
1714 (define-key dired-mode-map (kbd "C-o") nil)
1715 (define-key dired-mode-map (kbd "H") 'dired-omit-mode)
1716 (define-key dired-mode-map (kbd "DEL") (lambda () (interactive) (find-alternate-file "..")))
1717 (dired-omit-mode))))
1721 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1725 (setq diredp-hide-details-initially-flag nil)
1727 (define-key dired-mode-map (kbd "j") 'diredp-next-line)
1728 (define-key dired-mode-map (kbd "k") 'diredp-previous-line)
1729 (define-key dired-mode-map (kbd "g") 'dired-goto-file))
1733 company mode and company-statistics
1734 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1735 (use-package company
1737 :diminish company-mode
1738 :init (setq company-idle-delay 0.1)
1740 (global-company-mode))
1742 (use-package company-statistics
1745 (company-statistics-mode))
1748 * Programming Language
1750 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1751 (use-package color-identifiers-mode
1754 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1756 :diminish color-identifiers-mode)
1758 (global-prettify-symbols-mode t)
1761 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1762 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1763 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1767 (eval-after-load "lispy"
1769 (define-key lispy-mode-map (kbd "M-o") nil)))
1771 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1776 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1777 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1778 (defalias 'perl-mode 'cperl-mode)
1780 ;; (setq cperl-hairy t)
1781 ;; Turns on most of the CPerlMode options
1782 (setq cperl-auto-newline t)
1783 (setq cperl-highlight-variables-indiscriminately t)
1784 ;(setq cperl-indent-level 4)
1785 ;(setq cperl-continued-statement-offset 4)
1786 (setq cperl-close-paren-offset -4)
1787 (setq cperl-indent-parents-as-block t)
1788 (setq cperl-tab-always-indent t)
1789 ;(setq cperl-brace-offset 0)
1791 (add-hook 'cperl-mode-hook
1793 (cperl-set-style "C++")))
1795 (defalias 'perldoc 'cperl-perldoc)
1799 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1800 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1801 (eval-after-load 'autoinsert
1802 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1805 "#!/usr/bin/perl -w" \n
1807 "use strict;" > \n \n
1813 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1814 (font-lock-add-keywords 'cperl-mode
1815 '(("\\(say\\)" . cperl-nonoverridable-face)
1816 ("\\([0-9.]\\)*" . font-lock-constant-face)
1817 ("\".*\\(\\\n\\).*\"" . font-lock-constant-face)
1818 ("\n" . font-lock-constant-face)
1819 ("\\(^#!.*\\)$" . cperl-nonoverridable-face)))
1821 ;; (font-lock-add-keywords 'Man-mode
1822 ;; '(("\\(NAME\\)" . font-lock-function-name-face)))
1827 Change the compile-command to set the default command run when call =compile=
1828 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1829 to call =compilation= interactively.
1830 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1831 (defun my-perl-hook ()
1833 (setq-local compilation-read-command nil)
1834 (set (make-local-variable 'compile-command)
1835 (concat "/usr/bin/perl "
1836 (if buffer-file-name
1837 (shell-quote-argument buffer-file-name))))
1838 (local-set-key (kbd "s-r")
1841 ; (setq current-prefix-arg '(4)) ; C-u
1842 (call-interactively 'compile)))))
1844 (add-hook 'cperl-mode-hook 'my-perl-hook)
1848 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1849 (setq c-default-style "stroustrup"
1854 Set the environments vairables in compilation mode
1855 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1856 (use-package compile
1859 (setq compilation-environment (cons "LC_ALL=C" compilation-environment))
1860 (setq compilation-auto-jump-to-first-error t)
1861 (setq compilation-auto-jump-to-next t)
1862 (setq compilation-scroll-output 'first-error))
1864 ;; super-r to compile
1865 (with-eval-after-load "compile"
1866 (define-key compilation-mode-map (kbd "C-o") nil)
1867 (define-key compilation-mode-map (kbd "n") 'compilation-next-error)
1868 (define-key compilation-mode-map (kbd "p") 'compilation-previous-error)
1869 (define-key compilation-mode-map (kbd "r") #'recompile))
1873 ** Enable auto-insert mode
1874 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1875 (auto-insert-mode t)
1876 (setq auto-insert-query nil)
1880 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1881 (eval-after-load 'autoinsert
1882 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1884 "Short description:"
1886 "\n * " (file-name-nondirectory (buffer-file-name))
1888 "#include <iostream>" \n
1890 (file-name-sans-extension
1891 (file-name-nondirectory (buffer-file-name)))
1893 "using namespace std;" \n \n
1901 (eval-after-load 'autoinsert
1902 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1904 "Short description:"
1906 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1908 "#include <stdio.h>" \n
1910 (file-name-sans-extension
1911 (file-name-nondirectory (buffer-file-name)))
1922 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1923 (eval-after-load 'autoinsert
1924 '(define-auto-insert '("\\.\\(py\\)\\'" . "Python skeleton")
1933 Emacs lisp auto-insert, based on the default module in =autoinsert.el=, but replace =completing-read= as
1934 =completing-read-ido-ubiquitous= to fix the edge case of that =ido= cannot handle.
1935 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1936 (eval-after-load 'autoinsert
1937 '(define-auto-insert '("\\.el\\'" . "my Emacs Lisp header")
1939 "Short description: "
1940 ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str
1941 (make-string (max 2 (- 80 (current-column) 27)) ?\s)
1942 "-*- lexical-binding: t; -*-" '(setq lexical-binding t)
1944 ;; Copyright (C) " (format-time-string "%Y") " "
1945 (getenv "ORGANIZATION") | (progn user-full-name) "
1947 ;; Author: " (user-full-name)
1948 '(if (search-backward "&" (line-beginning-position) t)
1949 (replace-match (capitalize (user-login-name)) t t))
1950 '(end-of-line 1) " <" (progn user-mail-address) ">
1953 ;;'(setq v1 (apply 'vector (mapcar 'car finder-known-keywords)))
1954 '(setq v1 (mapcar (lambda (x) (list (symbol-name (car x))))
1955 finder-known-keywords)
1956 v2 (mapconcat (lambda (x) (format "%12s: %s" (car x) (cdr x)))
1957 finder-known-keywords
1959 ((let ((minibuffer-help-form v2))
1960 (completing-read-ido-ubiquitous "Keyword, C-h: " v1 nil t))
1963 \;; This program is free software; you can redistribute it and/or modify
1964 \;; it under the terms of the GNU General Public License as published by
1965 \;; the Free Software Foundation, either version 3 of the License, or
1966 \;; (at your option) any later version.
1968 \;; This program is distributed in the hope that it will be useful,
1969 \;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1970 \;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1971 \;; GNU General Public License for more details.
1973 \;; You should have received a copy of the GNU General Public License
1974 \;; along with this program. If not, see <http://www.gnu.org/licenses/>.
1986 \;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")))
1989 ** Org file template
1990 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1991 (eval-after-load 'autoinsert
1992 '(define-auto-insert '("\\.\\(org\\)\\'" . "Org-mode skeleton")
1995 "#+TITLE: " str (make-string 30 ?\s) > \n
1996 "#+AUTHOR: Peng Li\n"
1997 "#+EMAIL: seudut@gmail.com\n"
1998 "#+DATE: " (shell-command-to-string "echo -n $(date +%Y-%m-%d)") > \n
2004 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2005 (use-package markdown-mode
2007 :commands (markdown-mode gfm-mode)
2008 :mode (("README\\.md\\'" . gfm-mode)
2009 ("\\.md\\'" . markdown-mode)
2010 ("\\.markdown\\'" . markdown-mode))
2011 :init (setq markdown-command "multimarkdown"))
2014 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2015 (use-package markdown-preview-eww
2021 Refer [[https://www.emacswiki.org/emacs/GnusGmail][GnusGmail]]
2022 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2023 (setq user-mail-address "seudut@gmail.com"
2024 user-full-name "Peng Li")
2026 (setq gnus-select-method
2028 (nnimap-address "imap.gmail.com")
2029 (nnimap-server-port "imaps")
2030 (nnimap-stream ssl)))
2032 (setq smtpmail-smtp-service 587
2033 gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
2035 ;; Use gmail sending mail
2036 (setq message-send-mail-function 'smtpmail-send-it
2037 smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
2038 smtpmail-auth-credentials '(("smtp.gmail.com" 587 "seudut@gmail.com" nil))
2039 smtpmail-default-smtp-server "smtp.gmail.com"
2040 smtpmail-smtp-server "smtp.gmail.com"
2041 smtpmail-smtp-service 587
2042 starttls-use-gnutls t)
2045 And put the following in =~/.authinfo= file, replacing =<USE>= with your email address
2046 and =<PASSWORD>= with the password
2048 machine imap.gmail.com login <USER> password <PASSWORD> port imaps
2049 machine smtp.gmail.com login <USER> password <PASSWORD> port 587
2055 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2058 (setq gnus-permanently-visible-groups "\.*")
2060 (cond (window-system
2061 (setq custom-background-mode 'light)
2062 (defface my-group-face-1
2063 '((t (:foreground "Red" :bold t))) "First group face")
2064 (defface my-group-face-2
2065 '((t (:foreground "DarkSeaGreen4" :bold t)))
2066 "Second group face")
2067 (defface my-group-face-3
2068 '((t (:foreground "Green4" :bold t))) "Third group face")
2069 (defface my-group-face-4
2070 '((t (:foreground "SteelBlue" :bold t))) "Fourth group face")
2071 (defface my-group-face-5
2072 '((t (:foreground "Blue" :bold t))) "Fifth group face")))
2073 (setq gnus-group-highlight
2074 '(((> unread 200) . my-group-face-1)
2075 ((and (< level 3) (zerop unread)) . my-group-face-2)
2076 ((< level 3) . my-group-face-3)
2077 ((zerop unread) . my-group-face-4)
2078 (t . my-group-face-5))))
2082 (add-hook 'gnus-group-mode-hook (lambda ()
2083 (define-key gnus-group-mode-map "k" 'gnus-group-prev-group)
2084 (define-key gnus-group-mode-map "j" 'gnus-group-next-group)
2085 (define-key gnus-group-mode-map "g" 'gnus-group-jump-to-group)
2086 (define-key gnus-group-mode-map "v" (lambda () (interactive) (gnus-group-select-group t)))))
2089 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2090 (setq gnus-fetch-old-headers 't)
2094 (setq gnus-extract-address-components
2095 'mail-extract-address-components)
2097 (setq gnus-summary-line-format "%U%R%z%I%(%[%-20,20f%]%) %s%-80= %11&user-date;\n")
2098 (setq gnus-user-date-format-alist '(((gnus-seconds-today) . "%H:%M")
2099 ((+ 86400 (gnus-seconds-today)) . "%a %H:%M")
2100 (604800 . "%a, %b %-d")
2101 (15778476 . "%b %-d")
2104 (setq gnus-thread-sort-functions '((not gnus-thread-sort-by-number)))
2105 (setq gnus-unread-mark ?\.)
2106 (setq gnus-use-correct-string-widths t)
2109 (setq gnus-thread-hide-subtree t)
2111 ;; (with-eval-after-load 'gnus-summary-mode
2112 ;; (define-key gnus-summary-mode-map (kbd "C-o") 'sd/hydra-window/body))
2114 (add-hook 'gnus-summary-mode-hook (lambda ()
2115 (define-key gnus-summary-mode-map (kbd "C-o") nil)))
2121 See [[https://www.emacswiki.org/emacs/GnusWindowLayout][GnusWindowLayout]]
2122 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2123 (gnus-add-configuration
2129 (summary 1.0 poine)))))
2131 (gnus-add-configuration
2137 (summary 0.50 point)
2140 (with-eval-after-load 'gnus-group-mode
2141 (gnus-group-select-group "INBOX"))
2142 ;; (add-hook 'gnus-group-mode-map (lambda ()
2143 ;; (gnus-group-select-group "INBOX")))
2147 To fix some issue that =toolbar-make-button-list= is void, see the [[https://github.com/bruceravel/gnuplot-mode/issues/31][issue]], here I set some variable as =nil=
2148 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2149 (use-package gnuplot
2152 (setq gnuplot-help-xpm nil)
2153 (setq gnuplot-line-xpm nil)
2154 (setq gnuplot-region-xpm nil)
2155 (setq gnuplot-buffer-xpm nil)
2156 (setq gnuplot-doc-xpm nil))
2159 Use =gnuplot= on =Org-mode= file, see [[http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-gnuplot.html][ob-doc-gnuplot]]
2160 #+BEGIN_SRC gnuplot :exports code :file ./temp/file.png
2163 set title "Putting it All Together"
2176 h(x) = 10*sqrt(abs(x))
2178 plot f(x) w lp lw 1, g(x) w p lw 2, h(x) w l lw 3
2182 [[file:./temp/file.png]]
2185 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2194 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2195 (with-eval-after-load 'ediff
2196 (setq ediff-split-window-function 'split-window-horizontally)
2197 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
2198 (add-hook 'ediff-startup-hook 'ediff-toggle-wide-display)
2199 (add-hook 'ediff-cleanup-hook 'ediff-toggle-wide-display)
2200 (add-hook 'ediff-suspend-hook 'ediff-toggle-wide-display))
2203 * TODO Convert ASCII to key
2204 ** map =function-key-map= [[http://academic.evergreen.edu/projects/biophysics/technotes/program/ascii_ctrl.htm][ascii_ctrl]]
2205 new file =C-x C-f C-f=
2207 ** write color syntax for =Man-mode=
2209 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2210 (font-lock-add-keywords 'perl-mode '(("\\(|\\w+?\\(,\\w+?\\)?|\\)" 1 'py-builtins-face)))
2213 * TODO set fly-spell binding
2215 * TODO imenu bindings
2217 * DONE modified indicator
2219 - State "DONE" from "TODO" [2016-07-18 Mon 23:35]
2221 * DONE highlight selected ido candicate
2223 - State "DONE" from "TODO" [2016-07-19 Tue 01:49]
2225 * DONE show time in right of mode-line
2227 - State "DONE" from "TODO" [2016-07-19 Tue 01:11]
2231 - State "DONE" from "TODO" [2016-07-19 Tue 01:11]
2233 * TODO jump last change point
2234 * TODO emms mode-line
2237 Here are some global key bindings for basic editting
2238 ** Project operations - =super=
2239 =projectile= settins
2240 ** Windown & Buffer - =C-o=
2241 Defind a =hydra= function for windows, buffer & bookmark operations. And map it to =C-o= globally.
2242 Most use =C-o C-o= to switch buffers; =C-o x, v= to split window; =C-o o= to delete other windows
2243 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2246 (defhydra sd/hydra-window (:color red :columns nil)
2248 ("h" windmove-left nil :exit t)
2249 ("j" windmove-down nil :exit t)
2250 ("k" windmove-up nil :exit t)
2251 ("l" windmove-right nil :exit t)
2252 ("H" hydra-move-splitter-left nil)
2253 ("J" hydra-move-splitter-down nil)
2254 ("K" hydra-move-splitter-up nil)
2255 ("L" hydra-move-splitter-right nil)
2258 (split-window-right)
2263 (split-window-below)
2266 ("o" delete-other-windows "one" :exit t)
2267 ("C-o" ido-switch-buffer "buf" :exit t)
2268 ("C-k" sd/delete-current-window "del" :exit t)
2269 ("'" other-window "other" :exit t)
2270 ("a" ace-window "ace")
2271 ("s" ace-swap-window "swap")
2272 ("d" ace-delete-window "ace-one" :exit t)
2273 ("i" ace-maximize-window "ace-one" :exit t)
2274 ("b" ido-switch-buffer "buf" :exit t)
2275 ("C-b" ido-switch-buffer "buf" :exit t)
2276 ("m" bookmark-jump-other-window "open bmk" :exit t)
2277 ("M" bookmark-set "set bmk" :exit t)
2279 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
2280 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
2281 ("C-h" nil nil :exit t)
2282 ("C-j" nil nil :exit t)
2283 ;; ("C-k" nil :exit t)
2284 ("C-l" nil nil :exit t)
2285 ("C-;" nil nil :exit t)
2286 ("p" nil nil :exit t)
2287 ("n" nil nil :exit t)
2288 ("[" nil nil :exit t)
2289 ("]" nil nil :exit t)
2292 (global-unset-key (kbd "C-o"))
2293 (global-set-key (kbd "C-o") 'sd/hydra-window/body)
2297 - cut, yank, =C-w=, =C-y=
2299 - undo, redo - undo-tree
2300 - select, expand-region
2301 - spell check, flyspell
2304 Use =Avy= for motion
2305 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2309 (avy-setup-default))
2311 (global-set-key (kbd "C-M-j") 'avy-goto-line-below)
2312 (global-set-key (kbd "C-M-n") 'avy-goto-line-below)
2313 (global-set-key (kbd "C-M-k") 'avy-goto-line-above)
2314 (global-set-key (kbd "C-M-p") 'avy-goto-line-above)
2316 (global-set-key (kbd "C-M-f") 'avy-goto-word-1-below)
2317 (global-set-key (kbd "C-M-b") 'avy-goto-word-1-above)
2319 ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
2320 (global-set-key (kbd "C-M-w") 'avy-goto-char-timer)
2321 (global-set-key (kbd "C-M-l") 'avy-goto-char-in-line)
2323 ;; will delete above
2324 (global-set-key (kbd "M-g j") 'avy-goto-line-below)
2325 (global-set-key (kbd "M-g k") 'avy-goto-line-above)
2326 (global-set-key (kbd "M-g w") 'avy-goto-word-1-below)
2327 (global-set-key (kbd "M-g b") 'avy-goto-word-1-above)
2328 (global-set-key (kbd "M-g e") 'avy-goto-word-0)
2329 (global-set-key (kbd "M-g f") 'avy-goto-char-timer)
2330 (global-set-key (kbd "M-g c") 'avy-goto-char-in-line)
2332 ;; M-g TAB move-to-column
2333 ;; M-g ESC Prefix Command
2337 ;; M-g p previous-error
2339 ;; M-g M-g goto-line
2340 ;; M-g M-n next-error
2341 ;; M-g M-p previous-error
2344 =imenu=, mapping =C-M-i= to =counsel-imenu=
2345 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2346 (global-unset-key (kbd "C-M-i"))
2347 (global-set-key (kbd "C-M-i") #'counsel-imenu)
2350 ** Search & Replace / hightlight =M-s=
2354 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2356 ;; (defhydra sd/search-highlight (:color red :columns nil)
2358 ;; ("M-s" . isearch-forward-regexp "search-forward" :exit t)
2359 ;; ("s" . isearch-forward-regexp "search-forward" :exit t)
2360 ;; ("r" . isearch-backward-regexp "search-backward" :exit t)
2363 ;; (setq-default indicate-empty-lines t)
2367 Occur search key bindings
2368 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2369 (defun sd/occur-keys ()
2370 "My key bindings in occur-mode"
2372 (switch-to-buffer-other-window "*Occur*")
2373 (define-key occur-mode-map (kbd "C-o") nil)
2374 (define-key occur-mode-map (kbd "C-n") (lambda ()
2377 (occur-mode-goto-occurrence-other-window)
2380 (define-key occur-mode-map (kbd "C-p") (lambda ()
2383 (occur-mode-goto-occurrence-other-window)
2387 (add-hook 'occur-hook #'sd/occur-keys)
2389 (use-package color-moccur
2391 :commands (isearch-moccur isearch-all)
2393 (setq isearch-lazy-highlight t)
2395 (use-package moccur-edit))
2399 stolen from [[https://github.com/mariolong/emacs.d/blob/f6a061594ef1b5d1f4750e9dad9dc97d6e122840/emacs-init.org][here]]
2400 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2404 (setq ivy-use-virtual-buffers t)
2407 (global-set-key (kbd "s-/") 'swiper)
2408 (define-key swiper-map (kbd "M-r") 'swiper-query-replace))
2411 'ivy-current-match nil
2412 :background "Orange"
2413 :foreground "black")
2415 (eval-after-load 'swiper
2417 (define-key swiper-map (kbd "C-.")
2420 (insert (format "%s" (with-ivy-window (thing-at-point 'word))))))
2421 (define-key swiper-map (kbd "M-.")
2424 (insert (format "%s" (with-ivy-window (thing-at-point 'symbol))))))
2429 #+BEGIN_SRC ditaa :file temp/hello-world.png :cmdline -r
2438 [[file:temp/hello-world.png]]
2441 * =C-u C-h a= search funtions