emacs - tidy up hydra
[dotfiles.git] / emacs.d / config.org
index f1d0fe7..f022331 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
@@ -1151,7 +1155,7 @@ Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-ex
 *** hydra misc
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
   (defhydra sd/hydra-misc (:color red :columns nil)
-    "Miscellaneous Commands"
+    "Misc"
     ("e" eshell "eshell" :exit t)
     ("p" (lambda ()
            (interactive)
@@ -1477,6 +1481,18 @@ Dired+
     (define-key dired-mode-map (kbd "g") 'dired-goto-file))
 #+END_SRC
 
+* ibuffer
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (global-set-key (kbd "s-b") 'ibuffer)
+
+  (with-eval-after-load 'ibuffer
+    (define-key ibuffer-mode-map (kbd "C-o") nil)
+    (define-key ibuffer-mode-map (kbd "j") 'ibuffer-forward-line)
+    (define-key ibuffer-mode-map (kbd "k") 'ibuffer-backward-line)
+    (define-key ibuffer-mode-map (kbd "r") 'ibuffer-update)
+    (define-key ibuffer-mode-map (kbd "g") 'ibuffer-jump-to-buffer))
+#+END_SRC
+
 * Completion
 company mode and company-statistics
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
@@ -1947,7 +1963,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=
@@ -2090,7 +2106,8 @@ Most use =C-o C-o= to switch buffers; =C-o x, v= to split window; =C-o o= to del
       (delete-other-windows)))
 
   (defhydra sd/hydra-window (:color red :columns nil)
-    "window"
+    "Window"
+    ;; windows split
     ("h" windmove-left nil :exit t)
     ("j" windmove-down nil :exit t)
     ("k" windmove-up nil :exit t)
@@ -2109,21 +2126,27 @@ Most use =C-o C-o= to switch buffers; =C-o x, v= to split window; =C-o o= to del
            (split-window-below)
            (windmove-down))
      "horz" :exit t)
-    ;; ("o" delete-other-windows "one" :exit t)
+
+    ;; buffer / windows switch
     ("o" sd/toggle-max-windows "one" :exit t)
-    ("C-o" ido-switch-buffer "buf" :exit t)
     ("C-k" sd/delete-current-window "del" :exit t)
     ("'" other-window "other" :exit t)
-    ("a" ace-window "ace")
+    ;; ("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)
-    ("b" ido-switch-buffer "buf" :exit t)
-    ("C-b" ido-switch-buffer "buf" :exit t)
-    ("m" bookmark-jump-other-window "open bmk" :exit t)
-    ("M" bookmark-set "set bmk" :exit t)
+    ;; ("i" ace-maximize-window "ace-one" :exit t)
+
     ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
     ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo")
+
+    ;; ibuffer, dired, eshell, bookmarks
+    ;; ("d" ace-delete-window "ace-one" :exit t)
+    ("C-o" ido-switch-buffer "buf" :exit t)
+    ("d" dired-jump "dired" :exit t)
+    ("b" ibuffer "ibuffer" :exit t)
+    ("m" bookmark-jump-other-window "open bmk" :exit t)
+    ("M" bookmark-set "set bmk" :exit t)
+
+    ;; quit
     ("q" nil "cancel")
     ("<ESC>" nil)
     ("C-h" nil nil :exit t)
@@ -2207,10 +2230,6 @@ since there is no map such as =helm-mark-ring=map=, so I cannot binding a key to
 =C-x h= marks the whole buffer
 =C-M-h= marks the next defun
 =C-x C-p= marks the next page
-**** DONE Mapping toggle mark ring=
-:LOGBOOK:
-- State "DONE"       from "TODO"       [2016-07-22 Fri 23:18]
-:END:
 *** Registers
 Registers can save text, position, rectangles, file and configuration and other things.
 Here for movement, we can use register to save/jump position
@@ -2287,14 +2306,6 @@ Search, replace and hightlight will in later paragraph
   (global-set-key (kbd "M-y") #'helm-show-kill-ring)
 #+END_SRC
 
-*** Expand-region
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-  (use-package expand-region
-    :ensure t
-    :config
-    (global-set-key (kbd "C-=") 'er/expand-region))
-#+END_SRC
-
 *** undo-tree
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
   (use-package undo-tree
@@ -2370,18 +2381,11 @@ set the isearch history size, the default is only =16=
   (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)))
-
-  ;; (defun isearch-update-ring (string &optional regexp)
-  ;;   "Add STRING to the beginning of the search ring.
-  ;; REGEXP if non-nil says use the regexp search ring."
-  ;;   (add-to-history
-  ;;    (if regexp 'regexp-search-ring 'search-ring)
-  ;;    string
-  ;;    (if regexp regexp-search-ring-max search-ring-max)))
 #+END_SRC
 
 *** =M-s= prefix
@@ -2445,8 +2449,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
@@ -2499,6 +2501,81 @@ stolen from [[https://github.com/mariolong/emacs.d/blob/f6a061594ef1b5d1f4750e9d
                                          (insert (format "%s" (with-ivy-window (thing-at-point 'symbol)))))))
 #+END_SRC
 
+** Expand region map
+*** Install =expand-region=
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (use-package expand-region
+    :ensure t
+    :config
+    ;; (global-set-key (kbd "C-=") 'er/expand-region)
+    )
+#+END_SRC
+
+*** Add a =hydra= map for =expand-region= operations
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (defun sd/mark-line ()
+    "Mark current line without whitespace beginning"
+    (interactive)
+    (back-to-indentation)
+    (set-mark (line-end-position)))
+
+  (defhydra sd/expand-selected (:color pink :columns nil
+                                       :post (deactivate-mark))
+    "Selected"
+    ;; select
+    ;; ("e"  er/expand-region "+")
+    ("SPC"  er/expand-region "+")
+    ;; ("c"  er/contract-region "-")
+    ("S-SPC"  er/contract-region "-")
+    ("r"  (lambda ()
+            (interactive)
+            (er/contract-region 0))
+     "reset")
+
+    ("i'" er/mark-inside-quotes "in")
+    ("i\"" er/mark-inside-quotes nil)
+    ("o'" er/mark-outside-quotes "out")
+    ("o\"" er/mark-outside-quotes nil)
+
+    ("i{" er/mark-inside-pairs nil)
+    ("i(" er/mark-inside-pairs nil)
+    ("o{" er/mark-inside-pairs nil)
+    ("o(" er/mark-inside-pairs nil)
+
+    ("p"  er/mark-paragraph "paragraph")
+
+    ("l"  sd/mark-line "line")
+    ("u"  er/mark-url "url")
+    ("f"  er/mark-defun "fun")
+    ("n"  er/mark-next-accessor "next")
+
+    ("x" exchange-point-and-mark "exchange")
+
+    ;; Move
+    ;; ("h" backward-char nil)
+    ;; ("j" next-line nil)
+    ;; ("k" previous-line nil)
+    ;; ("l" foreward-char nil)
+
+    ;; Search
+    ;; higlight
+
+    ;; exit
+    ("d" kill-region "delete" :exit t)
+
+    ("y" kill-ring-save "yank" :exit t)
+    ("M-SPC" nil "quit" :exit t)
+    ("C-SPC" nil "quit" :exit t)
+    ("q" nil "quit" :exit t))
+
+  (global-set-key (kbd "M-SPC") (lambda ()
+                                (interactive)
+                                (er/mark-word)
+                                (sd/expand-selected/body)))
+#+END_SRC
+
+*** TODO make expand-region hydra work with lispy selected
+
 * 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=
@@ -2512,35 +2589,14 @@ 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= 
 
-* TODO Questions
-- interactive for anonymous function
-When define a key to a anonymous function, the lambda function should be interactive
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-  ;; (require 'saveplace)
-  ;; (setq-default save-place t)
-  ;; (delete-selection-mode 1)
-#+END_SRC
-
 * key
 - passion
 - vision
 - mission
 
-
 * M prefix
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
 
@@ -2585,5 +2641,3 @@ When define a key to a anonymous function, the lambda function should be interac
   ;; M-b 
 #+END_SRC
 
-* TODO ibuffer hydra
-* TODO expand region action, selected mode map