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

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

[elpa] scratch/add-vdiff 4dc6c89 077/258: Add next/prev fold commands an


From: Justin Burkett
Subject: [elpa] scratch/add-vdiff 4dc6c89 077/258: Add next/prev fold commands and update hydra
Date: Wed, 17 May 2017 08:13:26 -0400 (EDT)

branch: scratch/add-vdiff
commit 4dc6c892958bf67af40e4cd2237671918f5720ec
Author: justbur <address@hidden>
Commit: justbur <address@hidden>

    Add next/prev fold commands and update hydra
---
 README.org |  9 +++++++++
 vdiff.el   | 58 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/README.org b/README.org
index 7e970c1..36ba57d 100644
--- a/README.org
+++ b/README.org
@@ -45,6 +45,8 @@ the commands would be
 | =C-c g= | =vdiff-goto-corresponding-line= | Jump to the corresponding line 
in the other buffer |
 | =C-c n= | =vdiff-next-change=             | Move to next change in buffer    
                  |
 | =C-c p= | =vdiff-previous-change=         | Move to previous change in 
buffer                  |
+| =C-c N= | =vdiff-next-fold=               | Move to next fold in buffer      
                  |
+| =C-c P= | =vdiff-previous-fold=           | Move to previous fold in buffer  
                  |
 | =C-c r= | =vdiff-receive-changes=         | Receive the corresponding hunk 
from other buffer   |
 | =C-c s= | =vdiff-send-changes=            | Send this hunk (or all in 
region) to other buffer  |
 | =C-c c= | =vdiff-close-fold=              | Close fold at point or in region 
                  |
@@ -54,6 +56,7 @@ the commands would be
 | =C-c w= | =vdiff-save-buffers=            | Save both buffers                
                  |
 | =C-c q= | =vdiff-quit=                    | Quit vdiff                       
                  |
 | =C-l=   | =vdiff-sync-and-center=         | Recenter both buffers at current 
line              |
+| =C-c h= | =vdiff-maybe-hydra=             | Enter vdiff-hydra if defined 
(see below)           |
 
 Evil-mode users might prefer something like the following to use =,= as a 
prefix
 in normal state.
@@ -67,6 +70,12 @@ in normal state.
 To start vdiff, use either =vdiff-files= to select two files or =vdiff-buffers=
 to select two open buffers.
 
+** Hydra (optional)
+
+If the [[https://github.com/abo-abo/hydra][hydra package]] is loaded, 
=vdiff-hydra= is defined to allow quick movement
+and changes to be made in the buffer. By default it lives on the =h= command in
+the prefix map. Bind =vdiff-maybe-hydra= directly to customize this.
+
 ** Further customization
    
 The current customization options and there defaults are
diff --git a/vdiff.el b/vdiff.el
index 6d943a9..24926c7 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -233,6 +233,12 @@ text on the first line, and the width of the buffer."
          (overlay-get ovr 'vdiff-type)
          (not (eq (overlay-get ovr 'vdiff-type) 'fold)))))
 
+(defun vdiff--fold-at-point-p ()
+  (let ((ovr (vdiff--overlay-at-pos)))
+    (and (overlayp ovr)
+         (overlay-get ovr 'vdiff-type)
+         (eq (overlay-get ovr 'vdiff-type) 'fold))))
+
 (defun vdiff--overlays-in-region (beg end)
   (let (ovrs)
     (dolist (ovr (overlays-in beg end))
@@ -850,7 +856,7 @@ folds in the region."
 
 ;; * Movement
 
-(defun vdiff--nth-change (&optional n)
+(defun vdiff--nth-change (&optional n find-folds)
   (let* ((n (or n 1))
          (reverse (< n 0))
          pnt)
@@ -862,7 +868,10 @@ folds in the region."
         ;; Find next overlay
         (while (not (or (and reverse (bobp))
                         (and (not reverse) (eobp))
-                        (vdiff--change-at-point-p)))
+                        (and find-folds
+                             (vdiff--fold-at-point-p))
+                        (and (not find-folds)
+                             (vdiff--change-at-point-p))))
           (setq pnt
                 (goto-char (if reverse
                                (previous-overlay-change pnt)
@@ -881,6 +890,18 @@ folds in the region."
   (let ((count (or (- arg) -1)))
     (goto-char (vdiff--nth-change count))))
 
+(defun vdiff-next-fold (arg)
+  "Jump to next fold in this buffer."
+  (interactive "p")
+  (let ((count (or arg 1)))
+    (goto-char (vdiff--nth-change count t))))
+
+(defun vdiff-previous-fold (arg)
+  "Jump to previous fold in this buffer."
+  (interactive "p")
+  (let ((count (or (- arg) -1)))
+    (goto-char (vdiff--nth-change count t))))
+
 ;; * Entry points
 
 ;;;###autoload
@@ -959,6 +980,8 @@ asked to select two buffers."
     (define-key map "g" 'vdiff-goto-corresponding-line)
     (define-key map "n" 'vdiff-next-change)
     (define-key map "p" 'vdiff-previous-change)
+    (define-key map "N" 'vdiff-next-fold)
+    (define-key map "P" 'vdiff-previous-fold)
     (define-key map "s" 'vdiff-send-changes)
     (define-key map "r" 'vdiff-receive-changes)
     (define-key map "q" 'vdiff-quit)
@@ -967,6 +990,7 @@ asked to select two buffers."
     (define-key map "O" 'vdiff-open-all-folds)
     (define-key map "c" 'vdiff-close-fold)
     (define-key map "C" 'vdiff-close-all-folds)
+    (define-key map "h" 'vdiff-maybe-hydra)
     map))
 
 (defvar vdiff-scroll-lock-mode)
@@ -1021,16 +1045,21 @@ enabled automatically if `vdiff-lock-scrolling' is 
non-nil."
           (remove-hook 'post-command-hook #'vdiff--post-command-hook t))
          (message "Scrolling unlocked"))))
 
-(when (fboundp 'defhydra)
+(defun vdiff--define-hydra ()
+  "Define `vdiff-hydra'"
   (defhydra vdiff-hydra (nil nil :hint nil :foreign-keys run)
-    "
- Navigation^^             Transmit^^        Folds^^^^                Other^^
- -^^-------------------  --^^------------  -^^^^------------------  
--^-^-^-^-------------------
- [_n_] next change        [_s_] send        [_o_/_O_] open (all)     [_u_]^ ^  
update diff
- [_p_] previous change    [_r_] receive     [_c_/_C_] close (all)    [_w_]^ ^  
save buffers
- [_g_] goto corr. line     ^ ^               ^ ^ ^ ^                 [_q_/_Q_] 
quit hydra/vdiff"
+    (concat (propertize
+             "\
+ Navigation^^^^                Transmit^^        Folds^^^^                
Other^^^^                 "
+             'face 'header-line)
+            "
+ [_n_/_N_] next change/fold    [_s_] send        [_o_/_O_] open (all)     
[_u_]^ ^  update diff
+ [_p_/_P_] prev change/fold    [_r_] receive     [_c_/_C_] close (all)    
[_w_]^ ^  save buffers
+ [_g_]^ ^  goto corr. line     ^ ^               ^ ^ ^ ^                  
[_q_/_Q_] quit hydra/vdiff")
     ("n" vdiff-next-change)
     ("p" vdiff-previous-change)
+    ("N" vdiff-next-fold)
+    ("P" vdiff-previous-fold)
     ("g" vdiff-goto-corresponding-line)
     ("s" vdiff-send-changes)
     ("r" vdiff-receive-changes)
@@ -1043,5 +1072,16 @@ enabled automatically if `vdiff-lock-scrolling' is 
non-nil."
     ("q" nil :exit t)
     ("Q" vdiff-quit)))
 
+(defun vdiff-maybe-hydra ()
+  "Call `vdiff-hydra/body' if defined."
+  (interactive)
+  (cond ((fboundp 'vdiff-hydra/body)
+         (call-interactively 'vdiff-hydra/body))
+        ((require 'hydra nil t)
+         (vdiff--define-hydra)
+         (call-interactively 'vdiff-hydra/body))
+        (t
+         (message "hydra package not found."))))
+
 (provide 'vdiff)
 ;;; vdiff.el ends here



reply via email to

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