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 ** Search Replace and highlight
697 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
698 ;; (use-package swiper
702 ;; (setq ivy-use-virtual-buffers t)
703 ;; (global-set-key (kbd "s-/") 'swiper)
709 ;; (global-set-key "\C-s" 'swiper)
710 ;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
711 ;; (global-set-key (kbd "<f6>") 'ivy-resume)
712 (global-set-key (kbd "M-x") 'counsel-M-x)
713 ;; ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
714 (global-set-key (kbd "C-h f") 'counsel-describe-function)
715 (global-set-key (kbd "C-h v") 'counsel-describe-variable)
716 ;; (global-set-key (kbd "<f1> l") 'counsel-load-library)
717 ;; (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
718 ;; (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
719 ;; (global-set-key (kbd "C-c g") 'counsel-git)
720 ;; (global-set-key (kbd "C-c j") 'counsel-git-grep)
721 ;; (global-set-key (kbd "C-c k") 'counsel-ag)
722 ;; (global-set-key (kbd "C-x l") 'counsel-locate)
723 ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
724 ;; ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
726 ;; (set-face-attribute
727 ;; 'ivy-current-match nil
728 ;; :background "Orange"
729 ;; :foreground "black")
732 ;; (define-key swiper-map (kbd "M-%") 'swiper-aa-replace)
736 use the prefix =M-s= for searching in buffers
737 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
738 (defun sd/make-keymap (key bindings)
739 (setq keymap (make-sparse-keymap))
740 (dolist (binding bindings)
741 (define-key keymap (car binding) (cdr binding)))
742 (global-set-key key keymap))
744 (use-package highlight-symbol
747 (sd/make-keymap "\M-s"
748 '(("w" . save-buffer)
749 ;; ("\M-w" . save-buffer)
750 ("e" . revert-buffer)
751 ("s" . isearch-forward-regexp)
752 ("\M-s" . isearch-forward-regexp)
753 ("r" . isearch-backward-regexp)
754 ("." . isearch-forward-symbol-at-point)
756 ;; ("h" . highlight-symbol-at-point)
757 ("h" . highlight-symbol)
758 ("m" . highlight-regexp)
759 ("l" . highlight-lines-matching-regexp)
760 ("M" . unhighlight-regexp)
761 ("f" . keyboard-quit)
762 ("q" . keyboard-quit)))
764 ;; search and replace and highlight
765 (define-key isearch-mode-map (kbd "M-s") 'isearch-repeat-forward)
766 (define-key isearch-mode-map (kbd "M-r") 'isearch-repeat-backward)
767 (global-set-key (kbd "s-[") 'highlight-symbol-next)
768 (global-set-key (kbd "s-]") 'highlight-symbol-prev)
769 (global-set-key (kbd "s-\\") 'highlight-symbol-query-replace)
772 (define-key minibuffer-local-map "\M-s" nil)
774 (set-face-background 'ido-first-match "yellow")
776 ;; M-s M-w eww-search-words
786 ** Org-mode Basic setting
788 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
790 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
794 (setq org-startup-indented t)
795 (setq org-hide-leading-starts t)
796 (setq org-src-fontify-natively t)
797 (setq org-src-tab-acts-natively t)
798 (setq org-confirm-babel-evaluate nil)
799 (setq org-use-speed-commands t)
800 (setq org-completion-use-ido t))
802 (org-babel-do-load-languages
803 'org-babel-load-languages
819 ;; use current window for org source buffer editting
820 (setq org-src-window-setup 'current-window )
822 (define-key org-mode-map (kbd "C-'") nil)
823 ;; C-M-i is mapped to imenu globally
824 (define-key org-mode-map (kbd "C-M-i") nil)
826 ;; set the ditta.jar path
827 (setq org-ditaa-jar-path "/usr/local/Cellar/ditaa/0.9/libexec/ditaa0_9.jar")
829 (file-exists-p org-ditaa-jar-path)
830 (error "seudut: ditaa.jar not found at %s " org-ditaa-jar-path))
835 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
837 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
838 (use-package org-bullets
841 (add-hook 'org-mode-hook
843 (org-bullets-mode t))))
845 (setq org-bullets-bullet-list '("⦿" "✪" "◉" "○" "►" "◆"))
847 ;; increase font size when enter org-src-mode
848 (add-hook 'org-src-mode-hook (lambda () (text-scale-increase 2)))
853 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
854 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
855 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
856 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
858 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
863 :init (add-hook 'org-mode-hook 'worf-mode)
865 ;; (define-key worf-mode-map "[" nil)
866 ;; (define-key worf-mode-map "]" nil)
867 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
868 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
875 Refer to [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
880 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
881 (global-set-key "\C-cl" 'org-store-link)
882 (global-set-key "\C-ca" 'org-agenda)
883 (global-set-key "\C-cb" 'org-iswitchb)
888 Replace the list bullet =-=, =+=, with =•=, a litter change based [[https://github.com/howardabrams/dot-files/blob/master/emacs-org.org][here]]
890 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
891 ;; (use-package org-mode
893 ;; (font-lock-add-keywords 'org-mode
894 ;; '(("^ *\\([-+]\\) "
895 ;; (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•")))))))
900 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]],
902 To track TODO state changes, the =!= is to insert a timetamp, =@= is to insert a note with
903 timestamp for the state change.
905 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
906 ;; (setq org-todo-keywords
907 ;; '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
908 ;; (sequence "âš‘ WAITING(w)" "|")
909 ;; (sequence "|" "✘ CANCELLED(c)")))
910 ; (setq org-todo-keyword-faces
911 ; (quote ("TODO" . (:foreground "red" :weight bold))
912 ; ("NEXT" . (:foreground "blue" :weight bold))
913 ; ("WAITING" . (:foreground "forest green" :weight bold))
914 ; ("DONE" . (:foreground "magenta" :weight bold))
915 ; ("CANCELLED" . (:foreground "forest green" :weight bold))))
918 (setq org-todo-keywords
919 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!)")
920 ;; (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING")
921 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" ))))
923 (setq org-todo-keyword-faces
924 (quote (("TODO" :foreground "red" :weight bold)
925 ("NEXT" :foreground "blue" :weight bold)
926 ("DONE" :foreground "forest green" :weight bold)
927 ("WAITING" :foreground "orange" :weight bold)
928 ("HOLD" :foreground "magenta" :weight bold)
929 ("CANCELLED" :foreground "forest green" :weight bold)
930 ;; ("MEETING" :foreground "forest green" :weight bold)
931 ;; ("PHONE" :foreground "forest green" :weight bold)
937 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
938 (setq org-use-fast-todo-selection t)
939 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
942 TODO state triggers and tags, [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
944 - Moving a task to =CANCELLED=, adds a =CANCELLED= tag
945 - Moving a task to =WAITING=, adds a =WAITING= tag
946 - Moving a task to =HOLD=, add =HOLD= tags
947 - Moving a task to =DONE=, remove =WAITING=, =HOLD= tag
948 - Moving a task to =NEXT=, remove all waiting/hold/cancelled tags
950 This tags are used to filter tasks in agenda views
951 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
952 (setq org-todo-state-tags-triggers
953 (quote (("CANCELLED" ("CANCELLED" . t))
954 ("WAITING" ("WAITING" . t))
955 ("HOLD" ("WAITING") ("HOLD" . t))
956 (done ("WAITING") ("HOLD"))
957 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
958 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
959 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
963 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
964 ;; log time when task done
965 ;; (setq org-log-done (quote time))
966 ;; save clocking into to LOGBOOK
967 (setq org-clock-into-drawer t)
968 ;; save state change notes and time stamp into LOGBOOK drawer
969 (setq org-log-into-drawer t)
970 (setq org-clock-into-drawer "CLOCK")
974 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
975 (setq org-tag-alist (quote ((:startgroup)
981 ("CANCELLED" . ?c))))
983 ;; Allow setting single tags without the menu
984 (setq org-fast-tag-selection-single-key (quote expert))
987 *** Capture - Refile - Archive
989 Capture lets you quickly store notes with little interruption of your work flow.
991 **** Capture Templates
993 When a new taks needs to be added, categorize it as
995 All captured file which need next actions are stored in =refile.org=,
996 - A new task / note (t) =refile.org=
997 - A work task in office =office.org=
998 - A jourenl =diary.org=
999 - A new habit (h) =refile.org=
1001 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1002 (setq org-directory "~/org")
1003 (setq org-default-notes-file "~/org/refile.org")
1004 (setq sd/org-diary-file "~/org/diary.org")
1006 (global-set-key (kbd "C-c c") 'org-capture)
1008 (setq org-capture-templates
1009 (quote (("t" "Todo" entry (file org-default-notes-file)
1010 "* TODO %?\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1011 ("n" "Note" entry (file org-default-notes-file)
1012 "* %? :NOTE:\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1013 ("j" "Journal" entry (file+datetree sd/org-diary-file)
1014 "* %?\n:LOGBOOK:\n:END:" :clock-in t :clock-resume t)
1015 ("h" "Habit" entry (file org-default-notes-file)
1016 "* 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 "))))
1021 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1022 (setq org-refile-targets (quote (;; (nil :maxlevel . 9)
1023 (org-agenda-files :maxlevel . 9))))
1025 (setq org-refile-use-outline-path t)
1027 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1031 Setting agenda files and the agenda view
1032 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1033 (setq org-agenda-files (quote ("~/org/gtd.org"
1036 ;; only show today's tasks in agenda view
1037 (setq org-agenda-span 'day)
1038 ;; Use current windows for agenda view
1039 (setq org-agenda-window-setup 'current-window)
1041 ;; show all feature entries for repeating tasks,
1042 ;; this is already setting by default
1043 (setq org-agenda-repeating-timestamp-show-all t)
1045 ;; Show all agenda dates - even if they are empty
1046 (setq org-agenda-show-all-dates t)
1051 Install MacTex-basic and some tex packages
1055 sudo tlmgr update --self
1057 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
1061 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1062 ;; ;; allow for export=>beamer by placing
1064 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
1065 ;; #+LaTeX_CLASS: beamer in org files
1066 (unless (boundp 'org-export-latex-classes)
1067 (setq org-export-latex-classes nil))
1068 (add-to-list 'org-export-latex-classes
1069 ;; beamer class, for presentations
1071 "\\documentclass[11pt]{beamer}\n
1072 \\mode<{{{beamermode}}}>\n
1073 \\usetheme{{{{beamertheme}}}}\n
1074 \\usecolortheme{{{{beamercolortheme}}}}\n
1075 \\beamertemplateballitem\n
1076 \\setbeameroption{show notes}
1077 \\usepackage[utf8]{inputenc}\n
1078 \\usepackage[T1]{fontenc}\n
1079 \\usepackage{hyperref}\n
1081 \\usepackage{listings}
1082 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
1085 showspaces=false,showstringspaces=false,
1087 keywordstyle=\\color{blue}\\bfseries,
1088 commentstyle=\\color{red},
1090 \\usepackage{verbatim}\n
1091 \\institute{{{{beamerinstitute}}}}\n
1092 \\subject{{{{beamersubject}}}}\n"
1094 ("\\section{%s}" . "\\section*{%s}")
1096 ("\\begin{frame}[fragile]\\frametitle{%s}"
1098 "\\begin{frame}[fragile]\\frametitle{%s}"
1101 ;; letter class, for formal letters
1103 (add-to-list 'org-export-latex-classes
1106 "\\documentclass[11pt]{letter}\n
1107 \\usepackage[utf8]{inputenc}\n
1108 \\usepackage[T1]{fontenc}\n
1109 \\usepackage{color}"
1111 ("\\section{%s}" . "\\section*{%s}")
1112 ("\\subsection{%s}" . "\\subsection*{%s}")
1113 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1114 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1115 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1119 (require 'ox-beamer)
1121 (setq org-latex-pdf-process
1122 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1123 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1124 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
1126 (setq TeX-parse-self t)
1128 (setq TeX-PDF-mode t)
1129 (add-hook 'LaTeX-mode-hook
1132 (setq TeX-master t)))
1138 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
1140 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1142 (add-to-list 'org-structure-template-alist
1143 '("E" "#+BEGIN_SRC emacs-lisp :tangle yes :results silent\n?\n#+END_SRC"))
1144 (add-to-list 'org-structure-template-alist
1145 '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
1146 (add-to-list 'org-structure-template-alist
1147 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
1152 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
1153 and Defined keys, using vi keybindings, Refer abo-abo's setting [[https://github.com/abo-abo/oremacs/blob/c5cafdcebc88afe9e73cc8bd40c49b70675509c7/modes/ora-nextmagit.el][here]]
1154 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1158 ;; don't ask me to confirm the unsaved change
1159 (setq magit-save-repository-buffers nil)
1160 :commands magit-status magit-blame
1162 (dolist (map (list magit-status-mode-map
1165 magit-staged-section-map))
1166 (define-key map "j" 'magit-section-forward)
1167 (define-key map "k" 'magit-section-backward)
1168 (define-key map "D" 'magit-discard)
1169 (define-key map "O" 'magit-discard-file)
1170 (define-key map "n" nil)
1171 (define-key map "p" nil)
1172 (define-key map "v" 'recenter-top-bottom)
1173 (define-key map "i" 'magit-section-toggle)))
1178 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1179 (defalias 'e 'find-file)
1180 (defalias 'ff 'find-file)
1181 (defalias 'ee 'find-files)
1184 *** eshell temp directory
1185 set default eshell history folder
1186 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1187 (setq eshell-directory-name (concat sd-temp-directory "eshell"))
1190 *** Eshell erase buffer
1191 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1192 (defun sd/eshell-clear-buffer ()
1193 "Clear eshell buffer"
1195 (let ((inhibit-read-only t))
1197 (eshell-send-input)))
1199 (add-hook 'eshell-mode-hook (lambda ()
1200 (local-set-key (kbd "C-l") 'sd/eshell-clear-buffer)))
1204 Toggle an eshell in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
1205 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1206 (defun sd/window-has-eshell ()
1207 "Check if current windows list has a eshell buffer, and return the window"
1210 (walk-windows (lambda (window)
1211 (if (equal (with-current-buffer (window-buffer window) major-mode)
1217 (defun sd/toggle-eshell-here ()
1218 "Toggle a eshell buffer vertically"
1220 (if (sd/window-has-eshell)
1221 (if (equal major-mode 'eshell-mode)
1223 (if (equal (length (window-list)) 1)
1224 (mode-line-other-buffer)
1226 (select-window (sd/window-has-eshell)))
1228 (let ((dir default-directory))
1230 (split-window-vertically (- (/ (window-total-height) 3)))
1232 (unless (and (boundp 'eshell-buffer-name) (get-buffer eshell-buffer-name))
1234 (switch-to-buffer eshell-buffer-name)
1235 (goto-char (point-max))
1237 (insert (format "cd %s" dir))
1238 (eshell-send-input)))))
1240 ;; (global-unset-key (kbd "M-`"))
1241 (global-set-key (kbd "s-e") 'sd/toggle-eshell-here)
1244 *** TODO smart display
1247 ** [[https://github.com/abo-abo/hydra][Hydra]]
1249 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1252 ;; disable new line in minibuffer when hint hydra
1257 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1258 (defhydra sd/font-zoom (global-map "<f2>")
1260 ("g" text-scale-increase "in")
1261 ("l" text-scale-decrease "out"))
1264 *** Windmove Splitter
1266 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1268 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1270 (defun hydra-move-splitter-left (arg)
1271 "Move window splitter left."
1273 (if (let ((windmove-wrap-around))
1274 (windmove-find-other-window 'right))
1275 (shrink-window-horizontally arg)
1276 (enlarge-window-horizontally arg)))
1278 (defun hydra-move-splitter-right (arg)
1279 "Move window splitter right."
1281 (if (let ((windmove-wrap-around))
1282 (windmove-find-other-window 'right))
1283 (enlarge-window-horizontally arg)
1284 (shrink-window-horizontally arg)))
1286 (defun hydra-move-splitter-up (arg)
1287 "Move window splitter up."
1289 (if (let ((windmove-wrap-around))
1290 (windmove-find-other-window 'up))
1291 (enlarge-window arg)
1292 (shrink-window arg)))
1294 (defun hydra-move-splitter-down (arg)
1295 "Move window splitter down."
1297 (if (let ((windmove-wrap-around))
1298 (windmove-find-other-window 'up))
1300 (enlarge-window arg)))
1305 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1306 (defhydra sd/hydra-misc (:color red :columns nil)
1307 "Miscellaneous Commands"
1308 ("e" eshell "eshell" :exit t)
1311 (if (not (eq nil (get-buffer "*Packages*")))
1312 (switch-to-buffer "*Packages*")
1313 (package-list-packages)))
1314 "list-package" :exit t)
1315 ("g" magit-status "git-status" :exit t)
1316 ("'" mode-line-other-buffer "last buffer" :exit t)
1317 ("C-'" mode-line-other-buffer "last buffer" :exit t)
1318 ("m" man "man" :exit t)
1319 ("d" dired-jump "dired" :exit t)
1320 ("b" ibuffer "ibuffer" :exit t)
1324 (global-set-key (kbd "C-'") 'sd/hydra-misc/body)
1328 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1329 (defhydra sd/hydra-launcher (:color blue :columns 2)
1331 ("e" emms "emms" :exit t)
1337 Enable linum mode on programming modes
1339 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1340 (add-hook 'prog-mode-hook 'linum-mode)
1341 ;; (add-hook 'prog-mode-hook (lambda ()
1342 ;; (setq-default indicate-empty-lines t)))
1345 Fix the font size of line number
1347 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1349 (defun fix-linum-size ()
1351 (set-face-attribute 'linum nil :height 110))
1353 (add-hook 'linum-mode-hook 'fix-linum-size)
1357 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1359 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1361 (use-package linum-relative
1364 (defun linum-new-mode ()
1365 "If line numbers aren't displayed, then display them.
1366 Otherwise, toggle between absolute and relative numbers."
1369 (linum-relative-toggle)
1373 ("A-k" . linum-new-mode))
1375 ;; auto enable linum-new-mode in programming modes
1376 (add-hook 'prog-mode-hook 'linum-relative-mode)
1380 ** Save File Position
1382 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1384 (require 'saveplace)
1385 (setq-default save-place t)
1386 (setq save-place-forget-unreadable-files t)
1387 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1393 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1395 (use-package multi-term
1402 [[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
1403 Type =o= to go to the link
1405 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1407 (use-package ace-link
1410 (ace-link-setup-default))
1416 [[https://github.com/re5et/emux][emux]] is
1418 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1420 (el-get-bundle re5et/emux)
1426 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1428 (use-package smartparens
1432 (require 'smartparens-config)
1433 (add-hook 'prog-mode-hook 'smartparens-mode)))
1439 [[https://github.com/abo-abo/ace-window][ace-window]]
1441 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1443 (use-package ace-window
1447 ; (global-set-key (kbd "M-o") 'ace-window)
1449 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1455 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1457 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1459 (use-package which-key
1468 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1470 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1474 (setq emms-source-file-default-directory "~/Music/")
1477 (emms-default-players)
1478 (define-emms-simple-player mplayer '(file url)
1479 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1480 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1481 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1482 ".m4a" ".flv" ".ogv" ".pls"))
1483 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1484 (emms-history-load))
1490 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
1492 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1498 (require 'gnugo-imgen)
1499 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1500 (add-hook 'gnugo-start-game-hook '(lambda ()
1501 (gnugo-image-display-mode)
1504 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1510 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1512 ;; (use-package tabbar-ruler
1515 ;; (setq tabbar-ruler-global-tabbar t)
1516 ;; (setq tabbar-ruler-global-ruler t)
1517 ;; (setq tabbar-ruler-popu-menu t)
1518 ;; (setq tabbar-ruler-popu-toolbar t)
1519 ;; (setq tabbar-use-images t)
1521 ;; (tabbar-ruler-group-by-projectile-project)
1522 ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
1523 ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1527 ** View only for some directory
1528 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]]
1529 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1530 (dir-locals-set-class-variables
1532 '((nil . ((buffer-read-only . t)
1533 (show-trailing-whitespace . nil)
1535 (eval . (whitespace-mode -1))))))
1537 ;; (dir-locals-set-directory-class (expand-file-name "/usr/local/share/emacs") 'emacs)
1538 (dir-locals-set-directory-class "/usr/local/Cellar/emacs" 'emacs)
1539 ;; (dir-locals-set-directory-class "~/.emacs.d/elpa" 'emacs)
1540 (dir-locals-set-directory-class "~/dotfiles/emacs.d/elpa" 'emacs)
1541 (dir-locals-set-directory-class "~/dotfiles/emacs.d/el-get" 'emacs)
1545 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1546 (el-get-bundle info+
1547 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/info+.el"
1555 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1556 (defun sd/info-mode ()
1558 (unless (equal major-mode 'Info-mode)
1559 (unless (> (length (window-list)) 1)
1560 (split-window-right))
1565 ;; (global-set-key (kbd "C-h i") 'sd/info-mode)
1567 ;; open Info buffer in other window instead of current window
1568 (defadvice info (before my-info (&optional file buf) activate)
1571 (defadvice Info-exit (after my-info-exit activate)
1572 (sd/delete-current-window))
1578 ** TODO swiper to occur
1581 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1582 ;; (set-language-environment "UTF-8")
1583 ;; (set-default-coding-systems 'utf-8)
1587 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1588 ;; (el-get-bundle howardabrams/demo-it)
1590 (use-package org-tree-slide
1593 ;; (use-package yasnippet
1598 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1599 (use-package org-tree-slide
1602 ;; (define-key org-mode-map "\C-ccp" 'org-tree-slide-mode)
1603 (define-key org-tree-slide-mode-map (kbd "<ESC>") 'org-tree-slide-content)
1604 (define-key org-tree-slide-mode-map (kbd "<SPACE>") 'org-tree-slide-move-next-tree)
1605 (define-key org-tree-slide-mode-map [escape] 'org-tree-slide-move-previous-tree))
1609 =C-o= is defined as a global key for window operation, here unset it in dired mode
1610 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1614 (setq dired-omit-mode t)
1615 (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
1616 (add-hook 'dired-mode-hook (lambda ()
1617 (define-key dired-mode-map (kbd "C-o") nil)
1618 (define-key dired-mode-map (kbd "H") 'dired-omit-mode)
1619 (define-key dired-mode-map (kbd "DEL") (lambda () (interactive) (find-alternate-file "..")))
1620 (dired-omit-mode))))
1624 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1628 (setq diredp-hide-details-initially-flag nil)
1630 (define-key dired-mode-map (kbd "j") 'diredp-next-line)
1631 (define-key dired-mode-map (kbd "k") 'diredp-previous-line)
1632 (define-key dired-mode-map (kbd "g") 'dired-goto-file))
1636 company mode and company-statistics
1637 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1638 (use-package company
1640 :diminish company-mode
1641 :init (setq company-idle-delay 0.1)
1643 (global-company-mode))
1645 (use-package company-statistics
1648 (company-statistics-mode))
1651 * Programming Language
1653 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1654 (use-package color-identifiers-mode
1657 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1659 :diminish color-identifiers-mode)
1661 (global-prettify-symbols-mode t)
1664 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1665 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1666 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1670 (eval-after-load "lispy"
1672 (define-key lispy-mode-map (kbd "M-o") nil)))
1674 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1679 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1680 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1681 (defalias 'perl-mode 'cperl-mode)
1683 ;; (setq cperl-hairy t)
1684 ;; Turns on most of the CPerlMode options
1685 (setq cperl-auto-newline t)
1686 (setq cperl-highlight-variables-indiscriminately t)
1687 ;(setq cperl-indent-level 4)
1688 ;(setq cperl-continued-statement-offset 4)
1689 (setq cperl-close-paren-offset -4)
1690 (setq cperl-indent-parents-as-block t)
1691 (setq cperl-tab-always-indent t)
1692 ;(setq cperl-brace-offset 0)
1694 (add-hook 'cperl-mode-hook
1696 (cperl-set-style "C++")))
1698 (defalias 'perldoc 'cperl-perldoc)
1702 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1703 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1704 (eval-after-load 'autoinsert
1705 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1708 "#!/usr/bin/perl -w" \n
1710 "use strict;" > \n \n
1716 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1717 (font-lock-add-keywords 'cperl-mode
1718 '(("\\(say\\)" . cperl-nonoverridable-face)
1719 ("\\([0-9.]\\)*" . font-lock-constant-face)
1720 ("\".*\\(\\\n\\).*\"" . font-lock-constant-face)
1721 ("\n" . font-lock-constant-face)
1722 ("\\(^#!.*\\)$" . cperl-nonoverridable-face)))
1724 ;; (font-lock-add-keywords 'Man-mode
1725 ;; '(("\\(NAME\\)" . font-lock-function-name-face)))
1730 Change the compile-command to set the default command run when call =compile=
1731 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1732 to call =compilation= interactively.
1733 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1734 (defun my-perl-hook ()
1736 (setq-local compilation-read-command nil)
1737 (set (make-local-variable 'compile-command)
1738 (concat "/usr/bin/perl "
1739 (if buffer-file-name
1740 (shell-quote-argument buffer-file-name))))
1741 (local-set-key (kbd "s-r")
1744 ; (setq current-prefix-arg '(4)) ; C-u
1745 (call-interactively 'compile)))))
1747 (add-hook 'cperl-mode-hook 'my-perl-hook)
1751 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1752 (setq c-default-style "stroustrup"
1757 Set the environments vairables in compilation mode
1758 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1759 (use-package compile
1762 (setq compilation-environment (cons "LC_ALL=C" compilation-environment))
1763 (setq compilation-auto-jump-to-first-error t)
1764 (setq compilation-auto-jump-to-next t)
1765 (setq compilation-scroll-output 'first-error))
1767 ;; super-r to compile
1768 (with-eval-after-load "compile"
1769 (define-key compilation-mode-map (kbd "C-o") nil)
1770 (define-key compilation-mode-map (kbd "n") 'compilation-next-error)
1771 (define-key compilation-mode-map (kbd "p") 'compilation-previous-error)
1772 (define-key compilation-mode-map (kbd "r") #'recompile))
1776 ** Enable auto-insert mode
1777 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1778 (auto-insert-mode t)
1779 (setq auto-insert-query nil)
1783 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1784 (eval-after-load 'autoinsert
1785 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1787 "Short description:"
1789 "\n * " (file-name-nondirectory (buffer-file-name))
1791 "#include <iostream>" \n
1793 (file-name-sans-extension
1794 (file-name-nondirectory (buffer-file-name)))
1796 "using namespace std;" \n \n
1804 (eval-after-load 'autoinsert
1805 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1807 "Short description:"
1809 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1811 "#include <stdio.h>" \n
1813 (file-name-sans-extension
1814 (file-name-nondirectory (buffer-file-name)))
1825 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1826 (eval-after-load 'autoinsert
1827 '(define-auto-insert '("\\.\\(py\\)\\'" . "Python skeleton")
1836 Emacs lisp auto-insert, based on the default module in =autoinsert.el=, but replace =completing-read= as
1837 =completing-read-ido-ubiquitous= to fix the edge case of that =ido= cannot handle.
1838 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1839 (eval-after-load 'autoinsert
1840 '(define-auto-insert '("\\.el\\'" . "my Emacs Lisp header")
1842 "Short description: "
1843 ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str
1844 (make-string (max 2 (- 80 (current-column) 27)) ?\s)
1845 "-*- lexical-binding: t; -*-" '(setq lexical-binding t)
1847 ;; Copyright (C) " (format-time-string "%Y") " "
1848 (getenv "ORGANIZATION") | (progn user-full-name) "
1850 ;; Author: " (user-full-name)
1851 '(if (search-backward "&" (line-beginning-position) t)
1852 (replace-match (capitalize (user-login-name)) t t))
1853 '(end-of-line 1) " <" (progn user-mail-address) ">
1856 ;;'(setq v1 (apply 'vector (mapcar 'car finder-known-keywords)))
1857 '(setq v1 (mapcar (lambda (x) (list (symbol-name (car x))))
1858 finder-known-keywords)
1859 v2 (mapconcat (lambda (x) (format "%12s: %s" (car x) (cdr x)))
1860 finder-known-keywords
1862 ((let ((minibuffer-help-form v2))
1863 (completing-read-ido-ubiquitous "Keyword, C-h: " v1 nil t))
1866 \;; This program is free software; you can redistribute it and/or modify
1867 \;; it under the terms of the GNU General Public License as published by
1868 \;; the Free Software Foundation, either version 3 of the License, or
1869 \;; (at your option) any later version.
1871 \;; This program is distributed in the hope that it will be useful,
1872 \;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1873 \;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1874 \;; GNU General Public License for more details.
1876 \;; You should have received a copy of the GNU General Public License
1877 \;; along with this program. If not, see <http://www.gnu.org/licenses/>.
1889 \;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")))
1892 ** Org file template
1893 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1894 (eval-after-load 'autoinsert
1895 '(define-auto-insert '("\\.\\(org\\)\\'" . "Org-mode skeleton")
1898 "#+TITLE: " str (make-string 30 ?\s) > \n
1899 "#+AUTHOR: Peng Li\n"
1900 "#+EMAIL: seudut@gmail.com\n"
1901 "#+DATE: " (shell-command-to-string "echo -n $(date +%Y-%m-%d)") > \n
1907 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1908 (use-package markdown-mode
1910 :commands (markdown-mode gfm-mode)
1911 :mode (("README\\.md\\'" . gfm-mode)
1912 ("\\.md\\'" . markdown-mode)
1913 ("\\.markdown\\'" . markdown-mode))
1914 :init (setq markdown-command "multimarkdown"))
1917 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1918 (use-package markdown-preview-eww
1924 Refer [[https://www.emacswiki.org/emacs/GnusGmail][GnusGmail]]
1925 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1926 (setq user-mail-address "seudut@gmail.com"
1927 user-full-name "Peng Li")
1929 (setq gnus-select-method
1931 (nnimap-address "imap.gmail.com")
1932 (nnimap-server-port "imaps")
1933 (nnimap-stream ssl)))
1935 (setq smtpmail-smtp-service 587
1936 gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
1938 ;; Use gmail sending mail
1939 (setq message-send-mail-function 'smtpmail-send-it
1940 smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
1941 smtpmail-auth-credentials '(("smtp.gmail.com" 587 "seudut@gmail.com" nil))
1942 smtpmail-default-smtp-server "smtp.gmail.com"
1943 smtpmail-smtp-server "smtp.gmail.com"
1944 smtpmail-smtp-service 587
1945 starttls-use-gnutls t)
1948 And put the following in =~/.authinfo= file, replacing =<USE>= with your email address
1949 and =<PASSWORD>= with the password
1951 machine imap.gmail.com login <USER> password <PASSWORD> port imaps
1952 machine smtp.gmail.com login <USER> password <PASSWORD> port 587
1958 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1961 (setq gnus-permanently-visible-groups "\.*")
1963 (cond (window-system
1964 (setq custom-background-mode 'light)
1965 (defface my-group-face-1
1966 '((t (:foreground "Red" :bold t))) "First group face")
1967 (defface my-group-face-2
1968 '((t (:foreground "DarkSeaGreen4" :bold t)))
1969 "Second group face")
1970 (defface my-group-face-3
1971 '((t (:foreground "Green4" :bold t))) "Third group face")
1972 (defface my-group-face-4
1973 '((t (:foreground "SteelBlue" :bold t))) "Fourth group face")
1974 (defface my-group-face-5
1975 '((t (:foreground "Blue" :bold t))) "Fifth group face")))
1976 (setq gnus-group-highlight
1977 '(((> unread 200) . my-group-face-1)
1978 ((and (< level 3) (zerop unread)) . my-group-face-2)
1979 ((< level 3) . my-group-face-3)
1980 ((zerop unread) . my-group-face-4)
1981 (t . my-group-face-5))))
1985 (add-hook 'gnus-group-mode-hook (lambda ()
1986 (define-key gnus-group-mode-map "k" 'gnus-group-prev-group)
1987 (define-key gnus-group-mode-map "j" 'gnus-group-next-group)
1988 (define-key gnus-group-mode-map "g" 'gnus-group-jump-to-group)
1989 (define-key gnus-group-mode-map "v" (lambda () (interactive) (gnus-group-select-group t)))))
1992 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1993 (setq gnus-fetch-old-headers 't)
1997 (setq gnus-extract-address-components
1998 'mail-extract-address-components)
2000 (setq gnus-summary-line-format "%U%R%z%I%(%[%-20,20f%]%) %s%-80= %11&user-date;\n")
2001 (setq gnus-user-date-format-alist '(((gnus-seconds-today) . "%H:%M")
2002 ((+ 86400 (gnus-seconds-today)) . "%a %H:%M")
2003 (604800 . "%a, %b %-d")
2004 (15778476 . "%b %-d")
2007 (setq gnus-thread-sort-functions '((not gnus-thread-sort-by-number)))
2008 (setq gnus-unread-mark ?\.)
2009 (setq gnus-use-correct-string-widths t)
2012 (setq gnus-thread-hide-subtree t)
2014 ;; (with-eval-after-load 'gnus-summary-mode
2015 ;; (define-key gnus-summary-mode-map (kbd "C-o") 'sd/hydra-window/body))
2017 (add-hook 'gnus-summary-mode-hook (lambda ()
2018 (define-key gnus-summary-mode-map (kbd "C-o") nil)))
2024 See [[https://www.emacswiki.org/emacs/GnusWindowLayout][GnusWindowLayout]]
2025 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2026 (gnus-add-configuration
2032 (summary 1.0 poine)))))
2034 (gnus-add-configuration
2040 (summary 0.50 point)
2043 (with-eval-after-load 'gnus-group-mode
2044 (gnus-group-select-group "INBOX"))
2045 ;; (add-hook 'gnus-group-mode-map (lambda ()
2046 ;; (gnus-group-select-group "INBOX")))
2050 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=
2051 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2052 (use-package gnuplot
2055 (setq gnuplot-help-xpm nil)
2056 (setq gnuplot-line-xpm nil)
2057 (setq gnuplot-region-xpm nil)
2058 (setq gnuplot-buffer-xpm nil)
2059 (setq gnuplot-doc-xpm nil))
2062 Use =gnuplot= on =Org-mode= file, see [[http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-gnuplot.html][ob-doc-gnuplot]]
2063 #+BEGIN_SRC gnuplot :exports code :file ./temp/file.png
2066 set title "Putting it All Together"
2079 h(x) = 10*sqrt(abs(x))
2081 plot f(x) w lp lw 1, g(x) w p lw 2, h(x) w l lw 3
2085 [[file:./temp/file.png]]
2088 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2097 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2098 (with-eval-after-load 'ediff
2099 (setq ediff-split-window-function 'split-window-horizontally)
2100 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
2101 (add-hook 'ediff-startup-hook 'ediff-toggle-wide-display)
2102 (add-hook 'ediff-cleanup-hook 'ediff-toggle-wide-display)
2103 (add-hook 'ediff-suspend-hook 'ediff-toggle-wide-display))
2106 * TODO Convert ASCII to key
2107 ** map =function-key-map= [[http://academic.evergreen.edu/projects/biophysics/technotes/program/ascii_ctrl.htm][ascii_ctrl]]
2108 new file =C-x C-f C-f=
2110 ** write color syntax for =Man-mode=
2112 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2113 (font-lock-add-keywords 'perl-mode '(("\\(|\\w+?\\(,\\w+?\\)?|\\)" 1 'py-builtins-face)))
2116 * TODO set fly-spell binding
2118 * TODO imenu bindings
2120 * DONE modified indicator
2122 - State "DONE" from "TODO" [2016-07-18 Mon 23:35]
2124 * DONE highlight selected ido candicate
2126 - State "DONE" from "TODO" [2016-07-19 Tue 01:49]
2128 * DONE show time in right of mode-line
2130 - State "DONE" from "TODO" [2016-07-19 Tue 01:11]
2134 - State "DONE" from "TODO" [2016-07-19 Tue 01:11]
2136 * TODO jump last change point
2137 * TODO emms mode-line
2140 Here are some global key bindings for basic editting
2141 ** Project operations - =super=
2143 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2144 (use-package projectile
2147 (setq projectile-enable-caching t)
2149 (projectile-global-mode t))
2151 (use-package persp-projectile
2156 (:map projectile-mode-map
2157 ("s-t" . projectile-persp-switch-project)))
2159 ;; projectile-find-file
2160 ;; projectile-switch-buffer
2161 ;; projectile-find-file-other-window
2164 *** project config =super= keybindings
2165 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2166 ;; (global-set-key (kbd "s-h") 'keyboard-quit)
2167 ;; (global-set-key (kbd "s-j") 'ido-switch-buffer)
2168 ;; (global-set-key (kbd "s-k") 'ido-find-file)
2169 ;; (global-set-key (kbd "s-l") 'sd/delete-current-window)
2170 ;; s-l --> goto-line
2171 ;; (global-set-key (kbd "s-/") 'swiper)
2173 ;; s-' --> 'next-multiframe-window
2174 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
2176 (global-set-key (kbd "s-f") 'projectile-find-file)
2177 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
2179 (global-set-key (kbd "s-n") 'persp-next)
2180 (global-set-key (kbd "s-p") 'persp-prev)
2182 (global-set-key (kbd "s-=") 'text-scale-increase)
2183 (global-set-key (kbd "s--") 'text-scale-decrease)
2185 ;; (global-set-key (kbd "s-u") 'undo-tree-visualize)
2188 ;; someothers default mapping on super (command) key
2190 ;; s-k kill-this-buffer
2193 ;; s-h --> ns-do-hide-emacs
2194 ;; s-j --> ido-switch-buffer +
2195 ;; s-k --> kill-this-buffer
2196 ;; s-l --> goto-line
2197 ;; s-; --> undefined
2198 ;; s-' --> next-multiframe-window
2199 ;; s-ret --> toggle-frame-fullscreen +
2201 ;; s-y --> ns-paste-secondary
2202 ;; s-u --> revert-buffer
2203 ;; s-i --> undefined - but used for iterm globally
2204 ;; s-o --> used for emacs globally
2205 ;; s-p --> projectile-persp-switch-project +
2206 ;; s-[ --> next-buffer +
2207 ;; s-] --> previous-buffer +
2209 ;; s-0 --> undefined
2210 ;; s-9 --> undefined
2211 ;; s-8 --> undefined
2212 ;; s-7 --> undefined
2213 ;; s-6 --> undefined
2214 ;; s-- --> center-line
2215 ;; s-= --> undefined
2217 ;; s-n --> make-frame
2218 ;; s-m --> iconify-frame
2219 ;; s-b --> undefined
2220 ;; s-, --> customize
2221 ;; s-. --> undefined
2222 ;; s-/ --> undefined
2224 ;; s-g --> isearch-repeat-forward
2225 ;; s-f --> projectile-find-file +
2226 ;; s-d --> isearch-repeat-background
2227 ;; s-s --> save-buffer
2228 ;; s-a --> make-whole-buffer
2230 ;; s-b --> undefined
2232 ;; s-c --> ns-copy-including-secondary
2234 ;; s-t --> ns-popup-font-panel
2235 ;; s-r --> undefined
2236 ;; s-e --> isearch-yanqk-kill
2237 ;; s-w --> delete-frame
2238 ;; s-q --> same-buffers-kill-emacs
2240 ;; s-` --> other-frame
2243 ** Windown & Buffer - =C-o=
2244 Defind a =hydra= function for windows, buffer & bookmark operations. And map it to =C-o= globally.
2245 Most use =C-o C-o= to switch buffers; =C-o x, v= to split window; =C-o o= to delete other windows
2246 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2249 (defun sd/delete-current-window ()
2251 (if (> (length (window-list)) 1)
2253 (message "Only one Windows now!")))
2255 (defun sd/toggle-max-windows ()
2256 "Set maximize current if there are multiple windows, if only
2257 one window, window undo"
2259 (if (equal (length (window-list)) 1)
2261 (delete-other-windows)))
2263 (defhydra sd/hydra-window (:color red :columns nil)
2265 ("h" windmove-left nil :exit t)
2266 ("j" windmove-down nil :exit t)
2267 ("k" windmove-up nil :exit t)
2268 ("l" windmove-right nil :exit t)
2269 ("H" hydra-move-splitter-left nil)
2270 ("J" hydra-move-splitter-down nil)
2271 ("K" hydra-move-splitter-up nil)
2272 ("L" hydra-move-splitter-right nil)
2275 (split-window-right)
2280 (split-window-below)
2283 ;; ("o" delete-other-windows "one" :exit t)
2284 ("o" sd/toggle-max-windows "one" :exit t)
2285 ("C-o" ido-switch-buffer "buf" :exit t)
2286 ("C-k" sd/delete-current-window "del" :exit t)
2287 ("'" other-window "other" :exit t)
2288 ("a" ace-window "ace")
2289 ("s" ace-swap-window "swap")
2290 ("d" ace-delete-window "ace-one" :exit t)
2291 ("i" ace-maximize-window "ace-one" :exit t)
2292 ("b" ido-switch-buffer "buf" :exit t)
2293 ("C-b" ido-switch-buffer "buf" :exit t)
2294 ("m" bookmark-jump-other-window "open bmk" :exit t)
2295 ("M" bookmark-set "set bmk" :exit t)
2297 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
2298 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
2299 ("C-h" nil nil :exit t)
2300 ("C-j" nil nil :exit t)
2301 ;; ("C-k" nil :exit t)
2302 ("C-l" nil nil :exit t)
2303 ("C-;" nil nil :exit t)
2304 ("p" nil nil :exit t)
2305 ("n" nil nil :exit t)
2306 ("[" nil nil :exit t)
2307 ("]" nil nil :exit t)
2310 (global-unset-key (kbd "C-o"))
2311 (global-set-key (kbd "C-o") 'sd/hydra-window/body)
2316 [[https://www.masteringemacs.org/article/effective-editing-movement][effective-editing-movement]]
2317 *** Command Arguments, numeric argumens
2318 =C-u 4= same as =C-4=, =M-4=
2320 moving by line / word /
2321 =C-f=, =C-b=, =C-p=, =C-n=, =M-f=, =M-b=
2323 =M-m= (move first non-whitespace on this line)
2324 =M-}=, =M-{=, Move forward end of paragraph
2325 =M-a=, =M-e=, beginning / end of sentence
2326 =C-M-a=, =C-M-e=, move begining of defun
2327 =C-x ]=, =C-x [=, forward/backward one page
2328 =C-v=, =M-v=, =C-M-v=, =C-M-S-v= scroll down/up
2329 =M-<=, =M->=, beginning/end of buffer
2330 =M-r=, Repositiong point
2332 *** Moving by S-expression / List
2334 =C-<SPC>= set marks toggle the region
2335 =C-u C-<SPC>= Jump to the mark, repeated calls go further back the mark ring
2336 =C-x C-x= Exchanges the point and mark.
2338 Stolen [[https://www.masteringemacs.org/article/fixing-mark-commands-transient-mark-mode][fixing-mark-commands-transient-mark-mode]]
2339 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2340 (defun push-mark-no-activate ()
2341 "Pushes `point' to `mark-ring' and does not activate the region
2342 Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
2344 (push-mark (point) t nil)
2345 (message "Pushed mark to ring"))
2347 ;; (global-set-key (kbd "C-`") 'push-mark-no-activate)
2349 (defun jump-to-mark ()
2350 "Jumps to the local mark, respecting the `mark-ring' order.
2351 This is the same as using \\[set-mark-command] with the prefix argument."
2353 (set-mark-command 1))
2355 ;; (global-set-key (kbd "M-`") 'jump-to-mark)
2357 (defun exchange-point-and-mark-no-activate ()
2358 "Identical to \\[exchange-point-and-mark] but will not activate the region."
2360 (exchange-point-and-mark)
2361 (deactivate-mark nil))
2363 ;; (define-key global-map [remap exchange-point-and-mark] 'exchange-point-and-mark-no-activate)
2366 Show the mark ring using =helm-mark-ring=, also mapping =M-`= to quit minibuffer. so that =M-`= can
2367 toggle the mark ring. the best way is add a new action and mapping to =helm-source-mark-ring=, but
2368 since there is no map such as =helm-mark-ring=map=, so I cannot binding a key to the quit action.
2369 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2370 (global-set-key (kbd "M-`") #'helm-mark-ring)
2372 (define-key minibuffer-local-map (kbd "M-`") 'keyboard-escape-quit)
2375 =M-h= marks the next paragraph
2376 =C-x h= marks the whole buffer
2377 =C-M-h= marks the next defun
2378 =C-x C-p= marks the next page
2379 **** DONE Mapping toggle mark ring=
2381 - State "DONE" from "TODO" [2016-07-22 Fri 23:18]
2384 Registers can save text, position, rectangles, file and configuration and other things.
2385 Here for movement, we can use register to save/jump position
2386 =C-x r SPC= store point in register
2387 =C-x r j= jump to register
2388 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2389 (use-package list-register
2394 As I would like use bookmakr for different buffer/files. to help to swith
2395 different buffer/file quickly. this setting is in Windows/buffer node
2396 =C-x r m= set a bookmarks
2397 =C-x r l= list bookmarks
2398 =C-x r b= jump to bookmarks
2401 Search, replace and hightlight will in later paragraph
2402 *** =Avy= for easy motion
2403 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2407 (avy-setup-default))
2409 (global-set-key (kbd "C-M-j") 'avy-goto-line-below)
2410 (global-set-key (kbd "C-M-n") 'avy-goto-line-below)
2411 (global-set-key (kbd "C-M-k") 'avy-goto-line-above)
2412 (global-set-key (kbd "C-M-p") 'avy-goto-line-above)
2414 (global-set-key (kbd "C-M-f") 'avy-goto-word-1-below)
2415 (global-set-key (kbd "C-M-b") 'avy-goto-word-1-above)
2417 ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
2418 (global-set-key (kbd "C-M-w") 'avy-goto-char-timer)
2419 (global-set-key (kbd "C-M-l") 'avy-goto-char-in-line)
2421 ;; ;; will delete above
2422 ;; (global-set-key (kbd "M-g j") 'avy-goto-line-below)
2423 ;; (global-set-key (kbd "M-g k") 'avy-goto-line-above)
2424 ;; (global-set-key (kbd "M-g w") 'avy-goto-word-1-below)
2425 ;; (global-set-key (kbd "M-g b") 'avy-goto-word-1-above)
2426 ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
2427 ;; (global-set-key (kbd "M-g f") 'avy-goto-char-timer)
2428 ;; (global-set-key (kbd "M-g c") 'avy-goto-char-in-line)
2431 *** =Imenu= goto tag
2432 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2433 ;; (global-set-key (kbd "M-i") #'counsel-imenu)
2434 (global-set-key (kbd "M-i") #'imenu)
2436 ;; (global-set-key (kbd "M-l") 'goto-line)
2440 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2441 (global-set-key (kbd "M-l") 'goto-line)
2444 *** Movement effective
2447 =C-w=, put the word into search minibuffer, =M-y=
2448 =M-c=, toggle case sensitivity
2449 =M-n=, =M-p=, history
2453 - cut, yank, =C-w=, =C-y=
2455 - undo, redo - undo-tree
2456 - select, expand-region
2457 - spell check, flyspell
2460 =helm-show-kill-ring=
2461 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2462 (global-set-key (kbd "M-y") #'helm-show-kill-ring)
2465 ** Search & Replace / hightlight =M-s=
2469 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2471 ;; (defhydra sd/search-highlight (:color red :columns nil)
2473 ;; ("M-s" . isearch-forward-regexp "search-forward" :exit t)
2474 ;; ("s" . isearch-forward-regexp "search-forward" :exit t)
2475 ;; ("r" . isearch-backward-regexp "search-backward" :exit t)
2478 ;; (setq-default indicate-empty-lines t)
2482 Occur search key bindings
2483 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2484 (defun sd/occur-keys ()
2485 "My key bindings in occur-mode"
2487 (switch-to-buffer-other-window "*Occur*")
2488 (define-key occur-mode-map (kbd "C-o") nil)
2489 (define-key occur-mode-map (kbd "C-n") (lambda ()
2492 (occur-mode-goto-occurrence-other-window)
2495 (define-key occur-mode-map (kbd "C-p") (lambda ()
2498 (occur-mode-goto-occurrence-other-window)
2502 (add-hook 'occur-hook #'sd/occur-keys)
2504 (use-package color-moccur
2506 :commands (isearch-moccur isearch-all)
2508 (setq isearch-lazy-highlight t)
2510 (use-package moccur-edit))
2514 stolen from [[https://github.com/mariolong/emacs.d/blob/f6a061594ef1b5d1f4750e9dad9dc97d6e122840/emacs-init.org][here]]
2515 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2519 (setq ivy-use-virtual-buffers t)
2520 (set-face-attribute 'ivy-current-match nil :background "Orange" :foreground "black")
2523 (global-set-key (kbd "s-/") 'swiper)
2524 (define-key swiper-map (kbd "M-r") 'swiper-query-replace)
2525 (define-key swiper-map (kbd "C-.") (lambda ()
2527 (insert (format "%s" (with-ivy-window (thing-at-point 'word))))))
2528 (define-key swiper-map (kbd "M-.") (lambda ()
2530 (insert (format "%s" (with-ivy-window (thing-at-point 'symbol)))))))
2534 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2535 (use-package bing-dict
2538 (global-set-key (kbd "s-d") 'bing-dict-brief)
2539 :commands (bing-dict-brief))
2542 * TODO Temp directory for cached/history/temp files
2543 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2544 (use-package recentf
2546 (setq recentf-save-file (concat sd-temp-directory "recentf")))
2548 (use-package projectile
2550 (setq projectile-cache-file (concat sd-temp-directory "projectile.cache")))
2554 (setq ido-save-directory-list-file (concat sd-temp-directory "ido.last")))
2556 (use-package savehist
2558 (setq savehist-file (concat sd-temp-directory "history")))
2562 (setq emms-directory (concat sd-temp-directory "emms")))
2564 (setq auto-save-list-file-prefix (concat sd-temp-directory "auto-save-list/.saves-"))
2568 (setq smex-save-file (concat sd-temp-directory "smex-items")))
2572 #+BEGIN_SRC ditaa :file temp/hello-world.png :cmdline -r
2581 [[file:temp/hello-world.png]]
2583 #+BEGIN_SRC ditaa :file temp/hello.png
2594 [[file:temp/hello.png]]
2596 * =C-u C-h a= search funtions
2600 - interactive for anonymous function
2601 When define a key to a anonymous function, the lambda function should be interactive
2603 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2604 ;; (require 'saveplace)
2605 ;; (setq-default save-place t)
2606 ;; (delete-selection-mode 1)
2611 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2613 ;; M-h - mark-paragraph
2614 ;; M-j - new line indent
2615 ;; M-k - kill-sentence
2616 ;; M-l - downcase words ====== goto-line
2618 ;; M-'- abbrev-prefix-mark =======
2619 ;; M-RET none ======
2622 ;; M-u - upcase word
2623 ;; M-i - ====== imenu
2624 ;; M-o ====== prefix
2628 ;; M-\ deleter horizontal space =====
2632 ;; M-, --- mark stack====== =
2633 ;; M-. lisp-goto-symboo, find definitation
2641 ;; M-q - lisp fill, fill paragraph
2644 ;; M-r - rePositioning
2645 ;; M-t transpose word
2649 ;; M-c capitalize-word