emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 1c45b29 150/272: ivy-occur-mode: new commands on "j", "k",


From: Oleh Krehel
Subject: [elpa] master 1c45b29 150/272: ivy-occur-mode: new commands on "j", "k", "c"
Date: Mon, 25 Apr 2016 10:13:22 +0000

branch: master
commit 1c45b2940432fa0ee08ec3acfc151e556939308a
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    ivy-occur-mode: new commands on "j", "k", "c"
    
    * ivy.el (ivy-calling): Make variable buffer-local.
    (ivy-occur-toggle-calling): New command bound to "c".
    (ivy-occur-next-line): New command bound to "j".
    (ivy-occur-previous-line): New command bound to "k".
    
    This makes `ivy-occur' much more convenient, instead of "gjgjgjg", just
    "cjjj". Especially good for commands that change the contents of the
    other window, like `describe-function' or `counsel-git-grep'.
    
    Example:
    
    - "C-h f" (`describe-funtion')
    - "run" (`self-insert-command')
    - "C-c C-o" (`ivy-occur'); "C-o u" also works.
    - "cjjjjkkkk"
---
 ivy.el |   33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/ivy.el b/ivy.el
index a09f657..8a72546 100644
--- a/ivy.el
+++ b/ivy.el
@@ -686,7 +686,7 @@ If the text hasn't changed as a result, forward to 
`ivy-alt-done'."
      :dynamic-collection (ivy-state-dynamic-collection ivy-last)
      :caller (ivy-state-caller ivy-last))))
 
-(defvar ivy-calling nil
+(defvar-local ivy-calling nil
   "When non-nil, call the current action when `ivy--index' changes.")
 
 (defun ivy-set-index (index)
@@ -2677,17 +2677,44 @@ buffer would modify `ivy-last'.")
   (let ((map (make-sparse-keymap)))
     (define-key map [mouse-1] 'ivy-occur-click)
     (define-key map (kbd "RET") 'ivy-occur-press)
-    (define-key map (kbd "j") 'next-line)
-    (define-key map (kbd "k") 'previous-line)
+    (define-key map (kbd "j") 'ivy-occur-next-line)
+    (define-key map (kbd "k") 'ivy-occur-previous-line)
     (define-key map (kbd "h") 'backward-char)
     (define-key map (kbd "l") 'forward-char)
     (define-key map (kbd "g") 'ivy-occur-press)
     (define-key map (kbd "a") 'ivy-occur-read-action)
     (define-key map (kbd "o") 'ivy-occur-dispatch)
+    (define-key map (kbd "c") 'ivy-occur-toggle-calling)
     (define-key map (kbd "q") 'quit-window)
     map)
   "Keymap for Ivy Occur mode.")
 
+(defun ivy-occur-toggle-calling ()
+  "Toggle `ivy-calling'."
+  (interactive)
+  (if (setq ivy-calling (not ivy-calling))
+      (progn
+        (setq mode-name "Ivy-Occur [calling]")
+        (ivy-occur-press))
+    (setq mode-name "Ivy-Occur"))
+  (force-mode-line-update))
+
+(defun ivy-occur-next-line (&optional arg)
+  "Move the cursor down ARG lines.
+When `ivy-calling' isn't nil, call `ivy-occur-press'."
+  (interactive "p")
+  (forward-line arg)
+  (when ivy-calling
+    (ivy-occur-press)))
+
+(defun ivy-occur-previous-line (&optional arg)
+  "Move the cursor up ARG lines.
+When `ivy-calling' isn't nil, call `ivy-occur-press'."
+  (interactive "p")
+  (forward-line (- arg))
+  (when ivy-calling
+    (ivy-occur-press)))
+
 (define-derived-mode ivy-occur-mode fundamental-mode "Ivy-Occur"
   "Major mode for output from \\[ivy-occur].
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]