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

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

[elpa] scratch/add-vdiff 8daa391 133/258: Add case and whitespace toggle


From: Justin Burkett
Subject: [elpa] scratch/add-vdiff 8daa391 133/258: Add case and whitespace toggles
Date: Wed, 17 May 2017 08:13:38 -0400 (EDT)

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

    Add case and whitespace toggles
---
 README.org | 11 +++++++--
 vdiff.el   | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 81 insertions(+), 5 deletions(-)

diff --git a/README.org b/README.org
index e28b7cf..b5d0af5 100644
--- a/README.org
+++ b/README.org
@@ -79,6 +79,13 @@ the commands would be
 | =C-c o= | =vdiff-open-fold=                  | Open fold at point or in 
region     |
 | =C-c O= | =vdiff-open-all-folds=             | Open all folds in buffer      
      |
 
+*** Ignoring case and whitespace
+
+| Key       | Command                   | Description             |
+|-----------+---------------------------+-------------------------|
+| =C-c i c= | =vdiff-toggle-case=       | Toggle ignoring of case |
+| =C-c i w= | =vdiff-toggle-whitespace= | Toggle ignoring of case |
+
 *** Saving, Updating and Exiting
 
 | Key     | Command                 | Description                  |
@@ -88,8 +95,8 @@ the commands would be
 | (none)  | =vdiff-restore-windows= | Restore window configuration |
 | =C-c q= | =vdiff-quit=            | Quit vdiff                   |
 
-Evil-mode users might prefer something like the following to use =,= as a 
prefix
-in normal state.
+Evil-mode users might prefer something like the following to use a comma as a
+prefix in normal state.
 
 #+BEGIN_SRC emacs-lisp
 (require 'vdiff)
diff --git a/vdiff.el b/vdiff.el
index d1b1e04..3e94a7f 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -183,6 +183,17 @@ because those are handled differently.")
 (defvar vdiff--after-change-refresh-delay 1)
 (defvar vdiff--window-configuration nil)
 (defvar vdiff--new-command nil)
+(defvar vdiff--last-command nil)
+(defvar vdiff--case-args "")
+(defvar vdiff--case-options
+  '(("Don't ignore case" . "")
+    ("Ignore case (-i)" . "-i")))
+(defvar vdiff--whitespace-args "")
+(defvar vdiff--whitespace-options
+  '(("Don't ignore whitespace" . "")
+    ("Ignore all whitespace (-w)" . "-w")
+    ("Ignore space changes (-b)" . "-b")
+    ("Ignore blank lines (-B)" . "-B")))
 
 ;; * Utilities
 
@@ -276,6 +287,32 @@ because those are handled differently.")
        (with-current-buffer buf
          ,@body))))
 
+;; * Toggles
+
+(defun vdiff-toggle-case (command-line-arg)
+  "Toggle ignoring of case in diff command."
+  (interactive
+   (list (cdr-safe
+          (assoc-string
+           (completing-read "Case options: "
+                            vdiff--case-options)
+           vdiff--case-options))))
+  (setq vdiff--case-args command-line-arg)
+  (when vdiff-mode
+    (vdiff-refresh)))
+
+(defun vdiff-toggle-whitespace (command-line-arg)
+  "Toggle ignoring of whitespace in diff command."
+  (interactive
+   (list (cdr-safe
+          (assoc-string
+           (completing-read "Whitespace options: "
+                            vdiff--whitespace-options)
+           vdiff--whitespace-options))))
+  (setq vdiff--whitespace-args command-line-arg)
+  (when vdiff-mode
+    (vdiff-refresh)))
+
 ;; * Main overlay refresh routine
 
 (defun vdiff-refresh ()
@@ -287,6 +324,8 @@ because those are handled differently.")
                          (list
                           vdiff-diff-program
                           vdiff-diff-program-args
+                          vdiff--whitespace-args
+                          vdiff--case-args
                           tmp-a tmp-b)
                          " "))
          (proc (get-buffer-process
@@ -299,6 +338,7 @@ because those are handled differently.")
       (kill-process proc))
     (with-current-buffer (get-buffer-create vdiff--process-buffer)
       (erase-buffer))
+    (setq vdiff--last-command cmd)
     (setq proc (start-process-shell-command
                 vdiff--process-buffer
                 vdiff--process-buffer
@@ -1302,6 +1342,8 @@ asked to select two buffers."
     (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 "ic" 'vdiff-toggle-case)
+    (define-key map "iw" 'vdiff-toggle-whitespace)
     (define-key map "n" 'vdiff-next-hunk)
     (define-key map "N" 'vdiff-next-fold)
     (define-key map "o" 'vdiff-open-fold)
@@ -1369,15 +1411,41 @@ enabled automatically if `vdiff-lock-scrolling' is 
non-nil."
 
 (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
+             "\
+ Toggles"
+             '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))
+
   (defhydra vdiff-hydra (nil nil :hint nil :foreign-keys run)
     (concat (propertize
              "\
  Navigation^^^^          Refine^^   Transmit^^   Folds^^^^            
Other^^^^                 "
              'face 'header-line)
             "
- _n_/_N_ next hunk/fold  _f_ this   _s_ send     _o_/_O_ open (all)   _u_ ^ ^ 
update diff
- _p_/_P_ prev hunk/fold  _F_ all    _r_ receive  _c_/_C_ close (all)  _w_ ^ ^ 
save buffers
- _g_^ ^  switch buffers  _x_ clear  ^ ^          _t_ ^ ^ close other  _q_/_Q_ 
quit hydra/vdiff")
+ _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)
@@ -1395,6 +1463,7 @@ enabled automatically if `vdiff-lock-scrolling' is 
non-nil."
     ("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)))
 



reply via email to

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