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

From: Jambunathan K <[email-masked]>
Date: Sun, 12 Aug 2012 16:34:06 +0530

Andreas Schwab <[email-masked]> writes:

> Jambunathan K <[email-masked]> writes:
>
>> Andreas Schwab <[email-masked]> writes:
>>
>>> Jambunathan K <[email-masked]> writes:
>>>
>>>> +(defcustom vc-dir-hide-these-states '("up-to-date")
>>>> +  "States hidden by `vc-dir-hide-some-states'."
>>>> +  :type '(choice
>>>> +	  (const :tag "None")
>>>> +	  (set :tag "Choices"
>>>> +	       (string :tag "VC State" "added")
>>>
>>> Why a string?  Using the symbol would be more natural.
>>
>> There is a note up in the thread, which reads:
>>
>> ,----
>> | 2. Magnus' changes assumes that states are just elisp symbols.  This
>> | may not be true.  In case of locked states - designated as USER in
>> | `vc-state' - the state could actually be a string.
>> `----
>
> There is nothing wrong with using a string where the state is a string.
> But if the user name happens to match the name of one of the state
> symbols it becomes ambigous.

Sure, I will name my next kid `conflict' or even better `missing'.  In
the latter case, I will have hard time reporting to police if he ever
goes missing.

Here comes the modified patch.

I think I am hitting a bug with defcustom and I will open a separte
report for it.  When I do, M-x customize-variable RET
vc-hide-these-states RET, I see two "up-to-date"s and "added" goes
missing.

I will let you folks handle the defcustom issue.

,----
| Operate on all settings in this buffer:
|  Revert...   Apply   Apply and Save 
| 
| Hide Vc Dir Hide These States: Value Menu Choices:
| [X] VC State: up-to-date
| [ ] VC State: conflict
| [ ] VC State: edited
| [ ] VC State: ignored
| [ ] VC State: missing
| [ ] VC State: needs-merge
| [ ] VC State: needs-update
| [ ] VC State: removed
| [ ] VC State: unlocked-changes
| [ ] VC State: unregistered
| [ ] VC State: up-to-date
|     State : STANDARD.
|    States hidden by `vc-dir-hide-some-states'.
| Groups: Vc
`----

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-08-11 04:46:38 +0000
+++ lisp/ChangeLog	2012-08-12 01:44:26 +0000
@@ -1,3 +1,11 @@
+2012-08-12  Jambunathan K  <[email-masked]>
+
+	* vc/vc-dir.el (vc-dir-hide-these-states): New custom variable.
+	(vc-dir-hide-some-states): New command.
+	(vc-dir-hide-up-to-date): Use `vc-dir-hide-some-states'.
+	(vc-dir-mode-map): Map "x" to `vc-dir-hide-some-states' instead of
+	`vc-dir-hide-up-to-date'.
+
 2012-08-11  Glenn Morris  <[email-masked]>
 
 	* emacs-lisp/copyright.el (copyright-update-directory): Logic fix.

=== 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-12 10:47:23 +0000
@@ -51,6 +51,25 @@
   :type 'hook
   :group 'vc)
 
+(defcustom vc-dir-hide-these-states '(up-to-date)
+  "States hidden by `vc-dir-hide-some-states'."
+  :type '(choice
+	  (const :tag "None")
+	  (set :tag "Choices"
+	       (symbol :tag "VC State" added)
+	       (symbol :tag "VC State" conflict)
+	       (symbol :tag "VC State" edited)
+	       (symbol :tag "VC State" ignored)
+	       (symbol :tag "VC State" missing)
+	       (symbol :tag "VC State" needs-merge)
+	       (symbol :tag "VC State" needs-update)
+	       (symbol :tag "VC State" removed)
+	       (symbol :tag "VC State" unlocked-changes)
+	       (symbol :tag "VC State" unregistered)
+	       (symbol :tag "VC State" up-to-date)))
+  :group 'vc
+  :version "24.2")
+
 ;; Used to store information for the files displayed in the directory buffer.
 ;; Each item displayed corresponds to one of these defstructs.
 (cl-defstruct (vc-dir-fileinfo
@@ -271,7 +290,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-some-states)
     (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 +1125,43 @@
   (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-some-states (&optional states)
+  "Hide items that are in STATES from display.
+STATES is a list of vc states (see`vc-state').
+
+If STATES is nil, use `vc-dir-hide-these-states' as default.
+
+In interactive mode, if prefix argument is non-nil or if
+`vc-dir-hide-these-states' is nil, hide items that share the same
+state as file at point."
+  (interactive
+   ;; Interactive use.
+   (list
+    (or (and (not current-prefix-arg) vc-dir-hide-these-states)
+	;; Command is prefixed or `vc-dir-hide-these-states' is nil.
+	;; State to hide, is the one at point.
+	(let ((node (ewoc-locate vc-ewoc)))
+	  (unless node (error "No file available"))
+	  (let* ((data (ewoc-data node))
+		 (state (vc-dir-fileinfo->state data)))
+	    (unless state (error "No state at point"))
+	    (list state))))))
+  ;; Non-interactive use.
+  (unless (called-interactively-p 'any)
+    (setq states (or states vc-dir-hide-these-states)))
+  ;; Hide specified states.
+  (when states
+    (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
@@ -1129,9 +1171,14 @@
 		       ;; 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))
+		 (member (vc-dir-fileinfo->state data) states))
 	    (ewoc-delete vc-ewoc crt))
-	  (setq crt prev)))))
+	  (setq crt prev))))))
+
+(defun vc-dir-hide-up-to-date ()
+  "Hide up-to-date items from display."
+  (interactive)
+  (vc-dir-hide-some-states '(up-to-date)))
 
 (defun vc-dir-kill-line ()
   "Remove the current line from display."

> Andreas.