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)
89 *** Save minibuffer history
90 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
92 (setq history-length 1000)
96 Make a temp directory for all cache/history files
97 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
98 (defconst sd-temp-directory
99 (file-name-as-directory "~/.emacs.d/temp"))
101 (unless (file-exists-p sd-temp-directory)
102 (mkdir sd-temp-directory))
105 * Package Management Tools
109 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
111 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
113 (unless (package-installed-p 'use-package)
114 (package-refresh-contents)
115 (package-install 'use-package))
117 (require 'use-package)
123 [[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.
124 Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
126 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
131 (add-to-list 'load-path "~/.emacs.d/el-get"))
135 * Color and Fonts Settings
137 ** highlight current line
139 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
141 (global-hl-line-mode)
147 [[https://github.com/paldepind/smart-comment][smart-comments]]
149 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
151 (use-package smart-comment
153 :bind ("M-;" . smart-conmment))
161 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
163 (global-font-lock-mode 1)
167 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
169 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
172 (defvar sd/fixed-font-family
173 (cond ((x-list-fonts "Hasklig") "Hasklig")
174 ((x-list-fonts "Source Code Pro") "Source Code Pro:weight:light")
175 ((x-list-fonts "Anonymous Pro") "Anonymous Pro")
176 ((x-list-fonts "M+ 1mn") "M+ 1mn"))
177 "The fixed width font based on what is installed, `nil' if not defined."))
183 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
186 (when sd/fixed-font-family
187 (set-frame-font sd/fixed-font-family)
188 (set-face-attribute 'default nil :font sd/fixed-font-family :height 130)
189 (set-face-font 'default sd/fixed-font-family)))
195 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
197 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
199 (setq vc-follow-symlinks t)
201 (use-package color-theme
203 :init (require 'color-theme)
204 :config (use-package color-theme-sanityinc-tomorrow
208 (load-theme 'sanityinc-tomorrow-bright t)))
210 ;(eval-after-load 'color-theme
211 ; (load-theme 'sanityinc-tomorrow-bright t))
215 Change the Org-mode colors
217 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
219 (defun org-src-color-blocks-light ()
220 "Colors the block headers and footers to make them stand out more for lighter themes"
223 '(org-block-begin-line
224 ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
225 '(org-block-background
226 ((t (:background "#FFFFEA"))))
228 ((t (:background "#FFFFEA"))))
230 ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
232 '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
233 '(which-func ((t (:foreground "#008000"))))))
235 (defun org-src-color-blocks-dark ()
236 "Colors the block headers and footers to make them stand out more for dark themes"
239 '(org-block-begin-line
240 ((t (:foreground "#008ED1" :background "#002E41"))))
241 '(org-block-background
242 ((t (:background "#000000"))))
244 ((t (:background "#000000"))))
246 ((t (:foreground "#008ED1" :background "#002E41"))))
248 '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
249 '(which-func ((t (:foreground "green"))))))
251 (org-src-color-blocks-dark)
255 improve color for org-mode
256 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
257 (deftheme ha/org-theme "Sub-theme to beautify org mode")
260 (defvar sd/variable-font-tuple
261 (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
262 ((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
263 ((x-list-fonts "Verdana") '(:font "Verdana"))
264 ((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
265 (nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro.")))
266 "My variable width font available to org-mode files and whatnot."))
268 (defun sd/org-color ()
269 (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
270 (base-font-color (face-foreground 'default nil 'default))
271 (background-color (face-background 'default nil 'default))
272 (primary-color (face-foreground 'mode-line nil))
273 (secondary-color (face-background 'secondary-selection nil 'region))
274 (base-height (face-attribute 'default :height))
275 (headline `(:inherit default :weight bold :foreground ,base-font-color)))
276 (custom-theme-set-faces 'ha/org-theme
277 `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
278 `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
279 `(org-table ((t (:inherit 'fixed-pitched))))
280 `(org-block ((t (:inherit 'fixed-pitched))))
281 `(org-block-background ((t (:inherit 'fixed-pitched))))
282 `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
283 `(org-block-end-line ((t (:inherit 'fixed-pitched))))
284 `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
285 `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
286 `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
287 `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
288 `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
289 :height ,(round (* 1.1 base-height))))))
290 `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
291 :height ,(round (* 1.25 base-height))))))
292 `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
293 :height ,(round (* 1.5 base-height))))))
294 `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
295 :height ,(round (* 1.75 base-height))))))
296 `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
303 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
305 (use-package rainbow-delimiters
308 (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
314 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
316 (use-package page-break-lines
319 (turn-on-page-break-lines-mode))
325 Enable rainbow mode in emacs lisp mode
327 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
328 (use-package rainbow-mode
331 ; (add-hook emacs-lisp-mode-hook 'rainbow-mode)
340 clean mode line, Refer to [[https://www.masteringemacs.org/article/hiding-replacing-modeline-strings][Marstering Emacs]]
342 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
343 (defvar mode-line-cleaner-alist
344 `((auto-complete-mode . " α")
345 (yas/minor-mode . " Ï…")
346 (paredit-mode . " π")
349 (projectile-mode . "")
351 (undo-tree-mode . "")
353 (which-key-mode . "")
355 (smartparens-mode . "")
357 (linum-relative-mode . "")
359 (auto-revert-mode . "")
361 (org-indent-mode . "")
365 (lisp-interaction-mode . "λ")
368 (emacs-lisp-mode . "EL")
370 (nxhtml-mode . "nx"))
371 "Alist for `clean-mode-line'.
373 When you add a new element to the alist, keep in mind that you
374 must pass the correct minor/major mode symbol and a string you
375 want to use in the modeline *in lieu of* the original.")
378 (defun clean-mode-line ()
380 (loop for cleaner in mode-line-cleaner-alist
381 do (let* ((mode (car cleaner))
382 (mode-str (cdr cleaner))
383 (old-mode-str (cdr (assq mode minor-mode-alist))))
385 (setcar old-mode-str mode-str))
387 (when (eq mode major-mode)
388 (setq mode-name mode-str)))))
391 (add-hook 'after-change-major-mode-hook 'clean-mode-line)
396 Install powerline mode [[https://github.com/milkypostman/powerline][powerline]]
398 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
399 (use-package powerline
402 ;; (powerline-center-theme)
405 ;; (use-package smart-mode-line
407 ;; (use-package smart-mode-line-powerline-theme
411 Revised powerline-center-theme
412 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
413 (defun sd/powerline-simpler-vc (s)
415 (replace-regexp-in-string "Git[:-]" "" s)
418 (defface sd/powerline-active1 '((t (:background "yellow" :foreground "black" :inherit mode-line)))
419 "My Powerline face 1 based on powerline-active1."
422 (defface sd/buffer-modified-active1 '((t (:background "red" :foreground "black" :inherit mode-line)))
423 "My Powerline face 1 based on powerline-active1."
426 (defface sd/buffer-view-active1 '((t (:background "green" :foreground "black" :inherit mode-line)))
427 "My Powerline face 1 based on powerline-active1."
430 (defface sd/mode-line-buffer-id
431 '((t (:background "yellow" :foreground "black" :inherit mode-line-buffer-id)))
432 "My powerline mode-line face, based on mode-line-buffer-id"
435 ;; Don't show buffer modified for scratch and eshell mode
436 (defun sd/buffer-show-modified ()
437 "Dot not show modified indicator for buffers"
439 (unless (or (string-match "*scratch*" (buffer-name))
440 (equal major-mode 'eshell-mode))
443 (defun sd/powerline-center-theme_revised ()
444 "Setup a mode-line with major and minor modes centered."
446 (setq-default mode-line-format
449 (let* ((active (powerline-selected-window-active))
450 (mode-line-buffer-id (if active 'sd/mode-line-buffer-id 'mode-line-buffer-id-inactive))
451 (mode-line (if active 'mode-line 'mode-line-inactive))
452 (my-face1 (if active 'sd/powerline-active1 'powerline-inactive1))
453 (my-face-buffer-modified (if (and (sd/buffer-show-modified) (buffer-modified-p))
454 'sd/buffer-modified-active1
455 (if buffer-read-only 'sd/buffer-view-active1
457 (face1 (if active 'powerline-active1 'powerline-inactive1))
458 (face2 (if active 'powerline-active2 'powerline-inactive2))
459 (separator-left (intern (format "powerline-%s-%s"
460 (powerline-current-separator)
461 (car powerline-default-separator-dir))))
462 (separator-right (intern (format "powerline-%s-%s"
463 (powerline-current-separator)
464 (cdr powerline-default-separator-dir))))
465 (lhs (list (powerline-raw "%* " my-face-buffer-modified 'l)
466 ;; (powerline-buffer-size mode-line 'l)
467 (powerline-buffer-id mode-line-buffer-id 'l)
468 (powerline-raw " " my-face1)
469 (funcall separator-left my-face1 face1)
470 (powerline-narrow face1 'l)
471 ;; (powerline-vc face1)
472 (sd/powerline-simpler-vc (powerline-vc face1))))
473 (rhs (list (powerline-raw global-mode-string face1 'r)
474 (powerline-raw "%4l" face1 'r)
475 (powerline-raw ":" face1)
476 (powerline-raw "%3c" face1 'r)
477 (funcall separator-right face1 my-face1)
478 ;; (powerline-raw " " my-face1)
479 (powerline-raw (format-time-string " %I:%M %p ") my-face1 'r)
480 ;; (powerline-raw "%6p" my-face1 'r)
481 ;; (powerline-hud my-face1 face1 )
483 (center (list (powerline-raw " " face1)
484 (funcall separator-left face1 face2)
485 (when (and (boundp 'erc-track-minor-mode) erc-track-minor-mode)
486 (powerline-raw erc-modified-channels-object face2 'l))
487 (powerline-major-mode face2 'l)
488 (powerline-process face2)
489 (powerline-raw " :" face2)
490 (powerline-minor-modes face2 'l)
491 (powerline-raw " " face2)
492 (funcall separator-right face2 face1))))
493 (concat (powerline-render lhs)
494 (powerline-fill-center face1 (/ (powerline-width center) 2.0))
495 (powerline-render center)
496 (powerline-fill face1 (powerline-width rhs))
497 (powerline-render rhs)))))))
499 (sd/powerline-center-theme_revised)
502 Fix the issue in mode line when showing triangle
503 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
504 (setq ns-use-srgb-colorspace nil)
507 set height in mode line
508 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
509 (set-variable 'powerline-height 14)
510 (set-variable 'powerline-text-scale-factor (/ (float 100) 140))
511 ;; (custom-set-variables
512 ;; '(powerline-height 14)
513 ;; '(powerline-text-scale-factor (/ (float 100) 140)))
515 (set-face-attribute 'mode-line nil :height 100)
520 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
523 :init (setq ido-enable-flex-matching t
524 ido-ignore-extensions t
525 ido-use-virtual-buffers t
527 (setq ido-save-directory-list-file (concat sd-temp-directory "ido.last"))
531 (add-to-list 'completion-ignored-extensions ".pyc"))
537 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
540 :init (setq ido-enable-flex-matching t
542 :config (flx-ido-mode 1))
546 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
547 (use-package ido-vertical-mode
550 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
552 (ido-vertical-mode 1))
556 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
561 (setq smex-save-file (concat sd-temp-directory "smex-items"))
564 ("M-X" . smex-major-mode-commands))
568 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
569 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
570 (use-package ido-ubiquitous
573 (setq magit-completing-read-function 'magit-ido-completing-read)
574 (setq gnus-completing-read-function 'gnus-ido-completing-read)
576 (ido-ubiquitous-mode 1))
580 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
581 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
582 (use-package ido-exit-target
585 (mapcar (lambda (map)
586 (define-key map (kbd "C-j") #'ido-exit-target-split-window-right)
587 (define-key map (kbd "C-k") #'ido-exit-target-split-window-below))
588 (list ido-buffer-completion-map
589 ;; ido-common-completion-map
590 ido-file-completion-map
591 ido-file-dir-completion-map)))
595 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
600 (global-set-key (kbd "M-x") 'counsel-M-x)
601 (global-set-key (kbd "C-h f") 'counsel-describe-function)
602 (global-set-key (kbd "C-h v") 'counsel-describe-variable))
604 ;; (global-set-key "\C-s" 'swiper)
605 ;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
606 ;; (global-set-key (kbd "<f6>") 'ivy-resume)
607 ;; ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
608 ;; (global-set-key (kbd "<f1> l") 'counsel-load-library)
609 ;; (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
610 ;; (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
611 ;; (global-set-key (kbd "C-c g") 'counsel-git)
612 ;; (global-set-key (kbd "C-c j") 'counsel-git-grep)
613 ;; (global-set-key (kbd "C-c k") 'counsel-ag)
614 ;; (global-set-key (kbd "C-x l") 'counsel-locate)
615 ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
616 ;; ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
618 ;; (set-face-attribute
619 ;; 'ivy-current-match nil
620 ;; :background "Orange"
621 ;; :foreground "black")
624 ;; (define-key swiper-map (kbd "M-%") 'swiper-aa-replace)
628 let helm windows split inside current window
629 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
630 (with-eval-after-load 'helm
631 (setq helm-split-window-in-side-p t))
636 ** Org-mode Basic setting
638 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
640 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
644 (setq org-startup-indented t)
645 (setq org-hide-leading-starts t)
646 (setq org-src-fontify-natively t)
647 (setq org-src-tab-acts-natively t)
648 (setq org-confirm-babel-evaluate nil)
649 (setq org-use-speed-commands t)
650 (setq org-completion-use-ido t))
652 (org-babel-do-load-languages
653 'org-babel-load-languages
669 ;; use current window for org source buffer editting
670 (setq org-src-window-setup 'current-window )
672 (define-key org-mode-map (kbd "C-'") nil)
673 ;; C-M-i is mapped to imenu globally
674 (define-key org-mode-map (kbd "C-M-i") nil)
676 ;; set the ditta.jar path
677 (setq org-ditaa-jar-path "/usr/local/Cellar/ditaa/0.9/libexec/ditaa0_9.jar")
679 (file-exists-p org-ditaa-jar-path)
680 (error "seudut: ditaa.jar not found at %s " org-ditaa-jar-path))
685 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
687 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
688 (use-package org-bullets
691 (add-hook 'org-mode-hook
693 (org-bullets-mode t))))
695 (setq org-bullets-bullet-list '("⦿" "✪" "◉" "○" "►" "◆"))
697 ;; increase font size when enter org-src-mode
698 (add-hook 'org-src-mode-hook (lambda () (text-scale-increase 2)))
703 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
704 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
705 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
706 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
708 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
713 :init (add-hook 'org-mode-hook 'worf-mode)
715 ;; (define-key worf-mode-map "[" nil)
716 ;; (define-key worf-mode-map "]" nil)
717 ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward)
718 ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward)
725 Refer to [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
730 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
731 (global-set-key "\C-cl" 'org-store-link)
732 (global-set-key "\C-ca" 'org-agenda)
733 (global-set-key "\C-cb" 'org-iswitchb)
738 Replace the list bullet =-=, =+=, with =•=, a litter change based [[https://github.com/howardabrams/dot-files/blob/master/emacs-org.org][here]]
740 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
741 ;; (use-package org-mode
743 ;; (font-lock-add-keywords 'org-mode
744 ;; '(("^ *\\([-+]\\) "
745 ;; (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•")))))))
750 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]],
752 To track TODO state changes, the =!= is to insert a timetamp, =@= is to insert a note with
753 timestamp for the state change.
755 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
756 ;; (setq org-todo-keywords
757 ;; '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
758 ;; (sequence "âš‘ WAITING(w)" "|")
759 ;; (sequence "|" "✘ CANCELLED(c)")))
760 ; (setq org-todo-keyword-faces
761 ; (quote ("TODO" . (:foreground "red" :weight bold))
762 ; ("NEXT" . (:foreground "blue" :weight bold))
763 ; ("WAITING" . (:foreground "forest green" :weight bold))
764 ; ("DONE" . (:foreground "magenta" :weight bold))
765 ; ("CANCELLED" . (:foreground "forest green" :weight bold))))
768 (setq org-todo-keywords
769 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!)")
770 ;; (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING")
771 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" ))))
773 (setq org-todo-keyword-faces
774 (quote (("TODO" :foreground "red" :weight bold)
775 ("NEXT" :foreground "blue" :weight bold)
776 ("DONE" :foreground "forest green" :weight bold)
777 ("WAITING" :foreground "orange" :weight bold)
778 ("HOLD" :foreground "magenta" :weight bold)
779 ("CANCELLED" :foreground "forest green" :weight bold)
780 ;; ("MEETING" :foreground "forest green" :weight bold)
781 ;; ("PHONE" :foreground "forest green" :weight bold)
787 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
788 (setq org-use-fast-todo-selection t)
789 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
792 TODO state triggers and tags, [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
794 - Moving a task to =CANCELLED=, adds a =CANCELLED= tag
795 - Moving a task to =WAITING=, adds a =WAITING= tag
796 - Moving a task to =HOLD=, add =HOLD= tags
797 - Moving a task to =DONE=, remove =WAITING=, =HOLD= tag
798 - Moving a task to =NEXT=, remove all waiting/hold/cancelled tags
800 This tags are used to filter tasks in agenda views
801 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
802 (setq org-todo-state-tags-triggers
803 (quote (("CANCELLED" ("CANCELLED" . t))
804 ("WAITING" ("WAITING" . t))
805 ("HOLD" ("WAITING") ("HOLD" . t))
806 (done ("WAITING") ("HOLD"))
807 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
808 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
809 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
813 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
814 ;; log time when task done
815 ;; (setq org-log-done (quote time))
816 ;; save clocking into to LOGBOOK
817 (setq org-clock-into-drawer t)
818 ;; save state change notes and time stamp into LOGBOOK drawer
819 (setq org-log-into-drawer t)
820 (setq org-clock-into-drawer "CLOCK")
824 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
825 (setq org-tag-alist (quote ((:startgroup)
831 ("CANCELLED" . ?c))))
833 ;; Allow setting single tags without the menu
834 (setq org-fast-tag-selection-single-key (quote expert))
837 *** Capture - Refile - Archive
839 Capture lets you quickly store notes with little interruption of your work flow.
841 **** Capture Templates
843 When a new taks needs to be added, categorize it as
845 All captured file which need next actions are stored in =refile.org=,
846 - A new task / note (t) =refile.org=
847 - A work task in office =office.org=
848 - A jourenl =diary.org=
849 - A new habit (h) =refile.org=
851 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
852 (setq org-directory "~/org")
853 (setq org-default-notes-file "~/org/refile.org")
854 (setq sd/org-diary-file "~/org/diary.org")
856 (global-set-key (kbd "C-c c") 'org-capture)
858 (setq org-capture-templates
859 (quote (("t" "Todo" entry (file org-default-notes-file)
860 "* TODO %?\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
861 ("n" "Note" entry (file org-default-notes-file)
862 "* %? :NOTE:\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
863 ("j" "Journal" entry (file+datetree sd/org-diary-file)
864 "* %?\n:LOGBOOK:\n:END:" :clock-in t :clock-resume t)
865 ("h" "Habit" entry (file org-default-notes-file)
866 "* 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 "))))
871 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
872 (setq org-refile-targets (quote (;; (nil :maxlevel . 9)
873 (org-agenda-files :maxlevel . 9))))
875 (setq org-refile-use-outline-path t)
877 (setq org-refile-allow-creating-parent-nodes (quote confirm))
881 Setting agenda files and the agenda view
882 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
883 (setq org-agenda-files (quote ("~/org/gtd.org"
886 ;; only show today's tasks in agenda view
887 (setq org-agenda-span 'day)
888 ;; Use current windows for agenda view
889 (setq org-agenda-window-setup 'current-window)
891 ;; show all feature entries for repeating tasks,
892 ;; this is already setting by default
893 (setq org-agenda-repeating-timestamp-show-all t)
895 ;; Show all agenda dates - even if they are empty
896 (setq org-agenda-show-all-dates t)
901 Install MacTex-basic and some tex packages
905 sudo tlmgr update --self
907 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
911 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
912 ;; ;; allow for export=>beamer by placing
914 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
915 ;; #+LaTeX_CLASS: beamer in org files
916 (unless (boundp 'org-export-latex-classes)
917 (setq org-export-latex-classes nil))
918 (add-to-list 'org-export-latex-classes
919 ;; beamer class, for presentations
921 "\\documentclass[11pt]{beamer}\n
922 \\mode<{{{beamermode}}}>\n
923 \\usetheme{{{{beamertheme}}}}\n
924 \\usecolortheme{{{{beamercolortheme}}}}\n
925 \\beamertemplateballitem\n
926 \\setbeameroption{show notes}
927 \\usepackage[utf8]{inputenc}\n
928 \\usepackage[T1]{fontenc}\n
929 \\usepackage{hyperref}\n
931 \\usepackage{listings}
932 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
935 showspaces=false,showstringspaces=false,
937 keywordstyle=\\color{blue}\\bfseries,
938 commentstyle=\\color{red},
940 \\usepackage{verbatim}\n
941 \\institute{{{{beamerinstitute}}}}\n
942 \\subject{{{{beamersubject}}}}\n"
944 ("\\section{%s}" . "\\section*{%s}")
946 ("\\begin{frame}[fragile]\\frametitle{%s}"
948 "\\begin{frame}[fragile]\\frametitle{%s}"
951 ;; letter class, for formal letters
953 (add-to-list 'org-export-latex-classes
956 "\\documentclass[11pt]{letter}\n
957 \\usepackage[utf8]{inputenc}\n
958 \\usepackage[T1]{fontenc}\n
961 ("\\section{%s}" . "\\section*{%s}")
962 ("\\subsection{%s}" . "\\subsection*{%s}")
963 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
964 ("\\paragraph{%s}" . "\\paragraph*{%s}")
965 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
971 (setq org-latex-pdf-process
972 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
973 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
974 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
976 (setq TeX-parse-self t)
978 (setq TeX-PDF-mode t)
979 (add-hook 'LaTeX-mode-hook
982 (setq TeX-master t)))
988 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
990 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
992 (add-to-list 'org-structure-template-alist
993 '("E" "#+BEGIN_SRC emacs-lisp :tangle yes :results silent\n?\n#+END_SRC"))
994 (add-to-list 'org-structure-template-alist
995 '("S" "#+BEGIN_SRC sh\n?\n#+END_SRC"))
996 (add-to-list 'org-structure-template-alist
997 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
1002 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
1003 and Defined keys, using vi keybindings, Refer abo-abo's setting [[https://github.com/abo-abo/oremacs/blob/c5cafdcebc88afe9e73cc8bd40c49b70675509c7/modes/ora-nextmagit.el][here]]
1004 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1008 ;; don't ask me to confirm the unsaved change
1009 (setq magit-save-repository-buffers nil)
1010 :commands magit-status magit-blame
1012 (dolist (map (list magit-status-mode-map
1015 magit-staged-section-map))
1016 (define-key map "j" 'magit-section-forward)
1017 (define-key map "k" 'magit-section-backward)
1018 (define-key map "D" 'magit-discard)
1019 (define-key map "O" 'magit-discard-file)
1020 (define-key map "n" nil)
1021 (define-key map "p" nil)
1022 (define-key map "v" 'recenter-top-bottom)
1023 (define-key map "i" 'magit-section-toggle)))
1028 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1029 (defalias 'e 'find-file)
1030 (defalias 'ff 'find-file)
1031 (defalias 'ee 'find-files)
1034 *** eshell temp directory
1035 set default eshell history folder
1036 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1037 (setq eshell-directory-name (concat sd-temp-directory "eshell"))
1040 *** Eshell erase buffer
1041 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1042 (defun sd/eshell-clear-buffer ()
1043 "Clear eshell buffer"
1045 (let ((inhibit-read-only t))
1047 (eshell-send-input)))
1049 (add-hook 'eshell-mode-hook (lambda ()
1050 (local-set-key (kbd "C-l") 'sd/eshell-clear-buffer)))
1054 Toggle an eshell in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
1055 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1056 (defun sd/window-has-eshell ()
1057 "Check if current windows list has a eshell buffer, and return the window"
1060 (walk-windows (lambda (window)
1061 (if (equal (with-current-buffer (window-buffer window) major-mode)
1067 (defun sd/toggle-eshell-here ()
1068 "Toggle a eshell buffer vertically"
1070 (if (sd/window-has-eshell)
1071 (if (equal major-mode 'eshell-mode)
1073 (if (equal (length (window-list)) 1)
1074 (mode-line-other-buffer)
1076 (select-window (sd/window-has-eshell)))
1078 (let ((dir default-directory))
1080 (split-window-vertically (- (/ (window-total-height) 3)))
1082 (unless (and (boundp 'eshell-buffer-name) (get-buffer eshell-buffer-name))
1084 (switch-to-buffer eshell-buffer-name)
1085 (goto-char (point-max))
1087 (insert (format "cd %s" dir))
1088 (eshell-send-input)))))
1090 ;; (global-unset-key (kbd "M-`"))
1091 (global-set-key (kbd "s-e") 'sd/toggle-eshell-here)
1094 *** TODO smart display
1097 ** [[https://github.com/abo-abo/hydra][Hydra]]
1099 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1102 ;; disable new line in minibuffer when hint hydra
1106 *** Windmove Splitter
1108 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1110 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1112 (defun hydra-move-splitter-left (arg)
1113 "Move window splitter left."
1115 (if (let ((windmove-wrap-around))
1116 (windmove-find-other-window 'right))
1117 (shrink-window-horizontally arg)
1118 (enlarge-window-horizontally arg)))
1120 (defun hydra-move-splitter-right (arg)
1121 "Move window splitter right."
1123 (if (let ((windmove-wrap-around))
1124 (windmove-find-other-window 'right))
1125 (enlarge-window-horizontally arg)
1126 (shrink-window-horizontally arg)))
1128 (defun hydra-move-splitter-up (arg)
1129 "Move window splitter up."
1131 (if (let ((windmove-wrap-around))
1132 (windmove-find-other-window 'up))
1133 (enlarge-window arg)
1134 (shrink-window arg)))
1136 (defun hydra-move-splitter-down (arg)
1137 "Move window splitter down."
1139 (if (let ((windmove-wrap-around))
1140 (windmove-find-other-window 'up))
1142 (enlarge-window arg)))
1147 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1148 (defhydra sd/hydra-misc (:color red :columns nil)
1149 "Miscellaneous Commands"
1150 ("e" eshell "eshell" :exit t)
1153 (if (not (eq nil (get-buffer "*Packages*")))
1154 (switch-to-buffer "*Packages*")
1155 (package-list-packages)))
1156 "list-package" :exit t)
1157 ("g" magit-status "git-status" :exit t)
1158 ("'" mode-line-other-buffer "last buffer" :exit t)
1159 ("C-'" mode-line-other-buffer "last buffer" :exit t)
1160 ("m" man "man" :exit t)
1161 ("d" dired-jump "dired" :exit t)
1162 ("b" ibuffer "ibuffer" :exit t)
1166 (global-set-key (kbd "C-'") 'sd/hydra-misc/body)
1170 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1171 (defhydra sd/hydra-launcher (:color blue :columns 2)
1173 ("e" emms "emms" :exit t)
1179 Enable linum mode on programming modes
1181 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1182 (add-hook 'prog-mode-hook 'linum-mode)
1183 ;; (add-hook 'prog-mode-hook (lambda ()
1184 ;; (setq-default indicate-empty-lines t)))
1187 Fix the font size of line number
1189 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1191 (defun fix-linum-size ()
1193 (set-face-attribute 'linum nil :height 110))
1195 (add-hook 'linum-mode-hook 'fix-linum-size)
1199 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1201 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1203 (use-package linum-relative
1206 (defun linum-new-mode ()
1207 "If line numbers aren't displayed, then display them.
1208 Otherwise, toggle between absolute and relative numbers."
1211 (linum-relative-toggle)
1215 ("A-k" . linum-new-mode))
1217 ;; auto enable linum-new-mode in programming modes
1218 (add-hook 'prog-mode-hook 'linum-relative-mode)
1222 ** Save File Position
1224 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1226 (require 'saveplace)
1227 (setq-default save-place t)
1228 (setq save-place-forget-unreadable-files t)
1229 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1235 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1237 (use-package multi-term
1244 [[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
1245 Type =o= to go to the link
1247 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1249 (use-package ace-link
1252 (ace-link-setup-default))
1258 [[https://github.com/re5et/emux][emux]] is
1260 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1262 (el-get-bundle re5et/emux)
1268 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1270 (use-package smartparens
1274 (require 'smartparens-config)
1275 (add-hook 'prog-mode-hook 'smartparens-mode)))
1281 [[https://github.com/abo-abo/ace-window][ace-window]]
1283 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1285 (use-package ace-window
1289 ; (global-set-key (kbd "M-o") 'ace-window)
1291 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1297 [[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings
1299 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1301 (use-package which-key
1309 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
1310 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1314 (setq emms-source-file-default-directory "~/Music/")
1315 (setq emms-directory (concat sd-temp-directory "emms"))
1318 (emms-default-players)
1319 (define-emms-simple-player mplayer '(file url)
1320 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
1321 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
1322 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
1323 ".m4a" ".flv" ".ogv" ".pls"))
1324 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
1325 (emms-history-load))
1330 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
1332 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1338 (require 'gnugo-imgen)
1339 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
1340 (add-hook 'gnugo-start-game-hook '(lambda ()
1341 (gnugo-image-display-mode)
1344 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
1350 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1352 ;; (use-package tabbar-ruler
1355 ;; (setq tabbar-ruler-global-tabbar t)
1356 ;; (setq tabbar-ruler-global-ruler t)
1357 ;; (setq tabbar-ruler-popu-menu t)
1358 ;; (setq tabbar-ruler-popu-toolbar t)
1359 ;; (setq tabbar-use-images t)
1361 ;; (tabbar-ruler-group-by-projectile-project)
1362 ;; (global-set-key (kbd "s-1") 'tabbar-forward-group)
1363 ;; (global-set-key (kbd "s-2") 'tabbar-ruler-forward))
1367 ** View only for some directory
1368 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]]
1369 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1370 (dir-locals-set-class-variables
1372 '((nil . ((buffer-read-only . t)
1373 (show-trailing-whitespace . nil)
1375 (eval . (whitespace-mode -1))))))
1377 ;; (dir-locals-set-directory-class (expand-file-name "/usr/local/share/emacs") 'emacs)
1378 (dir-locals-set-directory-class "/usr/local/Cellar/emacs" 'emacs)
1379 ;; (dir-locals-set-directory-class "~/.emacs.d/elpa" 'emacs)
1380 (dir-locals-set-directory-class "~/dotfiles/emacs.d/elpa" 'emacs)
1381 (dir-locals-set-directory-class "~/dotfiles/emacs.d/el-get" 'emacs)
1385 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1386 (el-get-bundle info+
1387 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/info+.el"
1395 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1396 (defun sd/info-mode ()
1398 (unless (equal major-mode 'Info-mode)
1399 (unless (> (length (window-list)) 1)
1400 (split-window-right))
1405 ;; (global-set-key (kbd "C-h i") 'sd/info-mode)
1407 ;; open Info buffer in other window instead of current window
1408 (defadvice info (before my-info (&optional file buf) activate)
1411 (defadvice Info-exit (after my-info-exit activate)
1412 (sd/delete-current-window))
1418 ** TODO swiper to occur
1421 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1422 ;; (set-language-environment "UTF-8")
1423 ;; (set-default-coding-systems 'utf-8)
1427 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1428 ;; (el-get-bundle howardabrams/demo-it)
1430 (use-package org-tree-slide
1433 ;; (use-package yasnippet
1438 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1439 (use-package org-tree-slide
1442 ;; (define-key org-mode-map "\C-ccp" 'org-tree-slide-mode)
1443 (define-key org-tree-slide-mode-map (kbd "<ESC>") 'org-tree-slide-content)
1444 (define-key org-tree-slide-mode-map (kbd "<SPACE>") 'org-tree-slide-move-next-tree)
1445 (define-key org-tree-slide-mode-map [escape] 'org-tree-slide-move-previous-tree))
1449 =C-o= is defined as a global key for window operation, here unset it in dired mode
1450 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1454 (setq dired-omit-mode t)
1455 (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
1456 (add-hook 'dired-mode-hook (lambda ()
1457 (define-key dired-mode-map (kbd "C-o") nil)
1458 (define-key dired-mode-map (kbd "H") 'dired-omit-mode)
1459 (define-key dired-mode-map (kbd "DEL") (lambda () (interactive) (find-alternate-file "..")))
1460 (dired-omit-mode))))
1464 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1468 (setq diredp-hide-details-initially-flag nil)
1470 (define-key dired-mode-map (kbd "j") 'diredp-next-line)
1471 (define-key dired-mode-map (kbd "k") 'diredp-previous-line)
1472 (define-key dired-mode-map (kbd "g") 'dired-goto-file))
1476 company mode and company-statistics
1477 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1478 (use-package company
1480 :diminish company-mode
1481 :init (setq company-idle-delay 0.1)
1483 (global-company-mode))
1485 (use-package company-statistics
1488 (company-statistics-mode))
1491 * Programming Language
1493 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1494 (use-package color-identifiers-mode
1497 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
1499 :diminish color-identifiers-mode)
1501 (global-prettify-symbols-mode t)
1504 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
1505 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
1506 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1510 (eval-after-load "lispy"
1512 (define-key lispy-mode-map (kbd "M-o") nil)))
1514 (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1))))
1519 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
1520 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1521 (defalias 'perl-mode 'cperl-mode)
1523 ;; (setq cperl-hairy t)
1524 ;; Turns on most of the CPerlMode options
1525 (setq cperl-auto-newline t)
1526 (setq cperl-highlight-variables-indiscriminately t)
1527 ;(setq cperl-indent-level 4)
1528 ;(setq cperl-continued-statement-offset 4)
1529 (setq cperl-close-paren-offset -4)
1530 (setq cperl-indent-parents-as-block t)
1531 (setq cperl-tab-always-indent t)
1532 ;(setq cperl-brace-offset 0)
1534 (add-hook 'cperl-mode-hook
1536 (cperl-set-style "C++")))
1538 (defalias 'perldoc 'cperl-perldoc)
1542 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
1543 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1544 (eval-after-load 'autoinsert
1545 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
1548 "#!/usr/bin/perl -w" \n
1550 "use strict;" > \n \n
1556 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1557 (font-lock-add-keywords 'cperl-mode
1558 '(("\\(say\\)" . cperl-nonoverridable-face)
1559 ("\\([0-9.]\\)*" . font-lock-constant-face)
1560 ("\".*\\(\\\n\\).*\"" . font-lock-constant-face)
1561 ("\n" . font-lock-constant-face)
1562 ("\\(^#!.*\\)$" . cperl-nonoverridable-face)))
1564 ;; (font-lock-add-keywords 'Man-mode
1565 ;; '(("\\(NAME\\)" . font-lock-function-name-face)))
1570 Change the compile-command to set the default command run when call =compile=
1571 Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
1572 to call =compilation= interactively.
1573 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1574 (defun my-perl-hook ()
1576 (setq-local compilation-read-command nil)
1577 (set (make-local-variable 'compile-command)
1578 (concat "/usr/bin/perl "
1579 (if buffer-file-name
1580 (shell-quote-argument buffer-file-name))))
1581 (local-set-key (kbd "s-r")
1584 ; (setq current-prefix-arg '(4)) ; C-u
1585 (call-interactively 'compile)))))
1587 (add-hook 'cperl-mode-hook 'my-perl-hook)
1591 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1592 (setq c-default-style "stroustrup"
1597 Set the environments vairables in compilation mode
1598 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1599 (use-package compile
1602 (setq compilation-environment (cons "LC_ALL=C" compilation-environment))
1603 (setq compilation-auto-jump-to-first-error t)
1604 (setq compilation-auto-jump-to-next t)
1605 (setq compilation-scroll-output 'first-error))
1607 ;; super-r to compile
1608 (with-eval-after-load "compile"
1609 (define-key compilation-mode-map (kbd "C-o") nil)
1610 (define-key compilation-mode-map (kbd "n") 'compilation-next-error)
1611 (define-key compilation-mode-map (kbd "p") 'compilation-previous-error)
1612 (define-key compilation-mode-map (kbd "r") #'recompile))
1616 ** Enable auto-insert mode
1617 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1618 (auto-insert-mode t)
1619 (setq auto-insert-query nil)
1623 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1624 (eval-after-load 'autoinsert
1625 '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
1627 "Short description:"
1629 "\n * " (file-name-nondirectory (buffer-file-name))
1631 "#include <iostream>" \n
1633 (file-name-sans-extension
1634 (file-name-nondirectory (buffer-file-name)))
1636 "using namespace std;" \n \n
1644 (eval-after-load 'autoinsert
1645 '(define-auto-insert '("\\.c\\'" . "C skeleton")
1647 "Short description:"
1649 " * " (file-name-nondirectory (buffer-file-name)) "\n"
1651 "#include <stdio.h>" \n
1653 (file-name-sans-extension
1654 (file-name-nondirectory (buffer-file-name)))
1665 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1666 (eval-after-load 'autoinsert
1667 '(define-auto-insert '("\\.\\(py\\)\\'" . "Python skeleton")
1676 Emacs lisp auto-insert, based on the default module in =autoinsert.el=, but replace =completing-read= as
1677 =completing-read-ido-ubiquitous= to fix the edge case of that =ido= cannot handle.
1678 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1679 (eval-after-load 'autoinsert
1680 '(define-auto-insert '("\\.el\\'" . "my Emacs Lisp header")
1682 "Short description: "
1683 ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str
1684 (make-string (max 2 (- 80 (current-column) 27)) ?\s)
1685 "-*- lexical-binding: t; -*-" '(setq lexical-binding t)
1687 ;; Copyright (C) " (format-time-string "%Y") " "
1688 (getenv "ORGANIZATION") | (progn user-full-name) "
1690 ;; Author: " (user-full-name)
1691 '(if (search-backward "&" (line-beginning-position) t)
1692 (replace-match (capitalize (user-login-name)) t t))
1693 '(end-of-line 1) " <" (progn user-mail-address) ">
1696 ;;'(setq v1 (apply 'vector (mapcar 'car finder-known-keywords)))
1697 '(setq v1 (mapcar (lambda (x) (list (symbol-name (car x))))
1698 finder-known-keywords)
1699 v2 (mapconcat (lambda (x) (format "%12s: %s" (car x) (cdr x)))
1700 finder-known-keywords
1702 ((let ((minibuffer-help-form v2))
1703 (completing-read-ido-ubiquitous "Keyword, C-h: " v1 nil t))
1706 \;; This program is free software; you can redistribute it and/or modify
1707 \;; it under the terms of the GNU General Public License as published by
1708 \;; the Free Software Foundation, either version 3 of the License, or
1709 \;; (at your option) any later version.
1711 \;; This program is distributed in the hope that it will be useful,
1712 \;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1713 \;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1714 \;; GNU General Public License for more details.
1716 \;; You should have received a copy of the GNU General Public License
1717 \;; along with this program. If not, see <http://www.gnu.org/licenses/>.
1729 \;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")))
1732 ** Org file template
1733 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1734 (eval-after-load 'autoinsert
1735 '(define-auto-insert '("\\.\\(org\\)\\'" . "Org-mode skeleton")
1738 "#+TITLE: " str (make-string 30 ?\s) > \n
1739 "#+AUTHOR: Peng Li\n"
1740 "#+EMAIL: seudut@gmail.com\n"
1741 "#+DATE: " (shell-command-to-string "echo -n $(date +%Y-%m-%d)") > \n
1747 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1748 (use-package markdown-mode
1750 :commands (markdown-mode gfm-mode)
1751 :mode (("README\\.md\\'" . gfm-mode)
1752 ("\\.md\\'" . markdown-mode)
1753 ("\\.markdown\\'" . markdown-mode))
1754 :init (setq markdown-command "multimarkdown"))
1757 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1758 (use-package markdown-preview-eww
1764 Refer [[https://www.emacswiki.org/emacs/GnusGmail][GnusGmail]]
1765 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1766 (setq user-mail-address "seudut@gmail.com"
1767 user-full-name "Peng Li")
1769 (setq gnus-select-method
1771 (nnimap-address "imap.gmail.com")
1772 (nnimap-server-port "imaps")
1773 (nnimap-stream ssl)))
1775 (setq smtpmail-smtp-service 587
1776 gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
1778 ;; Use gmail sending mail
1779 (setq message-send-mail-function 'smtpmail-send-it
1780 smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
1781 smtpmail-auth-credentials '(("smtp.gmail.com" 587 "seudut@gmail.com" nil))
1782 smtpmail-default-smtp-server "smtp.gmail.com"
1783 smtpmail-smtp-server "smtp.gmail.com"
1784 smtpmail-smtp-service 587
1785 starttls-use-gnutls t)
1788 And put the following in =~/.authinfo= file, replacing =<USE>= with your email address
1789 and =<PASSWORD>= with the password
1791 machine imap.gmail.com login <USER> password <PASSWORD> port imaps
1792 machine smtp.gmail.com login <USER> password <PASSWORD> port 587
1798 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1801 (setq gnus-permanently-visible-groups "\.*")
1803 (cond (window-system
1804 (setq custom-background-mode 'light)
1805 (defface my-group-face-1
1806 '((t (:foreground "Red" :bold t))) "First group face")
1807 (defface my-group-face-2
1808 '((t (:foreground "DarkSeaGreen4" :bold t)))
1809 "Second group face")
1810 (defface my-group-face-3
1811 '((t (:foreground "Green4" :bold t))) "Third group face")
1812 (defface my-group-face-4
1813 '((t (:foreground "SteelBlue" :bold t))) "Fourth group face")
1814 (defface my-group-face-5
1815 '((t (:foreground "Blue" :bold t))) "Fifth group face")))
1816 (setq gnus-group-highlight
1817 '(((> unread 200) . my-group-face-1)
1818 ((and (< level 3) (zerop unread)) . my-group-face-2)
1819 ((< level 3) . my-group-face-3)
1820 ((zerop unread) . my-group-face-4)
1821 (t . my-group-face-5))))
1825 (add-hook 'gnus-group-mode-hook (lambda ()
1826 (define-key gnus-group-mode-map "k" 'gnus-group-prev-group)
1827 (define-key gnus-group-mode-map "j" 'gnus-group-next-group)
1828 (define-key gnus-group-mode-map "g" 'gnus-group-jump-to-group)
1829 (define-key gnus-group-mode-map "v" (lambda () (interactive) (gnus-group-select-group t)))))
1832 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1833 (setq gnus-fetch-old-headers 't)
1837 (setq gnus-extract-address-components
1838 'mail-extract-address-components)
1840 (setq gnus-summary-line-format "%U%R%z%I%(%[%-20,20f%]%) %s%-80= %11&user-date;\n")
1841 (setq gnus-user-date-format-alist '(((gnus-seconds-today) . "%H:%M")
1842 ((+ 86400 (gnus-seconds-today)) . "%a %H:%M")
1843 (604800 . "%a, %b %-d")
1844 (15778476 . "%b %-d")
1847 (setq gnus-thread-sort-functions '((not gnus-thread-sort-by-number)))
1848 (setq gnus-unread-mark ?\.)
1849 (setq gnus-use-correct-string-widths t)
1852 (setq gnus-thread-hide-subtree t)
1854 ;; (with-eval-after-load 'gnus-summary-mode
1855 ;; (define-key gnus-summary-mode-map (kbd "C-o") 'sd/hydra-window/body))
1857 (add-hook 'gnus-summary-mode-hook (lambda ()
1858 (define-key gnus-summary-mode-map (kbd "C-o") nil)))
1864 See [[https://www.emacswiki.org/emacs/GnusWindowLayout][GnusWindowLayout]]
1865 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1866 (gnus-add-configuration
1872 (summary 1.0 poine)))))
1874 (gnus-add-configuration
1880 (summary 0.50 point)
1883 (with-eval-after-load 'gnus-group-mode
1884 (gnus-group-select-group "INBOX"))
1885 ;; (add-hook 'gnus-group-mode-map (lambda ()
1886 ;; (gnus-group-select-group "INBOX")))
1890 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=
1891 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1892 (use-package gnuplot
1895 (setq gnuplot-help-xpm nil)
1896 (setq gnuplot-line-xpm nil)
1897 (setq gnuplot-region-xpm nil)
1898 (setq gnuplot-buffer-xpm nil)
1899 (setq gnuplot-doc-xpm nil))
1902 Use =gnuplot= on =Org-mode= file, see [[http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-gnuplot.html][ob-doc-gnuplot]]
1903 #+BEGIN_SRC gnuplot :exports code :file ./temp/file.png
1906 set title "Putting it All Together"
1919 h(x) = 10*sqrt(abs(x))
1921 plot f(x) w lp lw 1, g(x) w p lw 2, h(x) w l lw 3
1925 [[file:./temp/file.png]]
1927 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1928 (with-eval-after-load 'ediff
1929 (setq ediff-split-window-function 'split-window-horizontally)
1930 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
1931 (add-hook 'ediff-startup-hook 'ediff-toggle-wide-display)
1932 (add-hook 'ediff-cleanup-hook 'ediff-toggle-wide-display)
1933 (add-hook 'ediff-suspend-hook 'ediff-toggle-wide-display))
1937 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1938 (use-package bing-dict
1941 (global-set-key (kbd "s-d") 'bing-dict-brief)
1942 :commands (bing-dict-brief))
1946 Here are some global key bindings for basic editting
1947 ** Esc in minibuffer
1948 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
1949 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1950 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
1951 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
1952 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
1953 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
1954 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
1955 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
1956 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
1957 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
1958 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
1960 ;; Also map s-h same as C-g
1961 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
1964 ** Project operations - =super=
1966 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1967 (use-package projectile
1970 (setq projectile-enable-caching t)
1971 (setq projectile-cache-file (concat sd-temp-directory "projectile.cache"))
1973 (projectile-global-mode t))
1975 (use-package persp-projectile
1980 (:map projectile-mode-map
1981 ("s-t" . projectile-persp-switch-project)))
1983 ;; projectile-find-file
1984 ;; projectile-switch-buffer
1985 ;; projectile-find-file-other-window
1988 *** project config =super= keybindings
1989 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1990 ;; (global-set-key (kbd "s-h") 'keyboard-quit)
1991 ;; (global-set-key (kbd "s-j") 'ido-switch-buffer)
1992 ;; (global-set-key (kbd "s-k") 'ido-find-file)
1993 ;; (global-set-key (kbd "s-l") 'sd/delete-current-window)
1994 ;; s-l --> goto-line
1995 ;; (global-set-key (kbd "s-/") 'swiper)
1997 ;; s-' --> 'next-multiframe-window
1998 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
2000 (global-set-key (kbd "s-f") 'projectile-find-file)
2001 (global-set-key (kbd "s-`") 'mode-line-other-buffer)
2003 (global-set-key (kbd "s-n") 'persp-next)
2004 (global-set-key (kbd "s-p") 'persp-prev)
2006 (global-set-key (kbd "s-=") 'text-scale-increase)
2007 (global-set-key (kbd "s--") 'text-scale-decrease)
2009 ;; (global-set-key (kbd "s-u") 'undo-tree-visualize)
2012 ;; someothers default mapping on super (command) key
2014 ;; s-k kill-this-buffer
2017 ;; s-h --> ns-do-hide-emacs
2018 ;; s-j --> ido-switch-buffer +
2019 ;; s-k --> kill-this-buffer
2020 ;; s-l --> goto-line
2021 ;; s-; --> undefined
2022 ;; s-' --> next-multiframe-window
2023 ;; s-ret --> toggle-frame-fullscreen +
2025 ;; s-y --> ns-paste-secondary
2026 ;; s-u --> revert-buffer
2027 ;; s-i --> undefined - but used for iterm globally
2028 ;; s-o --> used for emacs globally
2029 ;; s-p --> projectile-persp-switch-project +
2030 ;; s-[ --> next-buffer +
2031 ;; s-] --> previous-buffer +
2033 ;; s-0 --> undefined
2034 ;; s-9 --> undefined
2035 ;; s-8 --> undefined
2036 ;; s-7 --> undefined
2037 ;; s-6 --> undefined
2038 ;; s-- --> center-line
2039 ;; s-= --> undefined
2041 ;; s-n --> make-frame
2042 ;; s-m --> iconify-frame
2043 ;; s-b --> undefined
2044 ;; s-, --> customize
2045 ;; s-. --> undefined
2046 ;; s-/ --> undefined
2048 ;; s-g --> isearch-repeat-forward
2049 ;; s-f --> projectile-find-file +
2050 ;; s-d --> isearch-repeat-background
2051 ;; s-s --> save-buffer
2052 ;; s-a --> make-whole-buffer
2054 ;; s-b --> undefined
2056 ;; s-c --> ns-copy-including-secondary
2058 ;; s-t --> ns-popup-font-panel
2059 ;; s-r --> undefined
2060 ;; s-e --> isearch-yanqk-kill
2061 ;; s-w --> delete-frame
2062 ;; s-q --> same-buffers-kill-emacs
2064 ;; s-` --> other-frame
2067 ** Windown & Buffer - =C-o=
2068 Defind a =hydra= function for windows, buffer & bookmark operations. And map it to =C-o= globally.
2069 Most use =C-o C-o= to switch buffers; =C-o x, v= to split window; =C-o o= to delete other windows
2070 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2073 (defun sd/delete-current-window ()
2075 (if (> (length (window-list)) 1)
2077 (message "Only one Windows now!")))
2079 (defun sd/toggle-max-windows ()
2080 "Set maximize current if there are multiple windows, if only
2081 one window, window undo"
2083 (if (equal (length (window-list)) 1)
2085 (delete-other-windows)))
2087 (defhydra sd/hydra-window (:color red :columns nil)
2089 ("h" windmove-left nil :exit t)
2090 ("j" windmove-down nil :exit t)
2091 ("k" windmove-up nil :exit t)
2092 ("l" windmove-right nil :exit t)
2093 ("H" hydra-move-splitter-left nil)
2094 ("J" hydra-move-splitter-down nil)
2095 ("K" hydra-move-splitter-up nil)
2096 ("L" hydra-move-splitter-right nil)
2099 (split-window-right)
2104 (split-window-below)
2107 ;; ("o" delete-other-windows "one" :exit t)
2108 ("o" sd/toggle-max-windows "one" :exit t)
2109 ("C-o" ido-switch-buffer "buf" :exit t)
2110 ("C-k" sd/delete-current-window "del" :exit t)
2111 ("'" other-window "other" :exit t)
2112 ("a" ace-window "ace")
2113 ("s" ace-swap-window "swap")
2114 ("d" ace-delete-window "ace-one" :exit t)
2115 ("i" ace-maximize-window "ace-one" :exit t)
2116 ("b" ido-switch-buffer "buf" :exit t)
2117 ("C-b" ido-switch-buffer "buf" :exit t)
2118 ("m" bookmark-jump-other-window "open bmk" :exit t)
2119 ("M" bookmark-set "set bmk" :exit t)
2120 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
2121 ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
2124 ("C-h" nil nil :exit t)
2125 ("C-j" nil nil :exit t)
2126 ;; ("C-k" nil :exit t)
2127 ("C-l" nil nil :exit t)
2128 ("C-;" nil nil :exit t)
2129 ("p" nil nil :exit t)
2130 ("n" nil nil :exit t)
2131 ("[" nil nil :exit t)
2132 ("]" nil nil :exit t)
2135 (global-unset-key (kbd "C-o"))
2136 (global-set-key (kbd "C-o") 'sd/hydra-window/body)
2141 [[https://www.masteringemacs.org/article/effective-editing-movement][effective-editing-movement]]
2142 *** Command Arguments, numeric argumens
2143 =C-u 4= same as =C-4=, =M-4=
2145 moving by line / word /
2146 =C-f=, =C-b=, =C-p=, =C-n=, =M-f=, =M-b=
2148 =M-m= (move first non-whitespace on this line)
2149 =M-}=, =M-{=, Move forward end of paragraph
2150 =M-a=, =M-e=, beginning / end of sentence
2151 =C-M-a=, =C-M-e=, move begining of defun
2152 =C-x ]=, =C-x [=, forward/backward one page
2153 =C-v=, =M-v=, =C-M-v=, =C-M-S-v= scroll down/up
2154 =M-<=, =M->=, beginning/end of buffer
2155 =M-r=, Repositiong point
2157 *** Moving by S-expression / List
2159 =C-<SPC>= set marks toggle the region
2160 =C-u C-<SPC>= Jump to the mark, repeated calls go further back the mark ring
2161 =C-x C-x= Exchanges the point and mark.
2163 Stolen [[https://www.masteringemacs.org/article/fixing-mark-commands-transient-mark-mode][fixing-mark-commands-transient-mark-mode]]
2164 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2165 (defun push-mark-no-activate ()
2166 "Pushes `point' to `mark-ring' and does not activate the region
2167 Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
2169 (push-mark (point) t nil)
2170 (message "Pushed mark to ring"))
2172 ;; (global-set-key (kbd "C-`") 'push-mark-no-activate)
2174 (defun jump-to-mark ()
2175 "Jumps to the local mark, respecting the `mark-ring' order.
2176 This is the same as using \\[set-mark-command] with the prefix argument."
2178 (set-mark-command 1))
2180 ;; (global-set-key (kbd "M-`") 'jump-to-mark)
2182 (defun exchange-point-and-mark-no-activate ()
2183 "Identical to \\[exchange-point-and-mark] but will not activate the region."
2185 (exchange-point-and-mark)
2186 (deactivate-mark nil))
2188 ;; (define-key global-map [remap exchange-point-and-mark] 'exchange-point-and-mark-no-activate)
2191 Show the mark ring using =helm-mark-ring=, also mapping =M-`= to quit minibuffer. so that =M-`= can
2192 toggle the mark ring. the best way is add a new action and mapping to =helm-source-mark-ring=, but
2193 since there is no map such as =helm-mark-ring=map=, so I cannot binding a key to the quit action.
2194 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2195 (setq mark-ring-max 50)
2196 (global-set-key (kbd "M-`") #'helm-mark-ring)
2198 (define-key minibuffer-local-map (kbd "M-`") 'keyboard-escape-quit)
2201 =M-h= marks the next paragraph
2202 =C-x h= marks the whole buffer
2203 =C-M-h= marks the next defun
2204 =C-x C-p= marks the next page
2205 **** DONE Mapping toggle mark ring=
2207 - State "DONE" from "TODO" [2016-07-22 Fri 23:18]
2210 Registers can save text, position, rectangles, file and configuration and other things.
2211 Here for movement, we can use register to save/jump position
2212 =C-x r SPC= store point in register
2213 =C-x r j= jump to register
2214 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2215 (use-package list-register
2220 As I would like use bookmakr for different buffer/files. to help to swith
2221 different buffer/file quickly. this setting is in Windows/buffer node
2222 =C-x r m= set a bookmarks
2223 =C-x r l= list bookmarks
2224 =C-x r b= jump to bookmarks
2227 Search, replace and hightlight will in later paragraph
2228 *** =Avy= for easy motion
2229 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2233 (avy-setup-default))
2235 (global-set-key (kbd "C-M-j") 'avy-goto-line-below)
2236 (global-set-key (kbd "C-M-n") 'avy-goto-line-below)
2237 (global-set-key (kbd "C-M-k") 'avy-goto-line-above)
2238 (global-set-key (kbd "C-M-p") 'avy-goto-line-above)
2240 (global-set-key (kbd "C-M-f") 'avy-goto-word-1-below)
2241 (global-set-key (kbd "C-M-b") 'avy-goto-word-1-above)
2243 ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
2244 (global-set-key (kbd "C-M-w") 'avy-goto-char-timer)
2245 (global-set-key (kbd "C-M-l") 'avy-goto-char-in-line)
2247 ;; ;; will delete above
2248 ;; (global-set-key (kbd "M-g j") 'avy-goto-line-below)
2249 ;; (global-set-key (kbd "M-g k") 'avy-goto-line-above)
2250 ;; (global-set-key (kbd "M-g w") 'avy-goto-word-1-below)
2251 ;; (global-set-key (kbd "M-g b") 'avy-goto-word-1-above)
2252 ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
2253 ;; (global-set-key (kbd "M-g f") 'avy-goto-char-timer)
2254 ;; (global-set-key (kbd "M-g c") 'avy-goto-char-in-line)
2257 *** =Imenu= goto tag
2258 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2259 ;; (global-set-key (kbd "M-i") #'counsel-imenu)
2260 (global-set-key (kbd "M-i") #'imenu)
2262 ;; (global-set-key (kbd "M-l") 'goto-line)
2266 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2267 (global-set-key (kbd "M-l") 'goto-line)
2270 *** Movement effective
2273 =C-w=, put the word into search minibuffer, =M-y=
2274 =M-c=, toggle case sensitivity
2275 =M-n=, =M-p=, history
2279 - cut, yank, =C-w=, =C-y=
2281 - undo, redo - undo-tree
2282 - select, expand-region
2283 - spell check, flyspell
2286 =helm-show-kill-ring=
2287 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2288 (setq kill-ring-max 100) ; default is 60p
2289 (global-set-key (kbd "M-y") #'helm-show-kill-ring)
2293 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2294 (use-package expand-region
2297 (global-set-key (kbd "C-=") 'er/expand-region))
2301 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2302 (use-package undo-tree
2305 (define-key undo-tree-visualizer-mode-map "j" 'undo-tree-visualize-redo)
2306 (define-key undo-tree-visualizer-mode-map "k" 'undo-tree-visualize-undo)
2307 (define-key undo-tree-visualizer-mode-map "h" 'undo-tree-visualize-switch-branch-left)
2308 (define-key undo-tree-visualizer-mode-map "l" 'undo-tree-visualize-switch-branch-right)
2309 (global-undo-tree-mode 1))
2311 (global-set-key (kbd "s-u") 'undo-tree-visualize)
2315 Stolen from [[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-spelling.el][here]], hunspell will search dictionary in =DICPATH=
2316 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2317 (setenv "DICPATH" "/usr/local/share/hunspell")
2319 (when (executable-find "hunspell")
2320 (setq-default ispell-program-name "hunspell")
2321 (setq ispell-really-hunspell t))
2323 ;; (defun text-mode-hook-setup ()
2324 ;; ;; Turn off RUN-TOGETHER option when spell check text-mode
2325 ;; (setq-local ispell-extra-args (flyspell-detect-ispell-args)))
2326 ;; (add-hook 'text-mode-hook 'text-mode-hook-setup)
2327 ;; (add-hook 'text-mode-hook 'flyspell-mode)
2329 ;; enable flyspell check on comments and strings in progmamming modes
2330 ;; (add-hook 'prog-mode-hook 'flyspell-prog-mode)
2332 ;; I don't use the default mappings
2333 (with-eval-after-load 'flyspell
2334 (define-key flyspell-mode-map (kbd "C-;") nil)
2335 (define-key flyspell-mode-map (kbd "C-,") nil)
2336 (define-key flyspell-mode-map (kbd "C-.") nil))
2339 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]]
2340 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2341 ;; NO spell check for embedded snippets
2342 (defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
2343 (let ((rlt ad-return-value)
2344 (begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\)")
2345 (end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\)")
2348 (when ad-return-value
2350 (setq old-flag case-fold-search)
2351 (setq case-fold-search t)
2352 (setq b (re-search-backward begin-regexp nil t))
2353 (if b (setq e (re-search-forward end-regexp nil t)))
2354 (setq case-fold-search old-flag))
2355 (if (and b e (< (point) e)) (setq rlt nil)))
2356 (setq ad-return-value rlt)))
2359 ** Search & Replace / hightlight =M-s=
2362 =C-w= add word at point to search string,
2364 =C-M-y= add character at point to search string
2365 =M-s C-e= add reset of line at point
2366 =C-y= yank from clipboard to search string
2367 =M-n=, =M-p=, history
2368 =C-M-i= complete search string
2369 set the isearch history size, the default is only =16=
2370 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2371 (setq history-length 5000)
2372 (set-variable regexp-search-ring-max 1000)
2373 (set-variable search-ring-max 1000)
2377 use the prefix =M-s= for searching in buffers
2378 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2379 (defun sd/make-keymap (key bindings)
2380 (setq keymap (make-sparse-keymap))
2381 (dolist (binding bindings)
2382 (define-key keymap (car binding) (cdr binding)))
2383 (global-set-key key keymap))
2385 ;; (sd/make-keymap "\M-s"
2386 ;; '(("w" . save-buffer)
2387 ;; ;; ("\M-w" . save-buffer)
2388 ;; ("e" . revert-buffer)
2389 ;; ("s" . isearch-forward-regexp)
2390 ;; ("\M-s" . isearch-forward-regexp)
2391 ;; ("r" . isearch-backward-regexp)
2392 ;; ("." . isearch-forward-symbol-at-point)
2394 ;; ;; ("h" . highlight-symbol-at-point)
2395 ;; ("h" . highlight-symbol)
2396 ;; ("m" . highlight-regexp)
2397 ;; ("l" . highlight-lines-matching-regexp)
2398 ;; ("M" . unhighlight-regexp)
2399 ;; ("f" . keyboard-quit)
2400 ;; ("q" . keyboard-quit)))
2403 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2404 (use-package highlight-symbol
2407 (defhydra sd/search-replace (:color red :columns nil)
2409 ("w" save-buffer "save" :exit t)
2410 ("e" revert-buffer "revert" :exit t)
2411 ("u" undo-tree-visualize "undo" :exit t)
2412 ("s" isearch-forward-regexp "s-search" :exit t)
2413 ("M-s" isearch-forward-regexp "s-search" :exit t)
2414 ("r" isearch-backward-regexp "r-search" :exit t)
2415 ("." isearch-forward-symbol-at-point "search point" :exit t)
2416 ("/" swiper "swiper" :exit t)
2417 ("o" occur "occur" :exit t)
2418 ("h" highlight-symbol "higlight" :exit t)
2419 ("l" highlight-lines-matching-regexp "higlight line" :exit t)
2420 ("m" highlight-regexp "higlight" :exit t)
2421 ("M" unhighlight-regexp "unhiglight" :exit t)
2425 (global-unset-key (kbd "M-s"))
2426 (global-set-key (kbd "M-s") 'sd/search-replace/body)
2429 ;; search and replace and highlight
2430 (define-key isearch-mode-map (kbd "M-s") 'isearch-repeat-forward)
2431 (define-key isearch-mode-map (kbd "M-r") 'isearch-repeat-backward)
2432 (global-set-key (kbd "s-[") 'highlight-symbol-next)
2433 (global-set-key (kbd "s-]") 'highlight-symbol-prev)
2434 (global-set-key (kbd "s-\\") 'highlight-symbol-query-replace)
2440 Occur search key bindings
2441 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2442 (defun sd/occur-keys ()
2443 "My key bindings in occur-mode"
2445 (switch-to-buffer-other-window "*Occur*")
2446 (define-key occur-mode-map (kbd "C-o") nil)
2447 (define-key occur-mode-map (kbd "C-n") (lambda ()
2450 (occur-mode-goto-occurrence-other-window)
2453 (define-key occur-mode-map (kbd "C-p") (lambda ()
2456 (occur-mode-goto-occurrence-other-window)
2460 (add-hook 'occur-hook #'sd/occur-keys)
2462 (use-package color-moccur
2464 :commands (isearch-moccur isearch-all)
2466 (setq isearch-lazy-highlight t)
2468 (use-package moccur-edit))
2472 stolen from [[https://github.com/mariolong/emacs.d/blob/f6a061594ef1b5d1f4750e9dad9dc97d6e122840/emacs-init.org][here]]
2473 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2477 (setq ivy-use-virtual-buffers t)
2478 (set-face-attribute 'ivy-current-match nil :background "Orange" :foreground "black")
2481 (global-set-key (kbd "s-/") 'swiper)
2482 (define-key swiper-map (kbd "M-r") 'swiper-query-replace)
2483 (define-key swiper-map (kbd "C-.") (lambda ()
2485 (insert (format "%s" (with-ivy-window (thing-at-point 'word))))))
2486 (define-key swiper-map (kbd "M-.") (lambda ()
2488 (insert (format "%s" (with-ivy-window (thing-at-point 'symbol)))))))
2491 * TODO Convert ASCII to key
2492 ** map =function-key-map= [[http://academic.evergreen.edu/projects/biophysics/technotes/program/ascii_ctrl.htm][ascii_ctrl]]
2493 new file =C-x C-f C-f=
2495 ** write color syntax for =Man-mode=
2497 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2498 (font-lock-add-keywords 'perl-mode '(("\\(|\\w+?\\(,\\w+?\\)?|\\)" 1 'py-builtins-face)))
2501 * TODO jump last change point
2502 * TODO emms mode-line
2504 * TODO Temp directory for cached/history/temp files
2505 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2506 (use-package recentf
2508 (setq recentf-save-file (concat sd-temp-directory "recentf")))
2510 ;; (use-package projectile
2512 ;; (setq projectile-cache-file (concat sd-temp-directory "projectile.cache")))
2516 ;; (setq ido-save-directory-list-file (concat sd-temp-directory "ido.last")))
2518 (use-package savehist
2520 (setq savehist-file (concat sd-temp-directory "history")))
2522 ;; (use-package emms
2524 ;; (setq emms-directory (concat sd-temp-directory "emms")))
2526 (setq auto-save-list-file-prefix (concat sd-temp-directory "auto-save-list/.saves-"))
2530 ;; (setq smex-save-file (concat sd-temp-directory "smex-items"))
2533 * =C-u C-h a= search funtions
2537 - interactive for anonymous function
2538 When define a key to a anonymous function, the lambda function should be interactive
2540 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2541 ;; (require 'saveplace)
2542 ;; (setq-default save-place t)
2543 ;; (delete-selection-mode 1)
2553 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2555 ;; M-h - mark-paragraph
2556 ;; M-j - new line indent
2557 ;; M-k - kill-sentence
2558 ;; M-l - downcase words ====== goto-line
2560 ;; M-'- abbrev-prefix-mark =======
2561 ;; M-RET none ======
2564 ;; M-u - upcase word
2565 ;; M-i - ====== imenu
2566 ;; M-o ====== prefix
2570 ;; M-\ deleter horizontal space =====
2574 ;; M-, --- mark stack====== =
2575 ;; M-. lisp-goto-symboo, find definitation
2583 ;; M-q - lisp fill, fill paragraph
2586 ;; M-r - rePositioning
2587 ;; M-t transpose word
2591 ;; M-c capitalize-word
2596 * TODO ibuffer hydra