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
78 ;; (setq-default indicate-empty-lines t)
82 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
83 (setq auto-save-default nil)
85 ;; restore last session
86 ;; (desktop-save-mode t)
90 Make a temp directory for all cache/history files
91 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
92 (defconst sd-temp-directory
93 (file-name-as-directory "~/.emacs.d/temp"))
95 (unless (file-exists-p sd-temp-directory)
96 (mkdir sd-temp-directory))
99 *** Save minibuffer history
100 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
101 (setq savehist-file (concat sd-temp-directory "history"))
102 (setq history-length 1000)
103 (setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring))
106 ;; set temp file path for recentf and auto-save
107 (setq recentf-save-file (concat sd-temp-directory "recentf"))
108 (setq auto-save-list-file-prefix (concat sd-temp-directory "auto-save-list/.saves-"))
111 * Package Management Tools
113 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
119 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
120 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
121 (unless (package-installed-p 'use-package)
122 (package-refresh-contents)
123 (package-install 'use-package))
125 (require 'use-package)
129 [[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.
130 Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
131 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
135 (add-to-list 'load-path "~/.emacs.d/el-get"))
138 * Color and Fonts Settings
140 ** highlight current line
142 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
144 (global-hl-line-mode)
150 [[https://github.com/paldepind/smart-comment][smart-comments]]
152 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
154 (use-package smart-comment
156 :bind ("M-;" . smart-conmment))
164 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
166 (global-font-lock-mode 1)
170 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
172 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
175 (defvar sd/fixed-font-family
176 (cond ((x-list-fonts "Hasklig") "Hasklig")
177 ((x-list-fonts "Source Code Pro") "Source Code Pro:weight:light")
178 ((x-list-fonts "Anonymous Pro") "Anonymous Pro")
179 ((x-list-fonts "M+ 1mn") "M+ 1mn"))
180 "The fixed width font based on what is installed, `nil' if not defined."))
186 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
189 (when sd/fixed-font-family
190 (set-frame-font sd/fixed-font-family)
191 (set-face-attribute 'default nil :font sd/fixed-font-family :height 130)
192 (set-face-font 'default sd/fixed-font-family)))
198 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
200 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
202 (setq vc-follow-symlinks t)
204 (use-package color-theme
206 :init (require 'color-theme)
207 :config (use-package color-theme-sanityinc-tomorrow
211 (load-theme 'sanityinc-tomorrow-bright t)))
213 ;(eval-after-load 'color-theme
214 ; (load-theme 'sanityinc-tomorrow-bright t))
218 Change the Org-mode colors
220 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
222 (defun org-src-color-blocks-light ()
223 "Colors the block headers and footers to make them stand out more for lighter themes"
226 '(org-block-begin-line
227 ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
228 '(org-block-background
229 ((t (:background "#FFFFEA"))))
231 ((t (:background "#FFFFEA"))))
233 ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
235 '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
236 '(which-func ((t (:foreground "#008000"))))))
238 (defun org-src-color-blocks-dark ()
239 "Colors the block headers and footers to make them stand out more for dark themes"
242 '(org-block-begin-line
243 ((t (:foreground "#008ED1" :background "#002E41"))))
244 '(org-block-background
245 ((t (:background "#000000"))))
247 ((t (:background "#000000"))))
249 ((t (:foreground "#008ED1" :background "#002E41"))))
251 '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
252 '(which-func ((t (:foreground "green"))))))
254 (org-src-color-blocks-dark)
258 improve color for org-mode
259 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
260 (deftheme ha/org-theme "Sub-theme to beautify org mode")
263 (defvar sd/variable-font-tuple
264 (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
265 ((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
266 ((x-list-fonts "Verdana") '(:font "Verdana"))
267 ((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
268 (nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro.")))
269 "My variable width font available to org-mode files and whatnot."))
271 (defun sd/org-color ()
272 (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
273 (base-font-color (face-foreground 'default nil 'default))
274 (background-color (face-background 'default nil 'default))
275 (primary-color (face-foreground 'mode-line nil))
276 (secondary-color (face-background 'secondary-selection nil 'region))
277 (base-height (face-attribute 'default :height))
278 (headline `(:inherit default :weight bold :foreground ,base-font-color)))
279 (custom-theme-set-faces 'ha/org-theme
280 `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
281 `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
282 `(org-table ((t (:inherit 'fixed-pitched))))
283 `(org-block ((t (:inherit 'fixed-pitched))))
284 `(org-block-background ((t (:inherit 'fixed-pitched))))
285 `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
286 `(org-block-end-line ((t (:inherit 'fixed-pitched))))
287 `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
288 `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
289 `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
290 `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
291 `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
292 :height ,(round (* 1.1 base-height))))))
293 `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
294 :height ,(round (* 1.25 base-height))))))
295 `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
296 :height ,(round (* 1.5 base-height))))))
297 `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
298 :height ,(round (* 1.75 base-height))))))
299 `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
306 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
308 (use-package rainbow-delimiters
311 (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
317 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
319 (use-package page-break-lines
322 (turn-on-page-break-lines-mode))
328 Enable rainbow mode in emacs lisp mode
330 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
331 (use-package rainbow-mode
334 ; (add-hook emacs-lisp-mode-hook 'rainbow-mode)
343 clean mode line, Refer to [[https://www.masteringemacs.org/article/hiding-replacing-modeline-strings][Marstering Emacs]]
345 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
346 (defvar mode-line-cleaner-alist
347 `((auto-complete-mode . " α")
348 (yas/minor-mode . " Ï…")
349 (paredit-mode . " π")
352 (projectile-mode . "")
354 (undo-tree-mode . "")
356 (which-key-mode . "")
358 (smartparens-mode . "")
360 (linum-relative-mode . "")
362 (auto-revert-mode . "")
364 (org-indent-mode . "")
368 (lisp-interaction-mode . "λ")
371 (emacs-lisp-mode . "EL")
373 (nxhtml-mode . "nx"))
374 "Alist for `clean-mode-line'.
376 When you add a new element to the alist, keep in mind that you
377 must pass the correct minor/major mode symbol and a string you
378 want to use in the modeline *in lieu of* the original.")
381 (defun clean-mode-line ()
383 (loop for cleaner in mode-line-cleaner-alist
384 do (let* ((mode (car cleaner))
385 (mode-str (cdr cleaner))
386 (old-mode-str (cdr (assq mode minor-mode-alist))))
388 (setcar old-mode-str mode-str))
390 (when (eq mode major-mode)
391 (setq mode-name mode-str)))))
394 (add-hook 'after-change-major-mode-hook 'clean-mode-line)
399 Install powerline mode [[https://github.com/milkypostman/powerline][powerline]]
401 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
402 (use-package powerline
405 ;; (powerline-center-theme)
408 ;; (use-package smart-mode-line
410 ;; (use-package smart-mode-line-powerline-theme
414 Revised powerline-center-theme
415 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
416 (defun sd/powerline-simpler-vc (s)
418 (replace-regexp-in-string "Git[:-]" "" s)
421 (defface sd/powerline-active1 '((t (:background "yellow" :foreground "black" :inherit mode-line)))
422 "My Powerline face 1 based on powerline-active1."
425 (defface sd/buffer-modified-active1 '((t (:background "red" :foreground "black" :inherit mode-line)))
426 "My Powerline face 1 based on powerline-active1."
429 (defface sd/buffer-view-active1 '((t (:background "green" :foreground "black" :inherit mode-line)))
430 "My Powerline face 1 based on powerline-active1."
433 (defface sd/mode-line-buffer-id
434 '((t (:background "yellow" :foreground "black" :inherit mode-line-buffer-id)))
435 "My powerline mode-line face, based on mode-line-buffer-id"
438 ;; Don't show buffer modified for scratch and eshell mode
439 (defun sd/buffer-show-modified ()
440 "Dot not show modified indicator for buffers"
442 (unless (or (string-match "*scratch*" (buffer-name))
443 (equal major-mode 'eshell-mode))
446 (defun sd/powerline-center-theme_revised ()
447 "Setup a mode-line with major and minor modes centered."
449 (setq-default mode-line-format
452 (let* ((active (powerline-selected-window-active))
453 (mode-line-buffer-id (if active 'sd/mode-line-buffer-id 'mode-line-buffer-id-inactive))
454 (mode-line (if active 'mode-line 'mode-line-inactive))
455 (my-face1 (if active 'sd/powerline-active1 'powerline-inactive1))
456 (my-face-buffer-modified (if (and (sd/buffer-show-modified) (buffer-modified-p))
457 'sd/buffer-modified-active1
458 (if buffer-read-only 'sd/buffer-view-active1
460 (face1 (if active 'powerline-active1 'powerline-inactive1))
461 (face2 (if active 'powerline-active2 'powerline-inactive2))
462 (separator-left (intern (format "powerline-%s-%s"
463 (powerline-current-separator)
464 (car powerline-default-separator-dir))))
465 (separator-right (intern (format "powerline-%s-%s"
466 (powerline-current-separator)
467 (cdr powerline-default-separator-dir))))
468 (lhs (list (powerline-raw "%* " my-face-buffer-modified 'l)
469 ;; (powerline-buffer-size mode-line 'l)
470 (powerline-buffer-id mode-line-buffer-id 'l)
471 (powerline-raw " " my-face1)
472 (funcall separator-left my-face1 face1)
473 (powerline-narrow face1 'l)
474 ;; (powerline-vc face1)
475 (sd/powerline-simpler-vc (powerline-vc face1))))
476 (rhs (list (powerline-raw global-mode-string face1 'r)
477 (powerline-raw "%4l" face1 'r)
478 (powerline-raw ":" face1)
479 (powerline-raw "%3c" face1 'r)
480 (funcall separator-right face1 my-face1)
481 ;; (powerline-raw " " my-face1)
482 (powerline-raw (format-time-string " %I:%M %p ") my-face1 'r)
483 ;; (powerline-raw "%6p" my-face1 'r)
484 ;; (powerline-hud my-face1 face1 )
486 (center (list (powerline-raw " " face1)
487 (funcall separator-left face1 face2)
488 (when (and (boundp 'erc-track-minor-mode) erc-track-minor-mode)
489 (powerline-raw erc-modified-channels-object face2 'l))
490 (powerline-major-mode face2 'l)
491 (powerline-process face2)
492 (powerline-raw " :" face2)
493 (powerline-minor-modes face2 'l)
494 (powerline-raw " " face2)
495 (funcall separator-right face2 face1))))
496 (concat (powerline-render lhs)
497 (powerline-fill-center face1 (/ (powerline-width center) 2.0))
498 (powerline-render center)
499 (powerline-fill face1 (powerline-width rhs))
500 (powerline-render rhs)))))))
502 (sd/powerline-center-theme_revised)
505 Fix the issue in mode line when showing triangle
506 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
507 (setq ns-use-srgb-colorspace nil)
510 set height in mode line
511 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
512 (set-variable 'powerline-height 14)
513 (set-variable 'powerline-text-scale-factor (/ (float 100) 140))
514 ;; (custom-set-variables
515 ;; '(powerline-height 14)
516 ;; '(powerline-text-scale-factor (/ (float 100) 140)))
518 (set-face-attribute 'mode-line nil :height 100)
523 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
526 :init (setq ido-enable-flex-matching t
527 ido-ignore-extensions t
528 ido-use-virtual-buffers t
530 (setq ido-save-directory-list-file (concat sd-temp-directory "ido.last"))
534 (add-to-list 'completion-ignored-extensions ".pyc"))
540 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
543 :init (setq ido-enable-flex-matching t
545 :config (flx-ido-mode 1))
549 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
550 (use-package ido-vertical-mode
553 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
555 (ido-vertical-mode 1))
559 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
563 (setq smex-save-file (concat sd-temp-directory "smex-items"))
567 ("M-X" . smex-major-mode-commands))
571 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
572 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
573 (use-package ido-ubiquitous
576 (setq magit-completing-read-function 'magit-ido-completing-read)
577 (setq gnus-completing-read-function 'gnus-ido-completing-read)
579 (ido-ubiquitous-mode 1))
583 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
584 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
585 (use-package ido-exit-target
588 (mapcar (lambda (map)
589 (define-key map (kbd "C-j") #'ido-exit-target-split-window-right)
590 (define-key map (kbd "C-k") #'ido-exit-target-split-window-below))
591 (list ido-buffer-completion-map
592 ;; ido-common-completion-map
593 ido-file-completion-map
594 ido-file-dir-completion-map)))
598 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
603 (global-set-key (kbd "M-x") 'counsel-M-x)
604 (global-set-key (kbd "C-h f") 'counsel-describe-function)
605 (global-set-key (kbd "C-h v") 'counsel-describe-variable)
606 ;; (set-face-attribute 'ivy-current-match nil :background "Orange" :foreground "black")
607 (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
608 (global-set-key (kbd "C-c C-r") 'ivy-resume))
612 ;; (global-set-key "\C-s" 'swiper)
613 ;; (global-set-key (kbd "<f6>") 'ivy-resume)
614 ;; ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
615 ;; (global-set-key (kbd "<f1> l") 'counsel-load-library)
616 ;; (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
617 ;; (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
618 ;; (global-set-key (kbd "C-c g") 'counsel-git)
619 ;; (global-set-key (kbd "C-c j") 'counsel-git-grep)
620 ;; (global-set-key (kbd "C-c k") 'counsel-ag)
621 ;; (global-set-key (kbd "C-x l") 'counsel-locate)
622 ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
624 ;; (set-face-attribute
625 ;; 'ivy-current-match nil
626 ;; :background "Orange"
627 ;; :foreground "black")
630 ;; (define-key swiper-map (kbd "M-%") 'swiper-aa-replace)
634 let helm windows split inside current window
635 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
636 (with-eval-after-load 'helm
637 (setq helm-split-window-in-side-p t))
642 ** Org-mode Basic setting
644 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
646 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
650 (setq org-startup-indented t)
651 (setq org-hide-leading-starts t)
652 (setq org-src-fontify-natively t)
653 (setq org-src-tab-acts-natively t)
654 (setq org-confirm-babel-evaluate nil)
655 (setq org-use-speed-commands t)
656 (setq org-completion-use-ido t))
658 (org-babel-do-load-languages
659 'org-babel-load-languages
675 ;; use current window for org source buffer editting
676 (setq org-src-window-setup 'current-window )
678 (define-key org-mode-map (kbd "C-'") nil)
679 ;; C-M-i is mapped to imenu globally
680 (define-key org-mode-map (kbd "C-M-i") nil)
682 ;; set the ditta.jar path
683 (setq org-ditaa-jar-path "/usr/local/Cellar/ditaa/0.9/libexec/ditaa0_9.jar")
685 (file-exists-p org-ditaa-jar-path)
686 (error "seudut: ditaa.jar not found at %s " org-ditaa-jar-path))
691 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
693 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
694 (use-package org-bullets
697 (add-hook 'org-mode-hook
699 (org-bullets-mode t))))
701 (setq org-bullets-bullet-list '("⦿" "✪" "◉" "○" "►" "◆"))
703 ;; increase font size when enter org-src-mode
704 (add-hook 'org-src-mode-hook (lambda () (text-scale-increase 2)))
709 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
710 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
711 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
712 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
714 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
719 :init (add-hook 'org-mode-hook 'worf-mode)
721 ;; (define-key worf-mode-map "[" nil)
722 ;; (define-key worf-mode-map "]" nil)
723 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
724 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
731 Refer to [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
736 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
737 (global-set-key "\C-cl" 'org-store-link)
738 (global-set-key "\C-ca" 'org-agenda)
739 (global-set-key "\C-cb" 'org-iswitchb)
744 Replace the list bullet =-=, =+=, with =•=, a litter change based [[https://github.com/howardabrams/dot-files/blob/master/emacs-org.org][here]]
746 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
747 ;; (use-package org-mode
749 ;; (font-lock-add-keywords 'org-mode
750 ;; '(("^ *\\([-+]\\) "
751 ;; (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•")))))))
756 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]],
758 To track TODO state changes, the =!= is to insert a timetamp, =@= is to insert a note with
759 timestamp for the state change.
761 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
762 ;; (setq org-todo-keywords
763 ;; '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
764 ;; (sequence "âš‘ WAITING(w)" "|")
765 ;; (sequence "|" "✘ CANCELLED(c)")))
766 ; (setq org-todo-keyword-faces
767 ; (quote ("TODO" . (:foreground "red" :weight bold))
768 ; ("NEXT" . (:foreground "blue" :weight bold))
769 ; ("WAITING" . (:foreground "forest green" :weight bold))
770 ; ("DONE" . (:foreground "magenta" :weight bold))
771 ; ("CANCELLED" . (:foreground "forest green" :weight bold))))
774 (setq org-todo-keywords
775 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!)")
776 ;; (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING")
777 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" ))))
779 (setq org-todo-keyword-faces
780 (quote (("TODO" :foreground "red" :weight bold)
781 ("NEXT" :foreground "blue" :weight bold)
782 ("DONE" :foreground "forest green" :weight bold)
783 ("WAITING" :foreground "orange" :weight bold)
784 ("HOLD" :foreground "magenta" :weight bold)
785 ("CANCELLED" :foreground "forest green" :weight bold)
786 ;; ("MEETING" :foreground "forest green" :weight bold)
787 ;; ("PHONE" :foreground "forest green" :weight bold)
793 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
794 (setq org-use-fast-todo-selection t)
795 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
798 TODO state triggers and tags, [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
800 - Moving a task to =CANCELLED=, adds a =CANCELLED= tag
801 - Moving a task to =WAITING=, adds a =WAITING= tag
802 - Moving a task to =HOLD=, add =HOLD= tags
803 - Moving a task to =DONE=, remove =WAITING=, =HOLD= tag
804 - Moving a task to =NEXT=, remove all waiting/hold/cancelled tags
806 This tags are used to filter tasks in agenda views
807 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
808 (setq org-todo-state-tags-triggers
809 (quote (("CANCELLED" ("CANCELLED" . t))
810 ("WAITING" ("WAITING" . t))
811 ("HOLD" ("WAITING") ("HOLD" . t))
812 (done ("WAITING") ("HOLD"))
813 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
814 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
815 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
819 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
820 ;; log time when task done
821 ;; (setq org-log-done (quote time))
822 ;; save clocking into to LOGBOOK
823 (setq org-clock-into-drawer t)
824 ;; save state change notes and time stamp into LOGBOOK drawer
825 (setq org-log-into-drawer t)
826 (setq org-clock-into-drawer "CLOCK")
830 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
831 (setq org-tag-alist (quote ((:startgroup)
837 ("CANCELLED" . ?c))))
839 ;; Allow setting single tags without the menu
840 (setq org-fast-tag-selection-single-key (quote expert))
843 *** Capture - Refile - Archive
845 Capture lets you quickly store notes with little interruption of your work flow.
847 **** Capture Templates
849 When a new taks needs to be added, categorize it as
851 All captured file which need next actions are stored in =refile.org=,
852 - A new task / note (t) =refile.org=
853 - A work task in office =office.org=
854 - A jourenl =diary.org=
855 - A new habit (h) =refile.org=
857 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
858 (setq org-directory "~/org")
859 (setq org-default-notes-file "~/org/refile.org")
860 (setq sd/org-diary-file "~/org/diary.org")
862 (global-set-key (kbd "C-c c") 'org-capture)
864 (setq org-capture-templates
865 (quote (("t" "Todo" entry (file org-default-notes-file)
866 "* TODO %?\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
867 ("n" "Note" entry (file org-default-notes-file)
868 "* %? :NOTE:\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
869 ("j" "Journal" entry (file+datetree sd/org-diary-file)
870 "* %?\n:LOGBOOK:\n:END:" :clock-in t :clock-resume t)
871 ("h" "Habit" entry (file org-default-notes-file)
872 "* 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 "))))
877 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
878 (setq org-refile-targets (quote (;; (nil :maxlevel . 9)
879 (org-agenda-files :maxlevel . 9))))
881 (setq org-refile-use-outline-path t)
883 (setq org-refile-allow-creating-parent-nodes (quote confirm))
887 Setting agenda files and the agenda view
888 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
889 (setq org-agenda-files (quote ("~/org/gtd.org"
892 ;; only show today's tasks in agenda view
893 (setq org-agenda-span 'day)
894 ;; Use current windows for agenda view
895 (setq org-agenda-window-setup 'current-window)
897 ;; show all feature entries for repeating tasks,
898 ;; this is already setting by default
899 (setq org-agenda-repeating-timestamp-show-all t)
901 ;; Show all agenda dates - even if they are empty
902 (setq org-agenda-show-all-dates t)
907 Install MacTex-basic and some tex packages
911 sudo tlmgr update --self
913 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
917 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
918 ;; ;; allow for export=>beamer by placing
920 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
921 ;; #+LaTeX_CLASS: beamer in org files
922 (unless (boundp 'org-export-latex-classes)
923 (setq org-export-latex-classes nil))
924 (add-to-list 'org-export-latex-classes
925 ;; beamer class, for presentations
927 "\\documentclass[11pt]{beamer}\n
928 \\mode<{{{beamermode}}}>\n
929 \\usetheme{{{{beamertheme}}}}\n
930 \\usecolortheme{{{{beamercolortheme}}}}\n
931 \\beamertemplateballitem\n
932 \\setbeameroption{show notes}
933 \\usepackage[utf8]{inputenc}\n
934 \\usepackage[T1]{fontenc}\n
935 \\usepackage{hyperref}\n
937 \\usepackage{listings}
938 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
941 showspaces=false,showstringspaces=false,
943 keywordstyle=\\color{blue}\\bfseries,
944 commentstyle=\\color{red},
946 \\usepackage{verbatim}\n
947 \\institute{{{{beamerinstitute}}}}\n
948 \\subject{{{{beamersubject}}}}\n"
950 ("\\section{%s}" . "\\section*{%s}")
952 ("\\begin{frame}[fragile]\\frametitle{%s}"
954 "\\begin{frame}[fragile]\\frametitle{%s}"
957 ;; letter class, for formal letters
959 (add-to-list 'org-export-latex-classes
962 "\\documentclass[11pt]{letter}\n
963 \\usepackage[utf8]{inputenc}\n
964 \\usepackage[T1]{fontenc}\n
967 ("\\section{%s}" . "\\section*{%s}")
968 ("\\subsection{%s}" . "\\subsection*{%s}")
969 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
970 ("\\paragraph{%s}" . "\\paragraph*{%s}")
971 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
977 (setq org-latex-pdf-process
978 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
979 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
980 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
982 (setq TeX-parse-self t)
984 (setq TeX-PDF-mode t)
985 (add-hook 'LaTeX-mode-hook
988 (setq TeX-master t)))
994 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
996 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
998 (add-to-list 'org-structure-template-alist
999 '("E" "#+BEGIN_SRC emacs-lisp :tangle yes :results silent\n?\n#+END_SRC"))
1000 (add-to-list 'org-structure-template-alist
1001 '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
1002 (add-to-list 'org-structure-template-alist
1003 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
1008 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
1009 and Defined keys, using vi keybindings, Refer abo-abo's setting [[https://github.com/abo-abo/oremacs/blob/c5cafdcebc88afe9e73cc8bd40c49b70675509c7/modes/ora-nextmagit.el][here]]
1010 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1014 ;; don't ask me to confirm the unsaved change
1015 (setq magit-save-repository-buffers nil)
1016 :commands magit-status magit-blame
1018 (dolist (map (list magit-status-mode-map
1021 magit-staged-section-map))
1022 (define-key map "j" 'magit-section-forward)
1023 (define-key map "k" 'magit-section-backward)
1024 (define-key map "D" 'magit-discard)
1025 (define-key map "O" 'magit-discard-file)
1026 (define-key map "n" nil)
1027 (define-key map "p" nil)
1028 (define-key map "v" 'recenter-top-bottom)
1029 (define-key map "i" 'magit-section-toggle)))
1034 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1035 (defalias 'e 'find-file)
1036 (defalias 'ff 'find-file)
1037 (defalias 'ee 'find-files)
1040 ** eshell temp directory
1041 set default eshell history folder
1042 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1043 (setq eshell-directory-name (concat sd-temp-directory "eshell"))
1046 ** Eshell erase buffer
1047 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1048 (defun sd/eshell-clear-buffer ()
1049 "Clear eshell buffer"
1051 (let ((inhibit-read-only t))
1053 (eshell-send-input)))
1055 (add-hook 'eshell-mode-hook (lambda ()
1056 (local-set-key (kbd "C-l") 'sd/eshell-clear-buffer)))
1060 Toggle an eshell in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
1061 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1062 (defun sd/window-has-eshell ()
1063 "Check if current windows list has a eshell buffer, and return the window"
1066 (walk-windows (lambda (window)
1067 (if (equal (with-current-buffer (window-buffer window) major-mode)
1073 (defun sd/toggle-eshell-here ()
1074 "Toggle a eshell buffer vertically"
1076 (if (sd/window-has-eshell)
1077 (if (equal major-mode 'eshell-mode)
1079 (if (equal (length (window-list)) 1)
1080 (mode-line-other-buffer)
1082 (select-window (sd/window-has-eshell)))
1084 (let ((dir default-directory))
1086 (split-window-vertically (- (/ (window-total-height) 3)))
1088 (unless (and (boundp 'eshell-buffer-name) (get-buffer eshell-buffer-name))
1090 (switch-to-buffer eshell-buffer-name)
1091 (goto-char (point-max))
1093 (insert (format "cd %s" dir))
1094 (eshell-send-input)))))
1096 ;; (global-unset-key (kbd "M-`"))
1097 (global-set-key (kbd "s-e") 'sd/toggle-eshell-here)
1100 ** TODO smart display
1103 ** [[https://github.com/abo-abo/hydra][Hydra]]
1105 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1108 ;; disable new line in minibuffer when hint hydra
1112 *** Windmove Splitter
1114 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1116 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1118 (defun hydra-move-splitter-left (arg)
1119 "Move window splitter left."
1121 (if (let ((windmove-wrap-around))
1122 (windmove-find-other-window 'right))
1123 (shrink-window-horizontally arg)
1124 (enlarge-window-horizontally arg)))
1126 (defun hydra-move-splitter-right (arg)
1127 "Move window splitter right."
1129 (if (let ((windmove-wrap-around))
1130 (windmove-find-other-window 'right))
1131 (enlarge-window-horizontally arg)
1132 (shrink-window-horizontally arg)))
1134 (defun hydra-move-splitter-up (arg)
1135 "Move window splitter up."
1137 (if (let ((windmove-wrap-around))
1138 (windmove-find-other-window 'up))
1139 (enlarge-window arg)
1140 (shrink-window arg)))
1142 (defun hydra-move-splitter-down (arg)
1143 "Move window splitter down."
1145 (if (let ((windmove-wrap-around))
1146 (windmove-find-other-window 'up))
1148 (enlarge-window arg)))
1153 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1154 (defhydra sd/hydra-misc (:color red :columns nil)
1156 ("e" eshell "eshell" :exit t)
1159 (if (not (eq nil (get-buffer "*Packages*")))
1160 (switch-to-buffer "*Packages*")
1161 (package-list-packages)))
1162 "list-package" :exit t)
1163 ("g" magit-status "git-status" :exit t)
1164 ("'" mode-line-other-buffer "last buffer" :exit t)
1165 ("C-'" mode-line-other-buffer "last buffer" :exit t)
1166 ("m" man "man" :exit t)
1167 ("d" dired-jump "dired" :exit t)
1168 ("b" ibuffer "ibuffer" :exit t)
1172 (global-set-key (kbd "C-'") 'sd/hydra-misc/body)
1176 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1177 (defhydra sd/hydra-launcher (:color blue :columns 2)
1179 ("e" emms "emms" :exit t)
1185 Enable linum mode on programming modes
1187 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1188 (add-hook 'prog-mode-hook 'linum-mode)
1189 ;; (add-hook 'prog-mode-hook (lambda ()
1190 ;; (setq-default indicate-empty-lines t)))
1193 Fix the font size of line number
1195 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1197 (defun fix-linum-size ()
1199 (set-face-attribute 'linum nil :height 110))
1201 (add-hook 'linum-mode-hook 'fix-linum-size)
1205 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1207 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1209 (use-package linum-relative
1212 (defun linum-new-mode ()
1213 "If line numbers aren't displayed, then display them.
1214 Otherwise, toggle between absolute and relative numbers."
1217 (linum-relative-toggle)
1221 ("A-k" . linum-new-mode))
1223 ;; auto enable linum-new-mode in programming modes
1224 (add-hook 'prog-mode-hook 'linum-relative-mode)
1228 ** Save File Position
1230 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1232 (require 'saveplace)
1233 (setq-default save-place t)
1234 (setq save-place-forget-unreadable-files t)
1235 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1241 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1243 (use-package multi-term
1250 [[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
1251 Type =o= to go to the link
1253 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1255 (use-package ace-link
1258 (ace-link-setup-default))
1264 [[https://github.com/re5et/emux][emux]] is
1266 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1268 (el-get-bundle re5et/emux)
1274 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1276 (use-package smartparens
1280 (require 'smartparens-config)
1281 (add-hook 'prog-mode-hook 'smartparens-mode)))
1287 [[https://github.com/abo-abo/ace-window][ace-window]]
1289 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1291 (use-package ace-window
1295 ; (global-set-key (kbd "M-o") 'ace-window)
1297 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1303 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1305 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1307 (use-package which-key
1316 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1318 ;; (use-package tabbar-ruler
1321 ;; (setq tabbar-ruler-global-tabbar t)
1322 ;; (setq tabbar-ruler-global-ruler t)
1323 ;; (setq tabbar-ruler-popu-menu t)
1324 ;; (setq tabbar-ruler-popu-toolbar t)
1325 ;; (setq tabbar-use-images t)
1327 ;; (tabbar-ruler-group-by-projectile-project)
1328 ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
1329 ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1333 ** View only for some directory
1334 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]]
1335 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1336 (dir-locals-set-class-variables
1338 '((nil . ((buffer-read-only . t)
1339 (show-trailing-whitespace . nil)
1341 (eval . (whitespace-mode -1))))))
1343 ;; (dir-locals-set-directory-class (expand-file-name "/usr/local/share/emacs") 'emacs)
1344 (dir-locals-set-directory-class "/usr/local/Cellar/emacs" 'emacs)
1345 ;; (dir-locals-set-directory-class "~/.emacs.d/elpa" 'emacs)
1346 (dir-locals-set-directory-class "~/dotfiles/emacs.d/elpa" 'emacs)
1347 (dir-locals-set-directory-class "~/dotfiles/emacs.d/el-get" 'emacs)
1351 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1352 (el-get-bundle info+
1353 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/info+.el"
1361 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1362 (defun sd/info-mode ()
1364 (unless (equal major-mode 'Info-mode)
1365 (unless (> (length (window-list)) 1)
1366 (split-window-right))
1371 ;; (global-set-key (kbd "C-h i") 'sd/info-mode)
1373 ;; open Info buffer in other window instead of current window
1374 (defadvice info (before my-info (&optional file buf) activate)
1377 (defadvice Info-exit (after my-info-exit activate)
1378 (sd/delete-current-window))
1384 ** TODO swiper to occur
1387 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1388 ;; (set-language-environment "UTF-8")
1389 ;; (set-default-coding-systems 'utf-8)
1393 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1394 ;; (el-get-bundle howardabrams/demo-it)
1396 (use-package org-tree-slide
1399 ;; (use-package yasnippet
1404 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1405 (use-package org-tree-slide
1408 ;; (define-key org-mode-map "\C-ccp" 'org-tree-slide-mode)
1409 (define-key org-tree-slide-mode-map (kbd "<ESC>") 'org-tree-slide-content)
1410 (define-key org-tree-slide-mode-map (kbd "<SPACE>") 'org-tree-slide-move-next-tree)
1411 (define-key org-tree-slide-mode-map [escape] 'org-tree-slide-move-previous-tree))
1416 =C-o= is defined as a global key for window operation, here unset it in dired mode
1417 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1421 (setq dired-omit-mode t)
1422 (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
1423 (add-hook 'dired-mode-hook (lambda ()
1424 (define-key dired-mode-map (kbd "C-o") nil)
1425 (define-key dired-mode-map (kbd "H") 'dired-omit-mode)
1426 (define-key dired-mode-map (kbd "DEL") (lambda () (interactive) (find-alternate-file "..")))
1427 (dired-omit-mode))))
1431 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1435 (setq diredp-hide-details-initially-flag nil)
1437 (define-key dired-mode-map (kbd "j") 'diredp-next-line)
1438 (define-key dired-mode-map (kbd "k") 'diredp-previous-line)
1439 (define-key dired-mode-map (kbd "g") 'dired-goto-file))
1443 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1444 (use-package dired-hacks-utils
1449 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1450 (global-set-key (kbd "s-b") 'ibuffer)
1452 (with-eval-after-load 'ibuffer
1453 (define-key ibuffer-mode-map (kbd "C-o") nil)
1454 (define-key ibuffer-mode-map (kbd "j") 'ibuffer-forward-line)
1455 (define-key ibuffer-mode-map (kbd "k") 'ibuffer-backward-line)
1456 (define-key ibuffer-mode-map (kbd "r") 'ibuffer-update)
1457 (define-key ibuffer-mode-map (kbd "g") 'ibuffer-jump-to-buffer))
1461 company mode and company-statistics
1462 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1463 (use-package company
1465 :diminish company-mode
1466 :init (setq company-idle-delay 0.1)
1468 (global-company-mode))
1470 (use-package company-statistics
1473 (company-statistics-mode))
1476 * Programming Language
1478 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1479 (use-package color-identifiers-mode
1482 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1484 :diminish color-identifiers-mode)
1486 (global-prettify-symbols-mode t)
1489 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1490 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1491 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1495 (eval-after-load "lispy"
1497 (define-key lispy-mode-map (kbd "M-o") nil)))
1499 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1504 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1505 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1506 (defalias 'perl-mode 'cperl-mode)
1508 ;; (setq cperl-hairy t)
1509 ;; Turns on most of the CPerlMode options
1510 (setq cperl-auto-newline t)
1511 (setq cperl-highlight-variables-indiscriminately t)
1512 ;(setq cperl-indent-level 4)
1513 ;(setq cperl-continued-statement-offset 4)
1514 (setq cperl-close-paren-offset -4)
1515 (setq cperl-indent-parents-as-block t)
1516 (setq cperl-tab-always-indent t)
1517 ;(setq cperl-brace-offset 0)
1519 (add-hook 'cperl-mode-hook
1521 (cperl-set-style "C++")))
1523 (defalias 'perldoc 'cperl-perldoc)
1527 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1528 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1529 (eval-after-load 'autoinsert
1530 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1533 "#!/usr/bin/perl -w" \n
1535 "use strict;" > \n \n
1541 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1542 (font-lock-add-keywords 'cperl-mode
1543 '(("\\(say\\)" . cperl-nonoverridable-face)
1544 ("\\([0-9.]\\)*" . font-lock-constant-face)
1545 ("\".*\\(\\\n\\).*\"" . font-lock-constant-face)
1546 ("\n" . font-lock-constant-face)
1547 ("\\(^#!.*\\)$" . cperl-nonoverridable-face)))
1549 ;; (font-lock-add-keywords 'Man-mode
1550 ;; '(("\\(NAME\\)" . font-lock-function-name-face)))
1555 Change the compile-command to set the default command run when call =compile=
1556 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1557 to call =compilation= interactively.
1558 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1559 (defun my-perl-hook ()
1561 (setq-local compilation-read-command nil)
1562 (set (make-local-variable 'compile-command)
1563 (concat "/usr/bin/perl "
1564 (if buffer-file-name
1565 (shell-quote-argument buffer-file-name))))
1566 (local-set-key (kbd "s-r")
1569 ; (setq current-prefix-arg '(4)) ; C-u
1570 (call-interactively 'compile)))))
1572 (add-hook 'cperl-mode-hook 'my-perl-hook)
1576 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1577 (setq c-default-style "stroustrup"
1582 Set the environments vairables in compilation mode
1583 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1584 (use-package compile
1587 (setq compilation-environment (cons "LC_ALL=C" compilation-environment))
1588 (setq compilation-auto-jump-to-first-error t)
1589 (setq compilation-auto-jump-to-next t)
1590 (setq compilation-scroll-output 'first-error))
1592 ;; super-r to compile
1593 (with-eval-after-load "compile"
1594 (define-key compilation-mode-map (kbd "C-o") nil)
1595 (define-key compilation-mode-map (kbd "n") 'compilation-next-error)
1596 (define-key compilation-mode-map (kbd "p") 'compilation-previous-error)
1597 (define-key compilation-mode-map (kbd "r") #'recompile))
1601 ** Enable auto-insert mode
1602 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1603 (auto-insert-mode t)
1604 (setq auto-insert-query nil)
1608 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1609 (eval-after-load 'autoinsert
1610 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1612 "Short description:"
1614 "\n * " (file-name-nondirectory (buffer-file-name))
1616 "#include <iostream>" \n
1618 (file-name-sans-extension
1619 (file-name-nondirectory (buffer-file-name)))
1621 "using namespace std;" \n \n
1629 (eval-after-load 'autoinsert
1630 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1632 "Short description:"
1634 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1636 "#include <stdio.h>" \n
1638 (file-name-sans-extension
1639 (file-name-nondirectory (buffer-file-name)))
1650 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1651 (eval-after-load 'autoinsert
1652 '(define-auto-insert '("\\.\\(py\\)\\'" . "Python skeleton")
1661 Emacs lisp auto-insert, based on the default module in =autoinsert.el=, but replace =completing-read= as
1662 =completing-read-ido-ubiquitous= to fix the edge case of that =ido= cannot handle.
1663 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1664 (eval-after-load 'autoinsert
1665 '(define-auto-insert '("\\.el\\'" . "my Emacs Lisp header")
1667 "Short description: "
1668 ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str
1669 (make-string (max 2 (- 80 (current-column) 27)) ?\s)
1670 "-*- lexical-binding: t; -*-" '(setq lexical-binding t)
1672 ;; Copyright (C) " (format-time-string "%Y") " "
1673 (getenv "ORGANIZATION") | (progn user-full-name) "
1675 ;; Author: " (user-full-name)
1676 '(if (search-backward "&" (line-beginning-position) t)
1677 (replace-match (capitalize (user-login-name)) t t))
1678 '(end-of-line 1) " <" (progn user-mail-address) ">
1681 ;;'(setq v1 (apply 'vector (mapcar 'car finder-known-keywords)))
1682 '(setq v1 (mapcar (lambda (x) (list (symbol-name (car x))))
1683 finder-known-keywords)
1684 v2 (mapconcat (lambda (x) (format "%12s: %s" (car x) (cdr x)))
1685 finder-known-keywords
1687 ((let ((minibuffer-help-form v2))
1688 (completing-read-ido-ubiquitous "Keyword, C-h: " v1 nil t))
1691 \;; This program is free software; you can redistribute it and/or modify
1692 \;; it under the terms of the GNU General Public License as published by
1693 \;; the Free Software Foundation, either version 3 of the License, or
1694 \;; (at your option) any later version.
1696 \;; This program is distributed in the hope that it will be useful,
1697 \;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1698 \;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1699 \;; GNU General Public License for more details.
1701 \;; You should have received a copy of the GNU General Public License
1702 \;; along with this program. If not, see <http://www.gnu.org/licenses/>.
1714 \;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")))
1717 ** Org file template
1718 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1719 (eval-after-load 'autoinsert
1720 '(define-auto-insert '("\\.\\(org\\)\\'" . "Org-mode skeleton")
1723 "#+TITLE: " str (make-string 30 ?\s) > \n
1724 "#+AUTHOR: Peng Li\n"
1725 "#+EMAIL: seudut@gmail.com\n"
1726 "#+DATE: " (shell-command-to-string "echo -n $(date +%Y-%m-%d)") > \n
1732 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1733 (use-package markdown-mode
1735 :commands (markdown-mode gfm-mode)
1736 :mode (("README\\.md\\'" . gfm-mode)
1737 ("\\.md\\'" . markdown-mode)
1738 ("\\.markdown\\'" . markdown-mode))
1739 :init (setq markdown-command "multimarkdown"))
1742 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1743 (use-package markdown-preview-eww
1749 Refer [[https://www.emacswiki.org/emacs/GnusGmail][GnusGmail]]
1750 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1751 (setq user-mail-address "seudut@gmail.com"
1752 user-full-name "Peng Li")
1754 (setq gnus-select-method
1756 (nnimap-address "imap.gmail.com")
1757 (nnimap-server-port "imaps")
1758 (nnimap-stream ssl)))
1760 (setq smtpmail-smtp-service 587
1761 gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
1763 ;; Use gmail sending mail
1764 (setq message-send-mail-function 'smtpmail-send-it
1765 smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
1766 smtpmail-auth-credentials '(("smtp.gmail.com" 587 "seudut@gmail.com" nil))
1767 smtpmail-default-smtp-server "smtp.gmail.com"
1768 smtpmail-smtp-server "smtp.gmail.com"
1769 smtpmail-smtp-service 587
1770 starttls-use-gnutls t)
1773 And put the following in =~/.authinfo= file, replacing =<USE>= with your email address
1774 and =<PASSWORD>= with the password
1776 machine imap.gmail.com login <USER> password <PASSWORD> port imaps
1777 machine smtp.gmail.com login <USER> password <PASSWORD> port 587
1783 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1786 (setq gnus-permanently-visible-groups "\.*")
1788 (cond (window-system
1789 (setq custom-background-mode 'light)
1790 (defface my-group-face-1
1791 '((t (:foreground "Red" :bold t))) "First group face")
1792 (defface my-group-face-2
1793 '((t (:foreground "DarkSeaGreen4" :bold t)))
1794 "Second group face")
1795 (defface my-group-face-3
1796 '((t (:foreground "Green4" :bold t))) "Third group face")
1797 (defface my-group-face-4
1798 '((t (:foreground "SteelBlue" :bold t))) "Fourth group face")
1799 (defface my-group-face-5
1800 '((t (:foreground "Blue" :bold t))) "Fifth group face")))
1801 (setq gnus-group-highlight
1802 '(((> unread 200) . my-group-face-1)
1803 ((and (< level 3) (zerop unread)) . my-group-face-2)
1804 ((< level 3) . my-group-face-3)
1805 ((zerop unread) . my-group-face-4)
1806 (t . my-group-face-5))))
1810 (add-hook 'gnus-group-mode-hook (lambda ()
1811 (define-key gnus-group-mode-map "k" 'gnus-group-prev-group)
1812 (define-key gnus-group-mode-map "j" 'gnus-group-next-group)
1813 (define-key gnus-group-mode-map "g" 'gnus-group-jump-to-group)
1814 (define-key gnus-group-mode-map "v" (lambda () (interactive) (gnus-group-select-group t)))))
1817 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1818 (setq gnus-fetch-old-headers 't)
1822 (setq gnus-extract-address-components
1823 'mail-extract-address-components)
1825 (setq gnus-summary-line-format "%U%R%z%I%(%[%-20,20f%]%) %s%-80= %11&user-date;\n")
1826 (setq gnus-user-date-format-alist '(((gnus-seconds-today) . "%H:%M")
1827 ((+ 86400 (gnus-seconds-today)) . "%a %H:%M")
1828 (604800 . "%a, %b %-d")
1829 (15778476 . "%b %-d")
1832 (setq gnus-thread-sort-functions '((not gnus-thread-sort-by-number)))
1833 (setq gnus-unread-mark ?\.)
1834 (setq gnus-use-correct-string-widths t)
1837 (setq gnus-thread-hide-subtree t)
1839 ;; (with-eval-after-load 'gnus-summary-mode
1840 ;; (define-key gnus-summary-mode-map (kbd "C-o") 'sd/hydra-window/body))
1842 (add-hook 'gnus-summary-mode-hook (lambda ()
1843 (define-key gnus-summary-mode-map (kbd "C-o") nil)))
1849 See [[https://www.emacswiki.org/emacs/GnusWindowLayout][GnusWindowLayout]]
1850 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1851 (gnus-add-configuration
1857 (summary 1.0 poine)))))
1859 (gnus-add-configuration
1865 (summary 0.50 point)
1868 (with-eval-after-load 'gnus-group-mode
1869 (gnus-group-select-group "INBOX"))
1870 ;; (add-hook 'gnus-group-mode-map (lambda ()
1871 ;; (gnus-group-select-group "INBOX")))
1875 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=
1876 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1877 (use-package gnuplot
1880 (setq gnuplot-help-xpm nil)
1881 (setq gnuplot-line-xpm nil)
1882 (setq gnuplot-region-xpm nil)
1883 (setq gnuplot-buffer-xpm nil)
1884 (setq gnuplot-doc-xpm nil))
1887 Use =gnuplot= on =Org-mode= file, see [[http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-gnuplot.html][ob-doc-gnuplot]]
1888 #+BEGIN_SRC gnuplot :exports code :file ./temp/file.png
1891 set title "Putting it All Together"
1904 h(x) = 10*sqrt(abs(x))
1906 plot f(x) w lp lw 1, g(x) w p lw 2, h(x) w l lw 3
1910 [[file:./temp/file.png]]
1912 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1913 (with-eval-after-load 'ediff
1914 (setq ediff-split-window-function 'split-window-horizontally)
1915 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
1916 (add-hook 'ediff-startup-hook 'ediff-toggle-wide-display)
1917 (add-hook 'ediff-cleanup-hook 'ediff-toggle-wide-display)
1918 (add-hook 'ediff-suspend-hook 'ediff-toggle-wide-display))
1923 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
1924 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1929 (require 'gnugo-imgen)
1930 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1931 (add-hook 'gnugo-start-game-hook '(lambda ()
1932 (gnugo-image-display-mode)
1935 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1939 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1940 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1944 (setq emms-directory (concat sd-temp-directory "emms"))
1945 (setq emms-source-file-default-directory "~/Music/")
1948 (emms-default-players)
1949 (define-emms-simple-player mplayer '(file url)
1950 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1951 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1952 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1953 ".m4a" ".flv" ".ogv" ".pls"))
1954 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1955 (emms-history-load))
1959 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1960 (use-package bing-dict
1963 (global-set-key (kbd "s-d") 'bing-dict-brief)
1964 :commands (bing-dict-brief))
1968 Here are some global key bindings for basic editting
1969 ** Esc in minibuffer
1970 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
1971 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1972 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
1973 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
1974 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
1975 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
1976 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
1977 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
1978 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
1979 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
1980 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
1982 ;; Also map s-h same as C-g
1983 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
1986 ** Project operations - =super=
1988 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1989 (use-package projectile
1992 (setq projectile-enable-caching t)
1993 (setq projectile-cache-file (concat sd-temp-directory "projectile.cache"))
1995 (add-to-list 'projectile-globally-ignored-files "GTAGS")
1996 (projectile-global-mode t))
1998 (use-package persp-projectile
2003 (:map projectile-mode-map
2004 ("s-t" . projectile-persp-switch-project)))
2006 ;; projectile-find-file
2007 ;; projectile-switch-buffer
2008 ;; projectile-find-file-other-window
2011 *** project config =super= keybindings
2012 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2013 ;; (global-set-key (kbd "s-h") 'keyboard-quit)
2014 ;; (global-set-key (kbd "s-j") 'ido-switch-buffer)
2015 ;; (global-set-key (kbd "s-k") 'ido-find-file)
2016 ;; (global-set-key (kbd "s-l") 'sd/delete-current-window)
2017 ;; s-l --> goto-line
2018 ;; (global-set-key (kbd "s-/") 'swiper)
2020 ;; s-' --> 'next-multiframe-window
2021 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
2023 (global-set-key (kbd "s-f") 'projectile-find-file)
2024 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
2026 (global-set-key (kbd "s-n") 'persp-next)
2027 (global-set-key (kbd "s-p") 'persp-prev)
2029 (global-set-key (kbd "s-=") 'text-scale-increase)
2030 (global-set-key (kbd "s--") 'text-scale-decrease)
2032 ;; (global-set-key (kbd "s-u") 'undo-tree-visualize)
2035 ;; someothers default mapping on super (command) key
2037 ;; s-k kill-this-buffer
2040 ;; s-h --> ns-do-hide-emacs
2041 ;; s-j --> ido-switch-buffer +
2042 ;; s-k --> kill-this-buffer
2043 ;; s-l --> goto-line
2044 ;; s-; --> undefined
2045 ;; s-' --> next-multiframe-window
2046 ;; s-ret --> toggle-frame-fullscreen +
2048 ;; s-y --> ns-paste-secondary
2049 ;; s-u --> revert-buffer
2050 ;; s-i --> undefined - but used for iterm globally
2051 ;; s-o --> used for emacs globally
2052 ;; s-p --> projectile-persp-switch-project +
2053 ;; s-[ --> next-buffer +
2054 ;; s-] --> previous-buffer +
2056 ;; s-0 --> undefined
2057 ;; s-9 --> undefined
2058 ;; s-8 --> undefined
2059 ;; s-7 --> undefined
2060 ;; s-6 --> undefined
2061 ;; s-- --> center-line
2062 ;; s-= --> undefined
2064 ;; s-n --> make-frame
2065 ;; s-m --> iconify-frame
2066 ;; s-b --> undefined
2067 ;; s-, --> customize
2068 ;; s-. --> undefined
2069 ;; s-/ --> undefined
2071 ;; s-g --> isearch-repeat-forward
2072 ;; s-f --> projectile-find-file +
2073 ;; s-d --> isearch-repeat-background
2074 ;; s-s --> save-buffer
2075 ;; s-a --> make-whole-buffer
2077 ;; s-b --> undefined
2079 ;; s-c --> ns-copy-including-secondary
2081 ;; s-t --> ns-popup-font-panel
2082 ;; s-r --> undefined
2083 ;; s-e --> isearch-yanqk-kill
2084 ;; s-w --> delete-frame
2085 ;; s-q --> same-buffers-kill-emacs
2087 ;; s-` --> other-frame
2090 ** Windown & Buffer - =C-o=
2091 Defind a =hydra= function for windows, buffer & bookmark operations. And map it to =C-o= globally.
2092 Most use =C-o C-o= to switch buffers; =C-o x, v= to split window; =C-o o= to delete other windows
2093 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2096 (defun sd/delete-current-window ()
2098 (if (> (length (window-list)) 1)
2100 (message "Only one Windows now!")))
2102 (defun sd/toggle-max-windows ()
2103 "Set maximize current if there are multiple windows, if only
2104 one window, window undo"
2106 (if (equal (length (window-list)) 1)
2108 (delete-other-windows)))
2110 (defhydra sd/hydra-window (:color red :columns nil)
2113 ("h" windmove-left nil :exit t)
2114 ("j" windmove-down nil :exit t)
2115 ("k" windmove-up nil :exit t)
2116 ("l" windmove-right nil :exit t)
2117 ("H" hydra-move-splitter-left nil)
2118 ("J" hydra-move-splitter-down nil)
2119 ("K" hydra-move-splitter-up nil)
2120 ("L" hydra-move-splitter-right nil)
2123 (split-window-right)
2128 (split-window-below)
2132 ;; buffer / windows switch
2133 ("o" sd/toggle-max-windows "one" :exit t)
2134 ("C-k" sd/delete-current-window "del" :exit t)
2135 ("'" other-window "other" :exit t)
2136 ;; ("a" ace-window "ace")
2137 ("s" ace-swap-window "swap")
2138 ;; ("i" ace-maximize-window "ace-one" :exit t)
2140 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
2141 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
2143 ;; ibuffer, dired, eshell, bookmarks
2144 ;; ("d" ace-delete-window "ace-one" :exit t)
2145 ("C-o" ido-switch-buffer nil :exit t)
2146 ("d" dired-jump nil :exit t)
2147 ("b" ibuffer nil n:exit t)
2148 ("e" eshell nil :exit t)
2149 ("m" bookmark-jump-other-window nil :exit t)
2150 ("M" bookmark-set nil :exit t)
2151 ("g" magit-status nil :exit t)
2152 ("p" paradox-list-packages nil :exit t)
2157 ("C-h" nil nil :exit t)
2158 ("C-j" nil nil :exit t)
2159 ;; ("C-k" nil :exit t)
2160 ("C-l" nil nil :exit t)
2161 ("C-;" nil nil :exit t)
2162 ("n" nil nil :exit t)
2163 ("[" nil nil :exit t)
2164 ("]" nil nil :exit t)
2167 (global-unset-key (kbd "C-o"))
2168 (global-set-key (kbd "C-o") 'sd/hydra-window/body)
2173 [[https://www.masteringemacs.org/article/effective-editing-movement][effective-editing-movement]]
2174 *** Command Arguments, numeric argumens
2175 =C-u 4= same as =C-4=, =M-4=
2177 moving by line / word /
2178 =C-f=, =C-b=, =C-p=, =C-n=, =M-f=, =M-b=
2180 =M-m= (move first non-whitespace on this line)
2181 =M-}=, =M-{=, Move forward end of paragraph
2182 =M-a=, =M-e=, beginning / end of sentence
2183 =C-M-a=, =C-M-e=, move begining of defun
2184 =C-x ]=, =C-x [=, forward/backward one page
2185 =C-v=, =M-v=, =C-M-v=, =C-M-S-v= scroll down/up
2186 =M-<=, =M->=, beginning/end of buffer
2187 =M-r=, Repositiong point
2189 *** Moving by S-expression / List
2191 =C-<SPC>= set marks toggle the region
2192 =C-u C-<SPC>= Jump to the mark, repeated calls go further back the mark ring
2193 =C-x C-x= Exchanges the point and mark.
2195 Stolen [[https://www.masteringemacs.org/article/fixing-mark-commands-transient-mark-mode][fixing-mark-commands-transient-mark-mode]]
2196 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2197 (defun push-mark-no-activate ()
2198 "Pushes `point' to `mark-ring' and does not activate the region
2199 Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
2201 (push-mark (point) t nil)
2202 (message "Pushed mark to ring"))
2204 ;; (global-set-key (kbd "C-`") 'push-mark-no-activate)
2206 (defun jump-to-mark ()
2207 "Jumps to the local mark, respecting the `mark-ring' order.
2208 This is the same as using \\[set-mark-command] with the prefix argument."
2210 (set-mark-command 1))
2212 ;; (global-set-key (kbd "M-`") 'jump-to-mark)
2214 (defun exchange-point-and-mark-no-activate ()
2215 "Identical to \\[exchange-point-and-mark] but will not activate the region."
2217 (exchange-point-and-mark)
2218 (deactivate-mark nil))
2220 ;; (define-key global-map [remap exchange-point-and-mark] 'exchange-point-and-mark-no-activate)
2223 Show the mark ring using =helm-mark-ring=, also mapping =M-`= to quit minibuffer. so that =M-`= can
2224 toggle the mark ring. the best way is add a new action and mapping to =helm-source-mark-ring=, but
2225 since there is no map such as =helm-mark-ring=map=, so I cannot binding a key to the quit action.
2226 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2227 (setq mark-ring-max 50)
2228 (global-set-key (kbd "M-`") #'helm-mark-ring)
2230 (define-key minibuffer-local-map (kbd "M-`") 'keyboard-escape-quit)
2233 =M-h= marks the next paragraph
2234 =C-x h= marks the whole buffer
2235 =C-M-h= marks the next defun
2236 =C-x C-p= marks the next page
2238 Registers can save text, position, rectangles, file and configuration and other things.
2239 Here for movement, we can use register to save/jump position
2240 =C-x r SPC= store point in register
2241 =C-x r j= jump to register
2242 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2243 (use-package list-register
2248 As I would like use bookmakr for different buffer/files. to help to swith
2249 different buffer/file quickly. this setting is in Windows/buffer node
2250 =C-x r m= set a bookmarks
2251 =C-x r l= list bookmarks
2252 =C-x r b= jump to bookmarks
2255 Search, replace and hightlight will in later paragraph
2256 *** =Avy= for easy motion
2257 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2261 (avy-setup-default))
2263 (global-set-key (kbd "C-M-j") 'avy-goto-line-below)
2264 (global-set-key (kbd "C-M-n") 'avy-goto-line-below)
2265 (global-set-key (kbd "C-M-k") 'avy-goto-line-above)
2266 (global-set-key (kbd "C-M-p") 'avy-goto-line-above)
2268 (global-set-key (kbd "C-M-f") 'avy-goto-word-1-below)
2269 (global-set-key (kbd "C-M-b") 'avy-goto-word-1-above)
2271 ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
2272 (global-set-key (kbd "C-M-w") 'avy-goto-char-timer)
2273 (global-set-key (kbd "C-M-l") 'avy-goto-char-in-line)
2275 ;; ;; will delete above
2276 ;; (global-set-key (kbd "M-g j") 'avy-goto-line-below)
2277 ;; (global-set-key (kbd "M-g k") 'avy-goto-line-above)
2278 ;; (global-set-key (kbd "M-g w") 'avy-goto-word-1-below)
2279 ;; (global-set-key (kbd "M-g b") 'avy-goto-word-1-above)
2280 ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
2281 ;; (global-set-key (kbd "M-g f") 'avy-goto-char-timer)
2282 ;; (global-set-key (kbd "M-g c") 'avy-goto-char-in-line)
2285 *** =Imenu= goto tag
2286 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2287 ;; (global-set-key (kbd "M-i") #'counsel-imenu)
2288 (global-set-key (kbd "M-i") #'imenu)
2290 ;; (global-set-key (kbd "M-l") 'goto-line)
2294 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2295 (global-set-key (kbd "M-l") 'goto-line)
2300 - cut, yank, =C-w=, =C-y=
2302 - undo, redo - undo-tree
2303 - select, expand-region
2304 - spell check, flyspell
2307 =helm-show-kill-ring=
2308 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2309 (setq kill-ring-max 100) ; default is 60p
2310 (global-set-key (kbd "M-y") #'helm-show-kill-ring)
2314 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2315 (use-package undo-tree
2318 (define-key undo-tree-visualizer-mode-map "j" 'undo-tree-visualize-redo)
2319 (define-key undo-tree-visualizer-mode-map "k" 'undo-tree-visualize-undo)
2320 (define-key undo-tree-visualizer-mode-map "h" 'undo-tree-visualize-switch-branch-left)
2321 (define-key undo-tree-visualizer-mode-map "l" 'undo-tree-visualize-switch-branch-right)
2322 (global-undo-tree-mode 1))
2324 (global-set-key (kbd "s-u") 'undo-tree-visualize)
2328 Stolen from [[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-spelling.el][here]], hunspell will search dictionary in =DICPATH=
2329 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2330 (setenv "DICPATH" "/usr/local/share/hunspell")
2332 (when (executable-find "hunspell")
2333 (setq-default ispell-program-name "hunspell")
2334 (setq ispell-really-hunspell t))
2336 ;; (defun text-mode-hook-setup ()
2337 ;; ;; Turn off RUN-TOGETHER option when spell check text-mode
2338 ;; (setq-local ispell-extra-args (flyspell-detect-ispell-args)))
2339 ;; (add-hook 'text-mode-hook 'text-mode-hook-setup)
2340 ;; (add-hook 'text-mode-hook 'flyspell-mode)
2342 ;; enable flyspell check on comments and strings in progmamming modes
2343 ;; (add-hook 'prog-mode-hook 'flyspell-prog-mode)
2345 ;; I don't use the default mappings
2346 (with-eval-after-load 'flyspell
2347 (define-key flyspell-mode-map (kbd "C-;") nil)
2348 (define-key flyspell-mode-map (kbd "C-,") nil)
2349 (define-key flyspell-mode-map (kbd "C-.") nil))
2352 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]]
2353 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2354 ;; NO spell check for embedded snippets
2355 (defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
2356 (let ((rlt ad-return-value)
2357 (begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\)")
2358 (end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\)")
2361 (when ad-return-value
2363 (setq old-flag case-fold-search)
2364 (setq case-fold-search t)
2365 (setq b (re-search-backward begin-regexp nil t))
2366 (if b (setq e (re-search-forward end-regexp nil t)))
2367 (setq case-fold-search old-flag))
2368 (if (and b e (< (point) e)) (setq rlt nil)))
2369 (setq ad-return-value rlt)))
2372 ** Search & Replace / hightlight =M-s=
2375 =C-w= add word at point to search string,
2377 =C-M-y= add character at point to search string
2378 =M-s C-e= add reset of line at point
2379 =C-y= yank from clipboard to search string
2380 =M-n=, =M-p=, history
2381 =C-M-i= complete search string
2382 set the isearch history size, the default is only =16=
2383 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2384 (setq history-length 5000)
2385 (setq regexp-search-ring-max 1000)
2386 (setq search-ring-max 1000)
2388 ;; when search a word or a symbol , also add the word into regexp-search-ring
2389 (defadvice isearch-update-ring (after sd/isearch-update-ring (string &optional regexp) activate)
2390 "Add search-ring to regexp-search-ring"
2392 (add-to-history 'regexp-search-ring string regexp-search-ring-max)))
2396 use the prefix =M-s= for searching in buffers
2397 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2398 (defun sd/make-keymap (key bindings)
2399 (setq keymap (make-sparse-keymap))
2400 (dolist (binding bindings)
2401 (define-key keymap (car binding) (cdr binding)))
2402 (global-set-key key keymap))
2404 ;; (sd/make-keymap "\M-s"
2405 ;; '(("w" . save-buffer)
2406 ;; ;; ("\M-w" . save-buffer)
2407 ;; ("e" . revert-buffer)
2408 ;; ("s" . isearch-forward-regexp)
2409 ;; ("\M-s" . isearch-forward-regexp)
2410 ;; ("r" . isearch-backward-regexp)
2411 ;; ("." . isearch-forward-symbol-at-point)
2413 ;; ;; ("h" . highlight-symbol-at-point)
2414 ;; ("h" . highlight-symbol)
2415 ;; ("m" . highlight-regexp)
2416 ;; ("l" . highlight-lines-matching-regexp)
2417 ;; ("M" . unhighlight-regexp)
2418 ;; ("f" . keyboard-quit)
2419 ;; ("q" . keyboard-quit)))
2422 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2423 (use-package highlight-symbol
2426 (defhydra sd/search-replace (:color red :columns nil)
2428 ("w" save-buffer "save" :exit t)
2429 ("e" revert-buffer "revert" :exit t)
2430 ("u" undo-tree-visualize "undo" :exit t)
2431 ("s" isearch-forward-regexp "s-search" :exit t)
2432 ("M-s" isearch-forward-regexp "s-search" :exit t)
2433 ("r" isearch-backward-regexp "r-search" :exit t)
2434 ("." isearch-forward-symbol-at-point "search point" :exit t)
2435 ("/" swiper "swiper" :exit t)
2436 ("o" occur "occur" :exit t)
2437 ("h" highlight-symbol "higlight" :exit t)
2438 ("l" highlight-lines-matching-regexp "higlight line" :exit t)
2439 ("m" highlight-regexp "higlight" :exit t)
2440 ("M" unhighlight-regexp "unhiglight" :exit t)
2444 (global-unset-key (kbd "M-s"))
2445 (global-set-key (kbd "M-s") 'sd/search-replace/body)
2448 ;; search and replace and highlight
2449 (define-key isearch-mode-map (kbd "M-s") 'isearch-repeat-forward)
2450 (define-key isearch-mode-map (kbd "M-r") 'isearch-repeat-backward)
2451 (global-set-key (kbd "s-[") 'highlight-symbol-next)
2452 (global-set-key (kbd "s-]") 'highlight-symbol-prev)
2453 (global-set-key (kbd "s-\\") 'highlight-symbol-query-replace)
2457 Occur search key bindings
2458 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2459 (defun sd/occur-keys ()
2460 "My key bindings in occur-mode"
2462 (switch-to-buffer-other-window "*Occur*")
2463 (define-key occur-mode-map (kbd "C-o") nil)
2464 (define-key occur-mode-map (kbd "C-n") (lambda ()
2467 (occur-mode-goto-occurrence-other-window)
2470 (define-key occur-mode-map (kbd "C-p") (lambda ()
2473 (occur-mode-goto-occurrence-other-window)
2477 (add-hook 'occur-hook #'sd/occur-keys)
2479 (use-package color-moccur
2481 :commands (isearch-moccur isearch-all)
2483 (setq isearch-lazy-highlight t)
2485 (use-package moccur-edit))
2489 stolen from [[https://github.com/mariolong/emacs.d/blob/f6a061594ef1b5d1f4750e9dad9dc97d6e122840/emacs-init.org][here]]
2490 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2494 (setq ivy-use-virtual-buffers t)
2495 (set-face-attribute 'ivy-current-match nil :background "Orange" :foreground "black")
2498 (global-set-key (kbd "s-/") 'swiper)
2499 (define-key swiper-map (kbd "M-r") 'swiper-query-replace)
2500 (define-key swiper-map (kbd "C-.") (lambda ()
2502 (insert (format "%s" (with-ivy-window (thing-at-point 'word))))))
2503 (define-key swiper-map (kbd "M-.") (lambda ()
2505 (insert (format "%s" (with-ivy-window (thing-at-point 'symbol)))))))
2508 ** Expand region map
2509 *** Install =expand-region=
2510 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2511 (use-package expand-region
2514 ;; (global-set-key (kbd "C-=") 'er/expand-region)
2518 *** Add a =hydra= map for =expand-region= operations
2519 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2520 (defun sd/mark-line ()
2521 "Mark current line without whitespace beginning"
2523 (back-to-indentation)
2524 (set-mark (line-end-position)))
2526 (defhydra sd/expand-selected (:color red :columns nil
2527 ;; :post (deactivate-mark)
2531 ;; ("e" er/expand-region "+")
2532 ("SPC" er/expand-region "+")
2533 ;; ("c" er/contract-region "-")
2534 ("S-SPC" er/contract-region "-")
2537 (er/contract-region 0))
2540 ("i'" er/mark-inside-quotes "in")
2541 ("i\"" er/mark-inside-quotes nil)
2542 ("o'" er/mark-outside-quotes "out")
2543 ("o\"" er/mark-outside-quotes nil)
2545 ("i{" er/mark-inside-pairs nil)
2546 ("i(" er/mark-inside-pairs nil)
2547 ("o{" er/mark-inside-pairs nil)
2548 ("o(" er/mark-inside-pairs nil)
2550 ("p" er/mark-paragraph "paragraph")
2552 ("l" sd/mark-line "line")
2553 ("u" er/mark-url "url")
2554 ("f" er/mark-defun "fun")
2555 ("n" er/mark-next-accessor "next")
2557 ("x" exchange-point-and-mark "exchange")
2560 ;; ("h" backward-char nil)
2561 ;; ("j" next-line nil)
2562 ;; ("k" previous-line nil)
2563 ;; ("l" foreward-char nil)
2569 ("d" kill-region "delete" :exit t)
2571 ("y" kill-ring-save "yank" :exit t)
2572 ;; ("M-SPC" nil "quit" :exit t)
2573 ("C-SPC" nil "quit" :exit t)
2574 ("q" nil "quit" :exit t))
2576 (global-set-key (kbd "C-SPC") (lambda ()
2578 (set-mark-command nil)
2580 (sd/expand-selected/body)))
2583 *** TODO make expand-region hydra work with lispy selected
2585 * TODO Convert ASCII to key
2586 ** map =function-key-map= [[http://academic.evergreen.edu/projects/biophysics/technotes/program/ascii_ctrl.htm][ascii_ctrl]]
2587 new file =C-x C-f C-f=
2589 ** write color syntax for =Man-mode=
2591 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2592 (font-lock-add-keywords 'perl-mode '(("\\(|\\w+?\\(,\\w+?\\)?|\\)" 1 'py-builtins-face)))
2595 * TODO jump last change point
2596 * TODO emms mode-line
2598 * =C-u C-h a= search funtions
2607 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2609 ;; M-h - mark-paragraph
2610 ;; M-j - new line indent
2611 ;; M-k - kill-sentence
2612 ;; M-l - downcase words ====== goto-line
2614 ;; M-'- abbrev-prefix-mark =======
2615 ;; M-RET none ======
2618 ;; M-u - upcase word
2619 ;; M-i - ====== imenu
2620 ;; M-o ====== prefix
2624 ;; M-\ deleter horizontal space =====
2628 ;; M-, --- mark stack====== =
2629 ;; M-. lisp-goto-symboo, find definitation
2637 ;; M-q - lisp fill, fill paragraph
2640 ;; M-r - rePositioning
2641 ;; M-t transpose word
2645 ;; M-c capitalize-word