+ (with-eval-after-load 'ediff
+ (setq ediff-split-window-function 'split-window-horizontally)
+ (setq ediff-window-setup-function 'ediff-setup-windows-plain)
+ (add-hook 'ediff-startup-hook 'ediff-toggle-wide-display)
+ (add-hook 'ediff-cleanup-hook 'ediff-toggle-wide-display)
+ (add-hook 'ediff-suspend-hook 'ediff-toggle-wide-display))
+#+END_SRC
+
+* Entertainment
+** GnuGo
+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
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package gnugo
+ :ensure t
+ :defer t
+ :init
+ (require 'gnugo-imgen)
+ (setq gnugo-xpms 'gnugo-imgen-create-xpms)
+ (add-hook 'gnugo-start-game-hook '(lambda ()
+ (gnugo-image-display-mode)
+ (gnugo-grid-mode)))
+ :config
+ (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1")))
+#+END_SRC
+
+** Emms
+We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package emms
+ :ensure t
+ :init
+ (setq emms-directory (concat sd-temp-directory "emms"))
+ (setq emms-source-file-default-directory "~/Music/")
+ :config
+ (emms-standard)
+ (emms-default-players)
+ (define-emms-simple-player mplayer '(file url)
+ (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape"
+ ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg"
+ "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob"
+ ".m4a" ".flv" ".ogv" ".pls"))
+ "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
+ (emms-history-load))
+#+END_SRC
+
+* Dictionary
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package bing-dict
+ :ensure t
+ :init
+ (global-set-key (kbd "s-d") 'bing-dict-brief)
+ :commands (bing-dict-brief))
+#+END_SRC
+
+* Key Bindings
+Here are some global key bindings for basic editting
+** Esc in minibuffer
+Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit)
+ (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit)
+
+ ;; Also map s-h same as C-g
+ (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit)
+#+END_SRC
+
+** Project operations - =super=
+*** Projectile
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (use-package projectile
+ :ensure t
+ :init
+ (setq projectile-enable-caching t)
+ (setq projectile-switch-project-action (lambda ()
+ (projectile-dired)
+ (sd/project-switch-action)))
+ (setq projectile-cache-file (concat sd-temp-directory "projectile.cache"))
+ :config
+ (add-to-list 'projectile-globally-ignored-files "GTAGS")
+ (projectile-global-mode t))
+
+ (use-package persp-projectile
+ :ensure t
+ :config
+ (persp-mode)
+ :bind
+ (:map projectile-mode-map
+ ("s-t" . projectile-persp-switch-project)))
+
+ ;; (defun sd/change-default-directory (buffer dir)
+ ;; "change defafult directory of buffer to dir"
+ ;; (with-current-buffer buffer
+ ;; (cd dir)))
+
+ ;; change default-directory of scratch buffer to projectile-project-root
+ (defun sd/project-switch-action ()
+ "Change default-directory of scratch buffer to current projectile-project-root directory"
+ (interactive)
+ (dolist (buffer (buffer-list))
+ (if (string-match (concat "scratch.*" (projectile-project-name))
+ (buffer-name buffer))
+ (let ((root (projectile-project-root)))
+ (with-current-buffer buffer
+ (cd root)))
+ ;; (sd/change-default-directory buffer (projectile-project-root))
+ )))
+#+END_SRC
+
+*** project config =super= keybindings
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ ;; (global-set-key (kbd "s-h") 'keyboard-quit)
+ ;; (global-set-key (kbd "s-j") 'ido-switch-buffer)
+ ;; (global-set-key (kbd "s-k") 'ido-find-file)
+ ;; (global-set-key (kbd "s-l") 'sd/delete-current-window)
+ ;; s-l --> goto-line
+ ;; (global-set-key (kbd "s-/") 'swiper)
+ ;; s-; -->
+ ;; s-' --> 'next-multiframe-window
+ (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
+
+ (global-set-key (kbd "s-f") 'projectile-find-file)
+ (global-set-key (kbd "s-`") 'mode-line-other-buffer)
+
+ (global-set-key (kbd "s-n") 'persp-next)
+ (global-set-key (kbd "s-p") 'persp-prev)
+ (global-set-key (kbd "s-;") 'persp-switch-last)
+
+ (global-set-key (kbd "s-=") 'text-scale-increase)
+ (global-set-key (kbd "s--") 'text-scale-decrease)
+
+ ;; (global-set-key (kbd "s-u") 'undo-tree-visualize)
+
+
+ ;; someothers default mapping on super (command) key
+ ;; s-s save-buffer
+ ;; s-k kill-this-buffer
+
+
+ ;; s-h --> ns-do-hide-emacs
+ ;; s-j --> ido-switch-buffer +
+ ;; s-k --> kill-this-buffer
+ ;; s-l --> goto-line
+ ;; s-; --> undefined
+ ;; s-' --> next-multiframe-window
+ ;; s-ret --> toggle-frame-fullscreen +
+
+ ;; s-y --> ns-paste-secondary
+ ;; s-u --> revert-buffer
+ ;; s-i --> undefined - but used for iterm globally
+ ;; s-o --> used for emacs globally
+ ;; s-p --> projectile-persp-switch-project +
+ ;; s-[ --> next-buffer +
+ ;; s-] --> previous-buffer +
+
+ ;; s-0 --> undefined
+ ;; s-9 --> undefined
+ ;; s-8 --> undefined
+ ;; s-7 --> undefined
+ ;; s-6 --> undefined
+ ;; s-- --> center-line
+ ;; s-= --> undefined
+
+ ;; s-n --> make-frame
+ ;; s-m --> iconify-frame
+ ;; s-b --> undefined
+ ;; s-, --> customize
+ ;; s-. --> undefined
+ ;; s-/ --> undefined
+
+ ;; s-g --> isearch-repeat-forward
+ ;; s-f --> projectile-find-file +
+ ;; s-d --> isearch-repeat-background
+ ;; s-s --> save-buffer
+ ;; s-a --> make-whole-buffer
+
+ ;; s-b --> undefined
+ ;; s-v --> yank
+ ;; s-c --> ns-copy-including-secondary
+
+ ;; s-t --> ns-popup-font-panel
+ ;; s-r --> undefined
+ ;; s-e --> isearch-yanqk-kill
+ ;; s-w --> delete-frame
+ ;; s-q --> same-buffers-kill-emacs
+
+ ;; s-` --> other-frame
+#+END_SRC
+
+** Windown & Buffer - =C-o=
+Defind a =hydra= function for windows, buffer & bookmark operations. And map it to =C-o= globally.
+Most use =C-o C-o= to switch buffers; =C-o x, v= to split window; =C-o o= to delete other windows
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (winner-mode 1)
+
+ (defun sd/delete-current-window ()
+ (interactive)
+ (if (> (length (window-list)) 1)
+ (delete-window)
+ (message "Only one Windows now!")))
+
+ (defun sd/toggle-max-windows ()
+ "Set maximize current if there are multiple windows, if only
+ one window, window undo"
+ (interactive)
+ (if (equal (length (window-list)) 1)
+ (winner-undo)
+ (delete-other-windows)))
+
+ (defhydra sd/hydra-window (:color red :columns nil)
+ "Window"
+ ;; windows switch
+ ("h" windmove-left nil :exit t)
+ ("j" windmove-down nil :exit t)
+ ("k" windmove-up nil :exit t)
+ ("l" windmove-right nil :exit t)
+ ("C-o" other-window nil :exit t)
+ ;; window resize
+ ("H" hydra-move-splitter-left nil)
+ ("J" hydra-move-splitter-down nil)
+ ("K" hydra-move-splitter-up nil)
+ ("L" hydra-move-splitter-right nil)
+ ;; windows split
+ ("v" (lambda ()
+ (interactive)
+ (split-window-right)
+ (windmove-right))
+ "vert" :exit t)
+ ("x" (lambda ()
+ (interactive)
+ (split-window-below)
+ (windmove-down))
+ "horz" :exit t)
+ ;; buffer / windows switch
+ ("o" sd/toggle-max-windows "one" :exit t)
+ ("C-k" sd/delete-current-window "del" :exit t)
+ ("C-d" (lambda ()
+ (interactive)
+ (kill-buffer)
+ (sd/delete-current-window))
+ "kill" :exit t)
+
+ ;; ace-window
+ ;; ("'" other-window "other" :exit t)
+ ;; ("a" ace-window "ace")
+ ("s" ace-swap-window "swap")
+ ("D" ace-delete-window "ace-one" :exit t)
+ ;; ("i" ace-maximize-window "ace-one" :exit t)
+ ;; Windows undo - redo
+ ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
+ ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
+
+ ;; ibuffer, dired, eshell, bookmarks
+ ;; ("C-i" other-window nil :exit t)
+ ("C-b" ido-switch-buffer nil :exit t)
+ ("C-f" projectile-find-file nil :exit t)
+ ("C-p" persp-switch :exit t)
+
+ ;; other special buffers
+ ("d" sd/project-or-dired-jump nil :exit t)
+ ("b" ibuffer nil :exit t)
+ ("t" multi-term nil :exit t)
+ ("e" sd/toggle-project-eshell nil :exit t)
+ ("m" bookmark-jump-other-window nil :exit t)
+ ("M" bookmark-set nil :exit t)
+ ("g" magit-status nil :exit t)
+ ;; ("p" paradox-list-packages nil :exit t)
+
+ ;; quit
+ ("q" nil "cancel")
+ ("<ESC>" nil)
+ ("C-h" nil nil :exit t)
+ ("C-j" nil nil :exit t)
+ ;; ("C-k" nil :exit t)
+ ("C-l" nil nil :exit t)
+ ("C-;" nil nil :exit t)
+ ("n" nil nil :exit t)
+ ("[" nil nil :exit t)
+ ("]" nil nil :exit t)
+ ("f" nil))
+
+ (global-unset-key (kbd "C-o"))
+ (global-set-key (kbd "C-o") 'sd/hydra-window/body)
+
+ (defun sd/project-or-dired-jump ()
+ "If under project, jump to the root directory, otherwise
+ jump to dired of current file"
+ (interactive)
+ (if (projectile-project-p)
+ (projectile-dired)
+ (dired-jump)))
+#+END_SRC
+
+** Motion
+- =C-M-=
+[[https://www.masteringemacs.org/article/effective-editing-movement][effective-editing-movement]]
+*** Command Arguments, numeric argumens
+=C-u 4= same as =C-4=, =M-4=
+*** Basic movement
+moving by line / word /
+=C-f=, =C-b=, =C-p=, =C-n=, =M-f=, =M-b=
+=C-a=, =C-e=
+=M-m= (move first non-whitespace on this line)
+=M-}=, =M-{=, Move forward end of paragraph
+=M-a=, =M-e=, beginning / end of sentence
+=C-M-a=, =C-M-e=, move begining of defun
+=C-x ]=, =C-x [=, forward/backward one page
+=C-v=, =M-v=, =C-M-v=, =C-M-S-v= scroll down/up
+=M-<=, =M->=, beginning/end of buffer
+=M-r=, Repositiong point
+
+*** Moving by S-expression / List
+*** Marks
+=C-<SPC>= set marks toggle the region
+=C-u C-<SPC>= Jump to the mark, repeated calls go further back the mark ring
+=C-x C-x= Exchanges the point and mark.
+
+Stolen [[https://www.masteringemacs.org/article/fixing-mark-commands-transient-mark-mode][fixing-mark-commands-transient-mark-mode]]
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (defun push-mark-no-activate ()
+ "Pushes `point' to `mark-ring' and does not activate the region
+ Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
+ (interactive)
+ (push-mark (point) t nil)
+ (message "Pushed mark to ring"))
+
+ ;; (global-set-key (kbd "C-`") 'push-mark-no-activate)
+
+ (defun jump-to-mark ()
+ "Jumps to the local mark, respecting the `mark-ring' order.
+ This is the same as using \\[set-mark-command] with the prefix argument."
+ (interactive)
+ (set-mark-command 1))
+
+ ;; (global-set-key (kbd "M-`") 'jump-to-mark)
+
+ (defun exchange-point-and-mark-no-activate ()
+ "Identical to \\[exchange-point-and-mark] but will not activate the region."
+ (interactive)
+ (exchange-point-and-mark)
+ (deactivate-mark nil))
+
+ ;; (define-key global-map [remap exchange-point-and-mark] 'exchange-point-and-mark-no-activate)
+#+END_SRC
+
+Show the mark ring using =helm-mark-ring=, also mapping =M-`= to quit minibuffer. so that =M-`= can
+toggle the mark ring. the best way is add a new action and mapping to =helm-source-mark-ring=, but
+since there is no map such as =helm-mark-ring=map=, so I cannot binding a key to the quit action.
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+ (setq mark-ring-max 50)
+
+ (use-package helm
+ :ensure t