unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* vc-revert-buffer and vc-dired-mode
@ 2006-12-12  4:37 Nick Roberts
  0 siblings, 0 replies; only message in thread
From: Nick Roberts @ 2006-12-12  4:37 UTC (permalink / raw)



Quite often I'd like to be able to try a multi-file patch and then later revert
it.  I always find it fiddly so I wrote the patch below to try to get
vc-revert-buffer to work with vc-dired-mode.  FATR (for after the release),
of course.  

Posted now for those who like to live in the present.  Its not heavily tested.
It might not work in multiple directories.  Maybe there's already another way
to do this.

-- 
Nick                                           http://www.inet.net.nz/~nickrob


PS It really also needs a command in Emacs to generate all the backup files
automatically when applying the patch (in diff mode?) so that it could all be
done locally.



*** vc.el	21 Oct 2006 08:39:40 +1300	1.423
--- vc.el	12 Dec 2006 17:35:52 +1300	
*************** This asks for confirmation if the buffer
*** 2503,2543 ****
  to that version.  This function does not automatically pick up newer
  changes found in the master file; use \\[universal-argument] \\[vc-next-action] to do so."
    (interactive)
!   (vc-ensure-vc-buffer)
!   ;; Make sure buffer is saved.  If the user says `no', abort since
!   ;; we cannot show the changes and ask for confirmation to discard them.
!   (vc-buffer-sync nil)
!   (let ((file buffer-file-name)
! 	;; This operation should always ask for confirmation.
! 	(vc-suppress-confirm nil)
! 	(obuf (current-buffer))
! 	status)
!     (if (vc-up-to-date-p file)
!         (unless (yes-or-no-p "File seems up-to-date.  Revert anyway? ")
!           (error "Revert canceled")))
!     (unless (vc-workfile-unchanged-p file)
!       (message "Finding changes...")
!       ;; vc-diff selects the new window, which is not what we want:
!       ;; if the new window is on another frame, that'd require the user
!       ;; moving her mouse to answer the yes-or-no-p question.
!       (let* ((vc-disable-async-diff (not vc-allow-async-revert))
!              (win (save-selected-window
!                     (setq status (vc-diff nil t)) (selected-window))))
! 	(vc-exec-after `(message nil))
! 	(when status
! 	  (unwind-protect
! 	      (unless (yes-or-no-p "Discard changes? ")
! 		(error "Revert canceled"))
! 	    (select-window win)
! 	    (if (one-window-p t)
! 		(if (window-dedicated-p (selected-window))
! 		    (make-frame-invisible))
! 	      (delete-window))))))
!     (set-buffer obuf)
!     ;; Do the reverting
!     (message "Reverting %s..." file)
!     (vc-revert-file file)
!     (message "Reverting %s...done" file)))
  
  ;;;###autoload
  (defun vc-update ()
--- 2503,2551 ----
  to that version.  This function does not automatically pick up newer
  changes found in the master file; use \\[universal-argument] \\[vc-next-action] to do so."
    (interactive)
!   (unless vc-dired-mode
!     (vc-ensure-vc-buffer)
!     ;; Make sure buffer is saved.  If the user says `no', abort since
!     ;; we cannot show the changes and ask for confirmation to discard them.
!     (vc-buffer-sync nil))
!   (let* ((vc vc-dired-mode)
! 	 (files (if vc (dired-get-marked-files)
! 		  (list buffer-file-name))))
!     ;; This operation should always ask for confirmation.
!     (dolist (file files)
!       (switch-to-buffer (find-file file))
!       (when vc
! 	(vc-ensure-vc-buffer)
! 	(vc-buffer-sync nil))
!       (let ((vc-suppress-confirm nil)
! 	    (obuf (current-buffer))
! 	    status)
! 	(if (vc-up-to-date-p file)
! 	    (unless (yes-or-no-p "File seems up-to-date.  Revert anyway? ")
! 	      (error "Revert canceled")))
! 	(unless (vc-workfile-unchanged-p file)
! 	  (message "Finding changes...")
! 	  ;; vc-diff selects the new window, which is not what we want:
! 	  ;; if the new window is on another frame, that'd require the user
! 	  ;; moving her mouse to answer the yes-or-no-p question.
! 	  (let* ((vc-disable-async-diff (not vc-allow-async-revert))
! 		 (win (save-selected-window
! 			(setq status (vc-diff nil t)) (selected-window))))
! 	    (vc-exec-after `(message nil))
! 	    (when status
! 	      (unwind-protect
! 		  (unless (yes-or-no-p "Discard changes? ")
! 		    (error "Revert canceled"))
! 		(select-window win)
! 		(if (one-window-p t)
! 		    (if (window-dedicated-p (selected-window))
! 			(make-frame-invisible))
! 		  (delete-window))))))
! 	(set-buffer obuf)
! 	;; Do the reverting
! 	(message "Reverting %s..." file)
! 	(vc-revert-file file)
! 	(message "Reverting %s...done" file))))))
  
  ;;;###autoload
  (defun vc-update ()

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-12-12  4:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-12  4:37 vc-revert-buffer and vc-dired-mode Nick Roberts

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).