[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/add-vdiff dcf811e 188/258: Add new on-quit options
From: |
Justin Burkett |
Subject: |
[elpa] scratch/add-vdiff dcf811e 188/258: Add new on-quit options |
Date: |
Wed, 17 May 2017 08:13:48 -0400 (EDT) |
branch: scratch/add-vdiff
commit dcf811e283f441d193ba6d69323de8caa2cf631f
Author: justbur <address@hidden>
Commit: justbur <address@hidden>
Add new on-quit options
Options to restore prior window configuration and kill vdiff buffers on
exit.
---
vdiff.el | 159 +++++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 98 insertions(+), 61 deletions(-)
diff --git a/vdiff.el b/vdiff.el
index 3f1613e..9de8091 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -223,8 +223,10 @@ because those are handled differently.")
window-config
case-args
whitespace-args
- ;; Quit hook
- on-quit)
+ ;; Quit hooks
+ on-quit
+ prior-window-config
+ kill-buffers-on-quit)
;; * Utilities
@@ -1525,14 +1527,18 @@ with non-nil USE-FOLDS."
;; * Session
-(defun vdiff--init-session (buffer-a buffer-b &optional buffer-c on-quit)
+(defun vdiff--init-session
+ (buffer-a buffer-b
+ &optional buffer-c on-quit prior-window-config kill-buffers-on-quit)
(make-vdiff-session
:buffers (vdiff--non-nil-list buffer-a buffer-b buffer-c)
:process-buffer (generate-new-buffer-name " *vdiff* ")
:word-diff-output-buffer (generate-new-buffer-name " *vdiff-word* ")
:case-args ""
:whitespace-args ""
- :on-quit on-quit))
+ :prior-window-config prior-window-config
+ :on-quit on-quit
+ :kill-buffers-on-quit kill-buffers-on-quit))
;; * Entry points
@@ -1559,13 +1565,19 @@ arguments."
horizontal on-quit))
;;;###autoload
-(defun vdiff-buffers (buffer-a buffer-b &optional horizontal on-quit)
+(defun vdiff-buffers
+ (buffer-a buffer-b
+ &optional horizontal on-quit restore-windows-on-quit kill-buffers-on-quit)
"Start a vdiff session. If called interactively, you will be
asked to select two buffers. HORIZONTAL adjusts the buffer's
initial layout. A prefix argument can be used to set this
variable interactively. ON-QUIT is a function to run on exiting
the vdiff session. It is called with the two vdiff buffers as
-arguments."
+arguments. The last two options, RESTORE-WINDOWS-ON-QUIT and
+KILL-BUFFERS-ON-QUIT restore the previous window configuration
+and kill the vdiff buffers after quitting vdiff. Note that if you
+are going to kill the buffers you should probably be using a
+function for ON-QUIT to do something useful with the result."
(interactive
(let* ((buffer-a
(get-buffer
@@ -1578,22 +1590,28 @@ arguments."
(format "[Buffer 1 %s] Buffer 2: " buffer-a)
(window-buffer (next-window (selected-window)))))
current-prefix-arg)))
- (delete-other-windows)
- (switch-to-buffer buffer-a)
- (save-selected-window
- (if horizontal
- (split-window-vertically)
- (split-window-horizontally))
- (switch-to-buffer-other-window buffer-b))
- (setq vdiff--temp-session
- (vdiff--init-session buffer-a buffer-b nil on-quit))
- (dolist (buf (list buffer-a buffer-b))
- (with-current-buffer buf
- (vdiff-mode -1)
- (vdiff-3way-mode -1)
- (vdiff-mode 1)))
- (vdiff-refresh)
- (vdiff-sync-and-center))
+ (let ((prior-window-config (when restore-windows-on-quit
+ (current-window-configuration)))
+ (buffer-a (get-buffer buffer-a))
+ (buffer-b (get-buffer buffer-b)))
+ (delete-other-windows)
+ (switch-to-buffer buffer-a)
+ (save-selected-window
+ (if horizontal
+ (split-window-vertically)
+ (split-window-horizontally))
+ (switch-to-buffer-other-window buffer-b))
+ (setq vdiff--temp-session
+ (vdiff--init-session
+ buffer-a buffer-b nil
+ on-quit prior-window-config kill-buffers-on-quit))
+ (dolist (buf (list buffer-a buffer-b))
+ (with-current-buffer buf
+ (vdiff-mode -1)
+ (vdiff-3way-mode -1)
+ (vdiff-mode 1)))
+ (vdiff-refresh)
+ (vdiff-sync-and-center)))
(defcustom vdiff-3way-layout-function 'vdiff-3way-layout-function-default
"Function to layout windows in 3way diffs"
@@ -1607,11 +1625,17 @@ arguments."
(set-window-buffer (split-window-horizontally) buffer-b))
;;;###autoload
-(defun vdiff-buffers3 (buffer-a buffer-b buffer-c &optional on-quit)
+(defun vdiff-buffers3
+ (buffer-a buffer-b buffer-c
+ &optional on-quit restore-windows-on-quit kill-buffers-on-quit)
"Start a vdiff session. If called interactively, you will be
asked to select two buffers. ON-QUIT is a function to run on
exiting the vdiff session. It is called with the three vdiff
-buffers as arguments."
+buffers as arguments. The last two options, RESTORE-WINDOWS-ON-QUIT and
+KILL-BUFFERS-ON-QUIT restore the previous window configuration
+and kill the vdiff buffers after quitting vdiff. Note that if you
+are going to kill the buffers you should probably be using a
+function for ON-QUIT to do something useful with the result."
(interactive
(let* ((buffer-a
(get-buffer
@@ -1628,16 +1652,23 @@ buffers as arguments."
(format "[1:%s 2:%s] Buffer 3: " buffer-a buffer-b)
(window-buffer (next-window (selected-window)))))))
(list buffer-a buffer-b buffer-c)))
- (funcall vdiff-3way-layout-function buffer-a buffer-b buffer-c)
- (setq vdiff--temp-session
- (vdiff--init-session buffer-a buffer-b buffer-c on-quit))
- (dolist (buf (list buffer-a buffer-b buffer-c))
- (with-current-buffer buf
- (vdiff-mode -1)
- (vdiff-3way-mode -1)
- (vdiff-3way-mode 1)))
- (vdiff-refresh)
- (vdiff-sync-and-center))
+ (let ((prior-window-config (when restore-windows-on-quit
+ (current-window-configuration)))
+ (buffer-a (get-buffer buffer-a))
+ (buffer-b (get-buffer buffer-b))
+ (buffer-c (get-buffer buffer-c)))
+ (funcall vdiff-3way-layout-function buffer-a buffer-b buffer-c)
+ (setq vdiff--temp-session
+ (vdiff--init-session
+ buffer-a buffer-b buffer-c
+ on-quit prior-window-config kill-buffers-on-quit))
+ (dolist (buf (list buffer-a buffer-b buffer-c))
+ (with-current-buffer buf
+ (vdiff-mode -1)
+ (vdiff-3way-mode -1)
+ (vdiff-3way-mode 1)))
+ (vdiff-refresh)
+ (vdiff-sync-and-center)))
;;;###autoload
(defun vdiff-files3 (file-a file-b file-c &optional on-quit)
@@ -1659,24 +1690,39 @@ you will be asked to select two files."
(list file-a file-b file-c)))
(vdiff-buffers3 (find-file-noselect file-a)
(find-file-noselect file-b)
- (find-file-noselect file-c)))
+ (find-file-noselect file-c)
+ on-quit))
-(defvar vdiff-quit-hook nil)
+;; (defvar vdiff-quit-hook nil)
(defun vdiff-quit ()
"Quit `vdiff-mode' and clean up."
(interactive)
(if (null vdiff--session)
(user-error "Not in a vdiff buffer")
- (when (functionp (vdiff-session-on-quit vdiff--session))
- (apply (vdiff-session-on-quit vdiff--session)
- (vdiff-session-buffers vdiff--session)))
- (dolist (buf (vdiff-session-buffers vdiff--session))
- (with-current-buffer buf
- (if vdiff-3way-mode
- (vdiff-3way-mode -1)
- (vdiff-mode -1))))
- (run-hooks 'vdiff-quit-hook)
+ (let ((ses vdiff--session))
+ (when (functionp (vdiff-session-on-quit ses))
+ (apply (vdiff-session-on-quit ses)
+ (vdiff-session-buffers ses)))
+ (dolist (buf (list (vdiff-session-process-buffer
+ ses)
+ (vdiff-session-word-diff-output-buffer
+ ses)))
+ (when (process-live-p (get-buffer-process buf))
+ (kill-process (get-buffer-process buf)))
+ (when (buffer-live-p buf) (kill-buffer buf)))
+ (dolist (buf (vdiff-session-buffers ses))
+ (with-current-buffer buf
+ (if vdiff-3way-mode
+ (vdiff-3way-mode -1)
+ (vdiff-mode -1)))
+ (when (vdiff-session-kill-buffers-on-quit ses)
+ (kill-buffer buf)))
+ ;; (run-hooks 'vdiff-quit-hook)
+ (when (vdiff-session-prior-window-config ses)
+ (set-window-configuration
+ (vdiff-session-prior-window-config ses))))
+ (setq vdiff--session nil)
(message "vdiff exited")))
(defvar vdiff-mode-map
@@ -1717,7 +1763,7 @@ you will be asked to select two files."
(defvar vdiff-scroll-lock-mode)
-(defun vdiff--init ()
+(defun vdiff--buffer-init ()
;; this is a buffer-local var
(setq vdiff--session vdiff--temp-session)
(setq cursor-in-non-selected-windows nil)
@@ -1727,23 +1773,14 @@ you will be asked to select two files."
(setf (vdiff-session-window-config vdiff--session)
(current-window-configuration)))
-(defun vdiff--cleanup ()
+(defun vdiff--buffer-cleanup ()
(vdiff--remove-all-overlays)
(setq cursor-in-non-selected-windows t)
(remove-hook 'after-save-hook #'vdiff-refresh t)
(remove-hook 'after-change-functions #'vdiff--after-change-function t)
(remove-hook 'pre-command-hook #'vdiff--flag-new-command t)
(when vdiff-scroll-lock-mode
- (vdiff-scroll-lock-mode -1))
- (when vdiff--session
- (dolist (buf (list (vdiff-session-process-buffer
- vdiff--session)
- (vdiff-session-word-diff-output-buffer
- vdiff--session)))
- (when (process-live-p (get-buffer-process buf))
- (kill-process (get-buffer-process buf)))
- (when (buffer-live-p buf) (kill-buffer buf))))
- (setq vdiff--session nil))
+ (vdiff-scroll-lock-mode -1)))
(define-minor-mode vdiff-mode
"Minor mode active in a vdiff session involving two
@@ -1753,11 +1790,11 @@ automatically after calling commands like `vdiff-files'
or
`vdiff-buffers'."
nil " vdiff" 'vdiff-mode-map
(cond (vdiff-mode
- (vdiff--init)
+ (vdiff--buffer-init)
(when vdiff-lock-scrolling
(vdiff-scroll-lock-mode 1)))
(t
- (vdiff--cleanup))))
+ (vdiff--buffer-cleanup))))
(define-minor-mode vdiff-3way-mode
"Minor mode active in a vdiff session involving three
@@ -1767,11 +1804,11 @@ automatically after calling commands like
`vdiff-files3' or
`vdiff-buffers3'."
nil " vdiff3" 'vdiff-3way-mode-map
(cond (vdiff-3way-mode
- (vdiff--init)
+ (vdiff--buffer-init)
(when vdiff-lock-scrolling
(vdiff-scroll-lock-mode 1)))
(t
- (vdiff--cleanup))))
+ (vdiff--buffer-cleanup))))
(define-minor-mode vdiff-scroll-lock-mode
"Lock scrolling between vdiff buffers. This minor mode will be
- [elpa] scratch/add-vdiff 905be9c 122/258: Map remove refinements command, (continued)
- [elpa] scratch/add-vdiff 905be9c 122/258: Map remove refinements command, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 717d5b6 121/258: Allow failed line translation, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff b267885 137/258: Merge branch 'gvol-master', Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 8daa391 133/258: Add case and whitespace toggles, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 95a1230 154/258: Fix vscroll bug, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff e556705 151/258: Simplify scroll function, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff f36b6b2 162/258: Fix line-translation error, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 13f553f 163/258: Fix fold logic for diff3, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 88e7f1c 178/258: Remove min-window-width, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 679617c 199/258: Force update of window-start on manual scroll-function, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff dcf811e 188/258: Add new on-quit options,
Justin Burkett <=
- [elpa] scratch/add-vdiff c82f2b5 090/258: Add docs on refinements, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 3fcf4b9 101/258: Fix sign problem in adding hunk overlays, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 9346e46 106/258: Simplify method for setting vscroll, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff c46b76b 111/258: Set window point on scroll, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff fd8c973 109/258: Remove post-command-hook, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 25a7516 128/258: Only run scroll-function once per command, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 25ec344 134/258: Require diff-mode so that diff-mode faces are available, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 371febc 135/258: Add option to automatically refine hunks, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 9b3ffb0 150/258: Don't distiguish exit code 0 from 1, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff d33845c 167/258: Minor change in cleanup, Justin Burkett, 2017/05/17