[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/add-vdiff 30b0f9c 213/258: Add vdiff-magit.el with two fu
From: |
Justin Burkett |
Subject: |
[elpa] scratch/add-vdiff 30b0f9c 213/258: Add vdiff-magit.el with two functions |
Date: |
Wed, 17 May 2017 08:13:54 -0400 (EDT) |
branch: scratch/add-vdiff
commit 30b0f9c499fc6a8ac98986d33120552bc445325f
Author: Justin Burkett <address@hidden>
Commit: Justin Burkett <address@hidden>
Add vdiff-magit.el with two functions
vdiff-magit-stage and vdiff-magit-dwim
---
vdiff-magit.el | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 149 insertions(+)
diff --git a/vdiff-magit.el b/vdiff-magit.el
new file mode 100644
index 0000000..7689244
--- /dev/null
+++ b/vdiff-magit.el
@@ -0,0 +1,149 @@
+;;; vdiff-magit.el --- magit integration for vdiff -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2016 Justin Burkett
+
+;; Author: Justin Burkett <address@hidden>
+;; URL: https://github.com/justbur/emacs-vdiff
+;; Version: 0.1
+;; Keywords: diff
+;; 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
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; A tool like vimdiff for Emacs
+
+;; Contributions and suggestions are very welcome.
+
+;; See https://github.com/justbur/emacs-vdiff for more information
+
+;;; Code:
+
+(require 'vdiff)
+(require 'magit)
+
+;;;###autoload
+(defun vdiff-magit-stage (file)
+ "Stage and unstage changes to FILE using vdiff.
+FILE has to be relative to the top directory of the repository."
+ (interactive
+ (list (magit-completing-read "Selectively stage file" nil
+ (magit-tracked-files) nil nil nil
+ (magit-current-file))))
+ (magit-with-toplevel
+ (let* ((conf (current-window-configuration))
+ (bufA (magit-get-revision-buffer "HEAD" file))
+ (bufB (get-buffer (concat file ".~{index}~")))
+ (bufBrw (and bufB (with-current-buffer bufB (not
buffer-read-only))))
+ (bufC (get-file-buffer file))
+ (fileBufC (or bufC (find-file-noselect file)))
+ (coding-system-for-read
+ (with-current-buffer fileBufC buffer-file-coding-system)))
+ (vdiff-buffers3
+ (or bufA (magit-find-file-noselect "HEAD" file))
+ (with-current-buffer (magit-find-file-index-noselect file t)
+ (setq buffer-read-only nil)
+ (current-buffer))
+ fileBufC
+ (lambda (bufA bufB bufC)
+ (and (buffer-live-p bufB)
+ (buffer-modified-p bufB)
+ (with-current-buffer bufB
+ (magit-update-index)))
+ (and (buffer-live-p bufC)
+ (buffer-modified-p bufC)
+ (with-current-buffer bufC
+ (when (y-or-n-p
+ (format "Save file %s? " buffer-file-name))
+ (save-buffer))))
+ ;; (let ((magit-ediff-previous-winconf ,conf))
+ ;; (run-hooks 'magit-ediff-quit-hook))
+ )
+ nil t))))
+
+;;;###autoload
+(defun vdiff-magit-dwim ()
+ "Compare, stage, or resolve using vdiff if possible.
+
+Falls back to ediff commands. This command tries to guess what
+file, and what commit or range the user wants to compare, stage,
+or resolve using Ediff. It might only be able to guess either
+the file, or range or commit, in which case the user is asked
+about the other. It might not always guess right, in which case
+the appropriate `magit-ediff-*' command has to be used
+explicitly. If it cannot read the user's mind at all, then it
+asks the user for a command to run."
+ (interactive)
+ (magit-section-case
+ (hunk (save-excursion
+ (goto-char (magit-section-start (magit-section-parent it)))
+ (magit-ediff-dwim)))
+ (t
+ (let ((range (magit-diff--dwim))
+ (file (magit-current-file))
+ command revA revB)
+ (pcase range
+ ((and (guard (not magit-ediff-dwim-show-on-hunks))
+ (or `unstaged `staged))
+ (setq command (if (magit-anything-unmerged-p)
+ #'magit-ediff-resolve
+ #'vdiff-magit-stage)))
+ (`unstaged (setq command #'magit-ediff-show-unstaged))
+ (`staged (setq command #'magit-ediff-show-staged))
+ (`(commit . ,value)
+ (setq command #'magit-ediff-show-commit
+ revB value))
+ (`(stash . ,value)
+ (setq command #'magit-ediff-show-stash
+ revB value))
+ ((pred stringp)
+ (-let [(a b) (magit-ediff-compare--read-revisions range)]
+ (setq command #'magit-ediff-compare
+ revA a
+ revB b)))
+ (_
+ (when (derived-mode-p 'magit-diff-mode)
+ (pcase (magit-diff-type)
+ (`committed (-let [(a b) (magit-ediff-compare--read-revisions
+ (car magit-refresh-args))]
+ (setq revA a revB b)))
+ ((guard (not magit-ediff-dwim-show-on-hunks))
+ (setq command #'vdiff-magit-stage))
+ (`unstaged (setq command #'magit-ediff-show-unstaged))
+ (`staged (setq command #'magit-ediff-show-staged))
+ (`undefined (setq command nil))
+ (_ (setq command nil))))))
+ (cond ((not command)
+ (call-interactively
+ (magit-read-char-case
+ "Failed to read your mind; do you want to " t
+ (?c "[c]ommit" 'magit-ediff-show-commit)
+ (?r "[r]ange" 'magit-ediff-compare)
+ (?s "[s]tage" 'vdiff-magit-stage)
+ (?v "resol[v]e" 'magit-ediff-resolve))))
+ ((eq command 'magit-ediff-compare)
+ (apply 'magit-ediff-compare revA revB
+ (magit-ediff-read-files revA revB file)))
+ ((eq command 'magit-ediff-show-commit)
+ (magit-ediff-show-commit revB))
+ ((eq command 'magit-ediff-show-stash)
+ (magit-ediff-show-stash revB))
+ (file
+ (funcall command file))
+ (t
+ (call-interactively command)))))))
+
+(provide 'vdiff-magit)
+;;; vdiff-magit.el ends here
- [elpa] scratch/add-vdiff e8d3d26 236/258: vdiff-magit: Try to switch resolve functions gracefully, (continued)
- [elpa] scratch/add-vdiff e8d3d26 236/258: vdiff-magit: Try to switch resolve functions gracefully, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 7c87360 244/258: vdiff: Add vdiff-current-file, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 8b32329 245/258: vdiff: Filter out killed buffers better, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 8aa5c45 250/258: vdiff-magit: Fix paren, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 466b852 173/258: Fix subtraction overlay addition, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff f3b6cec 179/258: Center on start, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 667a7e4 144/258: Generalize data structures to prepare for diff3, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 059d288 208/258: Update gitignore, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff cfad650 207/258: Provide missing function for emacs-nox users, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff e567468 221/258: vdiff-magit: Port show-working-tree, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 30b0f9c 213/258: Add vdiff-magit.el with two functions,
Justin Burkett <=
- [elpa] scratch/add-vdiff 64430c3 215/258: Cleanup merge, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 19f4616 217/258: vdiff-magit: Port compare and show-commit, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff a81d62a 240/258: README: Update recent changes, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 9be4fe3 066/258: Update install instructions in README, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff eda4b1b 204/258: Force update of window-start in manual calls to scroll func, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 7d60015 201/258: Add some doctrings, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 3037be6 222/258: vdiff-magit: Cleanup references in dwim, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 615e7bd 228/258: vdiff-magit: Fix killing of buffers in stage, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff a040a4b 246/258: vdiff: Add vdiff-merge-conflict, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 7fbb20e 205/258: Nil temp-session after using it, Justin Burkett, 2017/05/17