unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, 34949@debbugs.gnu.org
Subject: bug#34949: 27.0.50; Docstring of `vc-deduce-fileset' incomplete
Date: Wed, 25 Mar 2020 00:16:52 +0200	[thread overview]
Message-ID: <87369xs8zn.fsf@mail.linkov.net> (raw)
In-Reply-To: <44cda45a-db93-f2c1-626d-9ace68cd6fd1@yandex.ru> (Dmitry Gutov's message of "Mon, 16 Mar 2020 22:17:38 +0200")

[-- Attachment #1: Type: text/plain, Size: 1221 bytes --]

>> Maybe it's not working since vc-dir-refresh already doesn't use
>> vc-run-delayed to run vc-dir-refresh-files and vc-dir-update.
>
> I don't know if that's the way to determine this. Doing both calls in the
> callback is a good approach which is easy for vc-dir-refresh to
> take. dired-vc-next-action couldn't do that, so vc-run-delayed could be
> the next best option. Or not, of course.

Actually, vc-run-delayed can't be used because it's fired when the first
vc-process finishes, but vc-dir runs at least 4 processes in sequence.

So the only available callback is in vc-dir-refresh, and only when
`more-to-come' is nil.

> Here's a slight modification: create both the hook and a function inside
> the vc-dir package (let's call it vc-dir-mark-files) which will accept a
> list of file names and mark them. dired-vc-next-action will then call it
> from the hook.

All this works fine with the patch below.  The only part of the patch
that I don't like is too much code in the first part of vc-dir-mark-files
that just resolves discrepancy between Dired and VC-Dir:
dired-get-marked-files returns directory names without the trailing slash,
but vc-dir-fileinfo->name returns directories with the trailing slash.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vc-dir-mark-files.patch --]
[-- Type: text/x-diff, Size: 3749 bytes --]

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 6f50a3da6c..af4d29b556 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -3050,6 +3050,33 @@ dired-show-file-type
 	(backward-delete-char 1))
       (message "%s" (buffer-string)))))
 
+\f
+(declare-function vc-dir-mark-files "vc-dir")
+
+;;;###autoload
+(defun dired-vc-next-action (verbose)
+  "Do the next version control operation on marked files/directories.
+When only files are marked then call `vc-next-action' with the
+same value of the VERBOSE argument.
+When also directories are marked then call `vc-dir' and mark
+the same files/directories in the VC-Dir buffer that were marked
+in the Dired buffer."
+  (interactive "P")
+  (let ((mark-files
+         (let ((marked-files (dired-get-marked-files nil nil nil nil t)))
+           (when (cl-some #'file-directory-p marked-files)
+             marked-files))))
+    (if mark-files
+        (let ((transient-hook (make-symbol "vc-dir-mark-files")))
+          (fset transient-hook
+                (lambda ()
+                  (remove-hook 'vc-dir-refresh-hook transient-hook t)
+                  (vc-dir-mark-files mark-files)))
+          (vc-dir-root)
+          (add-hook 'vc-dir-refresh-hook transient-hook nil t))
+      (vc-next-action verbose))))
+
+\f
 (provide 'dired-aux)
 
 ;; Local Variables:
diff --git a/lisp/dired.el b/lisp/dired.el
index 438f5e7d8b..51aaf6b01d 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1865,6 +1870,7 @@ dired-mode-map
     (define-key map "\177" 'dired-unmark-backward)
     (define-key map [remap undo] 'dired-undo)
     (define-key map [remap advertised-undo] 'dired-undo)
+    (define-key map [remap vc-next-action] 'dired-vc-next-action)
     ;; thumbnail manipulation (image-dired)
     (define-key map "\C-td" 'image-dired-display-thumbs)
     (define-key map "\C-tt" 'image-dired-tag-files)
diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index 38b4937e85..43d4a7843c 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -771,6 +771,28 @@ vc-dir-toggle-mark
   (interactive "e")
   (vc-dir-at-event e (vc-dir-mark-unmark 'vc-dir-toggle-mark-file)))
 
+(defun vc-dir-mark-files (mark-files)
+  (let* ((backend (vc-responsible-backend default-directory))
+         (rootdir (vc-call-backend backend 'root default-directory)))
+    (when (listp mark-files)
+      (setq mark-files (mapcar (lambda (file)
+                                 (file-relative-name
+                                  (if (file-directory-p file)
+                                      (file-name-as-directory file)
+                                    file)
+                                  rootdir))
+                               mark-files)))
+    (vc-dir-unmark-all-files t)
+    (ewoc-map
+     (lambda (filearg)
+       (when (cond ((consp mark-files)
+                    (member (vc-dir-fileinfo->name filearg) mark-files))
+                   ((eq mark-files 'registered)
+                    (memq (vc-dir-fileinfo->state filearg) '(edited added removed))))
+         (setf (vc-dir-fileinfo->marked filearg) t)
+         t))
+     vc-ewoc)))
+
 (defun vc-dir-clean-files ()
   "Delete the marked files, or the current file if no marks.
 The files will not be marked as deleted in the version control
@@ -1193,7 +1215,8 @@ vc-dir-refresh
                    (if remaining
                        (vc-dir-refresh-files
                         (mapcar 'vc-dir-fileinfo->name remaining))
-                     (setq mode-line-process nil))))))))))))
+                     (setq mode-line-process nil)
+                     (run-hooks 'vc-dir-refresh-hook))))))))))))
 
 (defun vc-dir-show-fileentry (file)
   "Insert an entry for a specific file into the current *VC-dir* listing.

  reply	other threads:[~2020-03-24 22:16 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-22 17:50 bug#34949: 27.0.50; Docstring of `vc-deduce-fileset' incomplete Philipp Stephani
2019-10-09 22:40 ` Lars Ingebrigtsen
2019-12-24 19:53   ` Dmitry Gutov
2019-12-24 23:28     ` Juri Linkov
2020-02-17 23:42       ` Juri Linkov
2020-02-18 22:27         ` Dmitry Gutov
2020-02-18 23:36           ` Juri Linkov
2020-02-20 23:14             ` Juri Linkov
2020-02-21  0:22               ` Dmitry Gutov
2020-02-23  0:04                 ` Juri Linkov
2020-02-23  9:01                   ` Dmitry Gutov
2020-02-23 23:25                     ` Juri Linkov
2020-02-24  0:17                       ` Dmitry Gutov
2020-02-25  0:12                         ` Juri Linkov
2020-02-25 10:32                           ` Dmitry Gutov
2020-02-25 21:23                             ` Juri Linkov
2020-02-26 22:49                               ` Dmitry Gutov
2020-02-26 23:46                                 ` Juri Linkov
2020-02-27  7:28                                   ` Dmitry Gutov
2020-02-27 23:15                                     ` Juri Linkov
2020-02-28 19:22                                       ` Dmitry Gutov
2020-02-29 21:25                                         ` Juri Linkov
2020-02-29 22:25                                           ` Dmitry Gutov
2020-03-09 22:55                                             ` Juri Linkov
2020-03-12  0:08                                               ` Dmitry Gutov
2020-03-12  0:41                                                 ` Juri Linkov
2020-03-12 22:43                                                   ` Juri Linkov
2020-03-13 12:11                                                     ` Dmitry Gutov
2020-03-14 23:31                                                       ` Juri Linkov
2020-03-15 21:54                                                         ` Dmitry Gutov
2020-03-15 23:58                                                           ` Juri Linkov
2020-03-16 20:17                                                             ` Dmitry Gutov
2020-03-24 22:16                                                               ` Juri Linkov [this message]
2020-03-25 20:47                                                                 ` Juri Linkov
2020-03-25 21:32                                                                   ` Dmitry Gutov
2020-03-29 22:35                                                                     ` Juri Linkov
2020-03-30 19:53                                                                       ` Dmitry Gutov
2020-03-24 22:36                                                               ` Juri Linkov
2020-03-25 20:59                                                                 ` Juri Linkov
2020-03-25 21:15                                                                   ` Drew Adams
2020-03-25 21:50                                                                     ` Juri Linkov
2020-03-25 22:04                                                                       ` Drew Adams
2020-03-26 23:18                                                                         ` Juri Linkov
2020-03-27 16:11                                                                           ` Drew Adams
2020-03-27 22:41                                                                   ` Dmitry Gutov
2020-03-28 23:54                                                                     ` Juri Linkov
2020-03-29 18:41                                                                       ` Dmitry Gutov
2020-03-29 22:27                                                                         ` Juri Linkov
2020-03-30 20:01                                                                           ` Dmitry Gutov
2020-03-30 22:40                                                                             ` Juri Linkov
2020-03-30 23:22                                                                               ` Dmitry Gutov
2020-03-31  1:02                                                                               ` Drew Adams
2020-04-02 22:08                                                                             ` Juri Linkov
2020-04-03  0:21                                                                               ` Dmitry Gutov
2020-04-03 20:08                                                                               ` Philipp Stephani
2020-04-04 23:37                                                                                 ` Juri Linkov
2020-04-05  9:47                                                                                   ` Philipp Stephani
2020-04-05 23:05                                                                                     ` Juri Linkov
2020-04-09  8:41                                                                                   ` Eli Zaretskii
2020-04-11 23:38                                                                                     ` Juri Linkov
2020-04-12  6:33                                                                                       ` Eli Zaretskii
2020-04-12 23:51                                                                                         ` Juri Linkov
2020-04-13  4:31                                                                                           ` Eli Zaretskii
2020-04-13 23:25                                                                                             ` Juri Linkov
2020-03-25 21:59                                                                 ` Dmitry Gutov
2020-03-26 23:10                                                                   ` Juri Linkov
2020-03-26 23:51                                                                     ` Dmitry Gutov
2020-02-21  0:16             ` Dmitry Gutov
2019-12-25 21:45     ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87369xs8zn.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=34949@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).