Emacs - fix ivy swith buffer other window
authorPeng Li <seudut@gmail.com>
Sun, 5 Nov 2017 13:04:45 +0000 (21:04 +0800)
committerPeng Li <seudut@gmail.com>
Sun, 5 Nov 2017 13:04:45 +0000 (21:04 +0800)
emacs.d/config.org
emacs.d/emacs-evil.org

index e8b7f32..a828265 100644 (file)
@@ -729,33 +729,34 @@ let helm windows split inside current window
 #+END_SRC
 
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (ivy-set-actions
+   'projectile-switch-to-buffer
+   '(("j" ivy--switch-buffer-other-window-action "other window" )))
+
+  (ivy-set-actions
+   t
+   '(("q" (lambda (x) (ivy-quit-and-run (message "=="))) "exit")))
+
   (defun sd/swith-buffer-other-window ()
     (interactive)
-    (ivy-set-action (cond ((eq (ivy-state-caller ivy-last) 'ivy-switch-buffer)
-                           'ivy--switch-buffer-other-window-action)
-                          ((eq (ivy-state-caller ivy-last) 'counsel-recentf)
-                           'find-file-other-window)
-                          ((eq (ivy-state-caller ivy-last) 'projectile-find-file)
-                           'projectile-find-file-other-window)
-                          ((eq (ivy-state-caller ivy-last) 'counsel-projectile-find-file)
-                           'counsel-projectile-find-file-action-other-window)
-                          (t
-                           nil)))
+    (ivy-set-action (let ((last (ivy-state-caller ivy-last)))
+                      (cond ((eq last 'ivy-switch-buffer) 'ivy--switch-buffer-other-window-action)
+                            ((eq last 'counsel-recentf) 'find-file-other-window)
+                            ((eq last 'projectile-find-file) 'projectile-find-file-other-window)
+                            ((eq last 'counsel-projectile-find-file) 'counsel-projectile-find-file-action-other-window)
+                            ((eq last 'projectile-switch-to-buffer) 'ivy--switch-buffer-other-window-action)
+                            (t nil))))
     (ivy-done)
     (ivy-shrink-after-dispatching))
 
   (defun sd/exit-ivy-and-swith-to-buffer ()
     "exit ivy complete, and call swith to buffer"
     (interactive)
-    (ivy--exhibit)
-    (ivy-set-action (lambda (buf)
-                      (ivy-switch-buffer)))
-    (when (ivy-read-action)
-      (ivy-done))
-    (ivy-shrink-after-dispatching))
+    (ivy-quit-and-run
+     (ivy-switch-buffer)))
 
   (with-eval-after-load "ivy"
-    (define-key ivy-minibuffer-map (kbd "C-o") 'ivy-dispatching-done)
+    ;; (define-key ivy-minibuffer-map (kbd "C-o") 'ivy-dispatching-done)
     (define-key ivy-minibuffer-map (kbd "C-k") #'sd/swith-buffer-other-window)
     ;; (define-key ivy-minibuffer-map (kbd "M-o") nil)
     (define-key ivy-minibuffer-map (kbd "C-o") #'sd/exit-ivy-and-swith-to-buffer))
@@ -3185,45 +3186,8 @@ We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multi
     :commands (bing-dict-brief))
 #+END_SRC
 
-* Key Bindings
-Here are some global key bindings for basic editting
-** Global key bingding
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-  (global-set-key (kbd "C-h") 'delete-backward-char)
-  (global-set-key (kbd "s-m") 'man)
-  (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
-  (global-set-key (kbd "s-f") 'projectile-find-file)
-  (global-set-key (kbd "s-=") 'text-scale-increase)
-  (global-set-key (kbd "s--") 'text-scale-decrease)
-#+END_SRC
-
-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]]
-
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-  (require 'utilities)
-  (global-set-key (kbd "C-w") 'sd/kill-region-or-backward-kill-word)
-#+END_SRC
-
-
-** 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
+* Project operations - =super=
+** Projectile
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
   (use-package projectile
     :ensure t
@@ -3804,6 +3768,46 @@ Occur search key bindings
 
 *** TODO make expand-region hydra work with lispy selected
 
+* Key Bindings
+Here are some global key bindings for basic editting
+** Global key bingding
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (global-set-key (kbd "C-h") 'delete-backward-char)
+  (global-set-key (kbd "s-m") 'man)
+  (global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
+  ;; project operation
+  (global-set-key (kbd "s-p") 'projectile-switch-project)
+  (global-set-key (kbd "s-p") 'projectile-switch-project)
+  (global-set-key (kbd "s-f") 'projectile-find-file)
+  (global-set-key (kbd "s-=") 'text-scale-increase)
+  (global-set-key (kbd "s--") 'text-scale-decrease)
+#+END_SRC
+
+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]]
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (require 'utilities)
+  (global-set-key (kbd "C-w") 'sd/kill-region-or-backward-kill-word)
+#+END_SRC
+
+
+** 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
+
 * Developing
 ** perspeen
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
index 64a5ec2..d048345 100644 (file)
@@ -120,14 +120,17 @@ https://www.emacswiki.org/emacs/Evil.
   (defun sd/swith-to-buffer ()
     "switch to buffer"
     (interactive)
-    (call-interactively 'projectile-switch-to-buffer))
+    (if (projectile-project-p)
+        (projectile-switch-to-buffer)
+      (ivy-switch-buffer)))
+
+  (ivy-set-actions
+   'sd/swith-to-buffer
+   '(("j" ivy--switch-buffer-other-window-action "other window")))
 
   (with-eval-after-load "evil-leader"
     (cl-loop for (key . fun ) in '(("F" . counsel-projectile-switch-to-buffer)
-                                   ("f" . (lambda () (interactive)
-                                            (call-interactively (if (projectile-project-p)
-                                                                    'projectile-switch-to-buffer
-                                                                  'ivy-switch-buffer))))
+                                   ("f" . sd/swith-to-buffer)
                                    ("b" . counsel-projectile-find-file)
                                    ("r" . ivy-recentf)
                                    ("w" . save-buffer)