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 ;; (set-face-attribute 'org-table nil :family "Ubuntu Mono" :height 120)
585 ;; (set-face-attribute 'org-table nil :family "Ubuntu Mono" :height 120)
586 (dolist (charset '(han cjk-misc))
587 (set-fontset-font (frame-parameter nil 'font) charset
588 ;; (font-spec :family "HanziPen SC")
589 (font-spec :family my-ch-font))))
594 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
597 :init (setq ido-enable-flex-matching t
598 ido-ignore-extensions t
599 ido-use-virtual-buffers t
602 (setq ido-save-directory-list-file (concat sd-temp-directory "ido.last"))
606 (add-to-list 'completion-ignored-extensions ".pyc")
609 (define-key ido-buffer-completion-map (kbd "C-w") #'ido-delete-backward-word-updir)
610 (define-key ido-file-completion-map (kbd "C-w") #'ido-delete-backward-word-updir)
611 (define-key ido-file-dir-completion-map (kbd "C-w") #'ido-delete-backward-updir)
612 ;; (define-key ido-file-dir-completion-map (kbd "C-i") #'ido-copy-current-word)
619 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
622 :config (flx-ido-mode nil))
626 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
627 (use-package ido-vertical-mode
630 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
632 (ido-vertical-mode 1))
636 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
640 (setq smex-save-file (concat sd-temp-directory "smex-items"))
644 ("M-X" . smex-major-mode-commands))
648 Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido
649 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
650 (use-package ido-ubiquitous
653 (setq magit-completing-read-function 'magit-ido-completing-read)
654 (setq gnus-completing-read-function 'gnus-ido-completing-read)
656 (ido-ubiquitous-mode 1))
660 [[https://github.com/waymondo/ido-exit-target][ido-exit-target]] let you open file/buffer on =other-windows= when call =ido-switch-buffer=
661 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
662 (use-package ido-exit-target
665 (mapcar #'(lambda (map)
666 (define-key map (kbd "C-j") #'ido-exit-target-other-window)
667 (define-key map (kbd "C-k") #'ido-exit-target-split-window-below))
668 (list ido-buffer-completion-map
669 ;; ido-common-completion-map
670 ido-file-completion-map
671 ido-file-dir-completion-map)))
675 let helm windows split inside current window
676 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
677 (with-eval-after-load 'helm
678 (setq helm-split-window-in-side-p t))
682 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
683 (use-package projectile
686 (setq projectile-enable-caching t)
687 (setq projectile-switch-project-action 'projectile-dired)
688 (setq projectile-cache-file (concat sd-temp-directory "projectile.cache"))
689 (setq projectile-completion-system 'ivy)
691 (add-to-list 'projectile-globally-ignored-files "GTAGS")
692 (projectile-global-mode t))
694 ;; https://emacs.stackexchange.com/questions/16497/how-to-exclude-files-from-projectile
695 (if (executable-find "rg")
697 (defconst modi/rg-arguments
698 `("--line-number" ; line numbers
700 "--follow" ; follow symlinks
701 "--mmap") ; apply memory map optimization when possible
702 "Default rg arguments used in the functions in `projectile' package.")
704 (defun modi/advice-projectile-use-rg ()
705 "Always use `rg' for getting a list of all files in the project."
707 (append '("\\rg") ; used unaliased version of `rg': \rg
709 '("--null" ; output null separated results,
710 "--files")) ; get file names matching the regex '' (all files)
713 (advice-add 'projectile-get-ext-command :override #'modi/advice-projectile-use-rg))
714 (message "rg is not found"))
717 * Swiper & Ivy & Counsel
718 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
723 (use-package ivy :ensure t)
725 (setq ivy-use-virtual-buffers nil
727 ivy-count-format "%d/%d ")
728 (set-face-attribute 'ivy-current-match nil :background "Orange" :foreground "black")
729 (global-set-key (kbd "M-x") 'counsel-M-x)
730 ;; (global-set-key (kbd "C-h f") 'counsel-describe-function)
731 ;; (global-set-key (kbd "C-h v") 'counsel-describe-variable)
732 (global-set-key (kbd "C-x C-f") 'counsel-find-file)
733 (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
734 (global-set-key (kbd "C-c C-r") 'ivy-resume))
737 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
740 '(("q" (lambda (x) (ivy-quit-and-run (message "=="))) "exit")))
743 'projectile-switch-to-buffer
744 '(("j" ivy--switch-buffer-other-window-action "other window" )))
746 (defun sd/projectile-find-file-other-window-action (file)
747 (message "=========")
748 (message (projectile-expand-root file))
749 (find-file-other-window (projectile-expand-root file)))
752 'projectile-find-file
753 '(("j" sd/projectile-find-file-other-window-action "other-window")))
755 (defun sd/swith-to-buffer ()
758 (if (projectile-project-p)
759 (projectile-switch-to-buffer)
760 (ivy-switch-buffer)))
764 '(("j" ivy--switch-buffer-other-window-action "other window")))
766 (defun sd/exit-ivy-and-swith-to-buffer ()
767 "exit ivy complete, and call swith to buffer"
770 (ivy-switch-buffer)))
772 (defun my/ivy-read-action (key)
773 (let ((actions (ivy-state-action ivy-last)))
774 (if (null (ivy--actionp actions))
776 (let* ((action-idx (cl-position-if
777 (lambda (x) (equal (car x) key))
779 (cond ((member key '("
\e" "
\a"))
782 (message "%s is not bound" key)
786 (setcar actions (1+ action-idx))
787 (ivy-set-action actions)))))))
789 (with-eval-after-load "ivy"
790 (define-key ivy-minibuffer-map (kbd "C-o") 'ivy-dispatching-done)
791 (define-key ivy-minibuffer-map (kbd "C-k") (lambda () (interactive)
792 (my/ivy-read-action "j")
794 (define-key ivy-minibuffer-map (kbd "M-o") #'sd/exit-ivy-and-swith-to-buffer))
797 stolen from [[https://github.com/mariolong/emacs.d/blob/f6a061594ef1b5d1f4750e9dad9dc97d6e122840/emacs-init.org][here]]
798 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
804 (global-set-key (kbd "s-/") 'swiper)
805 (define-key swiper-map (kbd "M-r") 'swiper-query-replace)
806 (define-key swiper-map (kbd "C-.") (lambda ()
808 (insert (format "%s" (with-ivy-window (thing-at-point 'word))))))
809 (define-key swiper-map (kbd "M-.") (lambda ()
811 (insert (format "%s" (with-ivy-window (thing-at-point 'symbol)))))))
815 ** Org-mode Basic setting
816 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
817 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
821 (setq org-startup-indented t)
822 (setq org-hide-leading-starts t)
823 (setq org-src-fontify-natively t)
824 (setq org-src-tab-acts-natively t)
825 (setq org-confirm-babel-evaluate nil)
826 (setq org-use-speed-commands t)
827 (setq org-completion-use-ido t)
828 (setq org-startup-with-inline-images t)
830 ;; (setq org-startup-with-latex-preview t)
831 ;; (setq org-format-latex-options (plist-put org-format-latex-options :scale 1.2))
833 (add-to-list 'org-modules 'org-habit)
834 (setq org-habit-graph-column 50)
835 (setq org-hide-emphasis-markers t)
836 (setq org-html-validation-link nil)
837 ;; open link when return clicked
838 (setq org-return-follows-link t)
839 ;; open the ppt file by external open instead of emacs
840 (add-to-list 'org-file-apps '("\\.pptx" . "open %s"))
841 (add-to-list 'org-file-apps '("\\.doc" . "open %s"))
842 (setq org-image-actual-width nil))
846 *** Fix the default theme - molokai
847 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
848 (with-eval-after-load "org"
849 (set-face-attribute 'org-block-begin-line nil :background nil :foreground nil :inherit 'shadow :slant 'italic)
850 (set-face-attribute 'org-block-end-line nil :background nil :foreground nil :inherit 'shadow :slant 'italic)
851 ;; (set-face-attribute 'org-table nil :family "Ubuntu Mono" :height (face-attribute 'default :height))
854 ;; (x-list-fonts "Ubuntu Mono")
856 ;; (set-frame-font "Ubuntu Mono")
857 ;; (x-list-fonts "WenQuanYi Zen Hei")
858 ;; (set-frame-font "WenQuanYi Zen Hei Mono")
860 *** variable-pitch-mode and fixed-pitch-mode
861 [[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]]
862 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
863 ;(when (display-graphic-p)
864 ; (unless (find-font (font-spec :name "Ubuntu Mono"))
865 ; (warn "Font not found Ubuntu Mono"))
866 ; (unless (find-font (font-spec :name "Source Code Pro"))
867 ; (warn "Font not found Source Code Pro"))
868 ; (unless (find-font (font-spec :name "Source Sans Pro"))
869 ; (warn "Font not found Source Sans Pro")))
871 ;; (set-face-attribute 'variable-pitch nil :font "Source Sans Pro" :height 160)
872 ;; (set-face-attribute 'fixed-pitch nil :font "Source Code Pro" :height (face-attribute 'default :height))
875 ;; Install Ubuntu Mono fonts and apply it in org-table to align Chinese fonts
876 ;; (with-eval-after-load "org"
877 ;; (mapc (lambda (face)
878 ;; (set-face-attribute face nil :inherit 'fixed-pitch))
882 ;; 'org-block-background
883 ;; 'org-block-begin-line
884 ;; 'org-block-end-line))
885 ;; (set-face-attribute 'org-table nil :family "Ubuntu Mono" :height 100)
886 ;; (set-face-attribute 'org-formula nil :family "Ubuntu Mono" :height 100)
887 ;; ;; org-special-keyword inherited from font-lock-keywork originally; as org is changed to variable-pitch, it cause
888 ;; ;; the font in special-keywords are not monospace
889 ;; (set-face-attribute 'org-special-keyword nil :inherit '(font-lock-keyword-face fixed-pitch))
891 ;; (set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch))
892 ;; (set-face-attribute 'org-block-begin-line nil :inherit 'shadow :slant 'italic :foreground nil)
893 ;; (set-face-attribute 'org-block-end-line nil :inherit 'shadow :slant 'italic :foreground nil)
895 ;; ;; fix indent broken by variable-pitch-mode
896 ;; ;; http://emacs.stackexchange.com/questions/26864/variable-pitch-face-breaking-indentation-in-org-mode
897 ;; (require 'org-indent)
898 ;; (set-face-attribute 'org-indent nil :inherit '(org-hide fixed-pitch)))
900 ;; (with-eval-after-load "org"
901 ;; (let ((default-font-size (- (face-attribute 'default :height) (if (display-graphic-p) 20 0))))
902 ;; (set-face-attribute 'org-code nil :height default-font-size)
903 ;; (set-face-attribute 'org-block nil :height default-font-size)
904 ;; ;; (set-face-attribute 'org-block-begin-line nil :background nil :foreground nil :inherit 'shadow :slant 'italic :height default-font-size)
905 ;; ;; (set-face-attribute 'org-block-end-line nil :background nil :foreground nil :inherit 'shadow :slant 'italic :height default-font-size)
906 ;; (when (find-font (font-spec :name "Ubuntu Mono"))
907 ;; (set-face-attribute 'org-table nil :family "Ubutu Mono" :height default-font-size)
908 ;; (set-face-attribute 'org-formula nil :family "Ubutu Mono" :height default-font-size))))
910 ;; (add-hook 'org-mode-hook
912 ;; (let ((default-font-size (- (face-attribute 'default :height) (if (display-graphic-p) 20 0))))
913 ;; (set-face-attribute 'org-code nil :height default-font-size)
914 ;; (set-face-attribute 'org-block nil :height default-font-size)
915 ;; ;; (set-face-attribute 'org-block-begin-line nil :background nil :foreground nil :inherit 'shadow :slant 'italic :height default-font-size)
916 ;; ;; (set-face-attribute 'org-block-end-line nil :background nil :foreground nil :inherit 'shadow :slant 'italic :height default-font-size)
917 ;; (when (find-font (font-spec :name "Ubuntu Mono"))
918 ;; (set-face-attribute 'org-table nil :family "Ubutu Mono" :height default-font-size)
919 ;; (set-face-attribute 'org-formula nil :family "Ubutu Mono" :height default-font-size)))))
922 Also correct the face of =org-meta-line= in =org-table=
923 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
924 ;; (with-eval-after-load "org"
925 ;; (set-face-attribute 'org-meta-line nil :font "Source Code Pro" :height 120 :slant 'italic :inherit 'font-lock-comment-face))
930 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
931 ;; (with-eval-after-load "org"
932 ;; (let* ((base-height (face-attribute 'variable-pitch :height))
933 ;; (base-font-color (face-foreground 'default nil 'default)))
934 ;; (set-face-attribute 'org-document-title nil :weight 'bold :height (+ 60 base-height))
935 ;; (set-face-attribute 'org-level-1 nil :weight 'bold :height (+ 40 base-height))
936 ;; (set-face-attribute 'org-level-2 nil :weight 'bold :height (+ 30 base-height))
937 ;; (set-face-attribute 'org-level-3 nil :weight 'bold :height (+ 20 base-height))
938 ;; (set-face-attribute 'org-level-4 nil :weight 'bold :height (+ 10 base-height))
939 ;; (set-face-attribute 'org-level-5 nil :weight 'bold)
940 ;; (set-face-attribute 'org-level-6 nil :weight 'bold)
941 ;; (set-face-attribute 'org-level-7 nil :weight 'bold)
942 ;; (set-face-attribute 'org-level-8 nil :weight 'bold)))
947 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
948 (el-get-bundle hasu/emacs-ob-racket
952 ;; (use-package ob-lua
955 ;; use current window for org source buffer editting
957 ;; (setq org-src-window-setup 'current-window)
958 (define-key org-mode-map (kbd "C-'") nil)
959 ;; C-M-i is mapped to imenu globally
960 (define-key org-mode-map (kbd "C-M-i") nil)
961 ;; set the ditta.jar path
963 (setq org-ditaa-jar-path "/usr/local/Cellar/ditaa/0.9/libexec/ditaa0_9.jar")
965 (file-exists-p org-ditaa-jar-path)
966 (message "seudut: ditaa.jar not found at %s " org-ditaa-jar-path))
968 (org-babel-do-load-languages 'org-babel-load-languages
988 ;; toggle image preview
989 (add-hook 'org-babel-after-execute-hook 'sd/display-inline-images 'append)
991 (defun sd/display-inline-images ()
993 (org-display-inline-images)
997 (with-eval-after-load "artist"
998 (define-key artist-mode-map [down-mouse-3] 'artist-mouse-choose-operation))
1001 [[http://eschulte.github.io/babel-dev/DONE-integrate-plantuml-support.html][DONE-integrate-plantuml-support]]
1004 brew install plantuml
1007 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1008 (use-package plantuml-mode
1011 (setq org-plantuml-jar-path
1012 (expand-file-name "/usr/local/Cellar/plantuml/8041/plantuml.8041.jar"))
1014 (set-variable 'plantuml-jar-path
1015 (expand-file-name "/usr/local/Cellar/plantuml/8041/plantuml.8041.jar"))
1019 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
1020 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1021 (use-package org-bullets
1024 (add-hook 'org-mode-hook (apply-partially #'org-bullets-mode t)))
1026 (setq org-bullets-bullet-list '("β¦Ώ" "βͺ" "β" "β" "βΊ" "β"))
1028 ;; increase font size when enter org-src-mode
1029 ;; (add-hook 'org-src-mode-hook (lambda () (text-scale-increase 2)))
1031 ;; define a face for org-bullets
1032 (defface org-bullet-face
1033 '((t (:foreground "green yellow")))
1034 "Face used for the org-bullets.")
1035 (setq org-bullets-face-name (quote org-bullet-face))
1036 ;; (set-face-attribute 'org-bullet-face t :foreground "burlywood" :weight 'normal :height 1.6)
1040 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
1041 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
1042 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
1043 =M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
1044 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1050 (add-hook 'org-mode-hook 'worf-mode))
1054 Refer to [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
1056 standard key binding
1057 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1058 (global-set-key "\C-cl" 'org-store-link)
1059 (global-set-key "\C-ca" 'org-agenda)
1060 (global-set-key "\C-cb" 'org-iswitchb)
1064 Replace the list bullet =-=, =+=, with =β’=, a litter change based [[https://github.com/howardabrams/dot-files/blob/master/emacs-org.org][here]]
1065 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1066 ;; (use-package org-mode
1068 ;; (font-lock-add-keywords 'org-mode
1069 ;; '(("^ *\\([-+]\\) "
1070 ;; (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "β’")))))))
1074 refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][fancy todo states]],
1075 To track TODO state changes, the =!= is to insert a timetamp, =@= is to insert a note with
1076 timestamp for the state change.
1077 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1078 ;; (setq org-todo-keywords
1079 ;; '((sequence "β TODO(t)" "|" "β DONE(d)")
1080 ;; (sequence "β WAITING(w)" "|")
1081 ;; (sequence "|" "β CANCELLED(c)")))
1082 ; (setq org-todo-keyword-faces
1083 ; (quote ("TODO" . (:foreground "red" :weight bold))
1084 ; ("NEXT" . (:foreground "blue" :weight bold))
1085 ; ("WAITING" . (:foreground "forest green" :weight bold))
1086 ; ("DONE" . (:foreground "magenta" :weight bold))
1087 ; ("CANCELLED" . (:foreground "forest green" :weight bold))))
1090 (setq org-todo-keywords
1091 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!)")
1092 ;; (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING")
1093 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" ))))
1095 (setq org-todo-keyword-faces
1096 (quote (("TODO" :foreground "red" :weight bold)
1097 ("NEXT" :foreground "blue" :weight bold)
1098 ("DONE" :foreground "forest green" :weight bold)
1099 ("WAITING" :foreground "orange" :weight bold)
1100 ("HOLD" :foreground "magenta" :weight bold)
1101 ("CANCELLED" :foreground "forest green" :weight bold)
1102 ;; ("MEETING" :foreground "forest green" :weight bold)
1103 ;; ("PHONE" :foreground "forest green" :weight bold)
1107 Fast todo selections
1109 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1110 (setq org-use-fast-todo-selection t)
1111 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1114 TODO state triggers and tags, [[http://doc.norang.ca/org-mode.html][Organize Your Life in Plain Text]]
1116 - Moving a task to =CANCELLED=, adds a =CANCELLED= tag
1117 - Moving a task to =WAITING=, adds a =WAITING= tag
1118 - Moving a task to =HOLD=, add =HOLD= tags
1119 - Moving a task to =DONE=, remove =WAITING=, =HOLD= tag
1120 - Moving a task to =NEXT=, remove all waiting/hold/cancelled tags
1122 This tags are used to filter tasks in agenda views
1123 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1124 (setq org-todo-state-tags-triggers
1125 (quote (("CANCELLED" ("CANCELLED" . t))
1126 ("WAITING" ("WAITING" . t))
1127 ("HOLD" ("WAITING") ("HOLD" . t))
1128 (done ("WAITING") ("HOLD"))
1129 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1130 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1131 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1135 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1136 ;; log time when task done
1137 ;; (setq org-log-done (quote time))
1138 ;; save clocking into to LOGBOOK
1139 (setq org-clock-into-drawer t)
1140 ;; save state change notes and time stamp into LOGBOOK drawer
1141 (setq org-log-into-drawer t)
1142 (setq org-clock-into-drawer "CLOCK")
1146 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1147 (setq org-tag-alist (quote ((:startgroup)
1153 ("CANCELLED" . ?c))))
1155 ;; Allow setting single tags without the menu
1156 (setq org-fast-tag-selection-single-key (quote expert))
1159 *** Capture - Refile - Archive
1161 Capture lets you quickly store notes with little interruption of your work flow.
1163 **** Capture Templates
1165 When a new taks needs to be added, categorize it as
1167 All captured file which need next actions are stored in =refile.org=,
1168 - A new task / note (t) =refile.org=
1169 - A work task in office =office.org=
1170 - A jourenl =diary.org=
1171 - A new habit (h) =refile.org=
1173 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1174 (setq org-directory "~/org")
1175 (setq org-default-notes-file "~/org/refile.org")
1176 (setq sd/org-diary-file "~/org/diary.org")
1178 (global-set-key (kbd "C-c c") 'org-capture)
1180 (setq org-capture-templates
1181 (quote (("t" "Todo" entry (file org-default-notes-file)
1182 "* TODO %?\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1183 ("n" "Note" entry (file org-default-notes-file)
1184 "* %? :NOTE:\n:LOGBOOK:\n- Added: %U\t\tAt: %a\n:END:")
1185 ("j" "Journal" entry (file+datetree sd/org-diary-file)
1186 "* %?\n:LOGBOOK:\n:END:" :clock-in t :clock-resume t)
1187 ("h" "Habit" entry (file org-default-notes-file)
1188 "* 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 "))))
1193 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1194 (setq org-refile-targets (quote (;; (nil :maxlevel . 9)
1195 (org-agenda-files :maxlevel . 9))))
1197 (setq org-refile-use-outline-path t)
1199 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1203 Setting agenda files and the agenda view
1204 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1205 (setq org-agenda-files (quote ("~/org/gtd.org")))
1207 ;; only show today's tasks in agenda view
1208 ;; (setq org-agenda-span 'day)
1209 ;; Use current windows for agenda view
1210 ;; (setq org-agenda-window-setup 'current-window)
1212 ;; show all feature entries for repeating tasks,
1213 ;; this is already setting by default
1214 (setq org-agenda-repeating-timestamp-show-all t)
1216 ;; Show all agenda dates - even if they are empty
1217 (setq org-agenda-show-all-dates t)
1221 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1222 (with-eval-after-load "org"
1223 (require 'org-mobile)
1224 ;; Set to the location of your Org files on your local system
1225 ;; (setq org-directory "~/org")
1226 ;; Set to the name of the file where new notes will be stored
1227 (setq org-mobile-inbox-for-pull "~/org/flagged.org")
1228 ;; Set to <your Dropbox root directory>/MobileOrg.
1229 (setq org-mobile-directory "~/Dropbox/Apps/MobileOrg"))
1233 Install MacTex-basic [[http://www.tug.org/mactex/morepackages.html][MacTex-basic]] and some tex packages
1235 wget http://tug.org/cgi-bin/mactex-download/BasicTeX.pkg
1237 sudo tlmgr update --self
1239 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
1242 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1243 ;; ;; allow for export=>beamer by placing
1245 ;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
1246 ;; #+LaTeX_CLASS: beamer in org files
1247 (unless (boundp 'org-export-latex-classes)
1248 (setq org-export-latex-classes nil))
1249 (add-to-list 'org-export-latex-classes
1250 ;; beamer class, for presentations
1252 "\\documentclass[11pt]{beamer}\n
1253 \\mode<{{{beamermode}}}>\n
1254 \\usetheme{{{{beamertheme}}}}\n
1255 \\usecolortheme{{{{beamercolortheme}}}}\n
1256 \\beamertemplateballitem\n
1257 \\setbeameroption{show notes}
1258 \\usepackage[utf8]{inputenc}\n
1259 \\usepackage[T1]{fontenc}\n
1260 \\usepackage{hyperref}\n
1262 \\usepackage{listings}
1263 \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
1266 showspaces=false,showstringspaces=false,
1268 keywordstyle=\\color{blue}\\bfseries,
1269 commentstyle=\\color{red},
1271 \\usepackage{verbatim}\n
1272 \\institute{{{{beamerinstitute}}}}\n
1273 \\subject{{{{beamersubject}}}}\n"
1275 ("\\section{%s}" . "\\section*{%s}")
1277 ("\\begin{frame}[fragile]\\frametitle{%s}"
1279 "\\begin{frame}[fragile]\\frametitle{%s}"
1282 ;; letter class, for formal letters
1284 (add-to-list 'org-export-latex-classes
1287 "\\documentclass[11pt]{letter}\n
1288 \\usepackage[utf8]{inputenc}\n
1289 \\usepackage[T1]{fontenc}\n
1290 \\usepackage{color}"
1292 ("\\section{%s}" . "\\section*{%s}")
1293 ("\\subsection{%s}" . "\\subsection*{%s}")
1294 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1295 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1296 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1300 (require 'ox-beamer)
1302 (setq org-latex-pdf-process
1303 '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1304 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
1305 "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
1307 (setq TeX-parse-self t)
1309 (setq TeX-PDF-mode t)
1310 (add-hook 'LaTeX-mode-hook
1313 (setq TeX-master t)))
1318 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]]
1319 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1320 (use-package htmlize
1324 ** Org structure template
1325 extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-emacs/#orgheadline94][Extend org-modes' esay templates]]
1326 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1327 ;; βsβ β#+BEGIN_SRC ... #+END_SRCβ
1328 ;; βeβ β#+BEGIN_EXAMPLE ... #+END_EXAMPLEβ
1329 ;; βqβ β#+BEGIN_QUOTE ... #+END_QUOTEβ
1330 ;; βvβ β#+BEGIN_VERSE ... #+END_VERSEβ
1331 ;; βcβ β#+BEGIN_CENTER ... #+END_CENTERβ
1332 ;; βlβ β#+BEGIN_LaTeX ... #+END_LaTeXβ
1333 ;; βLβ β#+LaTeX:β
1334 ;; βhβ β#+BEGIN_HTML ... #+END_HTMLβ
1335 ;; βHβ β#+HTML:β
1336 ;; βaβ β#+BEGIN_ASCII ... #+END_ASCIIβ
1337 ;; βAβ β#+ASCII:β
1338 ;; βiβ β#+INDEX:β line
1339 ;; βIβ β#+INCLUDE:β line
1342 (add-to-list 'org-structure-template-alist
1343 '("E" "#+BEGIN_SRC emacs-lisp :tangle yes :results silent\n?\n#+END_SRC"))
1344 (add-to-list 'org-structure-template-alist
1345 '("R" "#+BEGIN_SRC racket :tangle no :results output replace\n?\n#+END_SRC"))
1346 (add-to-list 'org-structure-template-alist
1347 '("S" "#+BEGIN_SRC sh :results output replace\n?\n#+END_SRC"))
1348 (add-to-list 'org-structure-template-alist
1349 '("p" "#+BEGIN_SRC plantuml :file uml.png \n?\n#+END_SRC"))
1350 (add-to-list 'org-structure-template-alist
1351 '("P" "#+BEGIN_SRC perl \n?\n#+END_SRC"))
1352 (add-to-list 'org-structure-template-alist
1353 '("f" "#+BEGIN_SRC fundamental :tangle ?\n\n#+END_SRC"))
1354 (add-to-list 'org-structure-template-alist
1355 '("C" "#+BEGIN_SRC c :tangle ?\n\n#+END_SRC"))
1356 (add-to-list 'org-structure-template-alist
1357 '("m" "\\begin{equation}\n?\n\\end{equation}"))
1358 (add-to-list 'org-structure-template-alist
1359 '("b" "#+STARTUP: showall
1360 ,#+STARTUP: inlineimages
1361 ,#+OPTIONS: toc:nil\n"))
1362 (add-to-list 'org-structure-template-alist
1363 '("d" "#+BEGIN_SRC ditaa :file ? :cmdline -r -s 0.8 :cache yes \n\n#+END_SRC"))
1364 (add-to-list 'org-structure-template-alist
1365 '("u" "#+BEGIN_SRC plantuml :file ? \n\n#+END_SRC"))
1370 Fetch dependencies file, which is not in this repository.
1371 #+BEGIN_SRC perl :results silent :tangle yes
1372 print `curl https://raw.githubusercontent.com/seudut/blog/master/my-publish.el -o ./elisp/my-publish.el`;
1376 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1377 (add-to-list 'load-path "~/.emacs.d/elisp")
1379 (when (file-exists-p "~/.emacs.d/elisp/my-publish.el")
1380 (require 'my-publish)
1381 (blog-setup-project-alist "~/Private/blog/"))
1385 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]]
1388 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
1389 and Defined keys, using vi keybindings, Refer abo-abo's setting [[https://github.com/abo-abo/oremacs/blob/c5cafdcebc88afe9e73cc8bd40c49b70675509c7/modes/ora-nextmagit.el][here]]
1390 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1394 ;; don't ask me to confirm the unsaved change
1395 (setq magit-save-repository-buffers nil)
1397 (setq git-commit-summary-max-length 100)
1398 :commands magit-status magit-blame
1400 (dolist (map (list magit-status-mode-map
1403 magit-staged-section-map))
1404 (define-key map "j" 'magit-section-forward)
1405 (define-key map "k" 'magit-section-backward)
1406 (define-key map "D" 'magit-discard)
1407 (define-key map "O" 'magit-discard-file)
1408 (define-key map "n" nil)
1409 (define-key map "p" nil)
1410 (define-key map "v" 'recenter-top-bottom)
1411 (define-key map "i" 'magit-section-toggle))
1412 (define-key magit-mode-map "q" (lambda () (interactive)
1413 (magit-mode-bury-buffer t))))
1418 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1419 (defalias 'e 'find-file)
1420 (defalias 'ff 'find-file)
1421 (defalias 'ee 'find-files)
1424 ** eshell temp directory
1425 set default eshell history folder
1426 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1427 (setq eshell-directory-name (concat sd-temp-directory "eshell"))
1430 ** Eshell erase buffer
1431 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1432 (require 'utilities)
1434 ;; (add-hook 'eshell-mode-hook (lambda ()
1435 ;; (local-set-key (kbd "C-l") 'sd/eshell-clear-buffer)))
1436 ;; (add-hook 'eshell-mode-map (lambda () (interactive)
1437 ;; (define-key eshell-mode-map (kbd "<tab>") 'completion-at-point)))
1439 (defun sd/eshell-hook ()
1441 (define-key eshell-mode-map (kbd "C-j") #'eshell-send-input)
1442 (define-key eshell-mode-map (kbd "C-l") #'sd/eshell-clear-buffer))
1444 (add-hook 'eshell-mode-hook #'sd/eshell-hook)
1447 ;; (add-hook 'eshell-mode-hook (apply-partially #'local-set-key (kbd "C-l") 'sd/eshell-clear-buffer))
1451 Toggle an eshell in split window below, refer [[http://www.howardism.org/Technical/Emacs/eshell-fun.html][eshell-here]]
1452 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1453 (defun sd/window-has-eshell ()
1454 "Check if current windows list has a eshell buffer, and return the window"
1457 (walk-windows (lambda (window)
1458 (if (equal (with-current-buffer (window-buffer window) major-mode)
1464 (defun sd/toggle-project-eshell ()
1465 "Toggle a eshell buffer vertically"
1467 (if (sd/window-has-eshell)
1468 (if (equal major-mode 'eshell-mode)
1470 (if (equal (length (window-list)) 1)
1471 (mode-line-other-buffer)
1473 (select-window (sd/window-has-eshell)))
1475 (split-window-vertically (- (/ (window-total-height) 3)))
1477 (if (projectile-project-p)
1478 (projectile-run-eshell)
1481 (global-set-key (kbd "s-e") 'sd/toggle-project-eshell)
1484 ** exec-path-from-shell
1485 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1486 (use-package exec-path-from-shell
1489 (setq exec-path-from-shell-check-startup-files nil)
1491 (exec-path-from-shell-initialize))
1495 ** [[https://github.com/abo-abo/hydra][Hydra]]
1497 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1500 ;; disable new line in minibuffer when hint hydra
1502 (setq hydra-lv nil))
1505 *** Windmove Splitter
1507 Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter
1509 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1511 (defun hydra-move-splitter-left (arg)
1512 "Move window splitter left."
1514 (if (let ((windmove-wrap-around))
1515 (windmove-find-other-window 'right))
1516 (shrink-window-horizontally arg)
1517 (enlarge-window-horizontally arg)))
1519 (defun hydra-move-splitter-right (arg)
1520 "Move window splitter right."
1522 (if (let ((windmove-wrap-around))
1523 (windmove-find-other-window 'right))
1524 (enlarge-window-horizontally arg)
1525 (shrink-window-horizontally arg)))
1527 (defun hydra-move-splitter-up (arg)
1528 "Move window splitter up."
1530 (if (let ((windmove-wrap-around))
1531 (windmove-find-other-window 'up))
1532 (enlarge-window arg)
1533 (shrink-window arg)))
1535 (defun hydra-move-splitter-down (arg)
1536 "Move window splitter down."
1538 (if (let ((windmove-wrap-around))
1539 (windmove-find-other-window 'up))
1541 (enlarge-window arg)))
1546 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1547 (defhydra sd/hydra-misc (:color red :columns nil)
1549 ("e" eshell "eshell" :exit t)
1552 (if (not (eq nil (get-buffer "*Packages*")))
1553 (switch-to-buffer "*Packages*")
1554 (package-list-packages)))
1555 "list-package" :exit t)
1556 ("g" magit-status "git-status" :exit t)
1557 ("'" mode-line-other-buffer "last buffer" :exit t)
1558 ("C-'" mode-line-other-buffer "last buffer" :exit t)
1559 ("m" man "man" :exit t)
1560 ("d" dired-jump "dired" :exit t)
1561 ("b" ibuffer "ibuffer" :exit t)
1565 ;; (global-set-key (kbd "C-'") 'sd/hydra-misc/body)
1567 (defun sd/exchange-win-layout ()
1568 "Change the windos layout."
1570 (when (equal (length (window-list)) 2)
1571 (let ((current-layout (if (or (window-in-direction 'right) (window-in-direction 'left))
1574 (other-buf (window-buffer (or (window-in-direction 'right)
1575 (window-in-direction 'left)
1576 (window-in-direction 'below)
1577 (window-in-direction 'above)))))
1578 (delete-other-windows)
1579 (if (eq current-layout 'v)
1580 (split-window-below)
1581 (split-window-right))
1583 (switch-to-buffer other-buf))))
1585 (defhydra sd/hydra-window-layout (:color red :colums nil)
1587 ("m" sd/toggle-max-windows "Max-win" :exit t)
1588 ("s" ace-swap-window "Swap" :exit t)
1589 ("d" ace-delete-window "Delete" :exit t)
1590 ("x" sd/exchange-win-layout "eXchange" :exit t)
1591 ("u" winner-undo "window-Undo" :exit t)
1592 ("r" winner-redo "window-Redo" :exit t)
1593 ("C-h" (lambda () (interactive) (evil-window-increase-width 3)) "<<")
1594 ("C-l" (lambda () (interactive) (evil-window-decrease-width 3)) ">>")
1595 ("C-k" (lambda () (interactive) (evil-window-increase-height 3)) "^")
1596 ("C-j" (lambda () (interactive) (evil-window-decrease-height 3)) "v")
1597 ("=" balance-windows "=" :exit t)
1600 (defhydra sd/hydra-gtags (:color red :colums nil)
1602 ("d" sd/ggtags-find-definition "Definition" :exit t)
1603 ("r" ggtags-find-reference "Reference" :exit t)
1604 ("s" sd/ggtags-find-symbol "Symbol" :exit t))
1606 (defhydra sd/hydra-projectile (:color red :column nil)
1608 ("s" projectile-switch-open-project "Switch" :exit t)
1609 ("f" projectile-find-file "File" :exit t)
1610 ("b" projectile-switch-to-buffer "Buffer" :exit t)
1611 ("p" projectile-switch-project "Project" :exit t))
1615 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1616 (defhydra sd/hydra-launcher (:color blue :columns 2)
1618 ("e" emms "emms" :exit t)
1623 Enable linum mode on programming modes
1624 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1625 (add-hook 'prog-mode-hook 'linum-mode)
1628 Fix the font size of line number
1629 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1630 (defun fix-linum-size ()
1632 (set-face-attribute 'linum nil :height 110))
1634 (add-hook 'linum-mode-hook 'fix-linum-size)
1637 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
1638 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1639 (use-package linum-relative
1642 (setq linum-relative-current-symbol "")
1644 (defun linum-new-mode ()
1645 "If line numbers aren't displayed, then display them.
1646 Otherwise, toggle between absolute and relative numbers."
1649 (linum-relative-toggle)
1653 ("A-k" . linum-new-mode))
1655 ;; auto enable linum-new-mode in programming modes
1656 (add-hook 'prog-mode-hook 'linum-relative-mode)
1659 ** Save File Position
1660 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1661 (require 'saveplace)
1662 (setq save-place-file "~/.emacs.d/temp/saveplace")
1663 (setq-default save-place t)
1664 (setq save-place-forget-unreadable-files t)
1665 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
1669 define =multi-term= mapping to disable some mapping which is used globally.
1670 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1671 (use-package multi-term
1674 (defun sd/term-mode-mapping ()
1675 (mapcar #'(lambda (map)
1676 (define-key map (kbd "C-o") nil)
1677 (define-key map (kbd "C-g") nil))
1681 (with-eval-after-load 'multi-term
1682 (sd/term-mode-mapping))
1686 [[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
1687 Type =o= to go to the link
1688 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1689 (use-package ace-link
1692 (ace-link-setup-default))
1696 [[https://github.com/abo-abo/ace-window][ace-window]]
1697 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1698 (use-package ace-window
1702 ; (global-set-key (kbd "M-o") 'ace-window)
1704 (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l)))
1707 ** View only for some directory
1708 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]]
1709 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1710 (dir-locals-set-class-variables
1712 '((nil . ((buffer-read-only . t)
1713 (show-trailing-whitespace . nil)
1715 (eval . (whitespace-mode -1))
1716 ;; (eval . (when buffer-file-name
1717 ;; (setq-local view-no-disable-on-exit t)
1718 ;; (view-mode-enter)))
1719 (projectile-enable-caching . nil)
1722 ;; (dir-locals-set-directory-class (expand-file-name "/usr/local/share/emacs") 'emacs)
1723 (dir-locals-set-directory-class "/usr/local/Cellar/emacs" 'emacs)
1724 ;; (dir-locals-set-directory-class "~/.emacs.d/elpa" 'emacs)
1725 (dir-locals-set-directory-class "~/dotfiles/emacs.d/elpa" 'emacs)
1726 (dir-locals-set-directory-class "~/dotfiles/emacs.d/el-get" 'emacs)
1729 ;; Temporary minor mode
1730 ;; Main use is to enable it only in specific buffers to achieve the goal of
1731 ;; buffer-specific keymaps
1733 ;; (defvar sd/temp-mode-map (make-sparse-keymap)
1734 ;; "Keymap while temp-mode is active.")
1737 ;; (define-minor-mode sd/temp-mode
1738 ;; "A temporary minor mode to be activated only specific to a buffer."
1741 ;; sd/temp-mode-map)
1743 ;; (defun sd/temp-hook ()
1746 ;; (define-key sd/temp-mode-map (kbd "q") 'quit-window))))
1748 ;; (add-hook 'lispy-mode-hook (lambda ()
1753 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1754 (el-get-bundle info+
1755 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/info+.el"
1759 (with-eval-after-load 'info
1764 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1765 (defun sd/info-mode ()
1767 (unless (equal major-mode 'Info-mode)
1768 (unless (> (length (window-list)) 1)
1769 (split-window-right))
1772 ;; open Info buffer in other window instead of current window
1773 (defadvice info (before my-info (&optional file buf) activate)
1776 (defadvice Info-exit (after my-info-exit activate)
1777 (sd/delete-current-window))
1781 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1782 (use-package org-tree-slide
1785 ;; (define-key org-mode-map "\C-ccp" 'org-tree-slide-mode)
1786 (define-key org-tree-slide-mode-map (kbd "<ESC>") 'org-tree-slide-content)
1787 (define-key org-tree-slide-mode-map (kbd "<SPACE>") 'org-tree-slide-move-next-tree)
1788 (define-key org-tree-slide-mode-map [escape] 'org-tree-slide-move-previous-tree))
1793 #brew install poppler
1796 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1797 ;(use-package pdf-tools
1800 ; ;; run to complete the installation
1801 ; (pdf-tools-install)
1803 ; (add-to-list 'auto-mode-alist '("\.pdf$" . pdf-view-mode))
1804 ; (add-hook 'pdf-outline-buffer-mode-hook #'sd/pdf-outline-map))
1806 ;(defun sd/pdf-outline-map ()
1807 ; "My keybindings in pdf-outline-map"
1809 ; (define-key pdf-outline-buffer-mode-map (kbd "C-o") nil)
1810 ; (define-key pdf-outline-buffer-mode-map (kbd "i") 'outline-toggle-children)
1811 ; (define-key pdf-outline-buffer-mode-map (kbd "j") 'next-line)
1812 ; (define-key pdf-outline-buffer-mode-map (kbd "k") 'previous-line))
1816 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1817 (defun sd/help-mode-hook ()
1818 "Mapping for help mode"
1819 (define-key help-mode-map "j" 'next-line)
1820 (define-key help-mode-map "k" 'previous-line)
1821 (define-key help-mode-map "h" 'forward-char)
1822 (define-key help-mode-map "l" 'forward-char)
1823 (define-key help-mode-map "H" 'describe-mode)
1824 (define-key help-mode-map "v" 'recenter-top-bottom)
1825 (define-key help-mode-map "i" 'forward-button)
1826 (define-key help-mode-map "I" 'backward-button)
1827 (define-key help-mode-map "o" 'ace-link-help))
1829 (add-hook 'help-mode-hook 'sd/help-mode-hook)
1832 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=
1834 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1835 (el-get-bundle help-macro+
1836 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/help-macro+.el"
1837 :features help-macro+)
1838 (el-get-bundle help+
1839 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/help+.el"
1841 (el-get-bundle help-fns+
1842 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/help-fns+.el"
1843 :features help-fns+)
1844 (el-get-bundle help-mode+
1845 :url "https://raw.githubusercontent.com/emacsmirror/emacswiki.org/master/help-mode+.el"
1846 :features help-mode+)
1850 install =ag=, =the-silver-searcher= by homebrew on mac
1852 brew install the-silver-searcher
1855 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1860 ** Local Variable hooks
1861 [[https://www.emacswiki.org/emacs/LocalVariables][LocalVariables]], use =hack-local-variables-hook=, run a hook to set local variable in mode hook
1862 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1863 ;; make Emacs run a new "local variables hook" for each major mode
1864 (add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook)
1866 (defun run-local-vars-mode-hook ()
1867 "Run a hook for the major-mode after the local variables have been processed."
1868 (run-hooks (intern (concat (symbol-name major-mode) "-local-vars-hook"))))
1870 ;; (add-hook 'c++-mode-local-vars-hook #'sd/c++-mode-local-vars)
1874 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1875 (add-hook 'text-mode-hook 'table-recognize)
1879 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
1880 as a http download client tool
1881 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1882 (defun sd/download-file (&optional url download-dir download-name)
1885 (read-string "Enter download URL: ")))
1886 (download-dir (read-directory-name "Save to (~/Downloads): " "~/Downloads" "~/Downloads" 'confirm' nil)))
1887 (let ((download-buffer (url-retrieve-synchronously url)))
1889 (set-buffer download-buffer)
1890 ;; we may have to trim the http response
1891 (goto-char (point-min))
1892 (re-search-forward "^$" nil 'move)
1894 (delete-region (point-min) (point))
1895 (write-file (concat (or download-dir
1898 (car (last (split-string url "/" t))))))))))
1903 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1904 (setq dired-dwim-target t)
1906 (use-package dired-details
1909 (setq-default dired-details-hidden-string "--- ")
1910 (dired-details-install))
1914 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1915 (defun sd/dired-next-line (count)
1916 "Move to next line, and always focus on the file name."
1918 (dired-next-line count)
1919 (dired-move-to-filename))
1921 (defun sd/dired-previous-line (count)
1922 "Move to previous line, and always focus on the file name."
1924 (dired-previous-line count)
1925 (dired-move-to-filename))
1927 (defun sd/dired-up-directory ()
1928 "Go to up directory"
1930 (let ((old (current-buffer)))
1931 (dired-up-directory)
1936 =C-o= is defined as a global key for window operation, here unset it in dired mode
1937 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
1938 (defun sd/dired-key-map ()
1939 "My keybindings for dired"
1941 ;; these two prefix are used globally
1942 (define-key dired-mode-map (kbd "C-o") nil)
1943 (define-key dired-mode-map (kbd "M-s") nil)
1944 ;; toggle hidden files
1945 (define-key dired-mode-map (kbd "H") 'dired-omit-mode)
1947 (define-key dired-mode-map (kbd "SPC") 'scroll-up-command)
1948 (define-key dired-mode-map (kbd "DEL") 'scroll-down-command)
1949 (define-key dired-mode-map (kbd "j") 'diredp-next-line)
1950 (define-key dired-mode-map (kbd "k") 'diredp-previous-line)
1951 (define-key dired-mode-map (kbd "g") 'dired-goto-file)
1952 ;; (define-key dired-mode-map (kbd "S-SPC") 'scroll-down-command)
1954 (define-key dired-mode-map (kbd "f") 'dired-isearch-filenames)
1956 ;; i dired-maybe-insert-subdir
1957 ;; o dired-find-file-other-window (switch to other window)
1958 ;; O dired-display-file
1959 (define-key dired-mode-map (kbd "G") 'ido-dired)
1960 (define-key dired-mode-map (kbd "c") 'sd/dired-new-file)
1961 (define-key dired-mode-map (kbd "h") 'dired-summary)
1962 (define-key dired-mode-map (kbd "r") 'revert-buffer)
1963 (define-key dired-mode-map (kbd "l") 'dired-display-file)
1964 (define-key dired-mode-map [C-backspace] 'dired-up-directory)
1965 (define-key dired-mode-map (kbd "?") 'describe-mode)
1966 (define-key dired-mode-map (kbd "z") #'sd/dired-get-size)
1967 (define-key dired-mode-map (kbd "C-d") 'dired-kill-subdir)
1968 (define-key dired-mode-map (kbd "M-d") 'dired-kill-subdir)
1969 (define-key dired-mode-map (kbd "J") 'diredp-next-subdir)
1970 (define-key dired-mode-map (kbd "TAB") 'diredp-next-subdir)
1971 (define-key dired-mode-map (kbd "K") 'diredp-prev-subdir)
1972 (define-key dired-mode-map (kbd "O") 'dired-display-file)
1973 (define-key dired-mode-map (kbd "I") 'other-window)
1974 (define-key dired-mode-map (kbd "o") 'other-window))
1982 :init (setq diredp-hide-details-initially-flag nil))
1984 (setq dired-omit-mode t)
1985 (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
1986 (add-hook 'dired-mode-hook (lambda ()
1988 (dired-omit-mode))))
1990 (defadvice dired-summary (around sd/dired-summary activate)
1991 "Revisied dired summary."
1995 "Ξ: 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"))
1997 (defun sd/dired-high-level-dir ()
1998 "Go to higher level directory"
2000 (find-alternate-file ".."))
2003 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2004 (defun sd/dired-new-file-and-open ()
2005 "Create a new file in dired mode"
2007 (call-interactively 'find-file))
2009 (defun sd/dired-new-file (file)
2010 "Create a new file called FILE.
2011 If FILE already exists, signal an error."
2013 (list (read-file-name "Create file: " (dired-current-directory))))
2014 (let* ((expanded (expand-file-name file)))
2015 (if (file-exists-p expanded)
2016 (error "Cannot create file %s: file exists" expanded))
2017 (write-region "" nil expanded t)
2019 (dired-add-file expanded)
2020 (dired-move-to-filename))))
2022 ;; copied from abo-abo's config
2023 (defun sd/dired-get-size ()
2025 (let ((files (dired-get-marked-files)))
2027 (apply 'call-process "/usr/bin/du" nil t nil "-sch" files)
2029 "Size of all marked files: %s"
2031 (re-search-backward "\\(^[ 0-9.,]+[A-Za-z]+\\).*total$")
2032 (match-string 1))))))
2035 ** disable ido when dired new file
2036 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
2037 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β]]
2038 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2039 (defun mk-anti-ido-advice (func &rest args)
2040 "Temporarily disable IDO and call function FUNC with arguments ARGS."
2042 (let ((read-file-name-function #'read-file-name-default)
2043 (completing-read-function #'completing-read-default))
2044 (if (called-interactively-p 'any)
2045 (call-interactively func)
2046 (apply func args))))
2048 (defun mk-disable-ido (command)
2049 "Disable IDO when command COMMAND is called."
2050 (advice-add command :around #'mk-anti-ido-advice))
2052 (defun mk-anti-ido-no-completing-advice (func &rest args)
2053 "Temporarily disable IDO and call function FUNC with arguments ARGS."
2055 (let ((read-file-name-function #'read-file-name-default)
2056 ;; (completing-read-function #'completing-read-default)
2058 (if (called-interactively-p 'any)
2059 (call-interactively func)
2060 (apply func args))))
2062 (defun mk-disable-ido-no-completing (command)
2063 "Disable IDO when command COMMAND is called."
2064 (advice-add command :around #'mk-anti-ido-no-completing-advice))
2067 Disalble =ido= when new a directory or file in =dired= mode
2068 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2069 ;; call the function which you want to disable ido
2070 (mk-disable-ido 'dired-create-directory)
2071 (mk-disable-ido 'sd/dired-new-file-and-open)
2072 (mk-disable-ido 'sd/dired-new-file)
2073 (mk-disable-ido-no-completing 'dired-goto-file)
2077 =!= =dired-do-shell-command=
2078 =&= =dired-do-async-shell-command=
2079 here on Mac, just use "open" commands to pen =.pdf=, =.html= and image files
2080 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2081 (setq dired-guess-shell-alist-user
2082 '(("\\.pdf\\'" "open" "okular")
2083 ("\\.\\(?:djvu\\|eps\\)\\'" "evince")
2084 ("\\.\\(?:jpg\\|jpeg\\|png\\|gif\\|xpm\\)\\'" "open")
2085 ("\\.\\(?:xcf\\)\\'" "gimp")
2086 ("\\.csv\\'" "libreoffice")
2087 ("\\.tex\\'" "pdflatex" "latex")
2088 ("\\.\\(?:mp4\\|mkv\\|avi\\|rmvb\\|flv\\|ogv\\)\\(?:\\.part\\)?\\'" "mplayer")
2089 ("\\.\\(?:mp3\\|flac\\|wav\\)\\'" "mplayer")
2090 ("\\.html?\\'" "open")
2091 ("\\.dmg\\'" "open")
2092 ("\\.cue?\\'" "audacious")))
2095 (defun sd/dired-start-process (cmd &optional file-list)
2097 (let ((files (dired-get-marked-files t current-prefix-arg)))
2099 (dired-read-shell-command "& on %s: " current-prefix-arg files)
2102 ;; (let (list-switch))
2104 cmd nil shell-file-name
2105 shell-command-switch
2107 "nohup 1>/dev/null 2>/dev/null %s \"%s\""
2109 ;; (if (and (> (length file-list) 1)
2110 ;; (setq list-switch
2111 ;; (cadr (assoc cmd ora-dired-filelist-cmd))))
2112 ;; (format "%s %s" cmd list-switch)
2114 (mapconcat #'expand-file-name file-list "\" \""))))
2121 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2122 (use-package dired-hacks-utils
2128 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2129 ;;narrow dired to match filter
2130 (use-package dired-narrow
2132 :commands (dired-narrow)
2133 :bind (:map dired-mode-map
2134 ("/" . dired-narrow)))
2138 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2139 (global-set-key (kbd "s-b") 'ibuffer)
2141 (with-eval-after-load 'ibuffer
2142 (define-key ibuffer-mode-map (kbd "C-o") nil)
2143 (define-key ibuffer-mode-map (kbd "j") 'ibuffer-forward-line)
2144 (define-key ibuffer-mode-map (kbd "k") 'ibuffer-backward-line)
2145 (define-key ibuffer-mode-map (kbd "r") 'ibuffer-update)
2146 (define-key ibuffer-mode-map (kbd "g") 'ibuffer-jump-to-buffer)
2147 (define-key ibuffer-mode-map (kbd "h") 'sd/ibuffer-summary))
2149 (defun sd/ibuffer-summary ()
2150 "Show summary of keybindings in ibuffer mode"
2153 "Ξ: m|u - (un)mark, /-filter, //-remove filter, t, RET, g, k, S, D, Q; q to quit; h for help"))
2157 ** company mode and company-statistics
2158 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2159 (use-package company
2161 :diminish company-mode
2162 :init (setq company-idle-delay 0.1)
2163 (setq company-selection-wrap-around t)
2165 (define-key company-active-map (kbd "M-n") nil)
2166 (define-key company-active-map (kbd "M-p") nil)
2167 (define-key company-active-map (kbd "SPC") #'sd/company-stop-input-space)
2168 (define-key company-active-map (kbd "C-n") #'company-select-next)
2169 (define-key company-active-map (kbd "C-p") #'company-select-previous)
2170 ;; should map both (kbd "TAB") and [tab],https://github.com/company-mode/company-mode/issues/75
2171 (define-key company-active-map (kbd "TAB") #'company-complete-selection)
2172 (define-key company-active-map [tab] #'company-complete-selection)
2173 (define-key company-active-map (kbd "C-w") nil)
2174 (define-key company-active-map (kbd "C-h") nil)
2175 (global-company-mode)
2176 ;; magig-commit is text-modeh
2177 (setq company-global-modes '(not org-mode magit-status-mode text-mode eshell-mode gfm-mode markdown-mode)))
2179 (use-package company-statistics
2182 (setq company-statistics-file (concat MY-EMACS-TMP "/company-statistics-cache.el"))
2184 (company-statistics-mode))
2186 (defun sd/company-stop-input-space ()
2187 "Stop completing and input a space,a workaround of a semantic issue `https://github.com/company-mode/company-mode/issues/614'"
2195 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2196 (use-package yasnippet
2200 (add-hook 'prog-mode-hook #'yas-minor-mode)
2206 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2210 (use-package company-ycmd
2213 (setq company-ycmd-enable-fuzzy-matching nil)
2215 (company-ycmd-setup))
2216 (setq ycmd-force-semantic-completion t)
2217 (add-hook 'c++-mode-hook 'ycmd-mode)
2218 (add-hook 'c-mode-hook 'ycmd-mode)
2219 (set-variable 'ycmd-server-command '("python" "/Users/peng/project/ycmd/ycmd"))
2220 (set-variable 'ycmd-global-config "/Users/peng/project/ycmd/cpp/ycm/.ycm_extra_conf.py"))
2224 ** company and yasnippet
2225 Add yasnippet as the company candidates
2226 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2227 ;Add yasnippet support for all company backends
2228 ;https://github.com/syl20bnr/spacemacs/pull/179
2229 (defvar company-mode/enable-yas t
2230 "Enable yasnippet for all backends.")
2232 (defun company-mode/backend-with-yas (backend)
2233 (if (or (not company-mode/enable-yas) (and (listp backend) (member 'company-yasnippet backend)))
2235 (append (if (consp backend) backend (list backend))
2236 '(:with company-yasnippet))))
2238 (setq company-backends (mapcar #'company-mode/backend-with-yas company-backends))
2241 Refer, [[http://emacs.stackexchange.com/questions/7908/how-to-make-yasnippet-and-company-work-nicer][how-to-make-yasnippet-and-company-work-nicer]]
2242 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2243 (defun check-expansion ()
2245 (if (looking-at "\\_>") t
2247 (if (looking-at "\\.") t
2249 (if (looking-at "->") t nil)))))
2251 (defun do-yas-expand ()
2252 (let ((yas/fallback-behavior 'return-nil))
2255 (defun tab-indent-or-complete ()
2259 (minibuffer-complete))
2261 (indent-for-tab-command)
2262 (if (or (not yas/minor-mode)
2263 (null (do-yas-expand)))
2264 (if (check-expansion)
2266 (company-manual-begin)
2267 (if (null company-candidates)
2270 (indent-for-tab-command)))))))))
2272 (defun tab-complete-or-next-field ()
2274 (if (or (not yas/minor-mode)
2275 (null (do-yas-expand)))
2276 (if company-candidates
2277 (company-complete-selection)
2278 (if (check-expansion)
2280 (company-manual-begin)
2281 (if (null company-candidates)
2285 (yas-next-field)))))
2287 (defun expand-snippet-or-complete-selection ()
2289 (if (or (not yas/minor-mode)
2290 (null (do-yas-expand))
2292 (company-complete-selection)))
2294 (defun abort-company-or-yas ()
2296 (if (null company-candidates)
2301 ;; (require 'company)
2302 ;; (require 'yasnippet)
2305 ;; (global-set-key [tab] 'tab-indent-or-complete)
2306 ;; (global-set-key (kbd "TAB") 'tab-indent-or-complete)
2307 ;; (global-set-key [(control return)] 'company-complete-common)
2309 ;; (define-key company-active-map [tab] 'expand-snippet-or-complete-selection)
2310 ;; (define-key company-active-map (kbd "TAB") 'expand-snippet-or-complete-selection)
2312 ;; (define-key yas-minor-mode-map [tab] nil)
2313 ;; (define-key yas-minor-mode-map (kbd "TAB") nil)
2315 ;; (define-key yas-keymap [tab] 'tab-complete-or-next-field)
2316 ;; (define-key yas-keymap (kbd "TAB") 'tab-complete-or-next-field)
2317 ;; (define-key yas-keymap [(control tab)] 'yas-next-field)
2318 ;; (define-key yas-keymap (kbd "C-g") 'abort-company-or-yas)
2322 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2327 * Programming Language
2328 ** Color identiifiers mode
2329 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2330 (use-package color-identifiers-mode
2333 (dolist (mode '(emacs-lisp-mode-hook
2336 (add-hook mode #'color-identifiers-mode))
2337 :diminish color-identifiers-mode)
2339 (global-prettify-symbols-mode t)
2343 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2344 (set-face-attribute 'font-lock-keyword-face nil :foreground "#F92672" :weight 'bold)
2345 (set-face-attribute 'font-lock-builtin-face nil :weight 'bold)
2346 (set-face-attribute 'font-lock-function-name-face nil :foreground "#A6E22E" :weight 'normal :slant 'normal)
2347 (set-face-attribute 'font-lock-variable-name-face nil :foreground "#00FF00")
2349 (dolist (mode '(c-mode
2351 (font-lock-add-keywords mode
2353 '(("\\([%\\][a-zA-Z]\\)" (1 font-lock-keyword-face prepend))
2354 ("[^[:alpha:]]\\([[:digit:]]*\\)[^[:alpha:]]" (1 font-lock-constant-face append))
2356 ("[^[:alpha:]]\\(0[x\\|X][0-9a-fA-F]*\\)[^[:alpha:]]" (1 font-lock-constant-face append))
2357 ;; hightlight the function call
2358 ("\\s\"?\\(\\(\\sw\\|\\s_\\)+\\(<-\\)?\\)\\s\"?*\\s-*(" (1 font-lock-function-name-face))) t))
2360 (font-lock-add-keywords 'c++-mode
2362 ("[\s\\|::]\\(cin\\|cout\\|endl\\)[^[:alpha:][:digit:]]" (1 font-lock-constant-face append))
2367 In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key
2368 bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]]
2369 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2373 (setq lispy-delete-backward-recenter 0)
2374 (with-eval-after-load "lispy"
2375 (define-key lispy-mode-map (kbd "M-o") nil)
2376 (define-key lispy-mode-map (kbd "g") 'special-lispy-goto-local)
2377 (define-key lispy-mode-map (kbd "G") 'special-lispy-goto)
2378 (define-key lispy-mode-map (kbd "M-m") 'back-to-indentation))
2380 (add-hook 'emacs-lisp-mode-hook (apply-partially #'lispy-mode 1)))
2385 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
2386 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2387 (defalias 'perl-mode 'cperl-mode)
2389 ;; (setq cperl-hairy t)
2390 ;; Turns on most of the CPerlMode options
2391 (setq cperl-auto-newline t)
2392 (setq cperl-highlight-variables-indiscriminately t)
2393 ;(setq cperl-indent-level 4)
2394 ;(setq cperl-continued-statement-offset 4)
2395 (setq cperl-close-paren-offset -4)
2396 (setq cperl-indent-parents-as-block t)
2397 (setq cperl-tab-always-indent t)
2398 ;(setq cperl-brace-offset 0)
2400 (add-hook 'cperl-mode-hook (apply-partially #'cperl-set-style "C++"))
2402 (defalias 'perldoc 'cperl-perldoc)
2406 Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
2407 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2408 (eval-after-load 'autoinsert
2409 '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
2412 "#!/usr/bin/perl -w" \n
2414 "use strict;" > \n \n
2420 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2421 (font-lock-add-keywords 'cperl-mode
2422 '(("\\(say\\)" . cperl-nonoverridable-face)
2423 ("\\([0-9.]\\)*" . font-lock-constant-face)
2424 ("\".*\\(\\\n\\).*\"" 1 font-lock-constant-face prepend)
2425 ("\n" 0 font-lock-constant-face prepend)
2426 ;; ("[%\\][[:alpha:]]" . font-lock-constant-face)
2427 ("\\(^#!.*\\)$" . cperl-nonoverridable-face)))
2432 1. completion (file name, function name, variable name)
2433 2. template yasnippet (keywords, if, function)
2436 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2437 ;; (setq c-default-style "stroustrup"
2438 ;; c-basic-offset 4)
2440 ;; ;; "C-M-j" is my global binding for avy goto line below
2441 ;; ;; disable it in c mode
2442 ;; (mapcar #'(lambda (map)
2443 ;; (define-key map (kbd "C-M-j") nil))
2449 (add-to-list 'auto-mode-alist '("\\.mm\\'" . objc-mode))
2451 (setq-default c-hungry-delete-key t)
2454 ;; Looks `c-hanging-braces-alist' doesn't work as expected when `electric-pair-mode' is enabled.
2455 (electric-pair-mode 1)
2457 (defconst sd/c-style
2459 (c-tab-always-indent . t)
2460 (c-basic-offset . 4)
2461 (c-hanging-braces-alist . ((substatement-open before)
2462 (statement-block-intro before)))
2463 (c-hanging-colons-alist . ())
2464 (c-echo-syntactic-information-p . nil)
2465 (c-hanging-semi&comma-criteria . ()))
2466 "My C programming style")
2468 (c-add-style "sd-c-style" sd/c-style)
2470 (setq c-default-style "sd-c-style")
2472 (add-hook 'c-mode-hook '(lambda ()
2473 (c-toggle-auto-newline 1)
2474 (c-set-style "sd-c-style")))
2476 ;; (advice-add 'c-electric-brace :after (lambda (arg) "Add new line after insert {}" (newline-and-indent)))
2479 **** install irony server
2480 Install clang, on mac, it has =libclang.dylib=, but no develop headers. Install by =brew=
2482 brew install llvm --with-clang
2485 then install irony searver, and =LIBCLANG_LIBRARY= and =LIBCLANG_INCLUDE_DIR= accordingly
2486 #+BEGIN_SRC emacs-lisp :tangle no :results silent
2487 (irony-install-server)
2491 cmake -DLIBCLANG_LIBRARY\=/usr/local/Cellar/llvm/4.0.1/lib/libclang.dylib \
2492 -DLIBCLANG_INCLUDE_DIR=/usr/local/Cellar/llvm/4.0.1/include \
2493 -DCMAKE_INSTALL_PREFIX\=/Users/peng/.emacs.d/irony/ \
2494 /Users/peng/.emacs.d/elpa/irony-20160713.1245/server && cmake --build . --use-stderr --config Release --target install
2498 irony-mode-hook, copied from [[https://github.com/Sarcasm/irony-mode][irony-mode]] github
2499 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2500 ;; (use-package irony
2503 ;; (add-hook 'c++-mode-hook 'irony-mode)
2504 ;; (add-hook 'c-mode-hook 'irony-mode)
2505 ;; (add-hook 'objc-mode-hook 'irony-mode))
2507 ;; replace the `completion-at-point' and `complete-symbol' bindings in
2508 ;; irony-mode's buffers by irony-mode's function
2510 (defun my-irony-mode-hook ()
2511 (define-key irony-mode-map [remap completion-at-point]
2512 'irony-completion-at-point-async)
2513 (define-key irony-mode-map [remap complete-symbol]
2514 'irony-completion-at-point-async))
2516 ;; (add-hook 'irony-mode-hook 'my-irony-mode-hook)
2517 ;; (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
2519 ;; (add-hook 'c++-mode-local-vars-hook #'sd/c++-mode-local-vars)
2521 ;; add C++ completions, because by default c++ file can not complete
2522 ;; c++ std functions, another method is create .dir-local.el file, for p
2523 ;; for project see irony
2524 (defun sd/c++-mode-local-vars ()
2525 (setq irony--compile-options
2528 "-I/usr/include/c++/4.2.1")))
2532 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2533 ;; (use-package company-irony
2536 ;; (use-package flycheck-irony
2539 ;; (use-package company-c-headers
2542 ;; (add-to-list 'company-c-headers-path-system "/usr/include/c++/4.2.1/")
2543 ;; (add-to-list 'company-c-headers-path-system "/usr/local/include/"))
2545 ;; (with-eval-after-load 'company
2546 ;; (add-to-list 'company-backends 'company-irony)
2547 ;; (add-to-list 'company-backends 'company-c-headers))
2549 ;; (with-eval-after-load 'company
2550 ;; (push '(company-irony :with company-yasnippet) company-backends)
2551 ;; (push '(company-c-headers :with company-yasnippet) company-backends))
2553 ;; (with-eval-after-load 'flycheck
2554 ;; (add-hook 'flycheck-mode-hook #'flycheck-irony-setup))
2558 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2559 (use-package flycheck
2564 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2568 (define-key ggtags-mode-map (kbd "M-g d") 'ggtags-find-definition)
2569 (define-key ggtags-mode-map (kbd "M-g r") 'ggtags-find-reference)
2570 (define-key ggtags-mode-map (kbd "M-g r") 'ggtags-find-reference)
2571 (define-key ggtags-mode-map (kbd "C-c g s") 'ggtags-find-other-symbol)
2572 (define-key ggtags-mode-map (kbd "C-c g h") 'ggtags-view-tag-history)
2573 (define-key ggtags-mode-map (kbd "C-c g r") 'ggtags-find-reference)
2574 (define-key ggtags-mode-map (kbd "C-c g f") 'ggtags-find-file)
2575 (define-key ggtags-mode-map (kbd "C-c g c") 'ggtags-create-tags)
2576 (define-key ggtags-mode-map (kbd "C-c g u") 'ggtags-update-tags))
2578 (add-hook 'c-mode-common-hook
2580 (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
2583 (defun sd/ggtags-find-definition ()
2584 "Find the definition with current name completing."
2586 (setq current-prefix-arg '(4))
2587 (call-interactively 'ggtags-find-definition))
2589 (defun sd/ggtags-find-symbol ()
2592 (setq current-prefix-arg '(4))
2593 (call-interactively 'ggtags-find-other-symbol))
2597 (setq semanticdb-default-save-directory (concat MY-EMACS-TMP "/semantic/"))
2598 (unless (file-exists-p semanticdb-default-save-directory)
2599 (make-directory semanticdb-default-save-directory))
2601 (global-semanticdb-minor-mode 1)
2602 (global-semantic-idle-scheduler-mode 1)
2608 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2609 ;; (use-package google-c-style
2612 ;; (add-hook 'c-mode-hook 'google-set-c-style)
2613 ;; (add-hook 'c++-mode-hook 'google-set-c-style))
2616 *** Compile and Run the C file
2617 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2618 (defun my-cpp-hook ()
2619 (let* ((current-file-name)
2621 (when buffer-file-name
2622 (setq current-file-name (shell-quote-argument buffer-file-name))
2623 (setq out-file-name (shell-quote-argument (concat (file-name-sans-extension buffer-file-name) ".out"))))
2624 (setq-local compilation-read-command t)
2625 (set (make-local-variable 'compile-command)
2626 (concat "g++ -Wall -std=c++11 "
2633 (local-set-key (kbd "s-r") 'compile)))
2635 (add-hook 'c-mode-hook 'my-cpp-hook)
2636 (add-hook 'c++-mode-hook 'my-cpp-hook)
2640 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2641 (use-package lua-mode
2646 Install =guile=, =guile= is an implementation of =Scheme= programming language.
2651 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2652 (setq geiser-scheme-implementation 'guile)
2664 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2665 (use-package racket-mode
2668 (define-key racket-mode-map (kbd "s-r") 'racket-run)
2669 (add-to-list 'racket-mode-hook (lambda () (lispy-mode 1))))
2672 (setenv "PATH" (concat (getenv "PATH")
2673 ":" "/Applications/Racket v6.10.1/bin"))
2674 (setenv "MANPATH" (concat (getenv "MANPATH")
2675 ":" "/Applications/Racket v6.10.1/man"))
2676 (setq exec-path (append exec-path '("/Applications/Racket v6.10.1/bin")))
2678 (add-to-list 'auto-mode-alist '("\\.rkt\\'" . racket-mode))
2681 Set the environments vairables in compilation mode
2682 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2683 (use-package compile
2686 (setq compilation-environment (cons "LC_ALL=C" compilation-environment))
2687 (setq compilation-auto-jump-to-first-error t)
2688 (setq compilation-auto-jump-to-next t)
2689 (setq compilation-scroll-output 'first-error)
2690 ;; this will save all the modified buffers before compile
2691 (setq compilation-ask-about-save nil)
2692 (setq compilation-window-height (/ (window-total-height) 3)))
2694 ;; super-r to compile
2695 (with-eval-after-load "compile"
2696 (define-key compilation-mode-map (kbd "C-o") nil)
2697 (define-key compilation-mode-map (kbd "n") 'compilation-next-error)
2698 (define-key compilation-mode-map (kbd "p") 'compilation-previous-error)
2699 (define-key compilation-mode-map (kbd "q") (lambda () (interactive) (quit-window t)))
2700 (define-key compilation-mode-map (kbd "r") #'recompile))
2702 ;; here note dynamic binding the value of vv, otherwise it will resport error when run the hook.
2703 ;; https://emacs.stackexchange.com/questions/10394/scope-in-lambda
2705 (cperl-mode-hook . "perl")
2706 (lua-mode-hook . "lua")
2707 (python-mode-hook . "python")
2708 (shell-mode-hook . "sh")))
2709 (add-hook (car vv) `(lambda ()
2710 (unless (or (file-exists-p "makefile")
2711 (file-exists-p "Makefile"))
2712 (set (make-local-variable 'compile-command)
2715 (if buffer-file-name
2716 (shell-quote-argument buffer-file-name))))))))
2718 (global-set-key (kbd "s-r") 'compile)
2722 ** Enable auto-insert mode
2723 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2724 (auto-insert-mode t)
2725 (setq auto-insert-query nil)
2729 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2730 (eval-after-load 'autoinsert
2731 '(define-auto-insert '("\\.cpp\\|.cc\\'" . "C++ skeleton")
2733 "Short description:"
2735 "\n * " (file-name-nondirectory (buffer-file-name))
2737 "#include <iostream>" \n
2739 (file-name-sans-extension
2740 (file-name-nondirectory (buffer-file-name)))
2742 "using namespace std;" \n \n
2743 "int main (int argc, char *argv[])"
2750 (eval-after-load 'autoinsert
2751 '(define-auto-insert '("\\.c\\'" . "C skeleton")
2753 "Short description:"
2755 " * " (file-name-nondirectory (buffer-file-name)) "\n"
2757 "#include <stdio.h>" \n
2759 (file-name-sans-extension
2760 (file-name-nondirectory (buffer-file-name)))
2762 "int main (int argc, char *argv[])\n"
2769 (eval-after-load 'autoinsert
2770 '(define-auto-insert '("\\.h\\|.hpp\\'" . "c/c++ header")
2771 '((s-upcase (s-snake-case (file-name-nondirectory buffer-file-name)))
2772 "#ifndef " str n "#define " str "\n\n" _ "\n\n#endif // " str)))
2776 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2777 (eval-after-load 'autoinsert
2778 '(define-auto-insert '("\\.\\(py\\)\\'" . "Python skeleton")
2787 Emacs lisp auto-insert, based on the default module in =autoinsert.el=, but replace =completing-read= as
2788 =completing-read-ido-ubiquitous= to fix the edge case of that =ido= cannot handle.
2789 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2790 (eval-after-load 'autoinsert
2791 '(define-auto-insert '("\\.el\\'" . "my Emacs Lisp header")
2793 "Short description: "
2794 ";;; " (file-name-nondirectory (buffer-file-name)) " --- " str
2795 (make-string (max 2 (- 80 (current-column) 27)) ?\s)
2796 "-*- lexical-binding: t; -*-" '(setq lexical-binding t)
2798 ;; Copyright (C) " (format-time-string "%Y") " "
2799 (getenv "ORGANIZATION") | (progn user-full-name) "
2801 ;; Author: " (user-full-name)
2802 '(if (search-backward "&" (line-beginning-position) t)
2803 (replace-match (capitalize (user-login-name)) t t))
2804 '(end-of-line 1) " <" (progn user-mail-address) ">
2807 ;;'(setq v1 (apply 'vector (mapcar 'car finder-known-keywords)))
2808 '(setq v1 (mapcar (lambda (x) (list (symbol-name (car x))))
2809 finder-known-keywords)
2810 v2 (mapconcat (lambda (x) (format "%12s: %s" (car x) (cdr x)))
2811 finder-known-keywords
2813 ((let ((minibuffer-help-form v2))
2814 (completing-read-ido-ubiquitous "Keyword, C-h: " v1 nil t))
2817 \;; This program is free software; you can redistribute it and/or modify
2818 \;; it under the terms of the GNU General Public License as published by
2819 \;; the Free Software Foundation, either version 3 of the License, or
2820 \;; (at your option) any later version.
2822 \;; This program is distributed in the hope that it will be useful,
2823 \;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2824 \;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2825 \;; GNU General Public License for more details.
2827 \;; You should have received a copy of the GNU General Public License
2828 \;; along with this program. If not, see <http://www.gnu.org/licenses/>.
2840 \;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")))
2843 ** Org file template
2844 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2845 ;; (eval-after-load 'autoinsert
2846 ;; '(define-auto-insert '("\\.\\(org\\)\\'" . "Org-mode skeleton")
2849 ;; "#+TITLE: " str (make-string 30 ?\s) > \n
2850 ;; "#+AUTHOR: Peng Li\n"
2851 ;; "#+EMAIL: seudut@gmail.com\n"
2852 ;; "#+DATE: " (shell-command-to-string "echo -n $(date +%Y-%m-%d)") > \n
2858 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2859 (use-package markdown-mode
2861 :commands (markdown-mode gfm-mode)
2862 :mode (("README\\.md\\'" . gfm-mode)
2863 ("\\.md\\'" . markdown-mode)
2864 ("\\.markdown\\'" . markdown-mode))
2865 :init (setq markdown-command "multimarkdown"))
2867 ;; (add-hook 'gfm-mode-hook (lambda ()
2868 ;; (set-face-attribute 'markdown-inline-code-face nil :inherit 'fixed-pitch)
2869 ;; (set-face-attribute 'markdown-pre-face nil :inherit 'fixed-pitch)))
2870 ;; (with-eval-after-load "gfm-mode"
2871 ;; (set-face-attribute 'markdown-inline-code-face nil :inherit 'fixed-pitch)
2872 ;; (set-face-attribute 'markdown-pre-face nil :inherit 'fixed-pitch))
2875 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2876 (use-package markdown-preview-eww
2881 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2885 (global-set-key (kbd "C-;") #'iedit-mode))
2889 Refer [[https://www.emacswiki.org/emacs/GnusGmail][GnusGmail]]
2890 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2891 (setq user-mail-address "seudut@gmail.com"
2892 user-full-name "Peng Li")
2894 (setq gnus-select-method
2896 (nnimap-address "imap.gmail.com")
2897 (nnimap-server-port "imaps")
2898 (nnimap-stream ssl)))
2900 (setq smtpmail-smtp-service 587
2901 gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
2903 ;; Use gmail sending mail
2904 (setq message-send-mail-function 'smtpmail-send-it
2905 smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
2906 smtpmail-auth-credentials '(("smtp.gmail.com" 587 "seudut@gmail.com" nil))
2907 smtpmail-default-smtp-server "smtp.gmail.com"
2908 smtpmail-smtp-server "smtp.gmail.com"
2909 smtpmail-smtp-service 587
2910 starttls-use-gnutls t)
2913 And put the following in =~/.authinfo= file, replacing =<USE>= with your email address
2914 and =<PASSWORD>= with the password
2916 machine imap.gmail.com login <USER> password <PASSWORD> port imaps
2917 machine smtp.gmail.com login <USER> password <PASSWORD> port 587
2923 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2924 ;; (use-package gnus
2926 ;; (setq gnus-permanently-visible-groups "\.*")
2928 ;; (cond (window-system
2929 ;; (setq custom-background-mode 'light)
2930 ;; (defface my-group-face-1
2931 ;; '((t (:foreground "Red" :bold t))) "First group face")
2932 ;; (defface my-group-face-2
2933 ;; '((t (:foreground "DarkSeaGreen4" :bold t)))
2934 ;; "Second group face")
2935 ;; (defface my-group-face-3
2936 ;; '((t (:foreground "Green4" :bold t))) "Third group face")
2937 ;; (defface my-group-face-4
2938 ;; '((t (:foreground "SteelBlue" :bold t))) "Fourth group face")
2939 ;; (defface my-group-face-5
2940 ;; '((t (:foreground "Blue" :bold t))) "Fifth group face")))
2941 ;; (setq gnus-group-highlight
2942 ;; '(((> unread 200) . my-group-face-1)
2943 ;; ((and (< level 3) (zerop unread)) . my-group-face-2)
2944 ;; ((< level 3) . my-group-face-3)
2945 ;; ((zerop unread) . my-group-face-4)
2946 ;; (t . my-group-face-5))))
2950 ;; (add-hook 'gnus-group-mode-hook (lambda ()
2951 ;; (define-key gnus-group-mode-map "k" 'gnus-group-prev-group)
2952 ;; (define-key gnus-group-mode-map "j" 'gnus-group-next-group)
2953 ;; (define-key gnus-group-mode-map "g" 'gnus-group-jump-to-group)
2954 ;; (define-key gnus-group-mode-map "v" (lambda () (interactive) (gnus-group-select-group t)))))
2957 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2958 (setq gnus-fetch-old-headers 't)
2962 (setq gnus-extract-address-components
2963 'mail-extract-address-components)
2965 (setq gnus-summary-line-format "%U%R%z%I%(%[%-20,20f%]%) %s%-80= %11&user-date;\n")
2966 (setq gnus-user-date-format-alist '(((gnus-seconds-today) . "%H:%M")
2967 ((+ 86400 (gnus-seconds-today)) . "%a %H:%M")
2968 (604800 . "%a, %b %-d")
2969 (15778476 . "%b %-d")
2972 (setq gnus-thread-sort-functions '((not gnus-thread-sort-by-number)))
2973 (setq gnus-unread-mark ?\.)
2974 (setq gnus-use-correct-string-widths t)
2977 (setq gnus-thread-hide-subtree t)
2979 ;; (with-eval-after-load 'gnus-summary-mode
2980 ;; (define-key gnus-summary-mode-map (kbd "C-o") 'sd/hydra-window/body))
2982 ;; (add-hook 'gnus-summary-mode-hook (lambda ()
2983 ;; (define-key gnus-summary-mode-map (kbd "C-o") nil)))
2984 ;(add-hook 'gnus-summary-mode-hook (apply-partially #'define-key gnus-summary-mode-map (kbd "C-o") nil))
2990 See [[https://www.emacswiki.org/emacs/GnusWindowLayout][GnusWindowLayout]]
2991 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
2992 (gnus-add-configuration
2998 (summary 1.0 poine)))))
3000 (gnus-add-configuration
3006 (summary 0.50 point)
3009 (with-eval-after-load 'gnus-group-mode
3010 (gnus-group-select-group "INBOX"))
3011 ;; (add-hook 'gnus-group-mode-map (lambda ()
3012 ;; (gnus-group-select-group "INBOX")))
3016 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]]
3018 ** OfflineImap - download all mails from IMAP into local directory, and keep in sync
3019 #+BEGIN_SRC sh :results output replace
3021 brew install offline-imap
3023 cp /usr/local/etc/offlineimap.conf ~/.offlineimapr
3025 #For the =offlineimap= config on mac, using =sslcacertfile= instead of =cert_fingerpring=. On Mac
3026 sslcacertfile = /usr/local/etc/openssl/cert.pem
3036 localrepository = Gmail-Local
3037 remoterepository = Gmail-Remote
3039 [Repository Gmail-Local]
3041 localfolders = ~/.Mail/seudut@gmail.com
3043 [Repository Gmail-Remote]
3045 remotehost = imap.gmail.com
3046 remoteuser = seudut@gmail.com
3047 remotepass = xxxxxxxx
3050 #cert_fingerprint = <insert gmail server fingerprint here>
3051 sslcacertfile = /usr/local/etc/openssl/cert.pem
3053 folderfilter = lambda folder: folder not in ['[Gmail]/Trash',
3059 Then, run =offlineimap= to sync the mail
3061 ** Mu - fast search, view mails and extract attachments.
3063 EMACS=/usr/local/bin/emacs brew install mu --with-emacs
3066 Then, run =mu index --maildir=~/.Mail=
3068 ** Mu4e - Emacs frontend of Mu
3069 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]]
3070 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3071 (if (require 'mu4e nil 'noerror)
3073 (setq mu4e-maildir "~/.Mail")
3074 (setq mu4e-drafts-folder "/[Gmail].Drafts")
3075 (setq mu4e-sent-folder "/[Gmail].Sent Mail")
3076 ;; don't save message to Sent Messages, Gmail/IMAP takes care of this
3077 (setq mu4e-sent-messages-behavior 'delete)
3078 ;; allow for updating mail using 'U' in the main view:
3079 (setq mu4e-get-mail-command "offlineimap")
3082 (setq mu4e-maildir-shortcuts
3084 ("/[Gmail].Sent Mail" . ?s)))
3086 ;; something about ourselves
3088 user-mail-address "seudut@gmail.com"
3089 user-full-name "Peng Li"
3090 mu4e-compose-signature
3096 (setq mu4e-show-images t)
3098 ;; use imagemagick, if available
3099 (when (fboundp 'imagemagick-register-types)
3100 (imagemagick-register-types))
3102 ;; convert html emails properly
3103 ;; Possible options:
3104 ;; - html2text -utf8 -width 72
3105 ;; - textutil -stdin -format html -convert txt -stdout
3106 ;; - html2markdown | grep -v ' _place_holder;' (Requires html2text pypi)
3107 ;; - w3m -dump -cols 80 -T text/html
3108 ;; - view in browser (provided below)
3109 (setq mu4e-html2text-command "textutil -stdin -format html -convert txt -stdout")
3112 (add-hook 'mu4e-compose-mode-hook
3113 (defun my-do-compose-stuff ()
3114 "My settings for message composition."
3115 (set-fill-column 72)
3118 ;; add option to view html message in a browser
3119 ;; `aV` in view to activate
3120 (add-to-list 'mu4e-view-actions
3121 '("ViewInBrowser" . mu4e-action-view-in-browser) t)
3123 ;; fetch mail every 10 mins
3124 (setq mu4e-update-interval 600)
3127 (setq-default mu4e-headers-fields '((:flags . 6)
3129 (:mailing-list . 20)
3130 (:thread-subject . 70)
3131 (:human-date . 16))))
3132 (message "seudut:mu4e not installed, it won't work."))
3136 - =gnutls=, depends on =gnutls=, first confirm this is installed, otherwise, =brew install gnutls=
3138 #+BEGIN_SRC fundamental
3139 machine smtp.gmail.com login <gmail username> password <gmail password>
3141 - OPTIONAL, encrypt the =~/.authinfo= file
3142 #+BEGIN_SRC sh :results output replace
3143 gpg --output ~/.authinfo.gpg --symmetric ~/.authinfo
3147 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3148 (with-eval-after-load 'ediff
3149 (setq ediff-split-window-function 'split-window-horizontally)
3150 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
3151 (add-hook 'ediff-startup-hook 'ediff-toggle-wide-display)
3152 (add-hook 'ediff-cleanup-hook 'ediff-toggle-wide-display)
3153 (add-hook 'ediff-suspend-hook 'ediff-toggle-wide-display))
3158 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3159 (use-package yaml-mode
3162 (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)))
3167 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
3168 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3173 (require 'gnugo-imgen)
3174 (setq gnugo-xpms 'gnugo-imgen-create-xpms)
3175 (add-hook 'gnugo-start-game-hook '(lambda ()
3176 (gnugo-image-display-mode)
3179 (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
3183 We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
3184 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3188 (setq emms-directory (concat sd-temp-directory "emms"))
3189 (setq emms-source-file-default-directory "~/Music/")
3192 (emms-default-players)
3193 (define-emms-simple-player mplayer '(file url)
3194 (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
3195 ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
3196 "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
3197 ".m4a" ".flv" ".ogv" ".pls"))
3198 "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
3199 (emms-history-load))
3203 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3204 (use-package bing-dict
3207 (global-set-key (kbd "s-d") 'bing-dict-brief)
3208 :commands (bing-dict-brief))
3211 * Project operations - =super=
3213 ** Windown & Buffer - =C-o=
3214 Defind a =hydra= function for windows, buffer & bookmark operations. And map it to =C-o= globally.
3215 Most use =C-o C-o= to switch buffers; =C-o x, v= to split window; =C-o o= to delete other windows
3216 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3219 (require 'utilities)
3220 ;; (defhydra sd/hydra-window (:color red :columns nil)
3222 ;; ;; windows switch
3223 ;; ("h" windmove-left nil :exit t)
3224 ;; ("j" windmove-down nil :exit t)
3225 ;; ("k" windmove-up nil :exit t)
3226 ;; ("l" windmove-right nil :exit t)
3227 ;; ("C-o" other-window nil :exit t)
3229 ;; ("H" hydra-move-splitter-left nil)
3230 ;; ("J" hydra-move-splitter-down nil)
3231 ;; ("K" hydra-move-splitter-up nil)
3232 ;; ("L" hydra-move-splitter-right nil)
3236 ;; (split-window-right)
3237 ;; (windmove-right))
3241 ;; (split-window-below)
3244 ;; ;; buffer / windows switch
3245 ;; ("o" sd/toggle-max-windows nil :exit t)
3246 ;; ("C-k" sd/delete-current-window nil :exit t)
3247 ;; ("C-d" (lambda ()
3250 ;; (sd/delete-current-window))
3254 ;; ;; ("'" other-window "other" :exit t)
3255 ;; ;; ("a" ace-window "ace")
3256 ;; ("s" ace-swap-window nil)
3257 ;; ("D" ace-delete-window nil :exit t)
3258 ;; ;; ("i" ace-maximize-window "ace-one" :exit t)
3259 ;; ;; Windows undo - redo
3260 ;; ("u" (progn (winner-undo) (setq this-command 'winner-undo)) nil)
3261 ;; ("r" (progn (winner-redo) (setq this-command 'winner-redo)) nil)
3263 ;; ;; ibuffer, dired, eshell, bookmarks
3264 ;; ;; ("C-i" other-window nil :exit t)
3265 ;; ("C-b" ido-switch-buffer nil :exit t)
3266 ;; ("C-f" projectile-find-file nil :exit t)
3267 ;; ("C-r" ivy-recentf nil :exit t)
3268 ;; ;; ("C-p" persp-switch nil :exit t)
3269 ;; ;; ("C-t" projectile-persp-switch-project nil :exit t)
3271 ;; ;; other special buffers
3272 ;; ("d" sd/project-or-dired-jump nil :exit t)
3273 ;; ("b" ibuffer nil :exit t)
3274 ;; ("t" multi-term nil :exit t)
3275 ;; ("e" sd/toggle-project-eshell nil :exit t)
3276 ;; ("m" bookmark-jump-other-window nil :exit t)
3277 ;; ("M" bookmark-set nil :exit t)
3278 ;; ("g" magit-status nil :exit t)
3279 ;; ;; ("p" paradox-list-packages nil :exit t)
3283 ;; ("<ESC>" nil nil)
3284 ;; ("C-h" windmove-left nil :exit t)
3285 ;; ("C-j" windmove-down nil :exit t)
3286 ;; ("C-k" windmove-up nil :exit t)
3287 ;; ("C-l" windmove-right nil :exit t)
3288 ;; ("C-;" nil nil :exit t)
3289 ;; ("n" nil nil :exit t)
3290 ;; ("[" nil nil :exit t)
3291 ;; ("]" nil nil :exit t)
3294 ;; (global-unset-key (kbd "C-o"))
3295 ;; (global-set-key (kbd "C-o") 'sd/hydra-window/body)
3297 ;; (defun sd/project-or-dired-jump ()
3298 ;; "If under project, jump to the root directory, otherwise
3299 ;; jump to dired of current file"
3301 ;; (if (projectile-project-p)
3302 ;; (projectile-dired)
3306 Kill the help window and buffer when quit.
3307 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3308 (with-eval-after-load "help-mode"
3309 (define-key help-mode-map (kbd "q") (lambda ()
3313 (with-eval-after-load 'man
3314 (set-face-attribute 'Man-overstrike nil :inherit 'bold :foreground "orange red")
3315 (set-face-attribute 'Man-underline nil :inherit 'underline :foreground "forest green")
3316 (define-key Man-mode-map (kbd "q") (lambda ()
3321 ;; (advice-add 'man :after (lambda (man-args) (other-window 1)))
3322 (advice-add 'man :after (apply-partially 'other-window 1))
3325 (require 'shell-command-output-mode)
3327 (defun my/shell-command-after (command &optional output-buffer error-buffer)
3328 (let* ((buffer (get-buffer "*Shell Command Output*"))
3329 (window (get-buffer-window buffer)))
3330 (if buffer (with-current-buffer buffer
3331 (shell-command-output-mode)))
3333 (select-window window))))
3335 (advice-add 'shell-command :after 'my/shell-command-after)
3341 =C-<SPC>= set marks toggle the region
3342 =C-u C-<SPC>= Jump to the mark, repeated calls go further back the mark ring
3343 =C-x C-x= Exchanges the point and mark.
3345 Stolen [[https://www.masteringemacs.org/article/fixing-mark-commands-transient-mark-mode][fixing-mark-commands-transient-mark-mode]]
3346 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3347 (defun push-mark-no-activate ()
3348 "Pushes `point' to `mark-ring' and does not activate the region
3349 Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
3351 (push-mark (point) t nil)
3352 (message "Pushed mark to ring"))
3354 ;; (global-set-key (kbd "C-`") 'push-mark-no-activate)
3356 (defun jump-to-mark ()
3357 "Jumps to the local mark, respecting the `mark-ring' order.
3358 This is the same as using \\[set-mark-command] with the prefix argument."
3360 (set-mark-command 1))
3362 ;; (global-set-key (kbd "M-`") 'jump-to-mark)
3364 (defun exchange-point-and-mark-no-activate ()
3365 "Identical to \\[exchange-point-and-mark] but will not activate the region."
3367 (exchange-point-and-mark)
3368 (deactivate-mark nil))
3370 ;; (define-key global-map [remap exchange-point-and-mark] 'exchange-point-and-mark-no-activate)
3373 Show the mark ring using =helm-mark-ring=, also mapping =M-`= to quit minibuffer. so that =M-`= can
3374 toggle the mark ring. the best way is add a new action and mapping to =helm-source-mark-ring=, but
3375 since there is no map such as =helm-mark-ring=map=, so I cannot binding a key to the quit action.
3376 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3377 (setq mark-ring-max 50)
3382 (global-set-key (kbd "M-`") #'helm-mark-ring))
3384 (define-key minibuffer-local-map (kbd "M-`") 'keyboard-escape-quit)
3387 =M-h= marks the next paragraph
3388 =C-x h= marks the whole buffer
3389 =C-M-h= marks the next defun
3390 =C-x C-p= marks the next page
3392 Registers can save text, position, rectangles, file and configuration and other things.
3393 Here for movement, we can use register to save/jump position
3394 =C-x r SPC= store point in register
3395 =C-x r j= jump to register
3396 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3397 (use-package list-register
3401 *** =Avy= for easy motion
3402 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3406 (avy-setup-default))
3408 ;; (global-set-key (kbd "C-M-j") 'avy-goto-line-below)
3409 ;; (global-set-key (kbd "C-M-n") 'avy-goto-line-below)
3410 ;; (global-set-key (kbd "C-M-k") 'avy-goto-line-above)
3411 ;; (global-set-key (kbd "C-M-p") 'avy-goto-line-above)
3413 ;; (global-set-key (kbd "C-M-f") 'avy-goto-word-1-below)
3414 ;; (global-set-key (kbd "C-M-b") 'avy-goto-word-1-above)
3416 ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
3417 ;; (global-set-key (kbd "C-M-w") 'avy-goto-char-timer)
3418 ;; (global-set-key (kbd "C-M-l") 'avy-goto-char-in-line)
3420 ;; ;; will delete above
3421 ;; (global-set-key (kbd "M-g j") 'avy-goto-line-below)
3422 ;; (global-set-key (kbd "M-g k") 'avy-goto-line-above)
3423 ;; (global-set-key (kbd "M-g w") 'avy-goto-word-1-below)
3424 ;; (global-set-key (kbd "M-g b") 'avy-goto-word-1-above)
3425 ;; (global-set-key (kbd "M-g e") 'avy-goto-word-0)
3426 ;; (global-set-key (kbd "M-g f") 'avy-goto-char-timer)
3427 ;; (global-set-key (kbd "M-g c") 'avy-goto-char-in-line)
3428 (global-set-key (kbd "M-g c") 'avy-goto-char)
3429 (global-set-key (kbd "M-g b") 'avy-goto-word-0-above)
3430 (global-set-key (kbd "M-g w") 'avy-goto-word-0-below)
3433 *** =Imenu= goto tag
3434 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3435 (global-set-key (kbd "M-i") #'counsel-imenu)
3436 ;; (global-set-key (kbd "M-i") #'imenu)
3438 ;; define M-[ as C-M-a
3439 ;; http://ergoemacs.org/emacs/emacs_key-translation-map.html
3440 (define-key key-translation-map (kbd "M-[") (kbd "C-M-a"))
3441 (define-key key-translation-map (kbd "M-]") (kbd "C-M-e"))
3445 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3446 (global-set-key (kbd "M-l") 'goto-line)
3452 =helm-show-kill-ring=
3453 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3454 (setq kill-ring-max 100) ; default is 60p
3459 (global-set-key (kbd "M-y") #'helm-show-kill-ring))
3463 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3464 (use-package undo-tree
3467 (define-key undo-tree-visualizer-mode-map "j" 'undo-tree-visualize-redo)
3468 (define-key undo-tree-visualizer-mode-map "k" 'undo-tree-visualize-undo)
3469 (define-key undo-tree-visualizer-mode-map "h" 'undo-tree-visualize-switch-branch-left)
3470 (define-key undo-tree-visualizer-mode-map "l" 'undo-tree-visualize-switch-branch-right)
3471 (global-undo-tree-mode 1))
3473 (global-set-key (kbd "s-u") 'undo-tree-visualize)
3477 Stolen from [[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-spelling.el][here]], hunspell will search dictionary in =DICPATH=
3478 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3479 (setenv "DICPATH" "/usr/local/share/hunspell")
3481 (when (executable-find "hunspell")
3482 (setq-default ispell-program-name "hunspell")
3483 (setq ispell-really-hunspell t))
3485 ;; (defun text-mode-hook-setup ()
3486 ;; ;; Turn off RUN-TOGETHER option when spell check text-mode
3487 ;; (setq-local ispell-extra-args (flyspell-detect-ispell-args)))
3488 ;; (add-hook 'text-mode-hook 'text-mode-hook-setup)
3489 ;; (add-hook 'text-mode-hook 'flyspell-mode)
3491 ;; enable flyspell check on comments and strings in progmamming modes
3492 ;; (add-hook 'prog-mode-hook 'flyspell-prog-mode)
3494 ;; I don't use the default mappings
3495 (with-eval-after-load 'flyspell
3496 (define-key flyspell-mode-map (kbd "C-;") nil)
3497 (define-key flyspell-mode-map (kbd "C-,") nil)
3498 (define-key flyspell-mode-map (kbd "C-.") nil))
3501 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]]
3502 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3503 ;; NO spell check for embedded snippets
3504 (defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
3505 (let ((rlt ad-return-value)
3506 (begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\)")
3507 (end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\)")
3510 (when ad-return-value
3512 (setq old-flag case-fold-search)
3513 (setq case-fold-search t)
3514 (setq b (re-search-backward begin-regexp nil t))
3515 (if b (setq e (re-search-forward end-regexp nil t)))
3516 (setq case-fold-search old-flag))
3517 (if (and b e (< (point) e)) (setq rlt nil)))
3518 (setq ad-return-value rlt)))
3521 ** Search & Replace / hightlight =M-s=
3524 =C-w= add word at point to search string,
3526 =C-M-y= add character at point to search string
3527 =M-s C-e= add reset of line at point
3528 =C-y= yank from clipboard to search string
3529 =M-n=, =M-p=, history
3530 =C-M-i= complete search string
3531 set the isearch history size, the default is only =16=
3532 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3533 (setq history-length 5000)
3534 (setq regexp-search-ring-max 1000)
3535 (setq search-ring-max 1000)
3537 ;; when search a word or a symbol , also add the word into regexp-search-ring
3538 (defadvice isearch-update-ring (after sd/isearch-update-ring (string &optional regexp) activate)
3539 "Add search-ring to regexp-search-ring"
3541 (add-to-history 'regexp-search-ring string regexp-search-ring-max)))
3545 use the prefix =M-s= for searching in buffers
3546 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3547 (defun sd/make-keymap (key bindings)
3548 (setq keymap (make-sparse-keymap))
3549 (dolist (binding bindings)
3550 (define-key keymap (car binding) (cdr binding)))
3551 (global-set-key key keymap))
3553 ;; (sd/make-keymap "\M-s"
3554 ;; '(("w" . save-buffer)
3555 ;; ;; ("\M-w" . save-buffer)
3556 ;; ("e" . revert-buffer)
3557 ;; ("s" . isearch-forward-regexp)
3558 ;; ("\M-s" . isearch-forward-regexp)
3559 ;; ("r" . isearch-backward-regexp)
3560 ;; ("." . isearch-forward-symbol-at-point)
3562 ;; ;; ("h" . highlight-symbol-at-point)
3563 ;; ("h" . highlight-symbol)
3564 ;; ("m" . highlight-regexp)
3565 ;; ("l" . highlight-lines-matching-regexp)
3566 ;; ("M" . unhighlight-regexp)
3567 ;; ("f" . keyboard-quit)
3568 ;; ("q" . keyboard-quit)))
3571 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3572 (use-package highlight-symbol
3575 (defhydra sd/search-replace (:color red :columns nil)
3577 ("w" save-buffer "save" :exit t)
3578 ("e" revert-buffer "revert" :exit t)
3579 ("u" undo-tree-visualize "undo" :exit t)
3580 ("s" isearch-forward-regexp "s-search" :exit t)
3581 ("M-s" isearch-forward-regexp "s-search" :exit t)
3582 ("r" isearch-backward-regexp "r-search" :exit t)
3583 ("." isearch-forward-symbol-at-point "search point" :exit t)
3584 ("/" swiper "swiper" :exit t)
3585 ("o" occur "occur" :exit t)
3586 ("h" highlight-symbol "higlight" :exit t)
3587 ("l" highlight-lines-matching-regexp "higlight line" :exit t)
3588 ("m" highlight-regexp "higlight" :exit t)
3589 ("M" unhighlight-regexp "unhiglight" :exit t)
3593 (global-unset-key (kbd "M-s"))
3594 (global-set-key (kbd "M-s") 'sd/search-replace/body)
3597 ;; search and replace and highlight
3598 (define-key isearch-mode-map (kbd "M-s") 'isearch-repeat-forward)
3599 (define-key isearch-mode-map (kbd "M-r") 'isearch-repeat-backward)
3600 (global-set-key (kbd "s-[") 'highlight-symbol-next)
3601 (global-set-key (kbd "s-]") 'highlight-symbol-prev)
3602 (global-set-key (kbd "s-\\") 'highlight-symbol-query-replace)
3606 Occur search key bindings
3607 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3608 (defun sd/occur-keys ()
3609 "My key bindings in occur-mode"
3611 (switch-to-buffer-other-window "*Occur*")
3612 (define-key occur-mode-map (kbd "C-o") nil)
3613 (define-key occur-mode-map (kbd "C-n") (lambda ()
3616 (occur-mode-goto-occurrence-other-window)
3619 (define-key occur-mode-map (kbd "C-p") (lambda ()
3622 (occur-mode-goto-occurrence-other-window)
3626 (add-hook 'occur-hook #'sd/occur-keys)
3628 (use-package color-moccur
3630 :commands (isearch-moccur isearch-all)
3632 (setq isearch-lazy-highlight t)
3634 (use-package moccur-edit))
3638 ** Expand region map
3639 *** Install =expand-region=
3640 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3641 (use-package expand-region
3644 ;; (global-set-key (kbd "C-=") 'er/expand-region)
3648 *** Add a =hydra= map for =expand-region= operations
3649 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3650 (defun sd/mark-line ()
3651 "Mark current line without whitespace beginning"
3653 (back-to-indentation)
3654 (set-mark (line-end-position)))
3656 (defhydra sd/expand-selected (:color red :columns nil
3657 :post (deactivate-mark)
3661 ;; ("e" er/expand-region "+")
3662 ("SPC" er/expand-region "+")
3663 ;; ("c" er/contract-region "-")
3664 ("S-SPC" er/contract-region "-")
3667 (er/contract-region 0))
3670 ("i'" er/mark-inside-quotes "in")
3671 ("i\"" er/mark-inside-quotes nil)
3672 ("o'" er/mark-outside-quotes "out")
3673 ("o\"" er/mark-outside-quotes nil)
3675 ("i{" er/mark-inside-pairs nil)
3676 ("i(" er/mark-inside-pairs nil)
3677 ("o{" er/mark-inside-pairs nil)
3678 ("o(" er/mark-inside-pairs nil)
3680 ("p" er/mark-paragraph "paragraph")
3682 ("l" sd/mark-line "line")
3683 ("u" er/mark-url "url")
3684 ("f" er/mark-defun "fun")
3685 ("n" er/mark-next-accessor "next")
3687 ("x" exchange-point-and-mark "exchange")
3693 ("d" kill-region "delete" :exit t)
3695 ("y" kill-ring-save "yank" :exit t)
3696 ("M-SPC" nil "quit" :exit t)
3697 ;; ("C-SPC" "quit" :exit t)
3698 ("q" deactivate-mark "quit" :exit t))
3700 (global-set-key (kbd "M-SPC") (lambda ()
3702 (set-mark-command nil)
3703 ;; (er/expand-region 1)
3705 (sd/expand-selected/body)))
3708 *** TODO make expand-region hydra work with lispy selected
3711 Here are some global key bindings for basic editting
3712 ** Global key bingding
3713 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3714 (global-set-key (kbd "C-h") 'delete-backward-char)
3715 (global-set-key (kbd "s-m") 'man)
3716 (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
3717 ;; project operation
3718 (global-set-key (kbd "s-p") 'projectile-switch-open-project)
3719 (global-set-key (kbd "s-f") 'projectile-find-file)
3721 ;; (global-set-key (kbd "s-=") 'increase-emacs-font-size)
3722 ;; (global-set-key (kbd "s--") 'decrease-emacs-font-size)
3723 (global-set-key (kbd "s-=") 'text-scale-increase)
3724 (global-set-key (kbd "s--") 'text-scale-decrease)
3725 (global-unset-key (kbd "s-n"))
3728 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]]
3730 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3731 (require 'utilities)
3732 (global-set-key (kbd "C-w") 'sd/kill-region-or-backward-kill-word)
3736 ** Esc in minibuffer
3737 Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
3738 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3739 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
3740 (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
3741 (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
3742 (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
3743 (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
3744 (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
3745 (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
3746 (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
3747 (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
3749 ;; Also map s-h same as C-g
3750 (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
3755 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3756 ;; (use-package perspeen
3759 ;; (setq perspeen-use-tab nil)
3763 (el-get-bundle seudut/perspeen
3765 (setq perspeen-use-tab nil)
3769 ;; super-i to switch to ith workspace
3771 (defmacro sd/define-keys (map key func &rest args)
3772 "A macro to define multi keys "
3773 `(define-key ,map ,key (lambda () (interactive) (,func ,@args))))
3776 (with-eval-after-load "perspeen"
3778 (sd/define-keys perspeen-mode-map (kbd (concat "s-" (number-to-string (+ ii 1))))
3779 perspeen-goto-ws (+ ii 1)))
3780 (define-key perspeen-mode-map (kbd "s-c") 'perspeen-create-ws)
3781 (define-key perspeen-mode-map (kbd "s-n") 'perspeen-next-ws)
3782 (define-key perspeen-mode-map (kbd "s-p") 'perspeen-previous-ws)
3783 (define-key perspeen-mode-map (kbd "s-'") 'perspeen-last-ws)
3784 (define-key perspeen-mode-map (kbd "s-t") 'perspeen-tab-create-tab)
3785 (define-key perspeen-mode-map (kbd "s-t") 'perspeen-tab-create-tab))
3788 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
3789 (org-babel-load-file "~/.emacs.d/emacs-evil.org")
3794 [fn:1] [[http://coldnew.github.io/blog/2013/11-16_d2f3a/][解決 org-mode θ‘¨ζ Όε
§δΈθ±ζε°ι½ηει‘]]