Subject: Re: bug#12159: 24.1.50; vc-dir: Need a way to hide unregistered files

From: Jambunathan K <[email-masked]>
Date: Mon, 13 Aug 2012 23:16:23 +0530

FWIW, I am attaching two patches.  If you want any changes please do it
yourself.

patch-1 :: There is only one command 'x' - which hides state at point.
patch-2 :: `x' hides up-to-date and `C-u x' hides state at point.

Personally, I will go with patch 1.  It is simpler.  No prefix key is
used.

Btw, reviewer who takes infinite time to review could either be a
perfectionist or a procrastinator :-).

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-08-12 22:52:33 +0000
+++ lisp/ChangeLog	2012-08-13 17:26:55 +0000
@@ -1,3 +1,12 @@
+2012-08-13  Jambunathan K  <[email-masked]>
+
+	* vc/vc-dir.el (vc-dir-hide-up-to-date): Remove it.
+	(vc-dir-hide-state): New command.
+	(vc-dir-mode-map): Map key "x" to `vc-dir-hide-state' instead of
+	`vc-dir-hide-up-to-date'.
+	(vc-dir-menu-map): Use `vc-dir-hide-state' instead of
+	`vc-dir-hide-up-to-date'
+
 2012-08-12  Stefan Monnier  <[email-masked]>
 
 	* subr.el (internal--before-with-seleted-window)

=== modified file 'lisp/vc/vc-dir.el'
--- lisp/vc/vc-dir.el	2012-07-11 23:13:41 +0000
+++ lisp/vc/vc-dir.el	2012-08-13 17:32:12 +0000
@@ -123,9 +123,9 @@
       '(menu-item "Refresh" revert-buffer
 		  :enable (not (vc-dir-busy))
 		  :help "Refresh the contents of the directory buffer"))
-    (define-key map [remup]
-      '(menu-item "Hide Up-to-date" vc-dir-hide-up-to-date
-		  :help "Hide up-to-date items from display"))
+    (define-key map [hide]
+      '(menu-item "Hide current state" vc-dir-hide-state
+		  :help "Hide items share current state"))
     ;; Movement.
     (define-key map [sepmv] '("--"))
     (define-key map [next-line]
@@ -271,7 +271,7 @@
     (define-key map [down-mouse-3] 'vc-dir-menu)
     (define-key map [mouse-2] 'vc-dir-toggle-mark)
     (define-key map [follow-link] 'mouse-face)
-    (define-key map "x" 'vc-dir-hide-up-to-date)
+    (define-key map "x" 'vc-dir-hide-state)
     (define-key map [?\C-k] 'vc-dir-kill-line)
     (define-key map "S" 'vc-dir-search) ;; FIXME: Maybe use A like dired?
     (define-key map "Q" 'vc-dir-query-replace-regexp)
@@ -1106,20 +1106,30 @@
   (interactive "fShow file: ")
   (vc-dir-update (list (list (file-relative-name file) (vc-state file))) (current-buffer)))
 
-(defun vc-dir-hide-up-to-date ()
-  "Hide up-to-date items from display."
-  (interactive)
-  (let ((crt (ewoc-nth vc-ewoc -1))
-	(first (ewoc-nth vc-ewoc 0)))
-    ;; Go over from the last item to the first and remove the
-    ;; up-to-date files and directories with no child files.
-    (while (not (eq crt first))
-      (let* ((data (ewoc-data crt))
-	     (dir (vc-dir-fileinfo->directory data))
-	     (next (ewoc-next vc-ewoc crt))
-	     (prev (ewoc-prev vc-ewoc crt))
-	     ;; ewoc-delete does not work without this...
-	     (inhibit-read-only t))
+(defun vc-dir-hide-state (state)
+  "Hide items that are in STATE from display.
+See `vc-state' for valid values of STATE.
+
+Interactively, set STATE to state of item at point."
+  (interactive (list
+		;; Infer STATE from point.  Complain otherwise.
+		(let ((node (ewoc-locate vc-ewoc)))
+		  (unless node (error "No file available"))
+		  (or (vc-dir-fileinfo->state (ewoc-data node))
+		      (error "No state at point")))))
+  (when state
+    (message "Hiding items in state \"%s\"" state)
+    (let ((crt (ewoc-nth vc-ewoc -1))
+	  (first (ewoc-nth vc-ewoc 0)))
+      ;; Go over from the last item to the first and remove the
+      ;; up-to-date files and directories with no child files.
+      (while (not (eq crt first))
+	(let* ((data (ewoc-data crt))
+	       (dir (vc-dir-fileinfo->directory data))
+	       (next (ewoc-next vc-ewoc crt))
+	       (prev (ewoc-prev vc-ewoc crt))
+	       ;; ewoc-delete does not work without this...
+	       (inhibit-read-only t))
 	  (when (or
 		 ;; Remove directories with no child files.
 		 (and dir
@@ -1128,10 +1138,11 @@
 		       (not next)
 		       ;; Next item is a directory.
 		       (vc-dir-fileinfo->directory (ewoc-data next))))
-		 ;; Remove files in the up-to-date state.
-		 (eq (vc-dir-fileinfo->state data) 'up-to-date))
+		 ;; Remove files in specified STATE.  STATE can be a
+		 ;; symbol or a user-name.
+		 (equal (vc-dir-fileinfo->state data) state))
 	    (ewoc-delete vc-ewoc crt))
-	  (setq crt prev)))))
+	  (setq crt prev))))))
 
 (defun vc-dir-kill-line ()
   "Remove the current line from display."

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-08-12 22:52:33 +0000
+++ lisp/ChangeLog	2012-08-13 17:16:15 +0000
@@ -1,3 +1,8 @@
+2012-08-13  Jambunathan K  <[email-masked]>
+
+	* vc/vc-dir.el (vc-dir-hide-state): New command
+	(vc-dir-hide-up-to-date): Route it to `vc-dir-hide-state'.
+
 2012-08-12  Stefan Monnier  <[email-masked]>
 
 	* subr.el (internal--before-with-seleted-window)

=== modified file 'lisp/vc/vc-dir.el'
--- lisp/vc/vc-dir.el	2012-07-11 23:13:41 +0000
+++ lisp/vc/vc-dir.el	2012-08-13 17:12:16 +0000
@@ -1106,9 +1106,22 @@
   (interactive "fShow file: ")
   (vc-dir-update (list (list (file-relative-name file) (vc-state file))) (current-buffer)))
 
-(defun vc-dir-hide-up-to-date ()
-  "Hide up-to-date items from display."
-  (interactive)
+(defun vc-dir-hide-state (&optional state)
+  "Hide items that are in STATE from display.
+See `vc-state' for valid values of STATE.
+
+If STATE is nil, default it to up-to-date.
+
+Interactively, if `current-prefix-arg' is non-nil, set STATE to
+state of item at point.  Otherwise, set STATE to up-to-date."
+  (interactive (list
+		(and current-prefix-arg
+		     ;; Command is prefixed.  Infer STATE from point.
+		     (let ((node (ewoc-locate vc-ewoc)))
+		       (and node (vc-dir-fileinfo->state (ewoc-data node)))))))
+  ;; If STATE is un-specified, use up-to-date.
+  (setq state (or state 'up-to-date))
+  (message "Hiding items in state \"%s\"" state)
   (let ((crt (ewoc-nth vc-ewoc -1))
 	(first (ewoc-nth vc-ewoc 0)))
     ;; Go over from the last item to the first and remove the
@@ -1120,18 +1133,21 @@
 	     (prev (ewoc-prev vc-ewoc crt))
 	     ;; ewoc-delete does not work without this...
 	     (inhibit-read-only t))
-	  (when (or
-		 ;; Remove directories with no child files.
-		 (and dir
-		      (or
-		       ;; Nothing follows this directory.
-		       (not next)
-		       ;; Next item is a directory.
-		       (vc-dir-fileinfo->directory (ewoc-data next))))
-		 ;; Remove files in the up-to-date state.
-		 (eq (vc-dir-fileinfo->state data) 'up-to-date))
-	    (ewoc-delete vc-ewoc crt))
-	  (setq crt prev)))))
+	(when (or
+	       ;; Remove directories with no child files.
+	       (and dir
+		    (or
+		     ;; Nothing follows this directory.
+		     (not next)
+		     ;; Next item is a directory.
+		     (vc-dir-fileinfo->directory (ewoc-data next))))
+	       ;; Remove files in specified STATE.  STATE can be a
+	       ;; symbol or a user-name.
+	       (equal (vc-dir-fileinfo->state data) state))
+	  (ewoc-delete vc-ewoc crt))
+	(setq crt prev)))))
+
+(defalias 'vc-dir-hide-up-to-date 'vc-dir-hide-state)
 
 (defun vc-dir-kill-line ()
   "Remove the current line from display."

>> +	* vc/vc-dir.el (vc-dir-hide-these-states): New custom variable.
>
> Don't bother.  Just always default to up-to-date.
>
>> +(defun vc-dir-hide-some-states (&optional states)
>
> Make it `state' and not a list.
>
>> +  (interactive
>> +   ;; Interactive use.
>
> Redundant comment.
>
>> +  ;; Non-interactive use.
>> +  (unless (called-interactively-p 'any)
>> +    (setq states (or states vc-dir-hide-these-states)))
>
> The test is wrong (it prevents non-interactive use where you specify
> the state explicitly).
> The above should simply be (unless state (setq state 'up-to-date)).
>
>> +(defun vc-dir-hide-up-to-date ()
>> +  "Hide up-to-date items from display."
>> +  (interactive)
>> +  (vc-dir-hide-some-states '("up-to-date")))
>  
> Why bother?
>
>
>         Stefan