emacs-devel
[Top][All Lists]
Advanced

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

vc-revert-buffer and vc-dired-mode


From: Nick Roberts
Subject: vc-revert-buffer and vc-dired-mode
Date: Tue, 12 Dec 2006 17:37:01 +1300 (NZDT)

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 ()




reply via email to

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