emacs - add hydra for expand region
[dotfiles.git] / emacs.d / config.org
index b0b7496..7d3586b 100644 (file)
@@ -102,6 +102,10 @@ Make a temp directory for all cache/history files
   (setq history-length 1000)
   (setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring))
   (savehist-mode 1)
+
+  ;; set temp file path for recentf and auto-save
+  (setq recentf-save-file (concat sd-temp-directory "recentf"))
+  (setq auto-save-list-file-prefix (concat sd-temp-directory "auto-save-list/.saves-"))
 #+END_SRC
 
 * Package Management Tools
@@ -559,8 +563,8 @@ set height in mode line
   (use-package smex
     :ensure t
     :init
-    (smex-initialize)
     (setq smex-save-file (concat sd-temp-directory "smex-items"))
+    (smex-initialize)
     :bind
     ("M-x" . smex)
     ("M-X" . smex-major-mode-commands))
@@ -601,10 +605,14 @@ Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for
     :init
     (global-set-key (kbd "M-x") 'counsel-M-x)
     (global-set-key (kbd "C-h f") 'counsel-describe-function)
-    (global-set-key (kbd "C-h v") 'counsel-describe-variable))
+    (global-set-key (kbd "C-h v") 'counsel-describe-variable)
+    ;; (set-face-attribute 'ivy-current-match nil :background "Orange" :foreground "black")
+    (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
+    (global-set-key (kbd "C-c C-r") 'ivy-resume))
+
+
 
   ;; (global-set-key "\C-s" 'swiper)
-  ;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
   ;; (global-set-key (kbd "<f6>") 'ivy-resume)
   ;; ;; (global-set-key (kbd "C-x C-f") 'counsel-find-file)
   ;; (global-set-key (kbd "<f1> l") 'counsel-load-library)
@@ -615,7 +623,6 @@ Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for
   ;; (global-set-key (kbd "C-c k") 'counsel-ag)
   ;; (global-set-key (kbd "C-x l") 'counsel-locate)
   ;; (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
-  ;; ;; (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
 
   ;; (set-face-attribute
   ;;  'ivy-current-match nil
@@ -1313,8 +1320,8 @@ We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multi
   (use-package emms
     :ensure t
     :init
-    (setq emms-source-file-default-directory "~/Music/")
     (setq emms-directory (concat sd-temp-directory "emms"))
+    (setq emms-source-file-default-directory "~/Music/")
     :config
     (emms-standard)
     (emms-default-players)
@@ -1944,7 +1951,7 @@ Use =gnuplot= on =Org-mode= file, see [[http://orgmode.org/worg/org-contrib/babe
     :commands (bing-dict-brief))
 #+END_SRC
 
-* NEXT Key Bindings
+* 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=
@@ -2269,13 +2276,6 @@ Search, replace and hightlight will in later paragraph
   (global-set-key (kbd "M-l") 'goto-line)
 #+END_SRC
 
-*** Movement effective
-**** isearch
-=C-s=, =C-r=
-=C-w=, put the word into search minibuffer, =M-y=
-=M-c=, toggle case sensitivity
-=M-n=, =M-p=, history
-**** tagss
 ** Edit
 *** basic editting
 - cut, yank, =C-w=, =C-y=
@@ -2373,6 +2373,12 @@ set the isearch history size, the default is only =16=
   (setq history-length 5000)
   (setq regexp-search-ring-max 1000)
   (setq search-ring-max 1000)
+
+  ;; when search a word or a symbol , also add the word into regexp-search-ring
+  (defadvice isearch-update-ring (after sd/isearch-update-ring (string &optional regexp) activate)
+    "Add search-ring to regexp-search-ring"
+    (unless regexp
+      (add-to-history 'regexp-search-ring string regexp-search-ring-max)))
 #+END_SRC
 
 *** =M-s= prefix
@@ -2436,8 +2442,6 @@ use the prefix =M-s= for searching in buffers
   (global-set-key (kbd "s-\\") 'highlight-symbol-query-replace)
 #+END_SRC
 
-*** replace
-*** hightlight
 *** Occur
 Occur search key bindings
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
@@ -2490,6 +2494,45 @@ stolen from [[https://github.com/mariolong/emacs.d/blob/f6a061594ef1b5d1f4750e9d
                                          (insert (format "%s" (with-ivy-window (thing-at-point 'symbol)))))))
 #+END_SRC
 
+** TODO Expand region map
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (defhydra sd/expand-selected (:color red :columns nil
+                                       :post (deactivate-mark))
+    "Selected"
+    ;; select
+    ("e" er/expand-region "+")
+    ("c" er/contract-region "-")
+    ;; ("\"" er/mark-inside-quotes "inside \"")
+    ;; ("a\"" er/mark-outside-quotes "inside \"")
+    ;; exchange
+    ("x" exchange-point-and-mark "exchange")
+    ("o" exchange-point-and-mark "exchange")
+    ;; exit
+    ("d" kill-region "delete" :exit t)
+    ("i" kill-region "delete" :exit t)
+    ("y" kill-ring-save "yank" :exit t)
+    ("q" nil "quit" :exit t))
+
+  (global-set-key (kbd "C-=") (lambda ()
+                                (interactive)
+                                (er/mark-word)
+                                (sd/expand-selected/body)))
+
+  ;; er/mark-word
+  ;; er/mark-symbol
+  ;; er/mark-symbol-with-prefix
+  ;; er/mark-next-accessor
+  ;; er/mark-method-call
+  ;; er/mark-inside-quotes
+  ;; er/mark-outside-quotes
+  ;; er/mark-inside-pairs
+  ;; er/mark-outside-pairs
+  ;; er/mark-comment
+  ;; er/mark-url
+  ;; er/mark-email
+  ;; er/mark-defun
+#+END_SRC
+
 * TODO Convert ASCII to key
 ** map =function-key-map= [[http://academic.evergreen.edu/projects/biophysics/technotes/program/ascii_ctrl.htm][ascii_ctrl]]
 new file =C-x C-f C-f=
@@ -2503,16 +2546,6 @@ new file =C-x C-f C-f=
 * TODO jump last change point
 * TODO emms mode-line
 
-* TODO Temp directory for cached/history/temp files
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-  (use-package recentf
-    :init
-    (setq recentf-save-file (concat sd-temp-directory "recentf")))
-
-  (setq auto-save-list-file-prefix (concat sd-temp-directory "auto-save-list/.saves-")) 
-
-#+END_SRC
-
 * =C-u C-h a= search funtions 
 =apropos-command=