[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
- [elpa] scratch/add-vdiff bfdfc74 053/258: Modify gitignore, (continued)
- [elpa] scratch/add-vdiff bfdfc74 053/258: Modify gitignore, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff d25fe21 054/258: More arg name changes, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 875e6ce 057/258: Merge pull request #2 from purcell/patch-1, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 1640078 061/258: Merge remote-tracking branch 'origin/master', Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff c6c959d 071/258: Fix nth-change at beginning and end of buffer, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff d07e9fb 056/258: Fix typo in package description, remove redundant "for Emacs", Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 69c85cb 080/258: Better way to trigger other window update, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff cce8eb1 086/258: Don't close fold on point after change, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 8a88f84 074/258: Use simpler strategy for updating windows on line move, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff c5589a1 089/258: Delete temp files on deactivation, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 4dc6c89 077/258: Add next/prev fold commands and update hydra,
Justin Burkett <=
- [elpa] scratch/add-vdiff 4ea6afb 082/258: Add docstrings and rearrange some calls, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 52c675a 096/258: Add hydra screenshot, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 1276208 103/258: Recenter after next/prev hunk, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 4ee7fca 104/258: Set intangible property for closed folds, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 16eb802 107/258: Update README, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 0dc9fde 114/258: Try not to move point on change transmission, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff cc24574 115/258: Fix scroll update for other subtraction styles, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff c912ebc 120/258: Don't use window-size-change-hook, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 7561f87 100/258: Split line maps, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 32756c3 131/258: A little better than a WIP now, Justin Burkett, 2017/05/17