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

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

[elpa] scratch/add-vdiff e171b7c 140/258: Depend on hydra


From: Justin Burkett
Subject: [elpa] scratch/add-vdiff e171b7c 140/258: Depend on hydra
Date: Wed, 17 May 2017 08:13:39 -0400 (EDT)

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

    Depend on hydra
    
    It's useful enough to warrant a hard dependency
    
    Fixes #11
---
 README.org |  22 ++++++-------
 vdiff.el   | 104 +++++++++++++++++++++++++++----------------------------------
 2 files changed, 57 insertions(+), 69 deletions(-)

diff --git a/README.org b/README.org
index 48ec131..4cbe9c2 100644
--- a/README.org
+++ b/README.org
@@ -45,13 +45,13 @@ the commands would be
 
 *** Basics
     
-| Key     | Command                            | Description                   
      |
-|---------+------------------------------------+-------------------------------------|
-| =C-c g= | =vdiff-switch-buffer=              | Switch buffers at matching 
line     |
-| =C-c n= | =vdiff-next-hunk=                  | Move to next hunk in buffer   
      |
-| =C-c p= | =vdiff-previous-hunk=              | Move to previous hunk in 
buffer     |
-| =C-c h= | =vdiff-maybe-hydra=                | Enter vdiff-hydra if defined  
      |
-| =C-l=   | =vdiff-sync-and-center=            | Recenter both buffers at this 
line  |
+| Key     | Command                 | Description                        |
+|---------+-------------------------+------------------------------------|
+| =C-c g= | =vdiff-switch-buffer=   | Switch buffers at matching line    |
+| =C-c n= | =vdiff-next-hunk=       | Move to next hunk in buffer        |
+| =C-c p= | =vdiff-previous-hunk=   | Move to previous hunk in buffer    |
+| =C-c h= | =vdiff-hydra/body=      | Enter vdiff-hydra                  |
+| =C-l=   | =vdiff-sync-and-center= | Recenter both buffers at this line |
 
 *** Viewing and Transmitting Changes Between Buffers
 
@@ -107,11 +107,11 @@ prefix in normal state.
 To start vdiff, use either =vdiff-files= to select two files or =vdiff-buffers=
 to select two open buffers.
 
-** Hydra (optional)
+** Hydra
 
-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.
+Using the [[https://github.com/abo-abo/hydra][hydra package]], =vdiff-hydra= 
allows quick movement and changes to be
+made in the buffer. By default it lives on the =h= command in the prefix
+map. Bind =vdiff-hydra/body= directly to customize this key binding.
 
 [[file:img/hydra.png]]
 
diff --git a/vdiff.el b/vdiff.el
index df41f51..aa2ccef 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -6,7 +6,7 @@
 ;; URL: https://github.com/justbur/emacs-vdiff
 ;; Version: 0.1
 ;; Keywords: diff
-;; Package-Requires: ((emacs "24.4"))
+;; Package-Requires: ((emacs "24.4") (hydra "0.13.0"))
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -52,6 +52,7 @@
 (require 'cl-lib)
 (require 'subr-x)
 (require 'diff-mode)
+(require 'hydra)
 
 (defgroup vdiff nil
   "Diff tool that is like vimdiff"
@@ -1349,7 +1350,7 @@ asked to select two buffers."
     (define-key map "f" 'vdiff-refine-this-hunk)
     (define-key map "F" 'vdiff-refine-all-hunks)
     (define-key map "g" 'vdiff-switch-buffer)
-    (define-key map "h" 'vdiff-maybe-hydra)
+    (define-key map "h" 'vdiff-hydra/body)
     (define-key map "ic" 'vdiff-toggle-case)
     (define-key map "iw" 'vdiff-toggle-whitespace)
     (define-key map "n" 'vdiff-next-hunk)
@@ -1417,74 +1418,61 @@ enabled automatically if `vdiff-lock-scrolling' is 
non-nil."
           (remove-hook 'window-scroll-functions #'vdiff--scroll-function t))
          (message "Scrolling unlocked"))))
 
-(defun vdiff--define-hydra ()
-  "Define `vdiff-hydra'"
-  (defun vdiff--current-case ()
-    (if (string= "" vdiff--case-args) "off" "on (-i)"))
-
-  (defun vdiff--current-whitespace ()
-    (pcase vdiff--whitespace-args
-      ("" "off")
-      ("-w" "all (-w)")
-      ("-b" "space changes (-b)")
-      ("-B" "blank lines (-B)")))
-
-  (defhydra vdiff-toggle-hydra (nil nil :hint nil)
-    (concat (propertize
-             "\
+(defun vdiff--current-case ()
+  (if (string= "" vdiff--case-args) "off" "on (-i)"))
+
+(defun vdiff--current-whitespace ()
+  (pcase vdiff--whitespace-args
+    ("" "off")
+    ("-w" "all (-w)")
+    ("-b" "space changes (-b)")
+    ("-B" "blank lines (-B)")))
+
+(defhydra vdiff-toggle-hydra (nil nil :hint nil)
+  (concat (propertize
+           "\
  Toggles"
-             'face 'header-line)
-            "
+           'face 'header-line)
+          "
  _c_ ignore case (current: %s(vdiff--current-case))
  _w_ ignore whitespace (current: %s(vdiff--current-whitespace))
  _q_ back to main hydra")
 
-    ("c" vdiff-toggle-case)
-    ("w" vdiff-toggle-whitespace)
-    ("q" vdiff-hydra/body :exit t))
+  ("c" vdiff-toggle-case)
+  ("w" vdiff-toggle-whitespace)
+  ("q" vdiff-hydra/body :exit t))
 
-  (defhydra vdiff-hydra (nil nil :hint nil :foreign-keys run)
-    (concat (propertize
-             "\
+(defhydra vdiff-hydra (nil nil :hint nil :foreign-keys run)
+  (concat (propertize
+           "\
  Navigation^^^^          Refine^^   Transmit^^   Folds^^^^            
Other^^^^                 "
-             'face 'header-line)
-            "
+           'face 'header-line)
+          "
  _n_/_N_ next hunk/fold  _f_ this   _s_ send     _o_/_O_ open (all)   _i_ ^ ^ 
toggles
  _p_/_P_ prev hunk/fold  _F_ all    _r_ receive  _c_/_C_ close (all)  _u_ ^ ^ 
update diff
  _g_^ ^  switch buffers  _x_ clear  ^ ^          _t_ ^ ^ close other  _w_ ^ ^ 
save buffers
  ^ ^^ ^                  ^ ^        ^ ^          ^ ^ ^ ^              _q_/_Q_ 
quit hydra/vdiff
  ignore case: %s(vdiff--current-case) | ignore whitespace: 
%s(vdiff--current-whitespace)")
-    ("n" vdiff-next-hunk)
-    ("p" vdiff-previous-hunk)
-    ("N" vdiff-next-fold)
-    ("P" vdiff-previous-fold)
-    ("g" vdiff-switch-buffer)
-    ("s" vdiff-send-changes)
-    ("r" vdiff-receive-changes)
-    ("o" vdiff-open-fold)
-    ("O" vdiff-open-all-folds)
-    ("c" vdiff-close-fold)
-    ("C" vdiff-close-all-folds)
-    ("t" vdiff-close-other-folds)
-    ("u" vdiff-refresh)
-    ("w" vdiff-save-buffers)
-    ("f" vdiff-refine-this-hunk)
-    ("F" vdiff-refine-all-hunks)
-    ("x" vdiff-remove-refinements-in-hunk)
-    ("i" vdiff-toggle-hydra/body :exit t)
-    ("q" nil :exit t)
-    ("Q" vdiff-quit :exit t)))
-
-(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."))))
+  ("n" vdiff-next-hunk)
+  ("p" vdiff-previous-hunk)
+  ("N" vdiff-next-fold)
+  ("P" vdiff-previous-fold)
+  ("g" vdiff-switch-buffer)
+  ("s" vdiff-send-changes)
+  ("r" vdiff-receive-changes)
+  ("o" vdiff-open-fold)
+  ("O" vdiff-open-all-folds)
+  ("c" vdiff-close-fold)
+  ("C" vdiff-close-all-folds)
+  ("t" vdiff-close-other-folds)
+  ("u" vdiff-refresh)
+  ("w" vdiff-save-buffers)
+  ("f" vdiff-refine-this-hunk)
+  ("F" vdiff-refine-all-hunks)
+  ("x" vdiff-remove-refinements-in-hunk)
+  ("i" vdiff-toggle-hydra/body :exit t)
+  ("q" nil :exit t)
+  ("Q" vdiff-quit :exit t))
 
 (provide 'vdiff)
 ;;; vdiff.el ends here



reply via email to

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