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
11 Set system PATH and emacs exec path
12 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
13 (setenv "PATH" (concat (getenv "PATH")
15 ":" "/Library/TeX/texbin"))
16 (setq exec-path (append exec-path '("/usr/local/bin")))
17 (setq exec-path (append exec-path '("/Library/TeX/texbin/")))
20 ** Package Initialization
21 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
24 (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
25 ("gnu" . "http://elpa.gnu.org/packages/")
26 ("org" . "http://orgmode.org/elpa/")))
32 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
33 (defconst my-name "Peng Li")
34 (defconst my-email "seudut@gmail.com")
35 (defconst MY-EMACS-DIR (concat (getenv "HOME") "/.emacs.d"))
36 (defconst MY-EMACS-TMP (concat MY-EMACS-DIR "/temp"))
37 (unless (file-exists-p MY-EMACS-TMP)
42 *** scroll bar, tool-bar and menu-bar
43 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
44 (if (display-graphic-p)
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)
59 ;;supress the redefined warning at startup
60 (setq ad-redefinition-action 'accept)
63 (setq scroll-margin 5)
65 (when (display-graphic-p)
66 (fringe-mode '(0 . 0)))
69 ;; (setq-default indicate-empty-lines t)
70 ;; (setq-default indicate-abuffer-boundaries 'right)
74 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
75 (setq custom-file "~/.emacs.d/custom.el")
76 (if (file-exists-p custom-file)
80 *** Switch the focus to help window when it appears
81 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
82 (setq help-window-select t)
85 *** Set default window size
86 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
87 (setq initial-frame-alist
91 ;; (setq-default indicate-empty-lines t)
95 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
96 (setq auto-save-default nil)
98 ;; restore last session
99 ;; (desktop-save-mode t)
103 Make a temp directory for all cache/history files
104 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
105 (defconst sd-temp-directory
106 (file-name-as-directory "~/.emacs.d/temp"))
108 (unless (file-exists-p sd-temp-directory)
109 (mkdir sd-temp-directory))
112 *** Save minibuffer history
113 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
114 (setq savehist-file (concat sd-temp-directory "history"))
115 (setq history-length 1000)
116 (setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring))
119 ;; set temp file path for recentf and auto-save
120 (setq recentf-save-file (concat sd-temp-directory "recentf"))
121 (setq recentf-max-saved-items 1000)
122 (setq auto-save-list-file-prefix (concat sd-temp-directory "auto-save-list/.saves-"))
126 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
127 (setq large-file-warning-threshold nil)
131 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
132 (unless (display-graphic-p)
137 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
138 (setq vc-follow-symlinks t)
140 * Package Management Tools
142 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
143 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
144 (unless (package-installed-p 'use-package)
145 (package-refresh-contents)
146 (package-install 'use-package))
148 (require 'use-package)
152 [[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.
153 Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
154 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
158 (add-to-list 'load-path "~/.emacs.d/el-get"))
162 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
169 clean mode line, Refer to [[https://www.masteringemacs.org/article/hiding-replacing-modeline-strings][Marstering Emacs]], some greek character see [[http://xahlee.info/math/math_unicode_greek.html][math_unicode_greek]]
170 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
171 (defvar mode-line-cleaner-alist
172 `((auto-complete-mode . " Ξ±")
173 (paredit-mode . " Ο")
176 (projectile-mode . "")
178 (undo-tree-mode . "")
180 (which-key-mode . "")
182 (smartparens-mode . "")
184 (linum-relative-mode . "")
186 (auto-revert-mode . "")
188 (org-indent-mode . "")
192 (page-break-lines-mode . "")
193 (yas-minor-mode . "y")
195 (evil-escape-mode . "")
196 (auto-fill-mode . "")
198 (lisp-interaction-mode . "Ξ»")
201 (emacs-lisp-mode . "EL")
202 ;; (eshell-mode . "π")
203 ;; (dired-mode . "π")
204 ;; (ibuffer-mode . "π")
205 ;; (org-mode . "π")
206 (nxhtml-mode . "nx"))
207 "Alist for `clean-mode-line'.
209 When you add a new element to the alist, keep in mind that you
210 must pass the correct minor/major mode symbol and a string you
211 want to use in the modeline *in lieu of* the original.")
214 (defun clean-mode-line ()
216 (loop for cleaner in mode-line-cleaner-alist
217 do (let* ((mode (car cleaner))
218 (mode-str (cdr cleaner))
219 (old-mode-str (cdr (assq mode minor-mode-alist))))
221 (setcar old-mode-str mode-str))
223 (when (eq mode major-mode)
224 (setq mode-name mode-str)))))
227 (add-hook 'after-change-major-mode-hook 'clean-mode-line)
231 Install powerline mode [[https://github.com/milkypostman/powerline][powerline]]
232 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
233 (use-package powerline
238 Revised powerline-center-theme
239 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
240 (defun sd/powerline-simpler-vc (s)
242 (replace-regexp-in-string "Git[:-]" "" s)
245 (defface sd/powerline-active1 '((t (:background "yellow" :foreground "black" :inherit mode-line)))
246 "My Powerline face 1 based on powerline-active1."
249 (defface sd/buffer-modified-active1 '((t (:background "red" :foreground "black" :inherit mode-line)))
250 "My Powerline face 1 based on powerline-active1."
253 (defface sd/buffer-view-active1 '((t (:background "green" :foreground "black" :inherit mode-line)))
254 "My Powerline face 1 based on powerline-active1."
257 (defface sd/mode-line-buffer-id
258 '((t (:background "yellow" :foreground "black" :inherit mode-line-buffer-id)))
259 "My powerline mode-line face, based on mode-line-buffer-id"
262 ;; Don't show buffer modified for scratch and eshell mode
263 (defun sd/buffer-is-eshel-or-scratch ()
264 "Dot not show modified indicator for buffers"
266 (unless (or (string-match "*scratch*" (buffer-name))
267 (equal major-mode 'eshell-mode))
270 (defun sd/powerline-center-theme_revised ()
271 "Setup a mode-line with major and minor modes centered."
273 (setq-default mode-line-format
276 (let* ((active (powerline-selected-window-active))
277 (mode-line-buffer-id (if active 'sd/mode-line-buffer-id 'powerline-inactive1))
278 (mode-line (if active 'mode-line 'mode-line-inactive))
279 (my-face1 (if active 'sd/powerline-active1 'powerline-inactive1))
280 (my-face-buffer-modified (if (and (sd/buffer-is-eshel-or-scratch) (buffer-modified-p) (not buffer-read-only))
281 'sd/buffer-modified-active1
282 (if buffer-read-only 'sd/buffer-view-active1
284 (face1 (if active 'powerline-active1 'powerline-inactive1))
285 (face2 (if active 'powerline-active2 'powerline-inactive2))
286 (separator-left (intern (format "powerline-%s-%s"
287 (powerline-current-separator)
288 (car powerline-default-separator-dir))))
289 (separator-right (intern (format "powerline-%s-%s"
290 (powerline-current-separator)
291 (cdr powerline-default-separator-dir))))
292 (lhs (list (powerline-raw "%* " my-face-buffer-modified 'l)
293 (powerline-buffer-id mode-line-buffer-id 'l)
294 (powerline-raw " " my-face1)
295 (funcall separator-left my-face1 face1)
296 (powerline-narrow face1 'l)
297 (sd/powerline-simpler-vc (powerline-vc face1))))
298 (rhs (list (powerline-raw global-mode-string face1 'r)
299 (powerline-raw "%4l" face1 'r)
300 (powerline-raw ":" face1)
301 (powerline-raw "%3c" face1 'r)
302 (funcall separator-right face1 my-face1)
303 (powerline-raw (format-time-string " %I:%M %p ") my-face1 'r)))
304 (center (list (powerline-raw " " face1)
305 (funcall separator-left face1 face2)
306 (powerline-raw (when (and (boundp 'evil-mode) evil-mode) evil-mode-line-tag) face2)
307 (when (and (boundp 'erc-track-minor-mode) erc-track-minor-mode)
308 (powerline-raw erc-modified-channels-object face2 'l))
309 (powerline-major-mode face2 'l)
310 (powerline-process face2)
311 (powerline-raw " :" face2)
312 (powerline-minor-modes face2 'l)
313 (powerline-raw " " face2)
314 (funcall separator-right face2 face1))))
315 (concat (powerline-render lhs)
316 (powerline-fill-center face1 (/ (powerline-width center) 2.0))
317 (powerline-render center)
318 (powerline-fill face1 (powerline-width rhs))
319 (powerline-render rhs)))))))
321 (setq ns-use-srgb-colorspace nil) ;; Fix the issue in mode-line when showing triangle
322 (sd/powerline-center-theme_revised)
328 - hightligh current line
329 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
330 ;; (global-hl-line-mode)
331 ;; don't want high light current line in eshell/term mode
332 (add-hook 'prog-mode-hook 'hl-line-mode)
333 (add-hook 'text-mode-hook 'hl-line-mode)
334 (add-hook 'dired-mode-hook 'hl-line-mode)
336 ;; only highlight selected window
337 (setq hl-line-sticky-flag nil)
339 ;; (setq-default fill-column 120)
340 ;; (add-hook 'text-mode-hook 'turn-on-auto-fill)
343 - highlight searching text
344 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
345 (set-face-attribute 'lazy-highlight nil :background "yellow" :foreground "black" :weight 'bold)
349 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
351 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
352 (use-package molokai-theme
355 (use-package color-theme
357 :init (require 'color-theme)
358 :config (use-package color-theme-sanityinc-tomorrow
362 (load-theme 'molokai t)))
365 Change the Org-mode colors
367 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
368 ;; (defun org-src-color-blocks-light ()
369 ;; "Colors the block headers and footers to make them stand out more for lighter themes"
372 ;; '(org-block-begin-line
373 ;; ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
374 ;; '(org-block-background
375 ;; ((t (:background "#FFFFEA"))))
377 ;; ((t (:background "#FFFFEA"))))
378 ;; '(org-block-end-line
379 ;; ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
381 ;; '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
382 ;; '(which-func ((t (:foreground "#008000"))))))
384 ;; (defun org-src-color-blocks-dark ()
385 ;; "Colors the block headers and footers to make them stand out more for dark themes"
388 ;; '(org-block-begin-line
389 ;; ((t (:foreground "#008ED1" :background "#002E41"))))
390 ;; '(org-block-background
391 ;; ((t (:background "#000000"))))
393 ;; ((t (:background "#000000"))))
394 ;; '(org-block-end-line
395 ;; ((t (:foreground "#008ED1" :background "#002E41"))))
397 ;; '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
398 ;; '(which-func ((t (:foreground "green"))))))
400 ;; (org-src-color-blocks-dark)
404 improve color for org-mode
405 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
406 ;; (deftheme ha/org-theme "Sub-theme to beautify org mode")
409 ;; (defvar sd/variable-font-tuple
410 ;; (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
411 ;; ((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
412 ;; ((x-list-fonts "Verdana") '(:font "Verdana"))
413 ;; ((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
414 ;; (nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro.")))
415 ;; "My variable width font available to org-mode files and whatnot."))
417 ;; (defun sd/org-color ()
418 ;; (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
419 ;; (base-font-color (face-foreground 'default nil 'default))
420 ;; (background-color (face-background 'default nil 'default))
421 ;; (primary-color (face-foreground 'mode-line nil))
422 ;; (secondary-color (face-background 'secondary-selection nil 'region))
423 ;; (base-height (face-attribute 'default :height))
424 ;; (headline `(:inherit default :weight bold :foreground ,base-font-color)))
425 ;; (custom-theme-set-faces 'ha/org-theme
426 ;; `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
427 ;; `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
428 ;; `(org-table ((t (:inherit 'fixed-pitched))))
429 ;; `(org-block ((t (:inherit 'fixed-pitched))))
430 ;; `(org-block-background ((t (:inherit 'fixed-pitched))))
431 ;; `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
432 ;; `(org-block-end-line ((t (:inherit 'fixed-pitched))))
433 ;; `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
434 ;; `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
435 ;; `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
436 ;; `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
437 ;; `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
438 ;; :height ,(round (* 1.1 base-height))))))
439 ;; `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
440 ;; :height ,(round (* 1.25 base-height))))))
441 ;; `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
442 ;; :height ,(round (* 1.5 base-height))))))
443 ;; `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
444 ;; :height ,(round (* 1.75 base-height))))))
445 ;; `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
453 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
454 (use-package rainbow-delimiters
457 (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
461 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
462 (use-package page-break-lines
465 (global-page-break-lines-mode))
470 Enable rainbow mode in emacs lisp mode
472 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
473 (use-package rainbow-mode
476 ; (add-hook emacs-lisp-mode-hook 'rainbow-mode)
482 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
483 (if (display-graphic-p)
484 (set-cursor-color 'red))
489 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
490 (global-font-lock-mode 1)
494 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
495 (defvar my-font-family
496 (cond ((x-list-fonts "Source Code Pro") "Source Code Pro"))
497 (cond ((x-list-fonts "HanziPen SC") "HanziPen SC"))
498 ;; (cond ((x-list-fonts "Source Code Pro") "Source Code Pro:weight=light"))
501 ;; (when (display-graphic-p)
502 ;; (set-frame-font my-font-family)
503 ;; (set-face-attribute 'default nil :font my-font-family :height 120)
504 ;; (set-face-font 'default my-font-family))
509 Fix the font alignment issue when both Chinese and English hybird in org-mode table. Refer [fn:1]
510 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
511 ;; (defvar emacs-english-font "Source Code Pro:weight=light" "The font name of English.")
512 (defvar emacs-english-font "Source Code Pro" "The font name of English.")
514 ;; (defvar emacs-cjk-font "STHeiti" "The font name for CJK.")
515 (defvar emacs-cjk-font "HanziPen SC" "The font name for CJK.")
517 (defvar emacs-font-size-pair-list
520 (13 . 16) (14 . 16) (15 . 18) (16 . 20) (17 . 20)
521 (18 . 22) (19 . 22) (20 . 24) (21 . 26)
522 (24 . 28) (26 . 32) (28 . 34)
523 (30 . 36) (34 . 40) (36 . 44))
524 "This list is used to store matching (englis . chinese) font-size.")
525 ;; (defvar emacs-font-size-pair '(13 . 16) "Default font size pair for (english . chinese)")
527 ;; (defvar emacs-font-size-pair '(13 . 16) "Default font size pair for (english . chinese)")
529 (defvar emacs-font-size-pair (nth 3 emacs-font-size-pair-list) "Default font size pair for (english . chinese)")
531 (defun font-exist-p (fontname)
532 "Test if this font is exist or not."
533 (if (or (not fontname) (string= fontname ""))
535 (if (not (x-list-fonts fontname)) nil t)))
537 (defun set-font (english chinese size-pair)
538 "Setup emacs English and Chinese font on x window-system."
539 (if (font-exist-p english)
540 (set-frame-font english (format "%s:pixelsize=%d" english (car size-pair)) t)
541 ;; (set-face-attribute 'default nil :font english :height (* 10 (car size-pair)))
543 ;; (set-frame-font (format "%s:pixelsize=%d" english (car size-pair)) t)
545 (if (font-exist-p chinese)
546 (dolist (charset '(han cjk-misc) ;; '(kana han symbol cjk-misc bopomofo)
548 (set-fontset-font (frame-parameter nil 'font) charset
549 (font-spec :family chinese :size (cdr size-pair))))))
551 (defun emacs-step-font-size (step)
552 "Increase/Decrease emacs's font size."
553 (let ((scale-steps emacs-font-size-pair-list))
554 (if (< step 0) (setq scale-steps (reverse scale-steps)))
555 (setq emacs-font-size-pair
556 (or (cadr (member emacs-font-size-pair scale-steps))
557 emacs-font-size-pair))
558 (when emacs-font-size-pair
559 (message "emacs font size set to %.1f" (car emacs-font-size-pair))
560 (set-font emacs-english-font emacs-cjk-font emacs-font-size-pair))))
562 (defun increase-emacs-font-size ()
563 "Decrease emacs's font-size acording emacs-font-size-pair-list."
564 (interactive) (emacs-step-font-size 1))
566 (defun decrease-emacs-font-size ()
567 "Increase emacs's font-size acording emacs-font-size-pair-list."
568 (interactive) (emacs-step-font-size -1))
570 ; (set-font emacs-english-font emacs-cjk-font '(12 . 16))
571 ;; (set-font emacs-english-font emacs-cjk-font emacs-font-size-pair)
575 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
576 (when (display-graphic-p)
577 (setq my-ch-font "STkaiti")
578 ;; (setq face-font-rescale-alist `(("HanziPen SC" . ,(/ 16.0 13))))
579 (setq face-font-rescale-alist `((,my-ch-font . ,(/ 16.0 13))))
580 ;; (set-face-attribute 'default nil :font "Source Code Pro-13")
581 (set-face-attribute 'default nil :font "Source Code Pro:weight=light" :height 130)
582 ;; (set-fontset-font t 'han (font-spec :family "STkaiti"))
583 ;; (set-fontset-font t 'cjk-misc (font-spec :family "STkaiti"))
584 (dolist (charset '(han cjk-misc))
585 (set-fontset-font (frame-parameter nil 'font) charset
586 ;; (font-spec :family "HanziPen SC")
587 (font-spec :family my-ch-font))))
592 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
595 :init (setq ido-enable-flex-matching t
596 ido-ignore-extensions t
597 ido-use-virtual-buffers t
600 (setq ido-save-directory-list-file (concat sd-temp-directory "ido.last"))
604 (add-to-list 'completion-ignored-extensions ".pyc")
607 (define-key ido-buffer-completion-map (kbd "C-w") #'ido-delete-backward-word-updir)
608 (define-key ido-file-completion-map (kbd "C-w") #'ido-delete-backward-word-updir)
609 (define-key ido-file-dir-completion-map (kbd "C-w") #'ido-delete-backward-updir)
610 ;; (define-key ido-file-dir-completion-map (kbd "C-i") #'ido-copy-current-word)
617 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
620 :config (flx-ido-mode nil))
624 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
625 (use-package ido-vertical-mode
628 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
630 (ido-vertical-mode 1))
634 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
638 (setq smex-save-file (concat sd-temp-directory "smex-items"))
642 ("M-X" . smex-major-mode-commands))
646 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
647 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
648 (use-package ido-ubiquitous
651 (setq magit-completing-read-function 'magit-ido-completing-read)
652 (setq gnus-completing-read-function 'gnus-ido-completing-read)
654 (ido-ubiquitous-mode 1))
658 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
659 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
660 (use-package ido-exit-target
663 (mapcar #'(lambda (map)
664 (define-key map (kbd "C-j") #'ido-exit-target-other-window)
665 (define-key map (kbd "C-k") #'ido-exit-target-split-window-below))
666 (list ido-buffer-completion-map
667 ;; ido-common-completion-map
668 ido-file-completion-map
669 ido-file-dir-completion-map)))
673 let helm windows split inside current window
674 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
675 (with-eval-after-load 'helm
676 (setq helm-split-window-in-side-p t))
680 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
681 (use-package projectile
684 (setq projectile-enable-caching t)
685 (setq projectile-switch-project-action 'projectile-dired)
686 (setq projectile-cache-file (concat sd-temp-directory "projectile.cache"))
687 (setq projectile-completion-system 'ivy)
689 (add-to-list 'projectile-globally-ignored-files "GTAGS")
690 (projectile-global-mode t))
692 ;; https://emacs.stackexchange.com/questions/16497/how-to-exclude-files-from-projectile
693 (if (executable-find "rg")
695 (defconst modi/rg-arguments
696 `("--line-number" ; line numbers
698 "--follow" ; follow symlinks
699 "--mmap") ; apply memory map optimization when possible
700 "Default rg arguments used in the functions in `projectile' package.")
702 (defun modi/advice-projectile-use-rg ()
703 "Always use `rg' for getting a list of all files in the project."
705 (append '("\\rg") ; used unaliased version of `rg': \rg
707 '("--null" ; output null separated results,
708 "--files")) ; get file names matching the regex '' (all files)
711 (advice-add 'projectile-get-ext-command :override #'modi/advice-projectile-use-rg))
712 (message "rg is not found"))
715 * Swiper & Ivy & Counsel
716 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
721 (use-package ivy :ensure t)
723 (setq ivy-use-virtual-buffers nil
725 ivy-count-format "%d/%d ")
726 (set-face-attribute 'ivy-current-match nil :background "Orange" :foreground "black")
727 (global-set-key (kbd "M-x") 'counsel-M-x)
728 ;; (global-set-key (kbd "C-h f") 'counsel-describe-function)
729 ;; (global-set-key (kbd "C-h v") 'counsel-describe-variable)
730 (global-set-key (kbd "C-x C-f") 'counsel-find-file)
731 (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
732 (global-set-key (kbd "C-c C-r") 'ivy-resume))
735 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
738 '(("q" (lambda (x) (ivy-quit-and-run (message "=="))) "exit")))
741 'projectile-switch-to-buffer
742 '(("j" ivy--switch-buffer-other-window-action "other window" )))
744 (defun sd/projectile-find-file-other-window-action (file)
745 (message "=========")
746 (message (projectile-expand-root file))
747 (find-file-other-window (projectile-expand-root file)))
750 'projectile-find-file
751 '(("j" sd/projectile-find-file-other-window-action "other-window")))
753 (defun sd/swith-to-buffer ()
756 (if (projectile-project-p)
757 (projectile-switch-to-buffer)
758 (ivy-switch-buffer)))
762 '(("j" ivy--switch-buffer-other-window-action "other window")))
764 (defun sd/exit-ivy-and-swith-to-buffer ()
765 "exit ivy complete, and call swith to buffer"
768 (ivy-switch-buffer)))
770 (defun my/ivy-read-action (key)
771 (let ((actions (ivy-state-action ivy-last)))
772 (if (null (ivy--actionp actions))
774 (let* ((action-idx (cl-position-if
775 (lambda (x) (equal (car x) key))
777 (cond ((member key '("
\e" "
\a"))
780 (message "%s is not bound" key)
784 (setcar actions (1+ action-idx))
785 (ivy-set-action actions)))))))
787 (with-eval-after-load "ivy"
788 (define-key ivy-minibuffer-map (kbd "C-o") 'ivy-dispatching-done)
789 (define-key ivy-minibuffer-map (kbd "C-k") (lambda () (interactive)
790 (my/ivy-read-action "j")
792 (define-key ivy-minibuffer-map (kbd "M-o") #'sd/exit-ivy-and-swith-to-buffer))
795 stolen from [[https://github.com/mariolong/emacs.d/blob/f6a061594ef1b5d1f4750e9dad9dc97d6e122840/emacs-init.org][here]]
796 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
802 (global-set-key (kbd "s-/") 'swiper)
803 (define-key swiper-map (kbd "M-r") 'swiper-query-replace)
804 (define-key swiper-map (kbd "C-.") (lambda ()
806 (insert (format "%s" (with-ivy-window (thing-at-point 'word))))))
807 (define-key swiper-map (kbd "M-.") (lambda ()
809 (insert (format "%s" (with-ivy-window (thing-at-point 'symbol)))))))
813 ** Org-mode Basic setting
814 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
815 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
819 (setq org-startup-indented t)
820 (setq org-hide-leading-starts t)
821 (setq org-src-fontify-natively t)
822 (setq org-src-tab-acts-natively t)
823 (setq org-confirm-babel-evaluate nil)
824 (setq org-use-speed-commands t)
825 (setq org-completion-use-ido t)
826 (setq org-startup-with-inline-images t)
828 ;; (setq org-startup-with-latex-preview t)
829 ;; (setq org-format-latex-options (plist-put org-format-latex-options :scale 1.2))
831 (add-to-list 'org-modules 'org-habit)
832 (setq org-habit-graph-column 50)
833 (setq org-hide-emphasis-markers t)
834 (setq org-html-validation-link nil)
835 ;; open link when return clicked
836 (setq org-return-follows-link t)
837 ;; open the ppt file by external open instead of emacs
838 (add-to-list 'org-file-apps '("\\.pptx" . "open %s"))
839 (add-to-list 'org-file-apps '("\\.doc" . "open %s"))
840 (setq org-image-actual-width nil))
844 *** Fix the default theme - molokai
845 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
846 (with-eval-after-load "org"
847 (set-face-attribute 'org-block-begin-line nil :background nil :foreground nil :inherit 'shadow :slant 'italic)
848 (set-face-attribute 'org-block-end-line nil :background nil :foreground nil :inherit 'shadow :slant 'italic)
849 ;; (set-face-attribute 'org-table nil :family "Ubuntu Mono" :height (face-attribute 'default :height))
852 *** variable-pitch-mode and fixed-pitch-mode
853 [[https://yoo2080.wordpress.com/2013/05/30/monospace-font-in-tables-and-source-code-blocks-in-org-mode-proportional-font-in-other-parts/][monospace font in tables and source code blocks in org-mode, proportional font in other parts]]
854 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
855 ;(when (display-graphic-p)
856 ; (unless (find-font (font-spec :name "Ubuntu Mono"))
857 ; (warn "Font not found Ubuntu Mono"))
858 ; (unless (find-font (font-spec :name "Source Code Pro"))
859 ; (warn "Font not found Source Code Pro"))
860 ; (unless (find-font (font-spec :name "Source Sans Pro"))
861 ; (warn "Font not found Source Sans Pro")))
863 ;; (set-face-attribute 'variable-pitch nil :font "Source Sans Pro" :height 160)
864 ;; (set-face-attribute 'fixed-pitch nil :font "Source Code Pro" :height (face-attribute 'default :height))
867 ;; Install Ubuntu Mono fonts and apply it in org-table to align Chinese fonts
868 ;; (with-eval-after-load "org"
869 ;; (mapc (lambda (face)
870 ;; (set-face-attribute face nil :inherit 'fixed-pitch))
874 ;; 'org-block-background
875 ;; 'org-block-begin-line
876 ;; 'org-block-end-line))
877 ;; (set-face-attribute 'org-table nil :family "Ubuntu Mono" :height 100)
878 ;; (set-face-attribute 'org-formula nil :family "Ubuntu Mono" :height 100)
879 ;; ;; org-special-keyword inherited from font-lock-keywork originally; as org is changed to variable-pitch, it cause
880 ;; ;; the font in special-keywords are not monospace
881 ;; (set-face-attribute 'org-special-keyword nil :inherit '(font-lock-keyword-face fixed-pitch))
883 ;; (set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch))
884 ;; (set-face-attribute 'org-block-begin-line nil :inherit 'shadow :slant 'italic :foreground nil)
885 ;; (set-face-attribute 'org-block-end-line nil :inherit 'shadow :slant 'italic :foreground nil)
887 ;; ;; fix indent broken by variable-pitch-mode
888 ;; ;; http://emacs.stackexchange.com/questions/26864/variable-pitch-face-breaking-indentation-in-org-mode
889 ;; (require 'org-indent)
890 ;; (set-face-attribute 'org-indent nil :inherit '(org-hide fixed-pitch)))
892 ;; (with-eval-after-load "org"
893 ;; (let ((default-font-size (- (face-attribute 'default :height) (if (display-graphic-p) 20 0))))
894 ;; (set-face-attribute 'org-code nil :height default-font-size)
895 ;; (set-face-attribute 'org-block nil :height default-font-size)
896 ;; ;; (set-face-attribute 'org-block-begin-line nil :background nil :foreground nil :inherit 'shadow :slant 'italic :height default-font-size)
897 ;; ;; (set-face-attribute 'org-block-end-line nil :background nil :foreground nil :inherit 'shadow :slant 'italic :height default-font-size)
898 ;; (when (find-font (font-spec :name "Ubuntu Mono"))
899 ;; (set-face-attribute 'org-table nil :family "Ubutu Mono" :height default-font-size)
900 ;; (set-face-attribute 'org-formula nil :family "Ubutu Mono" :height default-font-size))))
902 ;; (add-hook 'org-mode-hook
904 ;; (let ((default-font-size (- (face-attribute 'default :height) (if (display-graphic-p) 20 0))))
905 ;; (set-face-attribute 'org-code nil :height default-font-size)
906 ;; (set-face-attribute 'org-block nil :height default-font-size)
907 ;; ;; (set-face-attribute 'org-block-begin-line nil :background nil :foreground nil :inherit 'shadow :slant 'italic :height default-font-size)
908 ;; ;; (set-face-attribute 'org-block-end-line nil :background nil :foreground nil :inherit 'shadow :slant 'italic :height default-font-size)
909 ;; (when (find-font (font-spec :name "Ubuntu Mono"))
910 ;; (set-face-attribute 'org-table nil :family "Ubutu Mono" :height default-font-size)
911 ;; (set-face-attribute 'org-formula nil :family "Ubutu Mono" :height default-font-size)))))
914 Also correct the face of =org-meta-line= in =org-table=
915 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
916 ;; (with-eval-after-load "org"
917 ;; (set-face-attribute 'org-meta-line nil :font "Source Code Pro" :height 120 :slant 'italic :inherit 'font-lock-comment-face))
922 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
923 ;; (with-eval-after-load "org"
924 ;; (let* ((base-height (face-attribute 'variable-pitch :height))
925 ;; (base-font-color (face-foreground 'default nil 'default)))
926 ;; (set-face-attribute 'org-document-title nil :weight 'bold :height (+ 60 base-height))
927 ;; (set-face-attribute 'org-level-1 nil :weight 'bold :height (+ 40 base-height))
928 ;; (set-face-attribute 'org-level-2 nil :weight 'bold :height (+ 30 base-height))
929 ;; (set-face-attribute 'org-level-3 nil :weight 'bold :height (+ 20 base-height))
930 ;; (set-face-attribute 'org-level-4 nil :weight 'bold :height (+ 10 base-height))
931 ;; (set-face-attribute 'org-level-5 nil :weight 'bold)
932 ;; (set-face-attribute 'org-level-6 nil :weight 'bold)
933 ;; (set-face-attribute 'org-level-7 nil :weight 'bold)
934 ;; (set-face-attribute 'org-level-8 nil :weight 'bold)))
939 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
940 (el-get-bundle hasu/emacs-ob-racket
944 ;; (use-package ob-lua
947 ;; use current window for org source buffer editting
949 ;; (setq org-src-window-setup 'current-window)
950 (define-key org-mode-map (kbd "C-'") nil)
951 ;; C-M-i is mapped to imenu globally
952 (define-key org-mode-map (kbd "C-M-i") nil)
953 ;; set the ditta.jar path
955 (setq org-ditaa-jar-path "/usr/local/Cellar/ditaa/0.9/libexec/ditaa0_9.jar")
957 (file-exists-p org-ditaa-jar-path)
958 (message "seudut: ditaa.jar not found at %s " org-ditaa-jar-path))
960 (org-babel-do-load-languages 'org-babel-load-languages
980 ;; toggle image preview
981 (add-hook 'org-babel-after-execute-hook 'sd/display-inline-images 'append)
983 (defun sd/display-inline-images ()
985 (org-display-inline-images)
989 (with-eval-after-load "artist"
990 (define-key artist-mode-map [down-mouse-3] 'artist-mouse-choose-operation))
993 [[http://eschulte.github.io/babel-dev/DONE-integrate-plantuml-support.html][DONE-integrate-plantuml-support]]
996 brew install plantuml
999 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1000 (use-package plantuml-mode
1003 (setq org-plantuml-jar-path
1004 (expand-file-name "/usr/local/Cellar/plantuml/8041/plantuml.8041.jar"))
1006 (set-variable 'plantuml-jar-path
1007 (expand-file-name "/usr/local/Cellar/plantuml/8041/plantuml.8041.jar"))
1011 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
1012 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1013 (use-package org-bullets
1016 (add-hook 'org-mode-hook (apply-partially #'org-bullets-mode t)))
1018 (setq org-bullets-bullet-list '("β¦Ώ" "βͺ" "β" "β" "βΊ" "β"))
1020 ;; increase font size when enter org-src-mode
1021 ;; (add-hook 'org-src-mode-hook (lambda () (text-scale-increase 2)))
1023 ;; define a face for org-bullets
1024 (defface org-bullet-face
1025 '((t (:foreground "green yellow")))
1026 "Face used for the org-bullets.")
1027 (setq org-bullets-face-name (quote org-bullet-face))
1028 ;; (set-face-attribute 'org-bullet-face t :foreground "burlywood" :weight 'normal :height 1.6)
1032 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
1033 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
1034 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
1035 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
1036 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1042 (add-hook 'org-mode-hook 'worf-mode))
1046 Refer to [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
1048 standard key binding
1049 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1050 (global-set-key "\C-cl" 'org-store-link)
1051 (global-set-key "\C-ca" 'org-agenda)
1052 (global-set-key "\C-cb" 'org-iswitchb)
1056 Replace the list bullet =-=, =+=, with =β’=, a litter change based [[https://github.com/howardabrams/dot-files/blob/master/emacs-org.org][here]]
1057 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1058 ;; (use-package org-mode
1060 ;; (font-lock-add-keywords 'org-mode
1061 ;; '(("^ *\\([-+]\\) "
1062 ;; (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "β’")))))))
1066 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]],
1067 To track TODO state changes, the =!= is to insert a timetamp, =@= is to insert a note with
1068 timestamp for the state change.
1069 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1070 ;; (setq org-todo-keywords
1071 ;; '((sequence "β TODO(t)" "|" "β DONE(d)")
1072 ;; (sequence "β WAITING(w)" "|")
1073 ;; (sequence "|" "β CANCELLED(c)")))
1074 ; (setq org-todo-keyword-faces
1075 ; (quote ("TODO" . (:foreground "red" :weight bold))
1076 ; ("NEXT" . (:foreground "blue" :weight bold))
1077 ; ("WAITING" . (:foreground "forest green" :weight bold))
1078 ; ("DONE" . (:foreground "magenta" :weight bold))
1079 ; ("CANCELLED" . (:foreground "forest green" :weight bold))))
1082 (setq org-todo-keywords
1083 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!)")
1084 ;; (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING")
1085 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" ))))
1087 (setq org-todo-keyword-faces
1088 (quote (("TODO" :foreground "red" :weight bold)
1089 ("NEXT" :foreground "blue" :weight bold)
1090 ("DONE" :foreground "forest green" :weight bold)
1091 ("WAITING" :foreground "orange" :weight bold)
1092 ("HOLD" :foreground "magenta" :weight bold)
1093 ("CANCELLED" :foreground "forest green" :weight bold)
1094 ;; ("MEETING" :foreground "forest green" :weight bold)
1095 ;; ("PHONE" :foreground "forest green" :weight bold)
1099 Fast todo selections
1101 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1102 (setq org-use-fast-todo-selection t)
1103 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1106 TODO state triggers and tags, [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
1108 - Moving a task to =CANCELLED=, adds a =CANCELLED= tag
1109 - Moving a task to =WAITING=, adds a =WAITING= tag
1110 - Moving a task to =HOLD=, add =HOLD= tags
1111 - Moving a task to =DONE=, remove =WAITING=, =HOLD= tag
1112 - Moving a task to =NEXT=, remove all waiting/hold/cancelled tags
1114 This tags are used to filter tasks in agenda views
1115 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1116 (setq org-todo-state-tags-triggers
1117 (quote (("CANCELLED" ("CANCELLED" . t))
1118 ("WAITING" ("WAITING" . t))
1119 ("HOLD" ("WAITING") ("HOLD" . t))
1120 (done ("WAITING") ("HOLD"))
1121 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1122 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1123 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1127 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1128 ;; log time when task done
1129 ;; (setq org-log-done (quote time))
1130 ;; save clocking into to LOGBOOK
1131 (setq org-clock-into-drawer t)
1132 ;; save state change notes and time stamp into LOGBOOK drawer
1133 (setq org-log-into-drawer t)
1134 (setq org-clock-into-drawer "CLOCK")
1138 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1139 (setq org-tag-alist (quote ((:startgroup)
1145 ("CANCELLED" . ?c))))
1147 ;; Allow setting single tags without the menu
1148 (setq org-fast-tag-selection-single-key (quote expert))
1151 *** Capture - Refile - Archive
1153 Capture lets you quickly store notes with little interruption of your work flow.
1155 **** Capture Templates
1157 When a new taks needs to be added, categorize it as
1159 All captured file which need next actions are stored in =refile.org=,
1160 - A new task / note (t) =refile.org=
1161 - A work task in office =office.org=
1162 - A jourenl =diary.org=
1163 - A new habit (h) =refile.org=
1165 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1166 (setq org-directory "~/org")
1167 (setq org-default-notes-file "~/org/refile.org")
1168 (setq sd/org-diary-file "~/org/diary.org")
1170 (global-set-key (kbd "C-c c") 'org-capture)
1172 (setq org-capture-templates
1173 (quote (("t" "Todo" entry (file org-default-notes-file)
1174 "* TODO %?\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1175 ("n" "Note" entry (file org-default-notes-file)
1176 "* %? :NOTE:\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1177 ("j" "Journal" entry (file+datetree sd/org-diary-file)
1178 "* %?\n:LOGBOOK:\n:END:" :clock-in t :clock-resume t)
1179 ("h" "Habit" entry (file org-default-notes-file)
1180 "* 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 "))))
1185 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1186 (setq org-refile-targets (quote (;; (nil :maxlevel . 9)
1187 (org-agenda-files :maxlevel . 9))))
1189 (setq org-refile-use-outline-path t)
1191 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1195 Setting agenda files and the agenda view
1196 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1197 (setq org-agenda-files (quote ("~/org/gtd.org")))
1199 ;; only show today's tasks in agenda view
1200 ;; (setq org-agenda-span 'day)
1201 ;; Use current windows for agenda view
1202 ;; (setq org-agenda-window-setup 'current-window)
1204 ;; show all feature entries for repeating tasks,
1205 ;; this is already setting by default
1206 (setq org-agenda-repeating-timestamp-show-all t)
1208 ;; Show all agenda dates - even if they are empty
1209 (setq org-agenda-show-all-dates t)
1213 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1214 (with-eval-after-load "org"
1215 (require 'org-mobile)
1216 ;; Set to the location of your Org files on your local system
1217 ;; (setq org-directory "~/org")
1218 ;; Set to the name of the file where new notes will be stored
1219 (setq org-mobile-inbox-for-pull "~/org/flagged.org")
1220 ;; Set to <your Dropbox root directory>/MobileOrg.
1221 (setq org-mobile-directory "~/Dropbox/Apps/MobileOrg"))
1225 Install MacTex-basic [[http://www.tug.org/mactex/morepackages.html][MacTex-basic]] and some tex packages
1227 wget http://tug.org/cgi-bin/mactex-download/BasicTeX.pkg
1229 sudo tlmgr update --self
1231 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
1234 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1235 ;; ;; allow for export=>beamer by placing
1237 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
1238 ;; #+LaTeX_CLASS: beamer in org files
1239 (unless (boundp 'org-export-latex-classes)
1240 (setq org-export-latex-classes nil))
1241 (add-to-list 'org-export-latex-classes
1242 ;; beamer class, for presentations
1244 "\\documentclass[11pt]{beamer}\n
1245 \\mode<{{{beamermode}}}>\n
1246 \\usetheme{{{{beamertheme}}}}\n
1247 \\usecolortheme{{{{beamercolortheme}}}}\n
1248 \\beamertemplateballitem\n
1249 \\setbeameroption{show notes}
1250 \\usepackage[utf8]{inputenc}\n
1251 \\usepackage[T1]{fontenc}\n
1252 \\usepackage{hyperref}\n
1254 \\usepackage{listings}
1255 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
1258 showspaces=false,showstringspaces=false,
1260 keywordstyle=\\color{blue}\\bfseries,
1261 commentstyle=\\color{red},
1263 \\usepackage{verbatim}\n
1264 \\institute{{{{beamerinstitute}}}}\n
1265 \\subject{{{{beamersubject}}}}\n"
1267 ("\\section{%s}" . "\\section*{%s}")
1269 ("\\begin{frame}[fragile]\\frametitle{%s}"
1271 "\\begin{frame}[fragile]\\frametitle{%s}"
1274 ;; letter class, for formal letters
1276 (add-to-list 'org-export-latex-classes
1279 "\\documentclass[11pt]{letter}\n
1280 \\usepackage[utf8]{inputenc}\n
1281 \\usepackage[T1]{fontenc}\n
1282 \\usepackage{color}"
1284 ("\\section{%s}" . "\\section*{%s}")
1285 ("\\subsection{%s}" . "\\subsection*{%s}")
1286 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1287 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1288 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1292 (require 'ox-beamer)
1294 (setq org-latex-pdf-process
1295 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1296 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1297 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
1299 (setq TeX-parse-self t)
1301 (setq TeX-PDF-mode t)
1302 (add-hook 'LaTeX-mode-hook
1305 (setq TeX-master t)))
1310 Color higlight the source code block in exported html, [[http://stackoverflow.com/questions/24082430/org-mode-no-syntax-highlighting-in-exported-html-page][org-mode-no-syntax-highlighting-in-exported-html-page]]
1311 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1312 (use-package htmlize
1316 ** Org structure template
1317 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
1318 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1319 ;; βsβ β#+BEGIN_SRC ... #+END_SRCβ
1320 ;; βeβ β#+BEGIN_EXAMPLE ... #+END_EXAMPLEβ
1321 ;; βqβ β#+BEGIN_QUOTE ... #+END_QUOTEβ
1322 ;; βvβ β#+BEGIN_VERSE ... #+END_VERSEβ
1323 ;; βcβ β#+BEGIN_CENTER ... #+END_CENTERβ
1324 ;; βlβ β#+BEGIN_LaTeX ... #+END_LaTeXβ
1325 ;; βLβ β#+LaTeX:β
1326 ;; βhβ β#+BEGIN_HTML ... #+END_HTMLβ
1327 ;; βHβ β#+HTML:β
1328 ;; βaβ β#+BEGIN_ASCII ... #+END_ASCIIβ
1329 ;; βAβ β#+ASCII:β
1330 ;; βiβ β#+INDEX:β line
1331 ;; βIβ β#+INCLUDE:β line
1334 (add-to-list 'org-structure-template-alist
1335 '("E" "#+BEGIN_SRC emacs-lisp :tangle yes :results silent\n?\n#+END_SRC"))
1336 (add-to-list 'org-structure-template-alist
1337 '("R" "#+BEGIN_SRC racket :tangle no :results output replace\n?\n#+END_SRC"))
1338 (add-to-list 'org-structure-template-alist
1339 '("S" "#+BEGIN_SRC sh :results output replace\n?\n#+END_SRC"))
1340 (add-to-list 'org-structure-template-alist
1341 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
1342 (add-to-list 'org-structure-template-alist
1343 '("P" "#+BEGIN_SRC perl \n?\n#+END_SRC"))
1344 (add-to-list 'org-structure-template-alist
1345 '("f" "#+BEGIN_SRC fundamental :tangle ?\n\n#+END_SRC"))
1346 (add-to-list 'org-structure-template-alist
1347 '("C" "#+BEGIN_SRC c :tangle ?\n\n#+END_SRC"))
1348 (add-to-list 'org-structure-template-alist
1349 '("m" "\\begin{equation}\n?\n\\end{equation}"))
1350 (add-to-list 'org-structure-template-alist
1351 '("b" "#+STARTUP: showall
1352 ,#+STARTUP: inlineimages
1353 ,#+OPTIONS: toc:nil\n"))
1354 (add-to-list 'org-structure-template-alist
1355 '("d" "#+BEGIN_SRC ditaa :file ? :cmdline -r -s 0.8 :cache yes \n\n#+END_SRC"))
1356 (add-to-list 'org-structure-template-alist
1357 '("u" "#+BEGIN_SRC plantuml :file ? \n\n#+END_SRC"))
1362 Fetch dependencies file, which is not in this repository.
1363 #+BEGIN_SRC perl :results silent :tangle yes
1364 print `curl https://raw.githubusercontent.com/seudut/blog/master/my-publish.el -o ./elisp/my-publish.el`;
1368 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1369 (add-to-list 'load-path "~/.emacs.d/elisp")
1371 (when (file-exists-p "~/.emacs.d/elisp/my-publish.el")
1372 (require 'my-publish)
1373 (blog-setup-project-alist "~/Private/blog/"))
1377 Refer to [[http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html][org-publish-html-tutorial]], and [[https://ogbe.net/blog/blogging_with_org.html][blogging_with_org]]
1380 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
1381 and Defined keys, using vi keybindings, Refer abo-abo's setting [[https://github.com/abo-abo/oremacs/blob/c5cafdcebc88afe9e73cc8bd40c49b70675509c7/modes/ora-nextmagit.el][here]]
1382 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1386 ;; don't ask me to confirm the unsaved change
1387 (setq magit-save-repository-buffers nil)
1389 (setq git-commit-summary-max-length 100)
1390 :commands magit-status magit-blame
1392 (dolist (map (list magit-status-mode-map
1395 magit-staged-section-map))
1396 (define-key map "j" 'magit-section-forward)
1397 (define-key map "k" 'magit-section-backward)
1398 (define-key map "D" 'magit-discard)
1399 (define-key map "O" 'magit-discard-file)
1400 (define-key map "n" nil)
1401 (define-key map "p" nil)
1402 (define-key map "v" 'recenter-top-bottom)
1403 (define-key map "i" 'magit-section-toggle))
1404 (define-key magit-mode-map "q" (lambda () (interactive)
1405 (magit-mode-bury-buffer t))))
1410 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1411 (defalias 'e 'find-file)
1412 (defalias 'ff 'find-file-other-window)
1413 (defalias 'ee 'find-files)
1416 ** eshell temp directory
1417 set default eshell history folder
1418 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1419 (setq eshell-directory-name (concat sd-temp-directory "eshell"))
1422 ** Eshell erase buffer
1423 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1424 (require 'utilities)
1426 (defun sd/eshell-hook ()
1428 (define-key eshell-mode-map (kbd "C-j") #'eshell-send-input)
1429 (define-key eshell-mode-map (kbd "C-l") #'sd/eshell-clear-buffer))
1431 (add-hook 'eshell-mode-hook #'sd/eshell-hook)
1435 Toggle an eshell in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
1436 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1437 (defun sd/window-has-eshell ()
1438 "Check if current windows list has a eshell buffer, and return the window"
1441 (walk-windows (lambda (window)
1442 (if (equal (with-current-buffer (window-buffer window) major-mode)
1448 (defun sd/toggle-project-eshell ()
1449 "Toggle a eshell buffer vertically"
1451 (if (sd/window-has-eshell)
1452 (if (equal major-mode 'eshell-mode)
1454 (if (equal (length (window-list)) 1)
1455 (mode-line-other-buffer)
1457 (select-window (sd/window-has-eshell)))
1459 (split-window-vertically (- (/ (window-total-height) 3)))
1461 (if (projectile-project-p)
1462 (projectile-run-eshell)
1465 (global-set-key (kbd "s-e") 'sd/toggle-project-eshell)
1468 ** exec-path-from-shell
1469 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1470 (use-package exec-path-from-shell
1473 (setq exec-path-from-shell-check-startup-files nil)
1475 (exec-path-from-shell-initialize))
1479 ** [[https://github.com/abo-abo/hydra][Hydra]]
1481 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1484 ;; disable new line in minibuffer when hint hydra
1486 (setq hydra-lv nil))
1489 *** Windmove Splitter
1491 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1493 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1495 (defun hydra-move-splitter-left (arg)
1496 "Move window splitter left."
1498 (if (let ((windmove-wrap-around))
1499 (windmove-find-other-window 'right))
1500 (shrink-window-horizontally arg)
1501 (enlarge-window-horizontally arg)))
1503 (defun hydra-move-splitter-right (arg)
1504 "Move window splitter right."
1506 (if (let ((windmove-wrap-around))
1507 (windmove-find-other-window 'right))
1508 (enlarge-window-horizontally arg)
1509 (shrink-window-horizontally arg)))
1511 (defun hydra-move-splitter-up (arg)
1512 "Move window splitter up."
1514 (if (let ((windmove-wrap-around))
1515 (windmove-find-other-window 'up))
1516 (enlarge-window arg)
1517 (shrink-window arg)))
1519 (defun hydra-move-splitter-down (arg)
1520 "Move window splitter down."
1522 (if (let ((windmove-wrap-around))
1523 (windmove-find-other-window 'up))
1525 (enlarge-window arg)))
1530 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1531 (defhydra sd/hydra-misc (:color red :columns nil)
1533 ("e" eshell "eshell" :exit t)
1536 (if (not (eq nil (get-buffer "*Packages*")))
1537 (switch-to-buffer "*Packages*")
1538 (package-list-packages)))
1539 "list-package" :exit t)
1540 ("g" magit-status "git-status" :exit t)
1541 ("'" mode-line-other-buffer "last buffer" :exit t)
1542 ("C-'" mode-line-other-buffer "last buffer" :exit t)
1543 ("m" man "man" :exit t)
1544 ("d" dired-jump "dired" :exit t)
1545 ("b" ibuffer "ibuffer" :exit t)
1549 ;; (global-set-key (kbd "C-'") 'sd/hydra-misc/body)
1551 (defun sd/exchange-win-layout ()
1552 "Change the windos layout."
1554 (when (equal (length (window-list)) 2)
1555 (let ((current-layout (if (or (window-in-direction 'right) (window-in-direction 'left))
1558 (other-buf (window-buffer (or (window-in-direction 'right)
1559 (window-in-direction 'left)
1560 (window-in-direction 'below)
1561 (window-in-direction 'above)))))
1562 (delete-other-windows)
1563 (if (eq current-layout 'v)
1564 (split-window-below)
1565 (split-window-right))
1567 (switch-to-buffer other-buf))))
1569 (defhydra sd/hydra-window-layout (:color red :colums nil)
1571 ("m" sd/toggle-max-windows "Max-win" :exit t)
1572 ("s" ace-swap-window "Swap" :exit t)
1573 ("d" ace-delete-window "Delete" :exit t)
1574 ("x" sd/exchange-win-layout "eXchange" :exit t)
1575 ("u" winner-undo "window-Undo" :exit t)
1576 ("r" winner-redo "window-Redo" :exit t)
1577 ("C-h" (lambda () (interactive) (evil-window-increase-width 3)) "<<")
1578 ("C-l" (lambda () (interactive) (evil-window-decrease-width 3)) ">>")
1579 ("C-k" (lambda () (interactive) (evil-window-increase-height 3)) "^")
1580 ("C-j" (lambda () (interactive) (evil-window-decrease-height 3)) "v")
1581 ("=" balance-windows "=" :exit t)
1584 (defhydra sd/hydra-gtags (:color red :colums nil)
1586 ("d" sd/ggtags-find-definition "Definition" :exit t)
1587 ("r" ggtags-find-reference "Reference" :exit t)
1588 ("s" sd/ggtags-find-symbol "Symbol" :exit t))
1590 (defhydra sd/hydra-projectile (:color red :column nil)
1592 ("s" projectile-switch-open-project "Switch" :exit t)
1593 ("f" projectile-find-file "File" :exit t)
1594 ("b" projectile-switch-to-buffer "Buffer" :exit t)
1595 ("p" projectile-switch-project "Project" :exit t))
1599 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1600 (defhydra sd/hydra-launcher (:color blue :columns 2)
1602 ("e" emms "emms" :exit t)
1607 Enable linum mode on programming modes
1608 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1609 (add-hook 'prog-mode-hook 'linum-mode)
1612 Fix the font size of line number
1613 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1614 (defun fix-linum-size ()
1616 (set-face-attribute 'linum nil :height 110))
1618 (add-hook 'linum-mode-hook 'fix-linum-size)
1621 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1622 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1623 (use-package linum-relative
1626 (setq linum-relative-current-symbol "")
1628 (defun linum-new-mode ()
1629 "If line numbers aren't displayed, then display them.
1630 Otherwise, toggle between absolute and relative numbers."
1633 (linum-relative-toggle)
1637 ("A-k" . linum-new-mode))
1639 ;; auto enable linum-new-mode in programming modes
1640 (add-hook 'prog-mode-hook 'linum-relative-mode)
1643 ** Save File Position
1644 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1645 (require 'saveplace)
1646 (setq save-place-file "~/.emacs.d/temp/saveplace")
1647 (setq-default save-place t)
1648 (setq save-place-forget-unreadable-files t)
1649 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1653 define =multi-term= mapping to disable some mapping which is used globally.
1654 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1655 (use-package multi-term
1658 (defun sd/term-mode-mapping ()
1659 (mapcar #'(lambda (map)
1660 (define-key map (kbd "C-o") nil)
1661 (define-key map (kbd "C-g") nil))
1665 (with-eval-after-load 'multi-term
1666 (sd/term-mode-mapping))
1670 [[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
1671 Type =o= to go to the link
1672 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1673 (use-package ace-link
1676 (ace-link-setup-default))
1680 [[https://github.com/abo-abo/ace-window][ace-window]]
1681 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1682 (use-package ace-window
1686 ; (global-set-key (kbd "M-o") 'ace-window)
1688 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1691 ** View only for some directory
1692 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]]
1693 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1694 (dir-locals-set-class-variables
1696 '((nil . ((buffer-read-only . t)
1697 (show-trailing-whitespace . nil)
1699 (eval . (whitespace-mode -1))
1700 ;; (eval . (when buffer-file-name
1701 ;; (setq-local view-no-disable-on-exit t)
1702 ;; (view-mode-enter)))
1703 (projectile-enable-caching . nil)
1706 ;; (dir-locals-set-directory-class (expand-file-name "/usr/local/share/emacs") 'emacs)
1707 (dir-locals-set-directory-class "/usr/local/Cellar/emacs" 'emacs)
1708 ;; (dir-locals-set-directory-class "~/.emacs.d/elpa" 'emacs)
1709 (dir-locals-set-directory-class "~/dotfiles/emacs.d/elpa" 'emacs)
1710 (dir-locals-set-directory-class "~/dotfiles/emacs.d/el-get" 'emacs)
1713 ;; Temporary minor mode
1714 ;; Main use is to enable it only in specific buffers to achieve the goal of
1715 ;; buffer-specific keymaps
1717 ;; (defvar sd/temp-mode-map (make-sparse-keymap)
1718 ;; "Keymap while temp-mode is active.")
1721 ;; (define-minor-mode sd/temp-mode
1722 ;; "A temporary minor mode to be activated only specific to a buffer."
1725 ;; sd/temp-mode-map)
1727 ;; (defun sd/temp-hook ()
1730 ;; (define-key sd/temp-mode-map (kbd "q") 'quit-window))))
1732 ;; (add-hook 'lispy-mode-hook (lambda ()
1737 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1738 (el-get-bundle info+
1739 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/info+.el"
1743 (with-eval-after-load 'info
1748 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1749 (defun sd/info-mode ()
1751 (unless (equal major-mode 'Info-mode)
1752 (unless (> (length (window-list)) 1)
1753 (split-window-right))
1756 ;; open Info buffer in other window instead of current window
1757 (defadvice info (before my-info (&optional file buf) activate)
1760 (defadvice Info-exit (after my-info-exit activate)
1761 (sd/delete-current-window))
1765 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1766 (use-package org-tree-slide
1769 ;; (define-key org-mode-map "\C-ccp" 'org-tree-slide-mode)
1770 (define-key org-tree-slide-mode-map (kbd "<ESC>") 'org-tree-slide-content)
1771 (define-key org-tree-slide-mode-map (kbd "<SPACE>") 'org-tree-slide-move-next-tree)
1772 (define-key org-tree-slide-mode-map [escape] 'org-tree-slide-move-previous-tree))
1777 #brew install poppler
1780 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1781 ;(use-package pdf-tools
1784 ; ;; run to complete the installation
1785 ; (pdf-tools-install)
1787 ; (add-to-list 'auto-mode-alist '("\.pdf$" . pdf-view-mode))
1788 ; (add-hook 'pdf-outline-buffer-mode-hook #'sd/pdf-outline-map))
1790 ;(defun sd/pdf-outline-map ()
1791 ; "My keybindings in pdf-outline-map"
1793 ; (define-key pdf-outline-buffer-mode-map (kbd "C-o") nil)
1794 ; (define-key pdf-outline-buffer-mode-map (kbd "i") 'outline-toggle-children)
1795 ; (define-key pdf-outline-buffer-mode-map (kbd "j") 'next-line)
1796 ; (define-key pdf-outline-buffer-mode-map (kbd "k") 'previous-line))
1800 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1801 (defun sd/help-mode-hook ()
1802 "Mapping for help mode"
1803 (define-key help-mode-map "j" 'next-line)
1804 (define-key help-mode-map "k" 'previous-line)
1805 (define-key help-mode-map "h" 'forward-char)
1806 (define-key help-mode-map "l" 'forward-char)
1807 (define-key help-mode-map "H" 'describe-mode)
1808 (define-key help-mode-map "v" 'recenter-top-bottom)
1809 (define-key help-mode-map "i" 'forward-button)
1810 (define-key help-mode-map "I" 'backward-button)
1811 (define-key help-mode-map "o" 'ace-link-help))
1813 (add-hook 'help-mode-hook 'sd/help-mode-hook)
1816 Wiki [[http://stackoverflow.com/questions/3480173/show-keys-in-emacs-keymap-value][show-keys-in-emacs-keymap-value]], Helpplus mode can show keymap as human-readable, use ~describe-keymap~ or =C-h M-k=
1818 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1819 (el-get-bundle help-macro+
1820 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/help-macro+.el"
1821 :features help-macro+)
1822 (el-get-bundle help+
1823 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/help+.el"
1825 (el-get-bundle help-fns+
1826 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/help-fns+.el"
1827 :features help-fns+)
1828 (el-get-bundle help-mode+
1829 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/help-mode+.el"
1830 :features help-mode+)
1834 install =ag=, =the-silver-searcher= by homebrew on mac
1836 brew install the-silver-searcher
1839 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1844 ** Local Variable hooks
1845 [[https://www.emacswiki.org/emacs/LocalVariables][LocalVariables]], use =hack-local-variables-hook=, run a hook to set local variable in mode hook
1846 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1847 ;; make Emacs run a new "local variables hook" for each major mode
1848 (add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook)
1850 (defun run-local-vars-mode-hook ()
1851 "Run a hook for the major-mode after the local variables have been processed."
1852 (run-hooks (intern (concat (symbol-name major-mode) "-local-vars-hook"))))
1854 ;; (add-hook 'c++-mode-local-vars-hook #'sd/c++-mode-local-vars)
1858 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1859 (add-hook 'text-mode-hook 'table-recognize)
1863 To download file in =elisp=, best is =url-copy-file=, here refer [[http://stackoverflow.com/questions/4448055/download-a-file-with-emacs-lisp][download-a-file-with-emacs-lisp]] using =url-retrieve-synchronously= wrapping
1864 as a http download client tool
1865 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1866 (defun sd/download-file (&optional url download-dir download-name)
1869 (read-string "Enter download URL: ")))
1870 (download-dir (read-directory-name "Save to (~/Downloads): " "~/Downloads" "~/Downloads" 'confirm' nil)))
1871 (let ((download-buffer (url-retrieve-synchronously url)))
1873 (set-buffer download-buffer)
1874 ;; we may have to trim the http response
1875 (goto-char (point-min))
1876 (re-search-forward "^$" nil 'move)
1878 (delete-region (point-min) (point))
1879 (write-file (concat (or download-dir
1882 (car (last (split-string url "/" t))))))))))
1887 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1888 (setq dired-dwim-target t)
1890 (use-package dired-details
1893 (setq-default dired-details-hidden-string "--- ")
1894 (dired-details-install))
1898 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1899 (defun sd/dired-next-line (count)
1900 "Move to next line, and always focus on the file name."
1902 (dired-next-line count)
1903 (dired-move-to-filename))
1905 (defun sd/dired-previous-line (count)
1906 "Move to previous line, and always focus on the file name."
1908 (dired-previous-line count)
1909 (dired-move-to-filename))
1911 (defun sd/dired-up-directory ()
1912 "Go to up directory"
1914 (let ((old (current-buffer)))
1915 (dired-up-directory)
1920 =C-o= is defined as a global key for window operation, here unset it in dired mode
1921 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1922 (defun sd/dired-key-map ()
1923 "My keybindings for dired"
1925 ;; these two prefix are used globally
1926 (define-key dired-mode-map (kbd "C-o") nil)
1927 (define-key dired-mode-map (kbd "M-s") nil)
1928 ;; toggle hidden files
1929 (define-key dired-mode-map (kbd "H") 'dired-omit-mode)
1931 (define-key dired-mode-map (kbd "SPC") 'scroll-up-command)
1932 (define-key dired-mode-map (kbd "DEL") 'scroll-down-command)
1933 (define-key dired-mode-map (kbd "j") 'diredp-next-line)
1934 (define-key dired-mode-map (kbd "k") 'diredp-previous-line)
1935 (define-key dired-mode-map (kbd "g") 'dired-goto-file)
1936 ;; (define-key dired-mode-map (kbd "S-SPC") 'scroll-down-command)
1938 (define-key dired-mode-map (kbd "f") 'dired-isearch-filenames)
1940 ;; i dired-maybe-insert-subdir
1941 ;; o dired-find-file-other-window (switch to other window)
1942 ;; O dired-display-file
1943 (define-key dired-mode-map (kbd "G") 'ido-dired)
1944 (define-key dired-mode-map (kbd "c") 'sd/dired-new-file)
1945 (define-key dired-mode-map (kbd "h") 'dired-summary)
1946 (define-key dired-mode-map (kbd "r") 'revert-buffer)
1947 (define-key dired-mode-map (kbd "l") 'dired-display-file)
1948 (define-key dired-mode-map [C-backspace] 'dired-up-directory)
1949 (define-key dired-mode-map (kbd "?") 'describe-mode)
1950 (define-key dired-mode-map (kbd "z") #'sd/dired-get-size)
1951 (define-key dired-mode-map (kbd "C-d") 'dired-kill-subdir)
1952 (define-key dired-mode-map (kbd "M-d") 'dired-kill-subdir)
1953 (define-key dired-mode-map (kbd "J") 'diredp-next-subdir)
1954 (define-key dired-mode-map (kbd "TAB") 'diredp-next-subdir)
1955 (define-key dired-mode-map (kbd "K") 'diredp-prev-subdir)
1956 (define-key dired-mode-map (kbd "O") 'dired-display-file)
1957 (define-key dired-mode-map (kbd "I") 'other-window)
1958 (define-key dired-mode-map (kbd "o") 'other-window))
1966 :init (setq diredp-hide-details-initially-flag nil))
1968 (setq dired-omit-mode t)
1969 (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
1970 (add-hook 'dired-mode-hook (lambda ()
1972 (dired-omit-mode))))
1974 (defadvice dired-summary (around sd/dired-summary activate)
1975 "Revisied dired summary."
1979 "Ξ: d-delete, u-ndelete, x-punge, f-ind, o-ther window, R-ename, C-opy, c-create, +new dir, r-evert, /-filter, v-iew, l-ist, z-Size, h-summary, ?-help"))
1981 (defun sd/dired-high-level-dir ()
1982 "Go to higher level directory"
1984 (find-alternate-file ".."))
1987 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1988 (defun sd/dired-new-file-and-open ()
1989 "Create a new file in dired mode"
1991 (call-interactively 'find-file))
1993 (defun sd/dired-new-file (file)
1994 "Create a new file called FILE.
1995 If FILE already exists, signal an error."
1997 (list (read-file-name "Create file: " (dired-current-directory))))
1998 (let* ((expanded (expand-file-name file)))
1999 (if (file-exists-p expanded)
2000 (error "Cannot create file %s: file exists" expanded))
2001 (write-region "" nil expanded t)
2003 (dired-add-file expanded)
2004 (dired-move-to-filename))))
2006 ;; copied from abo-abo's config
2007 (defun sd/dired-get-size ()
2009 (let ((files (dired-get-marked-files)))
2011 (apply 'call-process "/usr/bin/du" nil t nil "-sch" files)
2013 "Size of all marked files: %s"
2015 (re-search-backward "\\(^[ 0-9.,]+[A-Za-z]+\\).*total$")
2016 (match-string 1))))))
2019 ** disable ido when dired new file
2020 When create a new directory, I want to disalbe =ido= completion. see [[http://stackoverflow.com/questions/7479565/emacs-ido-mode-and-creating-new-files-in-directories-it-keeps-changing-the-dire][here]]. Thhis code snippets copied
2021 from [[https://emacs.stackexchange.com/questions/13713/how-to-disable-ido-in-dired-create-directory/13795#13795?newreg%3Ddb17c20f7af3490fb11cf15f1d888e9e][How to disable IDO in βdired-create-directoryβ]]
2022 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2023 (defun mk-anti-ido-advice (func &rest args)
2024 "Temporarily disable IDO and call function FUNC with arguments ARGS."
2026 (let ((read-file-name-function #'read-file-name-default)
2027 (completing-read-function #'completing-read-default))
2028 (if (called-interactively-p 'any)
2029 (call-interactively func)
2030 (apply func args))))
2032 (defun mk-disable-ido (command)
2033 "Disable IDO when command COMMAND is called."
2034 (advice-add command :around #'mk-anti-ido-advice))
2036 (defun mk-anti-ido-no-completing-advice (func &rest args)
2037 "Temporarily disable IDO and call function FUNC with arguments ARGS."
2039 (let ((read-file-name-function #'read-file-name-default)
2040 ;; (completing-read-function #'completing-read-default)
2042 (if (called-interactively-p 'any)
2043 (call-interactively func)
2044 (apply func args))))
2046 (defun mk-disable-ido-no-completing (command)
2047 "Disable IDO when command COMMAND is called."
2048 (advice-add command :around #'mk-anti-ido-no-completing-advice))
2051 Disalble =ido= when new a directory or file in =dired= mode
2052 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2053 ;; call the function which you want to disable ido
2054 (mk-disable-ido 'dired-create-directory)
2055 (mk-disable-ido 'sd/dired-new-file-and-open)
2056 (mk-disable-ido 'sd/dired-new-file)
2057 (mk-disable-ido-no-completing 'dired-goto-file)
2061 =!= =dired-do-shell-command=
2062 =&= =dired-do-async-shell-command=
2063 here on Mac, just use "open" commands to pen =.pdf=, =.html= and image files
2064 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2065 (setq dired-guess-shell-alist-user
2066 '(("\\.pdf\\'" "open" "okular")
2067 ("\\.\\(?:djvu\\|eps\\)\\'" "evince")
2068 ("\\.\\(?:jpg\\|jpeg\\|png\\|gif\\|xpm\\)\\'" "open")
2069 ("\\.\\(?:xcf\\)\\'" "gimp")
2070 ("\\.csv\\'" "libreoffice")
2071 ("\\.tex\\'" "pdflatex" "latex")
2072 ("\\.\\(?:mp4\\|mkv\\|avi\\|rmvb\\|flv\\|ogv\\)\\(?:\\.part\\)?\\'" "mplayer")
2073 ("\\.\\(?:mp3\\|flac\\|wav\\)\\'" "mplayer")
2074 ("\\.html?\\'" "open")
2075 ("\\.dmg\\'" "open")
2076 ("\\.cue?\\'" "audacious")))
2079 (defun sd/dired-start-process (cmd &optional file-list)
2081 (let ((files (dired-get-marked-files t current-prefix-arg)))
2083 (dired-read-shell-command "& on %s: " current-prefix-arg files)
2086 ;; (let (list-switch))
2088 cmd nil shell-file-name
2089 shell-command-switch
2091 "nohup 1>/dev/null 2>/dev/null %s \"%s\""
2093 ;; (if (and (> (length file-list) 1)
2094 ;; (setq list-switch
2095 ;; (cadr (assoc cmd ora-dired-filelist-cmd))))
2096 ;; (format "%s %s" cmd list-switch)
2098 (mapconcat #'expand-file-name file-list "\" \""))))
2105 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2106 (use-package dired-hacks-utils
2112 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2113 ;;narrow dired to match filter
2114 (use-package dired-narrow
2116 :commands (dired-narrow)
2117 :bind (:map dired-mode-map
2118 ("/" . dired-narrow)))
2122 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2123 (global-set-key (kbd "s-b") 'ibuffer)
2125 (with-eval-after-load 'ibuffer
2126 (define-key ibuffer-mode-map (kbd "C-o") nil)
2127 (define-key ibuffer-mode-map (kbd "j") 'ibuffer-forward-line)
2128 (define-key ibuffer-mode-map (kbd "k") 'ibuffer-backward-line)
2129 (define-key ibuffer-mode-map (kbd "r") 'ibuffer-update)
2130 (define-key ibuffer-mode-map (kbd "g") 'ibuffer-jump-to-buffer)
2131 (define-key ibuffer-mode-map (kbd "h") 'sd/ibuffer-summary))
2133 (defun sd/ibuffer-summary ()
2134 "Show summary of keybindings in ibuffer mode"
2137 "Ξ: m|u - (un)mark, /-filter, //-remove filter, t, RET, g, k, S, D, Q; q to quit; h for help"))
2141 ** company mode and company-statistics
2142 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2143 (use-package company
2145 :diminish company-mode
2146 :init (setq company-idle-delay 0.1)
2147 (setq company-selection-wrap-around t)
2149 (define-key company-active-map (kbd "M-n") nil)
2150 (define-key company-active-map (kbd "M-p") nil)
2151 (define-key company-active-map (kbd "SPC") #'sd/company-stop-input-space)
2152 (define-key company-active-map (kbd "C-n") #'company-select-next)
2153 (define-key company-active-map (kbd "C-p") #'company-select-previous)
2154 ;; should map both (kbd "TAB") and [tab],https://github.com/company-mode/company-mode/issues/75
2155 (define-key company-active-map (kbd "TAB") #'company-complete-selection)
2156 (define-key company-active-map [tab] #'company-complete-selection)
2157 (define-key company-active-map (kbd "C-w") nil)
2158 (define-key company-active-map (kbd "C-h") nil)
2159 (global-company-mode)
2160 ;; magig-commit is text-modeh
2161 (setq company-global-modes '(not org-mode magit-status-mode text-mode eshell-mode gfm-mode markdown-mode)))
2163 (use-package company-statistics
2166 (setq company-statistics-file (concat MY-EMACS-TMP "/company-statistics-cache.el"))
2168 (company-statistics-mode))
2170 (defun sd/company-stop-input-space ()
2171 "Stop completing and input a space,a workaround of a semantic issue `https://github.com/company-mode/company-mode/issues/614'"
2179 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2180 (use-package yasnippet
2184 (add-hook 'prog-mode-hook #'yas-minor-mode)
2190 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2194 (use-package company-ycmd
2197 (setq company-ycmd-enable-fuzzy-matching nil)
2199 (company-ycmd-setup))
2200 (setq ycmd-force-semantic-completion t)
2201 (add-hook 'c++-mode-hook 'ycmd-mode)
2202 (add-hook 'c-mode-hook 'ycmd-mode)
2203 (set-variable 'ycmd-server-command '("python" "/Users/peng/project/ycmd/ycmd"))
2204 (set-variable 'ycmd-global-config "/Users/peng/project/ycmd/cpp/ycm/.ycm_extra_conf.py"))
2208 ** company and yasnippet
2209 Add yasnippet as the company candidates
2210 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2211 ;Add yasnippet support for all company backends
2212 ;https://github.com/syl20bnr/spacemacs/pull/179
2213 (defvar company-mode/enable-yas t
2214 "Enable yasnippet for all backends.")
2216 (defun company-mode/backend-with-yas (backend)
2217 (if (or (not company-mode/enable-yas) (and (listp backend) (member 'company-yasnippet backend)))
2219 (append (if (consp backend) backend (list backend))
2220 '(:with company-yasnippet))))
2222 (setq company-backends (mapcar #'company-mode/backend-with-yas company-backends))
2225 Refer, [[http://emacs.stackexchange.com/questions/7908/how-to-make-yasnippet-and-company-work-nicer][how-to-make-yasnippet-and-company-work-nicer]]
2226 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2227 (defun check-expansion ()
2229 (if (looking-at "\\_>") t
2231 (if (looking-at "\\.") t
2233 (if (looking-at "->") t nil)))))
2235 (defun do-yas-expand ()
2236 (let ((yas/fallback-behavior 'return-nil))
2239 (defun tab-indent-or-complete ()
2243 (minibuffer-complete))
2245 (indent-for-tab-command)
2246 (if (or (not yas/minor-mode)
2247 (null (do-yas-expand)))
2248 (if (check-expansion)
2250 (company-manual-begin)
2251 (if (null company-candidates)
2254 (indent-for-tab-command)))))))))
2256 (defun tab-complete-or-next-field ()
2258 (if (or (not yas/minor-mode)
2259 (null (do-yas-expand)))
2260 (if company-candidates
2261 (company-complete-selection)
2262 (if (check-expansion)
2264 (company-manual-begin)
2265 (if (null company-candidates)
2269 (yas-next-field)))))
2271 (defun expand-snippet-or-complete-selection ()
2273 (if (or (not yas/minor-mode)
2274 (null (do-yas-expand))
2276 (company-complete-selection)))
2278 (defun abort-company-or-yas ()
2280 (if (null company-candidates)
2285 ;; (require 'company)
2286 ;; (require 'yasnippet)
2289 ;; (global-set-key [tab] 'tab-indent-or-complete)
2290 ;; (global-set-key (kbd "TAB") 'tab-indent-or-complete)
2291 ;; (global-set-key [(control return)] 'company-complete-common)
2293 ;; (define-key company-active-map [tab] 'expand-snippet-or-complete-selection)
2294 ;; (define-key company-active-map (kbd "TAB") 'expand-snippet-or-complete-selection)
2296 ;; (define-key yas-minor-mode-map [tab] nil)
2297 ;; (define-key yas-minor-mode-map (kbd "TAB") nil)
2299 ;; (define-key yas-keymap [tab] 'tab-complete-or-next-field)
2300 ;; (define-key yas-keymap (kbd "TAB") 'tab-complete-or-next-field)
2301 ;; (define-key yas-keymap [(control tab)] 'yas-next-field)
2302 ;; (define-key yas-keymap (kbd "C-g") 'abort-company-or-yas)
2306 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2311 * Programming Language
2312 ** Color identiifiers mode
2313 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2314 (use-package color-identifiers-mode
2317 (dolist (mode '(emacs-lisp-mode-hook
2320 (add-hook mode #'color-identifiers-mode))
2321 :diminish color-identifiers-mode)
2323 (global-prettify-symbols-mode t)
2327 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2328 (set-face-attribute 'font-lock-keyword-face nil :foreground "#F92672" :weight 'bold)
2329 (set-face-attribute 'font-lock-builtin-face nil :weight 'bold)
2330 (set-face-attribute 'font-lock-function-name-face nil :foreground "#A6E22E" :weight 'normal :slant 'normal)
2331 (set-face-attribute 'font-lock-variable-name-face nil :foreground "#00FF00")
2333 (dolist (mode '(c-mode
2335 (font-lock-add-keywords mode
2337 '(("\\([%\\][a-zA-Z]\\)" (1 font-lock-keyword-face prepend))
2338 ("[^[:alpha:]]\\([[:digit:]]*\\)[^[:alpha:]]" (1 font-lock-constant-face append))
2340 ("[^[:alpha:]]\\(0[x\\|X][0-9a-fA-F]*\\)[^[:alpha:]]" (1 font-lock-constant-face append))
2341 ;; hightlight the function call
2342 ("\\s\"?\\(\\(\\sw\\|\\s_\\)+\\(<-\\)?\\)\\s\"?*\\s-*(" (1 font-lock-function-name-face))) t))
2344 (font-lock-add-keywords 'c++-mode
2346 ("[\s\\|::]\\(cin\\|cout\\|endl\\)[^[:alpha:][:digit:]]" (1 font-lock-constant-face append))
2351 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
2352 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
2353 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2357 (setq lispy-delete-backward-recenter 0)
2358 (with-eval-after-load "lispy"
2359 (define-key lispy-mode-map (kbd "M-o") nil)
2360 (define-key lispy-mode-map (kbd "g") 'special-lispy-goto-local)
2361 (define-key lispy-mode-map (kbd "G") 'special-lispy-goto)
2362 (define-key lispy-mode-map (kbd "M-m") 'back-to-indentation))
2364 (add-hook 'emacs-lisp-mode-hook (apply-partially #'lispy-mode 1)))
2369 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
2370 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2371 (defalias 'perl-mode 'cperl-mode)
2373 ;; (setq cperl-hairy t)
2374 ;; Turns on most of the CPerlMode options
2375 (setq cperl-auto-newline t)
2376 (setq cperl-highlight-variables-indiscriminately t)
2377 ;(setq cperl-indent-level 4)
2378 ;(setq cperl-continued-statement-offset 4)
2379 (setq cperl-close-paren-offset -4)
2380 (setq cperl-indent-parents-as-block t)
2381 (setq cperl-tab-always-indent t)
2382 ;(setq cperl-brace-offset 0)
2384 (add-hook 'cperl-mode-hook (apply-partially #'cperl-set-style "C++"))
2386 (defalias 'perldoc 'cperl-perldoc)
2390 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
2391 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2392 (eval-after-load 'autoinsert
2393 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
2396 "#!/usr/bin/perl -w" \n
2398 "use strict;" > \n \n
2404 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2405 (font-lock-add-keywords 'cperl-mode
2406 '(("\\(say\\)" . cperl-nonoverridable-face)
2407 ("\\([0-9.]\\)*" . font-lock-constant-face)
2408 ("\".*\\(\\\n\\).*\"" 1 font-lock-constant-face prepend)
2409 ("\n" 0 font-lock-constant-face prepend)
2410 ;; ("[%\\][[:alpha:]]" . font-lock-constant-face)
2411 ("\\(^#!.*\\)$" . cperl-nonoverridable-face)))
2416 1. completion (file name, function name, variable name)
2417 2. template yasnippet (keywords, if, function)
2420 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2421 ;; (setq c-default-style "stroustrup"
2422 ;; c-basic-offset 4)
2424 ;; ;; "C-M-j" is my global binding for avy goto line below
2425 ;; ;; disable it in c mode
2426 ;; (mapcar #'(lambda (map)
2427 ;; (define-key map (kbd "C-M-j") nil))
2433 (add-to-list 'auto-mode-alist '("\\.mm\\'" . objc-mode))
2435 (setq-default c-hungry-delete-key t)
2438 ;; Looks `c-hanging-braces-alist' doesn't work as expected when `electric-pair-mode' is enabled.
2439 (electric-pair-mode 1)
2441 (defconst sd/c-style
2443 (c-tab-always-indent . t)
2444 (c-basic-offset . 4)
2445 (c-hanging-braces-alist . ((substatement-open before)
2446 (statement-block-intro before)))
2447 (c-hanging-colons-alist . ())
2448 (c-echo-syntactic-information-p . nil)
2449 (c-hanging-semi&comma-criteria . ()))
2450 "My C programming style")
2452 (c-add-style "sd-c-style" sd/c-style)
2454 (setq c-default-style "sd-c-style")
2456 (add-hook 'c-mode-hook '(lambda ()
2457 (c-toggle-auto-newline 1)
2458 (c-set-style "sd-c-style")))
2460 ;; (advice-add 'c-electric-brace :after (lambda (arg) "Add new line after insert {}" (newline-and-indent)))
2463 **** install irony server
2464 Install clang, on mac, it has =libclang.dylib=, but no develop headers. Install by =brew=
2466 brew install llvm --with-clang
2469 then install irony searver, and =LIBCLANG_LIBRARY= and =LIBCLANG_INCLUDE_DIR= accordingly
2470 #+BEGIN_SRC emacs-lisp :tangle no :results silent
2471 (irony-install-server)
2475 cmake -DLIBCLANG_LIBRARY\=/usr/local/Cellar/llvm/4.0.1/lib/libclang.dylib \
2476 -DLIBCLANG_INCLUDE_DIR=/usr/local/Cellar/llvm/4.0.1/include \
2477 -DCMAKE_INSTALL_PREFIX\=/Users/peng/.emacs.d/irony/ \
2478 /Users/peng/.emacs.d/elpa/irony-20160713.1245/server && cmake --build . --use-stderr --config Release --target install
2482 irony-mode-hook, copied from [[https://github.com/Sarcasm/irony-mode][irony-mode]] github
2483 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2484 ;; (use-package irony
2487 ;; (add-hook 'c++-mode-hook 'irony-mode)
2488 ;; (add-hook 'c-mode-hook 'irony-mode)
2489 ;; (add-hook 'objc-mode-hook 'irony-mode))
2491 ;; replace the `completion-at-point' and `complete-symbol' bindings in
2492 ;; irony-mode's buffers by irony-mode's function
2494 (defun my-irony-mode-hook ()
2495 (define-key irony-mode-map [remap completion-at-point]
2496 'irony-completion-at-point-async)
2497 (define-key irony-mode-map [remap complete-symbol]
2498 'irony-completion-at-point-async))
2500 ;; (add-hook 'irony-mode-hook 'my-irony-mode-hook)
2501 ;; (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
2503 ;; (add-hook 'c++-mode-local-vars-hook #'sd/c++-mode-local-vars)
2505 ;; add C++ completions, because by default c++ file can not complete
2506 ;; c++ std functions, another method is create .dir-local.el file, for p
2507 ;; for project see irony
2508 (defun sd/c++-mode-local-vars ()
2509 (setq irony--compile-options
2512 "-I/usr/include/c++/4.2.1")))
2516 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2517 ;; (use-package company-irony
2520 ;; (use-package flycheck-irony
2523 ;; (use-package company-c-headers
2526 ;; (add-to-list 'company-c-headers-path-system "/usr/include/c++/4.2.1/")
2527 ;; (add-to-list 'company-c-headers-path-system "/usr/local/include/"))
2529 ;; (with-eval-after-load 'company
2530 ;; (add-to-list 'company-backends 'company-irony)
2531 ;; (add-to-list 'company-backends 'company-c-headers))
2533 ;; (with-eval-after-load 'company
2534 ;; (push '(company-irony :with company-yasnippet) company-backends)
2535 ;; (push '(company-c-headers :with company-yasnippet) company-backends))
2537 ;; (with-eval-after-load 'flycheck
2538 ;; (add-hook 'flycheck-mode-hook #'flycheck-irony-setup))
2542 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2543 (use-package flycheck
2548 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2552 (define-key ggtags-mode-map (kbd "M-g d") 'ggtags-find-definition)
2553 (define-key ggtags-mode-map (kbd "M-g r") 'ggtags-find-reference)
2554 (define-key ggtags-mode-map (kbd "M-g r") 'ggtags-find-reference)
2555 (define-key ggtags-mode-map (kbd "C-c g s") 'ggtags-find-other-symbol)
2556 (define-key ggtags-mode-map (kbd "C-c g h") 'ggtags-view-tag-history)
2557 (define-key ggtags-mode-map (kbd "C-c g r") 'ggtags-find-reference)
2558 (define-key ggtags-mode-map (kbd "C-c g f") 'ggtags-find-file)
2559 (define-key ggtags-mode-map (kbd "C-c g c") 'ggtags-create-tags)
2560 (define-key ggtags-mode-map (kbd "C-c g u") 'ggtags-update-tags))
2562 (add-hook 'c-mode-common-hook
2564 (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
2567 (defun sd/ggtags-find-definition ()
2568 "Find the definition with current name completing."
2570 (setq current-prefix-arg '(4))
2571 (call-interactively 'ggtags-find-definition))
2573 (defun sd/ggtags-find-symbol ()
2576 (setq current-prefix-arg '(4))
2577 (call-interactively 'ggtags-find-other-symbol))
2581 (setq semanticdb-default-save-directory (concat MY-EMACS-TMP "/semantic/"))
2582 (unless (file-exists-p semanticdb-default-save-directory)
2583 (make-directory semanticdb-default-save-directory))
2585 (global-semanticdb-minor-mode 1)
2586 (global-semantic-idle-scheduler-mode 1)
2592 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2593 ;; (use-package google-c-style
2596 ;; (add-hook 'c-mode-hook 'google-set-c-style)
2597 ;; (add-hook 'c++-mode-hook 'google-set-c-style))
2600 *** Compile and Run the C file
2601 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2602 (defun my-cpp-hook ()
2603 (let* ((current-file-name)
2605 (when buffer-file-name
2606 (setq current-file-name (shell-quote-argument buffer-file-name))
2607 (setq out-file-name (shell-quote-argument (concat (file-name-sans-extension buffer-file-name) ".out"))))
2608 (setq-local compilation-read-command t)
2609 (set (make-local-variable 'compile-command)
2610 (concat "g++ -Wall -std=c++11 "
2617 (local-set-key (kbd "s-r") 'compile)))
2619 (add-hook 'c-mode-hook 'my-cpp-hook)
2620 (add-hook 'c++-mode-hook 'my-cpp-hook)
2624 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2625 (use-package lua-mode
2630 Install =guile=, =guile= is an implementation of =Scheme= programming language.
2635 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2636 (setq geiser-scheme-implementation 'guile)
2648 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2649 (use-package racket-mode
2652 (define-key racket-mode-map (kbd "s-r") 'racket-run)
2653 (add-to-list 'racket-mode-hook (lambda () (lispy-mode 1))))
2656 (setenv "PATH" (concat (getenv "PATH")
2657 ":" "/Applications/Racket v6.10.1/bin"))
2658 (setenv "MANPATH" (concat (getenv "MANPATH")
2659 ":" "/Applications/Racket v6.10.1/man"))
2660 (setq exec-path (append exec-path '("/Applications/Racket v6.10.1/bin")))
2662 (add-to-list 'auto-mode-alist '("\\.rkt\\'" . racket-mode))
2665 Set the environments vairables in compilation mode
2666 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2667 (use-package compile
2670 (setq compilation-environment (cons "LC_ALL=C" compilation-environment))
2671 (setq compilation-auto-jump-to-first-error t)
2672 (setq compilation-auto-jump-to-next t)
2673 (setq compilation-scroll-output 'first-error)
2674 ;; this will save all the modified buffers before compile
2675 (setq compilation-ask-about-save nil)
2676 (setq compilation-window-height (/ (window-total-height) 3)))
2678 ;; super-r to compile
2679 (with-eval-after-load "compile"
2680 (define-key compilation-mode-map (kbd "C-o") nil)
2681 (define-key compilation-mode-map (kbd "n") 'compilation-next-error)
2682 (define-key compilation-mode-map (kbd "p") 'compilation-previous-error)
2683 (define-key compilation-mode-map (kbd "q") (lambda () (interactive) (quit-window t)))
2684 (define-key compilation-mode-map (kbd "r") #'recompile))
2686 ;; here note dynamic binding the value of vv, otherwise it will resport error when run the hook.
2687 ;; https://emacs.stackexchange.com/questions/10394/scope-in-lambda
2689 (cperl-mode-hook . "perl")
2690 (lua-mode-hook . "lua")
2691 (python-mode-hook . "python")
2692 (shell-mode-hook . "sh")))
2693 (add-hook (car vv) `(lambda ()
2694 (unless (or (file-exists-p "makefile")
2695 (file-exists-p "Makefile"))
2696 (set (make-local-variable 'compile-command)
2699 (if buffer-file-name
2700 (shell-quote-argument buffer-file-name))))))))
2702 (global-set-key (kbd "s-r") 'compile)
2706 ** Enable auto-insert mode
2707 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2708 (auto-insert-mode t)
2709 (setq auto-insert-query nil)
2713 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2714 (eval-after-load 'autoinsert
2715 '(define-auto-insert '("\\.cpp\\|.cc\\'" . "C++ skeleton")
2717 "Short description:"
2719 "\n * " (file-name-nondirectory (buffer-file-name))
2721 "#include <iostream>" \n
2723 (file-name-sans-extension
2724 (file-name-nondirectory (buffer-file-name)))
2726 "using namespace std;" \n \n
2727 "int main (int argc, char *argv[])"
2734 (eval-after-load 'autoinsert
2735 '(define-auto-insert '("\\.c\\'" . "C skeleton")
2737 "Short description:"
2739 " * " (file-name-nondirectory (buffer-file-name)) "\n"
2741 "#include <stdio.h>" \n
2743 (file-name-sans-extension
2744 (file-name-nondirectory (buffer-file-name)))
2746 "int main (int argc, char *argv[])\n"
2753 (eval-after-load 'autoinsert
2754 '(define-auto-insert '("\\.h\\|.hpp\\'" . "c/c++ header")
2755 '((s-upcase (s-snake-case (file-name-nondirectory buffer-file-name)))
2756 "#ifndef " str n "#define " str "\n\n" _ "\n\n#endif // " str)))
2760 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2761 (eval-after-load 'autoinsert
2762 '(define-auto-insert '("\\.\\(py\\)\\'" . "Python skeleton")
2771 Emacs lisp auto-insert, based on the default module in =autoinsert.el=, but replace =completing-read= as
2772 =completing-read-ido-ubiquitous= to fix the edge case of that =ido= cannot handle.
2773 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2774 (eval-after-load 'autoinsert
2775 '(define-auto-insert '("\\.el\\'" . "my Emacs Lisp header")
2777 "Short description: "
2778 ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str
2779 (make-string (max 2 (- 80 (current-column) 27)) ?\s)
2780 "-*- lexical-binding: t; -*-" '(setq lexical-binding t)
2782 ;; Copyright (C) " (format-time-string "%Y") " "
2783 (getenv "ORGANIZATION") | (progn user-full-name) "
2785 ;; Author: " (user-full-name)
2786 '(if (search-backward "&" (line-beginning-position) t)
2787 (replace-match (capitalize (user-login-name)) t t))
2788 '(end-of-line 1) " <" (progn user-mail-address) ">
2791 ;;'(setq v1 (apply 'vector (mapcar 'car finder-known-keywords)))
2792 '(setq v1 (mapcar (lambda (x) (list (symbol-name (car x))))
2793 finder-known-keywords)
2794 v2 (mapconcat (lambda (x) (format "%12s: %s" (car x) (cdr x)))
2795 finder-known-keywords
2797 ((let ((minibuffer-help-form v2))
2798 (completing-read-ido-ubiquitous "Keyword, C-h: " v1 nil t))
2801 \;; This program is free software; you can redistribute it and/or modify
2802 \;; it under the terms of the GNU General Public License as published by
2803 \;; the Free Software Foundation, either version 3 of the License, or
2804 \;; (at your option) any later version.
2806 \;; This program is distributed in the hope that it will be useful,
2807 \;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2808 \;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2809 \;; GNU General Public License for more details.
2811 \;; You should have received a copy of the GNU General Public License
2812 \;; along with this program. If not, see <http://www.gnu.org/licenses/>.
2824 \;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")))
2827 ** Org file template
2828 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2829 ;; (eval-after-load 'autoinsert
2830 ;; '(define-auto-insert '("\\.\\(org\\)\\'" . "Org-mode skeleton")
2833 ;; "#+TITLE: " str (make-string 30 ?\s) > \n
2834 ;; "#+AUTHOR: Peng Li\n"
2835 ;; "#+EMAIL: seudut@gmail.com\n"
2836 ;; "#+DATE: " (shell-command-to-string "echo -n $(date +%Y-%m-%d)") > \n
2842 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2843 (use-package markdown-mode
2845 :commands (markdown-mode gfm-mode)
2846 :mode (("README\\.md\\'" . gfm-mode)
2847 ("\\.md\\'" . markdown-mode)
2848 ("\\.markdown\\'" . markdown-mode))
2849 :init (setq markdown-command "multimarkdown"))
2851 ;; (add-hook 'gfm-mode-hook (lambda ()
2852 ;; (set-face-attribute 'markdown-inline-code-face nil :inherit 'fixed-pitch)
2853 ;; (set-face-attribute 'markdown-pre-face nil :inherit 'fixed-pitch)))
2854 ;; (with-eval-after-load "gfm-mode"
2855 ;; (set-face-attribute 'markdown-inline-code-face nil :inherit 'fixed-pitch)
2856 ;; (set-face-attribute 'markdown-pre-face nil :inherit 'fixed-pitch))
2859 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2860 (use-package markdown-preview-eww
2865 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2869 (global-set-key (kbd "C-;") #'iedit-mode))
2873 Refer [[https://www.emacswiki.org/emacs/GnusGmail][GnusGmail]]
2874 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2875 (setq user-mail-address "seudut@gmail.com"
2876 user-full-name "Peng Li")
2878 (setq gnus-select-method
2880 (nnimap-address "imap.gmail.com")
2881 (nnimap-server-port "imaps")
2882 (nnimap-stream ssl)))
2884 (setq smtpmail-smtp-service 587
2885 gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
2887 ;; Use gmail sending mail
2888 (setq message-send-mail-function 'smtpmail-send-it
2889 smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
2890 smtpmail-auth-credentials '(("smtp.gmail.com" 587 "seudut@gmail.com" nil))
2891 smtpmail-default-smtp-server "smtp.gmail.com"
2892 smtpmail-smtp-server "smtp.gmail.com"
2893 smtpmail-smtp-service 587
2894 starttls-use-gnutls t)
2897 And put the following in =~/.authinfo= file, replacing =<USE>= with your email address
2898 and =<PASSWORD>= with the password
2900 machine imap.gmail.com login <USER> password <PASSWORD> port imaps
2901 machine smtp.gmail.com login <USER> password <PASSWORD> port 587
2907 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2908 ;; (use-package gnus
2910 ;; (setq gnus-permanently-visible-groups "\.*")
2912 ;; (cond (window-system
2913 ;; (setq custom-background-mode 'light)
2914 ;; (defface my-group-face-1
2915 ;; '((t (:foreground "Red" :bold t))) "First group face")
2916 ;; (defface my-group-face-2
2917 ;; '((t (:foreground "DarkSeaGreen4" :bold t)))
2918 ;; "Second group face")
2919 ;; (defface my-group-face-3
2920 ;; '((t (:foreground "Green4" :bold t))) "Third group face")
2921 ;; (defface my-group-face-4
2922 ;; '((t (:foreground "SteelBlue" :bold t))) "Fourth group face")
2923 ;; (defface my-group-face-5
2924 ;; '((t (:foreground "Blue" :bold t))) "Fifth group face")))
2925 ;; (setq gnus-group-highlight
2926 ;; '(((> unread 200) . my-group-face-1)
2927 ;; ((and (< level 3) (zerop unread)) . my-group-face-2)
2928 ;; ((< level 3) . my-group-face-3)
2929 ;; ((zerop unread) . my-group-face-4)
2930 ;; (t . my-group-face-5))))
2934 ;; (add-hook 'gnus-group-mode-hook (lambda ()
2935 ;; (define-key gnus-group-mode-map "k" 'gnus-group-prev-group)
2936 ;; (define-key gnus-group-mode-map "j" 'gnus-group-next-group)
2937 ;; (define-key gnus-group-mode-map "g" 'gnus-group-jump-to-group)
2938 ;; (define-key gnus-group-mode-map "v" (lambda () (interactive) (gnus-group-select-group t)))))
2941 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2942 (setq gnus-fetch-old-headers 't)
2946 (setq gnus-extract-address-components
2947 'mail-extract-address-components)
2949 (setq gnus-summary-line-format "%U%R%z%I%(%[%-20,20f%]%) %s%-80= %11&user-date;\n")
2950 (setq gnus-user-date-format-alist '(((gnus-seconds-today) . "%H:%M")
2951 ((+ 86400 (gnus-seconds-today)) . "%a %H:%M")
2952 (604800 . "%a, %b %-d")
2953 (15778476 . "%b %-d")
2956 (setq gnus-thread-sort-functions '((not gnus-thread-sort-by-number)))
2957 (setq gnus-unread-mark ?\.)
2958 (setq gnus-use-correct-string-widths t)
2961 (setq gnus-thread-hide-subtree t)
2963 ;; (with-eval-after-load 'gnus-summary-mode
2964 ;; (define-key gnus-summary-mode-map (kbd "C-o") 'sd/hydra-window/body))
2966 ;; (add-hook 'gnus-summary-mode-hook (lambda ()
2967 ;; (define-key gnus-summary-mode-map (kbd "C-o") nil)))
2968 ;(add-hook 'gnus-summary-mode-hook (apply-partially #'define-key gnus-summary-mode-map (kbd "C-o") nil))
2974 See [[https://www.emacswiki.org/emacs/GnusWindowLayout][GnusWindowLayout]]
2975 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2976 (gnus-add-configuration
2982 (summary 1.0 poine)))))
2984 (gnus-add-configuration
2990 (summary 0.50 point)
2993 (with-eval-after-load 'gnus-group-mode
2994 (gnus-group-select-group "INBOX"))
2995 ;; (add-hook 'gnus-group-mode-map (lambda ()
2996 ;; (gnus-group-select-group "INBOX")))
3000 Refer [[http://www.kirang.in/2014/11/13/emacs-as-email-client-with-offlineimap-and-mu4e-on-osx][emacs-as-email-client-with-offlineimap-and-mu4e-on-osx]]
3002 ** OfflineImap - download all mails from IMAP into local directory, and keep in sync
3003 #+BEGIN_SRC sh :results output replace
3005 brew install offline-imap
3007 cp /usr/local/etc/offlineimap.conf ~/.offlineimapr
3009 #For the =offlineimap= config on mac, using =sslcacertfile= instead of =cert_fingerpring=. On Mac
3010 sslcacertfile = /usr/local/etc/openssl/cert.pem
3020 localrepository = Gmail-Local
3021 remoterepository = Gmail-Remote
3023 [Repository Gmail-Local]
3025 localfolders = ~/.Mail/seudut@gmail.com
3027 [Repository Gmail-Remote]
3029 remotehost = imap.gmail.com
3030 remoteuser = seudut@gmail.com
3031 remotepass = xxxxxxxx
3034 #cert_fingerprint = <insert gmail server fingerprint here>
3035 sslcacertfile = /usr/local/etc/openssl/cert.pem
3037 folderfilter = lambda folder: folder not in ['[Gmail]/Trash',
3043 Then, run =offlineimap= to sync the mail
3045 ** Mu - fast search, view mails and extract attachments.
3047 EMACS=/usr/local/bin/emacs brew install mu --with-emacs
3050 Then, run =mu index --maildir=~/.Mail=
3052 ** Mu4e - Emacs frontend of Mu
3053 config from [[http://www.kirang.in/2014/11/13/emacs-as-email-client-with-offlineimap-and-mu4e-on-osx/][emacs-as-email-client-with-offlineimap-and-mu4e-on-osx]]
3054 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3055 (if (require 'mu4e nil 'noerror)
3057 (setq mu4e-maildir "~/.Mail")
3058 (setq mu4e-drafts-folder "/[Gmail].Drafts")
3059 (setq mu4e-sent-folder "/[Gmail].Sent Mail")
3060 ;; don't save message to Sent Messages, Gmail/IMAP takes care of this
3061 (setq mu4e-sent-messages-behavior 'delete)
3062 ;; allow for updating mail using 'U' in the main view:
3063 (setq mu4e-get-mail-command "offlineimap")
3066 (setq mu4e-maildir-shortcuts
3068 ("/[Gmail].Sent Mail" . ?s)))
3070 ;; something about ourselves
3072 user-mail-address "seudut@gmail.com"
3073 user-full-name "Peng Li"
3074 mu4e-compose-signature
3080 (setq mu4e-show-images t)
3082 ;; use imagemagick, if available
3083 (when (fboundp 'imagemagick-register-types)
3084 (imagemagick-register-types))
3086 ;; convert html emails properly
3087 ;; Possible options:
3088 ;; - html2text -utf8 -width 72
3089 ;; - textutil -stdin -format html -convert txt -stdout
3090 ;; - html2markdown | grep -v ' _place_holder;' (Requires html2text pypi)
3091 ;; - w3m -dump -cols 80 -T text/html
3092 ;; - view in browser (provided below)
3093 (setq mu4e-html2text-command "textutil -stdin -format html -convert txt -stdout")
3096 (add-hook 'mu4e-compose-mode-hook
3097 (defun my-do-compose-stuff ()
3098 "My settings for message composition."
3099 (set-fill-column 72)
3102 ;; add option to view html message in a browser
3103 ;; `aV` in view to activate
3104 (add-to-list 'mu4e-view-actions
3105 '("ViewInBrowser" . mu4e-action-view-in-browser) t)
3107 ;; fetch mail every 10 mins
3108 (setq mu4e-update-interval 600)
3111 (setq-default mu4e-headers-fields '((:flags . 6)
3113 (:mailing-list . 20)
3114 (:thread-subject . 70)
3115 (:human-date . 16))))
3116 (message "seudut:mu4e not installed, it won't work."))
3120 - =gnutls=, depends on =gnutls=, first confirm this is installed, otherwise, =brew install gnutls=
3122 #+BEGIN_SRC fundamental
3123 machine smtp.gmail.com login <gmail username> password <gmail password>
3125 - OPTIONAL, encrypt the =~/.authinfo= file
3126 #+BEGIN_SRC sh :results output replace
3127 gpg --output ~/.authinfo.gpg --symmetric ~/.authinfo
3131 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3132 (with-eval-after-load 'ediff
3133 (setq ediff-split-window-function 'split-window-horizontally)
3134 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
3135 (add-hook 'ediff-startup-hook 'ediff-toggle-wide-display)
3136 (add-hook 'ediff-cleanup-hook 'ediff-toggle-wide-display)
3137 (add-hook 'ediff-suspend-hook 'ediff-toggle-wide-display))
3142 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3143 (use-package yaml-mode
3146 (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)))
3151 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
3152 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3157 (require 'gnugo-imgen)
3158 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
3159 (add-hook 'gnugo-start-game-hook '(lambda ()
3160 (gnugo-image-display-mode)
3163 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
3167 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
3168 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3172 (setq emms-directory (concat sd-temp-directory "emms"))
3173 (setq emms-source-file-default-directory "~/Music/")
3176 (emms-default-players)
3177 (define-emms-simple-player mplayer '(file url)
3178 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
3179 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
3180 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
3181 ".m4a" ".flv" ".ogv" ".pls"))
3182 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
3183 (emms-history-load))
3187 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3188 (use-package bing-dict
3191 (global-set-key (kbd "s-d") 'bing-dict-brief)
3192 :commands (bing-dict-brief))
3195 * Project operations - =super=
3197 ** Windown & Buffer - =C-o=
3198 Defind a =hydra= function for windows, buffer & bookmark operations. And map it to =C-o= globally.
3199 Most use =C-o C-o= to switch buffers; =C-o x, v= to split window; =C-o o= to delete other windows
3200 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3203 (require 'utilities)
3204 ;; (defhydra sd/hydra-window (:color red :columns nil)
3206 ;; ;; windows switch
3207 ;; ("h" windmove-left nil :exit t)
3208 ;; ("j" windmove-down nil :exit t)
3209 ;; ("k" windmove-up nil :exit t)
3210 ;; ("l" windmove-right nil :exit t)
3211 ;; ("C-o" other-window nil :exit t)
3213 ;; ("H" hydra-move-splitter-left nil)
3214 ;; ("J" hydra-move-splitter-down nil)
3215 ;; ("K" hydra-move-splitter-up nil)
3216 ;; ("L" hydra-move-splitter-right nil)
3220 ;; (split-window-right)
3221 ;; (windmove-right))
3225 ;; (split-window-below)
3228 ;; ;; buffer / windows switch
3229 ;; ("o" sd/toggle-max-windows nil :exit t)
3230 ;; ("C-k" sd/delete-current-window nil :exit t)
3231 ;; ("C-d" (lambda ()
3234 ;; (sd/delete-current-window))
3238 ;; ;; ("'" other-window "other" :exit t)
3239 ;; ;; ("a" ace-window "ace")
3240 ;; ("s" ace-swap-window nil)
3241 ;; ("D" ace-delete-window nil :exit t)
3242 ;; ;; ("i" ace-maximize-window "ace-one" :exit t)
3243 ;; ;; Windows undo - redo
3244 ;; ("u" (progn (winner-undo) (setq this-command 'winner-undo)) nil)
3245 ;; ("r" (progn (winner-redo) (setq this-command 'winner-redo)) nil)
3247 ;; ;; ibuffer, dired, eshell, bookmarks
3248 ;; ;; ("C-i" other-window nil :exit t)
3249 ;; ("C-b" ido-switch-buffer nil :exit t)
3250 ;; ("C-f" projectile-find-file nil :exit t)
3251 ;; ("C-r" ivy-recentf nil :exit t)
3252 ;; ;; ("C-p" persp-switch nil :exit t)
3253 ;; ;; ("C-t" projectile-persp-switch-project nil :exit t)
3255 ;; ;; other special buffers
3256 ;; ("d" sd/project-or-dired-jump nil :exit t)
3257 ;; ("b" ibuffer nil :exit t)
3258 ;; ("t" multi-term nil :exit t)
3259 ;; ("e" sd/toggle-project-eshell nil :exit t)
3260 ;; ("m" bookmark-jump-other-window nil :exit t)
3261 ;; ("M" bookmark-set nil :exit t)
3262 ;; ("g" magit-status nil :exit t)
3263 ;; ;; ("p" paradox-list-packages nil :exit t)
3267 ;; ("<ESC>" nil nil)
3268 ;; ("C-h" windmove-left nil :exit t)
3269 ;; ("C-j" windmove-down nil :exit t)
3270 ;; ("C-k" windmove-up nil :exit t)
3271 ;; ("C-l" windmove-right nil :exit t)
3272 ;; ("C-;" nil nil :exit t)
3273 ;; ("n" nil nil :exit t)
3274 ;; ("[" nil nil :exit t)
3275 ;; ("]" nil nil :exit t)
3278 ;; (global-unset-key (kbd "C-o"))
3279 ;; (global-set-key (kbd "C-o") 'sd/hydra-window/body)
3281 ;; (defun sd/project-or-dired-jump ()
3282 ;; "If under project, jump to the root directory, otherwise
3283 ;; jump to dired of current file"
3285 ;; (if (projectile-project-p)
3286 ;; (projectile-dired)
3290 Kill the help window and buffer when quit.
3291 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3292 (with-eval-after-load "help-mode"
3293 (define-key help-mode-map (kbd "q") (lambda ()
3297 (with-eval-after-load 'man
3298 (set-face-attribute 'Man-overstrike nil :inherit 'bold :foreground "orange red")
3299 (set-face-attribute 'Man-underline nil :inherit 'underline :foreground "forest green")
3300 (define-key Man-mode-map (kbd "q") (lambda ()
3305 ;; (advice-add 'man :after (lambda (man-args) (other-window 1)))
3306 (advice-add 'man :after (apply-partially 'other-window 1))
3309 (require 'shell-command-output-mode)
3311 (defun my/shell-command-after (command &optional output-buffer error-buffer)
3312 (let* ((buffer (get-buffer "*Shell Command Output*"))
3313 (window (get-buffer-window buffer)))
3314 (if buffer (with-current-buffer buffer
3315 (shell-command-output-mode)))
3317 (select-window window))))
3319 (advice-add 'shell-command :after 'my/shell-command-after)
3325 =C-<SPC>= set marks toggle the region
3326 =C-u C-<SPC>= Jump to the mark, repeated calls go further back the mark ring
3327 =C-x C-x= Exchanges the point and mark.
3329 Stolen [[https://www.masteringemacs.org/article/fixing-mark-commands-transient-mark-mode][fixing-mark-commands-transient-mark-mode]]
3330 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3331 (defun push-mark-no-activate ()
3332 "Pushes `point' to `mark-ring' and does not activate the region
3333 Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
3335 (push-mark (point) t nil)
3336 (message "Pushed mark to ring"))
3338 ;; (global-set-key (kbd "C-`") 'push-mark-no-activate)
3340 (defun jump-to-mark ()
3341 "Jumps to the local mark, respecting the `mark-ring' order.
3342 This is the same as using \\[set-mark-command] with the prefix argument."
3344 (set-mark-command 1))
3346 ;; (global-set-key (kbd "M-`") 'jump-to-mark)
3348 (defun exchange-point-and-mark-no-activate ()
3349 "Identical to \\[exchange-point-and-mark] but will not activate the region."
3351 (exchange-point-and-mark)
3352 (deactivate-mark nil))
3354 ;; (define-key global-map [remap exchange-point-and-mark] 'exchange-point-and-mark-no-activate)
3357 Show the mark ring using =helm-mark-ring=, also mapping =M-`= to quit minibuffer. so that =M-`= can
3358 toggle the mark ring. the best way is add a new action and mapping to =helm-source-mark-ring=, but
3359 since there is no map such as =helm-mark-ring=map=, so I cannot binding a key to the quit action.
3360 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3361 (setq mark-ring-max 50)
3366 (global-set-key (kbd "M-`") #'helm-mark-ring))
3368 (define-key minibuffer-local-map (kbd "M-`") 'keyboard-escape-quit)
3371 =M-h= marks the next paragraph
3372 =C-x h= marks the whole buffer
3373 =C-M-h= marks the next defun
3374 =C-x C-p= marks the next page
3376 Registers can save text, position, rectangles, file and configuration and other things.
3377 Here for movement, we can use register to save/jump position
3378 =C-x r SPC= store point in register
3379 =C-x r j= jump to register
3380 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3381 (use-package list-register
3385 *** =Avy= for easy motion
3386 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3390 (avy-setup-default))
3392 ;; (global-set-key (kbd "C-M-j") 'avy-goto-line-below)
3393 ;; (global-set-key (kbd "C-M-n") 'avy-goto-line-below)
3394 ;; (global-set-key (kbd "C-M-k") 'avy-goto-line-above)
3395 ;; (global-set-key (kbd "C-M-p") 'avy-goto-line-above)
3397 ;; (global-set-key (kbd "C-M-f") 'avy-goto-word-1-below)
3398 ;; (global-set-key (kbd "C-M-b") 'avy-goto-word-1-above)
3400 ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
3401 ;; (global-set-key (kbd "C-M-w") 'avy-goto-char-timer)
3402 ;; (global-set-key (kbd "C-M-l") 'avy-goto-char-in-line)
3404 ;; ;; will delete above
3405 ;; (global-set-key (kbd "M-g j") 'avy-goto-line-below)
3406 ;; (global-set-key (kbd "M-g k") 'avy-goto-line-above)
3407 ;; (global-set-key (kbd "M-g w") 'avy-goto-word-1-below)
3408 ;; (global-set-key (kbd "M-g b") 'avy-goto-word-1-above)
3409 ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
3410 ;; (global-set-key (kbd "M-g f") 'avy-goto-char-timer)
3411 ;; (global-set-key (kbd "M-g c") 'avy-goto-char-in-line)
3412 (global-set-key (kbd "M-g c") 'avy-goto-char)
3413 (global-set-key (kbd "M-g b") 'avy-goto-word-0-above)
3414 (global-set-key (kbd "M-g w") 'avy-goto-word-0-below)
3417 *** =Imenu= goto tag
3418 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3419 (global-set-key (kbd "M-i") #'counsel-imenu)
3420 ;; (global-set-key (kbd "M-i") #'imenu)
3422 ;; define M-[ as C-M-a
3423 ;; http://ergoemacs.org/emacs/emacs_key-translation-map.html
3424 (define-key key-translation-map (kbd "M-[") (kbd "C-M-a"))
3425 (define-key key-translation-map (kbd "M-]") (kbd "C-M-e"))
3429 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3430 (global-set-key (kbd "M-l") 'goto-line)
3436 =helm-show-kill-ring=
3437 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3438 (setq kill-ring-max 100) ; default is 60p
3443 (global-set-key (kbd "M-y") #'helm-show-kill-ring))
3447 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3448 (use-package undo-tree
3451 (define-key undo-tree-visualizer-mode-map "j" 'undo-tree-visualize-redo)
3452 (define-key undo-tree-visualizer-mode-map "k" 'undo-tree-visualize-undo)
3453 (define-key undo-tree-visualizer-mode-map "h" 'undo-tree-visualize-switch-branch-left)
3454 (define-key undo-tree-visualizer-mode-map "l" 'undo-tree-visualize-switch-branch-right)
3455 (global-undo-tree-mode 1))
3457 (global-set-key (kbd "s-u") 'undo-tree-visualize)
3461 Stolen from [[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-spelling.el][here]], hunspell will search dictionary in =DICPATH=
3462 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3463 (setenv "DICPATH" "/usr/local/share/hunspell")
3465 (when (executable-find "hunspell")
3466 (setq-default ispell-program-name "hunspell")
3467 (setq ispell-really-hunspell t))
3469 ;; (defun text-mode-hook-setup ()
3470 ;; ;; Turn off RUN-TOGETHER option when spell check text-mode
3471 ;; (setq-local ispell-extra-args (flyspell-detect-ispell-args)))
3472 ;; (add-hook 'text-mode-hook 'text-mode-hook-setup)
3473 ;; (add-hook 'text-mode-hook 'flyspell-mode)
3475 ;; enable flyspell check on comments and strings in progmamming modes
3476 ;; (add-hook 'prog-mode-hook 'flyspell-prog-mode)
3478 ;; I don't use the default mappings
3479 (with-eval-after-load 'flyspell
3480 (define-key flyspell-mode-map (kbd "C-;") nil)
3481 (define-key flyspell-mode-map (kbd "C-,") nil)
3482 (define-key flyspell-mode-map (kbd "C-.") nil))
3485 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]]
3486 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3487 ;; NO spell check for embedded snippets
3488 (defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
3489 (let ((rlt ad-return-value)
3490 (begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\)")
3491 (end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\)")
3494 (when ad-return-value
3496 (setq old-flag case-fold-search)
3497 (setq case-fold-search t)
3498 (setq b (re-search-backward begin-regexp nil t))
3499 (if b (setq e (re-search-forward end-regexp nil t)))
3500 (setq case-fold-search old-flag))
3501 (if (and b e (< (point) e)) (setq rlt nil)))
3502 (setq ad-return-value rlt)))
3505 ** Search & Replace / hightlight =M-s=
3508 =C-w= add word at point to search string,
3510 =C-M-y= add character at point to search string
3511 =M-s C-e= add reset of line at point
3512 =C-y= yank from clipboard to search string
3513 =M-n=, =M-p=, history
3514 =C-M-i= complete search string
3515 set the isearch history size, the default is only =16=
3516 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3517 (setq history-length 5000)
3518 (setq regexp-search-ring-max 1000)
3519 (setq search-ring-max 1000)
3521 ;; when search a word or a symbol , also add the word into regexp-search-ring
3522 (defadvice isearch-update-ring (after sd/isearch-update-ring (string &optional regexp) activate)
3523 "Add search-ring to regexp-search-ring"
3525 (add-to-history 'regexp-search-ring string regexp-search-ring-max)))
3529 use the prefix =M-s= for searching in buffers
3530 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3531 (defun sd/make-keymap (key bindings)
3532 (setq keymap (make-sparse-keymap))
3533 (dolist (binding bindings)
3534 (define-key keymap (car binding) (cdr binding)))
3535 (global-set-key key keymap))
3537 ;; (sd/make-keymap "\M-s"
3538 ;; '(("w" . save-buffer)
3539 ;; ;; ("\M-w" . save-buffer)
3540 ;; ("e" . revert-buffer)
3541 ;; ("s" . isearch-forward-regexp)
3542 ;; ("\M-s" . isearch-forward-regexp)
3543 ;; ("r" . isearch-backward-regexp)
3544 ;; ("." . isearch-forward-symbol-at-point)
3546 ;; ;; ("h" . highlight-symbol-at-point)
3547 ;; ("h" . highlight-symbol)
3548 ;; ("m" . highlight-regexp)
3549 ;; ("l" . highlight-lines-matching-regexp)
3550 ;; ("M" . unhighlight-regexp)
3551 ;; ("f" . keyboard-quit)
3552 ;; ("q" . keyboard-quit)))
3555 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3556 (use-package highlight-symbol
3559 (defhydra sd/search-replace (:color red :columns nil)
3561 ("w" save-buffer "save" :exit t)
3562 ("e" revert-buffer "revert" :exit t)
3563 ("u" undo-tree-visualize "undo" :exit t)
3564 ("s" isearch-forward-regexp "s-search" :exit t)
3565 ("M-s" isearch-forward-regexp "s-search" :exit t)
3566 ("r" isearch-backward-regexp "r-search" :exit t)
3567 ("." isearch-forward-symbol-at-point "search point" :exit t)
3568 ("/" swiper "swiper" :exit t)
3569 ("o" occur "occur" :exit t)
3570 ("h" highlight-symbol "higlight" :exit t)
3571 ("l" highlight-lines-matching-regexp "higlight line" :exit t)
3572 ("m" highlight-regexp "higlight" :exit t)
3573 ("M" unhighlight-regexp "unhiglight" :exit t)
3577 (global-unset-key (kbd "M-s"))
3578 (global-set-key (kbd "M-s") 'sd/search-replace/body)
3581 ;; search and replace and highlight
3582 (define-key isearch-mode-map (kbd "M-s") 'isearch-repeat-forward)
3583 (define-key isearch-mode-map (kbd "M-r") 'isearch-repeat-backward)
3584 (global-set-key (kbd "s-[") 'highlight-symbol-next)
3585 (global-set-key (kbd "s-]") 'highlight-symbol-prev)
3586 (global-set-key (kbd "s-\\") 'highlight-symbol-query-replace)
3590 Occur search key bindings
3591 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3592 (defun sd/occur-keys ()
3593 "My key bindings in occur-mode"
3595 (switch-to-buffer-other-window "*Occur*")
3596 (define-key occur-mode-map (kbd "C-o") nil)
3597 (define-key occur-mode-map (kbd "C-n") (lambda ()
3600 (occur-mode-goto-occurrence-other-window)
3603 (define-key occur-mode-map (kbd "C-p") (lambda ()
3606 (occur-mode-goto-occurrence-other-window)
3610 (add-hook 'occur-hook #'sd/occur-keys)
3612 (use-package color-moccur
3614 :commands (isearch-moccur isearch-all)
3616 (setq isearch-lazy-highlight t)
3618 (use-package moccur-edit))
3622 ** Expand region map
3623 *** Install =expand-region=
3624 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3625 (use-package expand-region
3628 ;; (global-set-key (kbd "C-=") 'er/expand-region)
3632 *** Add a =hydra= map for =expand-region= operations
3633 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3634 (defun sd/mark-line ()
3635 "Mark current line without whitespace beginning"
3637 (back-to-indentation)
3638 (set-mark (line-end-position)))
3640 (defhydra sd/expand-selected (:color red :columns nil
3641 :post (deactivate-mark)
3645 ;; ("e" er/expand-region "+")
3646 ("SPC" er/expand-region "+")
3647 ;; ("c" er/contract-region "-")
3648 ("S-SPC" er/contract-region "-")
3651 (er/contract-region 0))
3654 ("i'" er/mark-inside-quotes "in")
3655 ("i\"" er/mark-inside-quotes nil)
3656 ("o'" er/mark-outside-quotes "out")
3657 ("o\"" er/mark-outside-quotes nil)
3659 ("i{" er/mark-inside-pairs nil)
3660 ("i(" er/mark-inside-pairs nil)
3661 ("o{" er/mark-inside-pairs nil)
3662 ("o(" er/mark-inside-pairs nil)
3664 ("p" er/mark-paragraph "paragraph")
3666 ("l" sd/mark-line "line")
3667 ("u" er/mark-url "url")
3668 ("f" er/mark-defun "fun")
3669 ("n" er/mark-next-accessor "next")
3671 ("x" exchange-point-and-mark "exchange")
3677 ("d" kill-region "delete" :exit t)
3679 ("y" kill-ring-save "yank" :exit t)
3680 ("M-SPC" nil "quit" :exit t)
3681 ;; ("C-SPC" "quit" :exit t)
3682 ("q" deactivate-mark "quit" :exit t))
3684 (global-set-key (kbd "M-SPC") (lambda ()
3686 (set-mark-command nil)
3687 ;; (er/expand-region 1)
3689 (sd/expand-selected/body)))
3692 *** TODO make expand-region hydra work with lispy selected
3695 Here are some global key bindings for basic editting
3696 ** Global key bingding
3697 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3698 (global-set-key (kbd "C-h") 'delete-backward-char)
3699 (global-set-key (kbd "s-m") 'man)
3700 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
3701 ;; project operation
3702 (global-set-key (kbd "s-p") 'projectile-switch-open-project)
3703 (global-set-key (kbd "s-f") 'projectile-find-file)
3705 ;; (global-set-key (kbd "s-=") 'increase-emacs-font-size)
3706 ;; (global-set-key (kbd "s--") 'decrease-emacs-font-size)
3707 (global-set-key (kbd "s-=") 'text-scale-increase)
3708 (global-set-key (kbd "s--") 'text-scale-decrease)
3709 (global-unset-key (kbd "s-n"))
3712 Refer [[https://github.com/fnwiya/dotfiles/blob/c9ca79f1b22c919d9f4c3a0f944ba8281255a594/setup/.emacs.d/loader-init/_90-kill-region-or-backward-kill-word.el][kill-region-or-backward-kill-word]]
3714 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3715 (require 'utilities)
3716 (global-set-key (kbd "C-w") 'sd/kill-region-or-backward-kill-word)
3720 ** Esc in minibuffer
3721 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
3722 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3723 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
3724 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
3725 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
3726 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
3727 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
3728 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
3729 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
3730 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
3731 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
3733 ;; Also map s-h same as C-g
3734 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
3739 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3740 ;; (use-package perspeen
3743 ;; (setq perspeen-use-tab nil)
3747 (el-get-bundle seudut/perspeen
3749 (setq perspeen-use-tab nil)
3753 ;; super-i to switch to ith workspace
3755 (defmacro sd/define-keys (map key func &rest args)
3756 "A macro to define multi keys "
3757 `(define-key ,map ,key (lambda () (interactive) (,func ,@args))))
3760 (with-eval-after-load "perspeen"
3762 (sd/define-keys perspeen-mode-map (kbd (concat "s-" (number-to-string (+ ii 1))))
3763 perspeen-goto-ws (+ ii 1)))
3764 (define-key perspeen-mode-map (kbd "s-c") 'perspeen-create-ws)
3765 (define-key perspeen-mode-map (kbd "s-n") 'perspeen-next-ws)
3766 (define-key perspeen-mode-map (kbd "s-p") 'perspeen-previous-ws)
3767 (define-key perspeen-mode-map (kbd "s-'") 'perspeen-last-ws)
3768 (define-key perspeen-mode-map (kbd "s-t") 'perspeen-tab-create-tab)
3769 (define-key perspeen-mode-map (kbd "s-t") 'perspeen-tab-create-tab))
3772 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3773 (org-babel-load-file "~/.emacs.d/emacs-evil.org")
3778 [fn:1] [[http://coldnew.github.io/blog/2013/11-16_d2f3a/][解決 org-mode θ‘¨ζ Όε
§δΈθ±ζε°ι½ηει‘]]