emacs-devel
[Top][All Lists]
Advanced

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

some vc-status updates


From: Tom Tromey
Subject: some vc-status updates
Date: Tue, 08 Jan 2008 18:31:18 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.990 (gnu/linux)

This adds a bunch of functionality to vc-status.
Most of the new stuff actually works :).

A few notes:

* I tried to register a new file with svn, but it failed.
  This was reported a few days ago but not fixed.

* vc-diff does not work unless you have a file marked.  Maybe
  vc-status-marked-files should return the current directory in this
  case?

* vc-status-move-to-goal-column is a hack

BTW ewoc is pretty nice.  I think I will switch package.el to use it.


Mostly this was an experiment, to see how easy it would be to turn
vc-status into a pcvs replacement.  It doesn't look super hard, I
guess, though there is still a good amount to do.  In particular:

* Asynchronous operation
* Updates.  Can you do a full-directory update in VC?  Or do we need
  another new backend method?
* A new backend method for "ignore".
* Saving buffers should probably update the vc-status buffer.
* Maybe other places checking vc-dired-mode should check for
  vc-status-mode.

Tom

2008-01-09  Tom Tromey  <address@hidden>

        * vc.el (vc-status-headers): Rename from
        vc-status-insert-headers.  Just return header.
        (vc-status-move-to-goal-column): New function.
        (vc-status-mode-map): Define more keys.
        (vc-status-mode): Use vc-status-refresh.  Now 'special.
        (vc-status-refresh): New function.
        (vc-status-next-line): Likewise.
        (vc-status-previous-line): Likewise.
        (vc-status-mark-file): Use vc-status-next-line.
        (vc-status-unmark-file): Use vc-status-previous-line.
        (vc-status-unmark-file-up): New function.
        (vc-status-register): Likewise.
        (vc-status-find-file): Likewise.
        (vc-status-find-file-other-window): Likewise.
        (vc-status-current-file): Likewise.
        (vc-ensure-vc-buffer): Understand vc-status mode.

Index: vc.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/vc.el,v
retrieving revision 1.508
diff -u -c -r1.508 vc.el
cvs diff: conflicting specifications of output style
*** vc.el       6 Jan 2008 16:02:38 -0000       1.508
--- vc.el       9 Jan 2008 01:56:25 -0000
***************
*** 1307,1314 ****
  
  (defun vc-ensure-vc-buffer ()
    "Make sure that the current buffer visits a version-controlled file."
!   (if vc-dired-mode
!       (set-buffer (find-file-noselect (dired-get-filename)))
      (while (and vc-parent-buffer
                  (buffer-live-p vc-parent-buffer)
                ;; Avoid infinite looping when vc-parent-buffer and
--- 1307,1318 ----
  
  (defun vc-ensure-vc-buffer ()
    "Make sure that the current buffer visits a version-controlled file."
!   (cond
!    (vc-dired-mode
!     (set-buffer (find-file-noselect (dired-get-filename))))
!    ((eq major-mode 'vc-status-mode)
!     (set-buffer (find-file-noselect (vc-status-current-file))))
!    (t
      (while (and vc-parent-buffer
                  (buffer-live-p vc-parent-buffer)
                ;; Avoid infinite looping when vc-parent-buffer and
***************
*** 1318,1324 ****
      (if (not buffer-file-name)
        (error "Buffer %s is not associated with a file" (buffer-name))
        (if (not (vc-backend buffer-file-name))
!         (error "File %s is not under version control" buffer-file-name)))))
  
  ;;; Support for the C-x v v command.  This is where all the 
single-file-oriented
  ;;; code from before the fileset rewrite lives.
--- 1322,1328 ----
      (if (not buffer-file-name)
        (error "Buffer %s is not associated with a file" (buffer-name))
        (if (not (vc-backend buffer-file-name))
!         (error "File %s is not under version control" buffer-file-name))))))
  
  ;;; Support for the C-x v v command.  This is where all the 
single-file-oriented
  ;;; code from before the fileset rewrite lives.
***************
*** 2512,2530 ****
  
  (defvar vc-status nil)
  
! (defun vc-status-insert-headers (backend dir)
!   (insert (format "VC backend :%s\n" backend))
!   (insert "Repository : The repository goes here\n")
!   (insert (format "Working dir: %s\n\n\n" dir)))
  
  (defun vc-status-printer (fileentry)
    "Pretty print FILEENTRY."
    (insert
     (format "%c   %-20s %s"
           (if (vc-status-fileinfo->marked fileentry) ?* ? )
           (vc-status-fileinfo->state fileentry)
           (vc-status-fileinfo->name fileentry))))
  
  (defun vc-status (dir)
    "Show the VC status for DIR."
    (interactive "DVC status for directory: ")
--- 2518,2543 ----
  
  (defvar vc-status nil)
  
! (defun vc-status-headers (backend dir)
!   (concat
!    (format "VC backend : %s\n" backend)
!    "Repository : The repository goes here\n"
!    (format "Working dir: %s\n" dir)))
  
  (defun vc-status-printer (fileentry)
    "Pretty print FILEENTRY."
    (insert
+    ;; If you change this, change vc-status-move-to-goal-column.
     (format "%c   %-20s %s"
           (if (vc-status-fileinfo->marked fileentry) ?* ? )
           (vc-status-fileinfo->state fileentry)
           (vc-status-fileinfo->name fileentry))))
  
+ (defun vc-status-move-to-goal-column ()
+   (beginning-of-line)
+   ;; Must be in sync with vc-status-printer.
+   (forward-char 25))
+ 
  (defun vc-status (dir)
    "Show the VC status for DIR."
    (interactive "DVC status for directory: ")
***************
*** 2534,2542 ****
    (vc-status-mode))
  
  (defvar vc-status-mode-map 
!   (let ((map (make-sparse-keymap)))
      (define-key map "m" 'vc-status-mark-file)
      (define-key map "u" 'vc-status-unmark-file)
      map)
    "Keymap for VC status")
  
--- 2547,2576 ----
    (vc-status-mode))
  
  (defvar vc-status-mode-map 
!   (let ((map (make-keymap)))
!     (suppress-keymap map)
!     ;; Marking.
      (define-key map "m" 'vc-status-mark-file)
      (define-key map "u" 'vc-status-unmark-file)
+     (define-key map "\C-?" 'vc-status-unmark-file-up)
+     ;; Movement.
+     (define-key map "n" 'vc-status-next-line)
+     (define-key map " " 'vc-status-next-line)
+     (define-key map "\t" 'vc-status-next-line)
+     (define-key map "p" 'vc-status-previous-line)
+     (define-key map [backtab] 'vc-status-previous-line)
+     ;; VC commands.
+     (define-key map "=" 'vc-diff)
+     (define-key map "a" 'vc-status-register)
+     ;; Can't be "g" (as in vc map), so "A" for "Annotate".
+     (define-key map "A" 'vc-annotate)
+     ;; vc-print-log uses the current buffer, not a file.
+     ;; (define-key map "l" 'vc-status-print-log)
+     ;; The remainder.
+     (define-key map "f" 'vc-status-find-file)
+     (define-key map "o" 'vc-status-find-file-other-window)
+     (define-key map "q" 'bury-buffer)
+     (define-key map "g" 'vc-status-refresh)
      map)
    "Keymap for VC status")
  
***************
*** 2552,2581 ****
        entries)
      (erase-buffer)
      (set (make-local-variable 'vc-status)
!        (ewoc-create #'vc-status-printer))
!     (vc-status-insert-headers backend default-directory)
!     (setq entries (vc-call-backend backend 'dir-status default-directory))
!     (dolist (entry entries)
!       (ewoc-enter-last 
!        vc-status (vc-status-create-fileinfo (cdr entry) (car entry))))))
  
  (defun vc-status-mark-file ()
!   "Mark the current file."
    (interactive)
    (let* ((crt (ewoc-locate vc-status))
           (file (ewoc-data crt)))
      (setf (vc-status-fileinfo->marked file) t)
      (ewoc-invalidate vc-status crt)
!     (ewoc-goto-next vc-status 1)))
  
  (defun vc-status-unmark-file ()
!   "Mark the current file."
    (interactive)
    (let* ((crt (ewoc-locate vc-status))
           (file (ewoc-data crt)))
      (setf (vc-status-fileinfo->marked file) nil)
      (ewoc-invalidate vc-status crt)
!     (ewoc-goto-next vc-status 1)))
  
  (defun vc-status-marked-files ()
    "Return the list of marked files"
--- 2586,2675 ----
        entries)
      (erase-buffer)
      (set (make-local-variable 'vc-status)
!        (ewoc-create #'vc-status-printer
!                     (vc-status-headers backend default-directory)))
!     (vc-status-refresh)))
! 
! (put 'vc-status-mode 'mode-class 'special)
! 
! (defun vc-status-refresh ()
!   "Refresh the contents of the VC status buffer."
!   (interactive)
!   ;; This is not very efficient; ewoc could use a new function here.
!   (ewoc-filter vc-status (lambda (node) nil))
!   (let ((backend (vc-responsible-backend default-directory)))
!     (dolist (entry (vc-call-backend backend 'dir-status default-directory))
!       (ewoc-enter-last vc-status
!                      (vc-status-create-fileinfo (cdr entry) (car entry)))))
!   (ewoc-goto-node vc-status (ewoc-nth vc-status 0)))
! 
! (defun vc-status-next-line (arg)
!   "Go to the next line.
! If a prefix argument is given, move by that many lines."
!   (interactive "p")
!   (ewoc-goto-next vc-status arg)
!   (vc-status-move-to-goal-column))
! 
! (defun vc-status-previous-line (arg)
!   "Go to the previous line.
! If a prefix argument is given, move by that many lines."
!   (interactive "p")
!   (ewoc-goto-prev vc-status arg)
!   (vc-status-move-to-goal-column))
  
  (defun vc-status-mark-file ()
!   "Mark the current file and move to the next line."
    (interactive)
    (let* ((crt (ewoc-locate vc-status))
           (file (ewoc-data crt)))
      (setf (vc-status-fileinfo->marked file) t)
      (ewoc-invalidate vc-status crt)
!     (vc-status-next-line 1)))
  
  (defun vc-status-unmark-file ()
!   "Unmark the current file and move to the next line."
    (interactive)
    (let* ((crt (ewoc-locate vc-status))
           (file (ewoc-data crt)))
      (setf (vc-status-fileinfo->marked file) nil)
      (ewoc-invalidate vc-status crt)
!     (vc-status-next-line 1)))
! 
! (defun vc-status-unmark-file-up ()
!   "Move to the previous line and unmark the file."
!   (interactive)
!   ;; If we're on the first line, we won't move up, but we will still
!   ;; remove the mark.  This seems a bit odd but it is what buffer-menu
!   ;; does.
!   (let* ((prev (ewoc-goto-prev vc-status 1))
!        (file (ewoc-data prev)))
!     (setf (vc-status-fileinfo->marked file) nil)
!     (ewoc-invalidate vc-status prev)
!     (vc-status-move-to-goal-column)))
! 
! (defun vc-status-register ()
!   "Register the marked files, or the current file if no marks."
!   (interactive)
!   (let ((files (or (vc-status-marked-files)
!                  (list (vc-status-current-file)))))
!     (dolist (file files)
!       (vc-register file))))
! 
! (defun vc-status-find-file ()
!   "Find the file on the current line."
!   (interactive)
!   (find-file (vc-status-current-file)))
! 
! (defun vc-status-find-file-other-window ()
!   "Find the file on the current line, in another window."
!   (interactive)
!   (find-file-other-window (vc-status-current-file)))
! 
! (defun vc-status-current-file ()
!   (let ((node (ewoc-locate vc-status)))
!     (unless node
!       (error "No file available."))
!     (expand-file-name (vc-status-fileinfo->name (ewoc-data node)))))
  
  (defun vc-status-marked-files ()
    "Return the list of marked files"




reply via email to

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