GNU bug report logs - #61449
30.0.50; diff-hl-dired: Consider adding a cookie to diff-hl-dired overlay

Previous Next

Package: emacs;

Reported by: Ramesh Nedunchezian <rameshnedunchezian <at> outlook.com>

Date: Sun, 12 Feb 2023 05:38:02 UTC

Severity: normal

Found in version 30.0.50

To reply to this bug, email your comments to 61449 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#61449; Package emacs. (Sun, 12 Feb 2023 05:38:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ramesh Nedunchezian <rameshnedunchezian <at> outlook.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 12 Feb 2023 05:38:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ramesh Nedunchezian <rameshnedunchezian <at> outlook.com>
To: bug-gnu-emacs <at> gnu.org, ", dgutov"@yandex.ru
Subject: 30.0.50; diff-hl-dired: Consider adding a cookie to diff-hl-dired
 overlay
Date: Sun, 12 Feb 2023 11:02:16 +0530
[Message part 1 (text/plain, inline)]
Would you mind adding a cookie to the overlay in
`diff-hl-dired-highlight-items`.

    (overlay-put o 'diff-hl-dired-cookie type)

If this cookie is available, I can use it in the following ways.

1. Mark the files based on vc state.  See command
   `diff-hl-dired-mark-vc-states` and the associated screenshot `M-x
   diff-hl-dired-mark-vc-states.png`.

2. Fontify the file names based on vc state.  See command
   `diff-hl-dired-fontify` and the associated screenshot `M-x
   diff-hl-dired-fontify.png`.

   
In a sense, (1) is a GOOD---this is subjective, ofcourse---one other
way of fontifying a dired lines on vc state.

- diff-hl-dired-mode :: Put the vc state in indicator in fringe
- diff-hl-margin-mode ::  Put the vc state in margin
- diff-hl-inline-mode(?) :: Put the vc state right on the file name or
  the dired line.  


I only need the cookie, and NOT the commands that I have attached.
Bonus points if you introduce some variation of my custom command in
the library.

----------------

Backstory: Yesterday, I was cleaning up a repo which I had been
working on-and-off for the last few years.  Even though it was version
controlled, there were lots of artifacts which were never checked in.
I was apprehensive that could be some interesting titbits in the
"unknown" file.  And there were quite a good number of "unknown" files
.... and I found `M-x vc-dired` too wordy, and distracting.

----------------

Remarks, and possible areas of improvement:

1. `diff-hl-dired-mode` kicks of an async process, and I wanted some
   visual indication that the async process has finished, and I am
   seeing ALL OF the unknown files.  I would have appreciated an echo
   area message, or a mode line indicator that the process has
   finished.

2. `C-x v d` recursively lists all "unregistered" files, but
   `diff-hl-dired-mode` lists only the entries in current directory.

    I would have appreciated an option to do a recursive listing of
   files ....

----------------

(require 'dash)
(require 'diff-hl-dired)

(add-hook 'dired-mode-hook
          'diff-hl-dired-mode)

(add-hook 'dired-mode-hook
          'dired-hide-details-mode)

(custom-set-faces
 '(diff-hl-dired-change ((t (:foreground "orange"))))
 '(diff-hl-dired-delete ((t (:foreground "red"))))
 '(diff-hl-dired-ignored ((t (:inherit dired-ignored :foreground "grey50"))))
 '(diff-hl-dired-insert ((t (:foreground "green"))))
 '(diff-hl-dired-unknown ((t (:inherit dired-ignored :foreground "grey75")))))

(defvar diff-hl-dired-types
  (->> (my-get-faces-matching-regexp "^diff-hl-dired-")
       (--map (->> it
                   symbol-name
                   (replace-regexp-in-string "^diff-hl-dired-" "")
                   intern))
       (cons nil)))

(defun diff-hl-dired-mark-vc-states (types)
  (interactive
   (->> (completing-read-multiple "VC State: "
                                  diff-hl-dired-types
                                  nil t)
        (-map #'intern)
        list))
  (when types
    (dired-mark-if
     (memq
      (when-let* ((diff-hl-overlay
                   (->> (overlays-in
                         (line-beginning-position)
                         (line-end-position))
                        (--filter (overlay-get it 'diff-hl))
                        car)))
        (overlay-get diff-hl-overlay 'diff-hl-dired-cookie))
      types)
     (format "files in vc-states `%s'"
             (string-join (mapcar #'symbol-name types) ",")))))

(defun dired-walk (f)
  (let ((beg (point-min))
        (end (point-max)))
    (save-excursion
      (goto-char beg)
      (while (< (point) end)
        (funcall f)
        (forward-line 1)))))

(defun diff-hl-dired-fontify ()
  (interactive)
  (dired-walk
   (lambda ()
     (when-let* ((diff-hl-overlay
                  (->> (overlays-in
                        (line-beginning-position)
                        (line-end-position))
                       (--filter (overlay-get it 'diff-hl))
                       car))
                 (cookie (overlay-get diff-hl-overlay 'diff-hl-dired-cookie)))
       (overlay-put (make-overlay (line-beginning-position) (line-end-position))
                    'face (diff-hl-dired-face-from-type cookie 'ignored))))))



[Message part 2 (text/html, inline)]
[M-x diff-hl-dired-mark-vc-states.png (image/png, attachment)]
[M-x diff-hl-dired-fontify.png (image/png, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61449; Package emacs. (Sun, 12 Feb 2023 05:43:02 GMT) Full text and rfc822 format available.

Message #8 received at 61449 <at> debbugs.gnu.org (full text, mbox):

From: Ramesh Nedunchezian <rameshnedunchezian <at> outlook.com>
To: 61449 <at> debbugs.gnu.org
Cc: dgutov <at> yandex.ru
Subject: Re: bug#61449: Acknowledgement (30.0.50; diff-hl-dired: Consider
 adding a cookie to diff-hl-dired overlay)
Date: Sun, 12 Feb 2023 11:11:37 +0530
Courtesy copy to the author of `diff-hl`






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61449; Package emacs. (Sun, 12 Feb 2023 06:35:01 GMT) Full text and rfc822 format available.

Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ramesh Nedunchezian <rameshnedunchezian <at> outlook.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: 30.0.50; diff-hl-dired: Consider adding a cookie to diff-hl-dired
 overlay
Date: Sun, 12 Feb 2023 12:04:09 +0530
[Message part 1 (text/plain, inline)]
On 12/02/23 11:02, Ramesh Nedunchezian wrote:
> (defvar diff-hl-dired-types
>   (->> (my-get-faces-matching-regexp "^diff-hl-dired-")
>        (--map (->> it
>                    symbol-name
>                    (replace-regexp-in-string "^diff-hl-dired-" "")
>                    intern))
>        (cons nil)))
>
I forgot this fragment

    (defun my-get-faces-matching-regexp (regexp)
      (cl-loop for sym being the symbols
               when (facep sym)
               when (string-match-p regexp (format "%s" sym))
               collect sym))

or you can do this

    (setq diff-hl-dired-types
          '(nil insert delete unknown ignored change))



[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61449; Package emacs. (Sun, 12 Feb 2023 13:13:02 GMT) Full text and rfc822 format available.

Message #14 received at 61449 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Ramesh Nedunchezian <rameshnedunchezian <at> outlook.com>, 61449 <at> debbugs.gnu.org
Subject: Re: bug#61449: 30.0.50; diff-hl-dired: Consider adding a cookie to
 diff-hl-dired overlay
Date: Sun, 12 Feb 2023 15:12:27 +0200
On 12/02/2023 07:32, Ramesh Nedunchezian wrote:
> 1. `diff-hl-dired-mode` kicks of an async process, and I wanted some
>     visual indication that the async process has finished, and I am
>     seeing ALL OF the unknown files.  I would have appreciated an echo
>     area message, or a mode line indicator that the process has
>     finished.

I was worried it could be too distracting, to show that every time one 
enters a directory. Perhaps a user option could be added.

> 2. `C-x v d` recursively lists all "unregistered" files, but
>     `diff-hl-dired-mode` lists only the entries in current directory.
> 
>      I would have appreciated an option to do a recursive listing of
>     files ....

I'm pretty sure the unregistered files are mentioned recursively. But 
the indicator is put on the containing directory. How else would we do that?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61449; Package emacs. (Sun, 12 Feb 2023 13:13:02 GMT) Full text and rfc822 format available.

Message #17 received at 61449 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Ramesh Nedunchezian <rameshnedunchezian <at> outlook.com>, 61449 <at> debbugs.gnu.org
Subject: Re: bug#61449: 30.0.50; diff-hl-dired: Consider adding a cookie to
 diff-hl-dired overlay
Date: Sun, 12 Feb 2023 15:12:37 +0200
Hi!

On 12/02/2023 07:32, Ramesh Nedunchezian wrote:
>        (when-let* ((diff-hl-overlay
>                     (->> (overlays-in
>                           (line-beginning-position)
>                           (line-end-position))
>                          (--filter (overlay-get it 'diff-hl))
>                          car)))
>          (overlay-get diff-hl-overlay 'diff-hl-dired-cookie))

Why do you need a cookie here?

IIUC all such overlays (with 'diff-hl' property) inside Dired buffers 
are relevant.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61449; Package emacs. (Mon, 13 Feb 2023 11:20:01 GMT) Full text and rfc822 format available.

Message #20 received at 61449 <at> debbugs.gnu.org (full text, mbox):

From: Ramesh Nedunchezian <rameshnedunchezian <at> outlook.com>
To: Dmitry Gutov <dgutov <at> yandex.ru>, 61449 <at> debbugs.gnu.org
Subject: Re: bug#61449: 30.0.50; diff-hl-dired: Consider adding a cookie to
 diff-hl-dired overlay
Date: Mon, 13 Feb 2023 16:49:35 +0530
[Message part 1 (text/plain, inline)]
On 12/02/23 18:42, Dmitry Gutov wrote:
> Hi!
>
> On 12/02/2023 07:32, Ramesh Nedunchezian wrote:
>>        (when-let* ((diff-hl-overlay
>>                     (->> (overlays-in
>>                           (line-beginning-position)
>>                           (line-end-position))
>>                          (--filter (overlay-get it 'diff-hl))
>>                          car)))
>>          (overlay-get diff-hl-overlay 'diff-hl-dired-cookie))
>
> Why do you need a cookie here?
>
> IIUC all such overlays (with 'diff-hl' property) inside Dired buffers are relevant.


I have attached screenshots on what I could achieve with the cookie.
I have also provided recipes for how the cookie could be used.

----------------

The information I am looking for is vc state, and it is buried too
deep inside.

Let me elaborate ... if I eval the form you have quoted above, I would
get

    (setq x '(modification-hooks
              (diff-hl-overlay-modified)
              diff-hl-dired-cookie change before-string
              #(" " 0 1
                (display
                 ((left-fringe exclamation-mark diff-hl-dired-change))))
              diff-hl t))


Note that the `diff-hl-dired-cookie` is added by me, and
`diff-hl-dired` adds the follwing properties
          

- `diff-hl-dired-cookie` :: This is added by me, and contains the vc
  state.
- `diff-hl` :: This is added by `diff-hl-dired`, and `t` isn't much
  useful for the task I have hand.
- `before-string` :: This is added by `diff-hl-dired`, and the vc
  state is avaiable as a face property.

  If I have to get to that property, this is the kind of manoeuvre I
  need to do

    (->> x
         (memq 'before-string)
         cadr
         (get-text-property 0 'display)
         car
         (-filter 'facep)
         car)

If you add a cookie, I can do whatever with it. 

Mind you ... I am not saying the relevant information is /not/ there; 
I am only saying that it is buried too deep, and not readily accessible.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61449; Package emacs. (Mon, 13 Feb 2023 11:33:02 GMT) Full text and rfc822 format available.

Message #23 received at 61449 <at> debbugs.gnu.org (full text, mbox):

From: Ramesh Nedunchezian <rameshnedunchezian <at> outlook.com>
To: Dmitry Gutov <dgutov <at> yandex.ru>, 61449 <at> debbugs.gnu.org
Subject: Re: bug#61449: 30.0.50; diff-hl-dired: Consider adding a cookie to
 diff-hl-dired overlay
Date: Mon, 13 Feb 2023 17:02:19 +0530
On 12/02/23 18:42, Dmitry Gutov wrote:
> On 12/02/2023 07:32, Ramesh Nedunchezian wrote:
>> 1. `diff-hl-dired-mode` kicks of an async process, and I wanted some
>>     visual indication that the async process has finished, and I am
>>     seeing ALL OF the unknown files.  I would have appreciated an echo
>>     area message, or a mode line indicator that the process has
>>     finished.
>
> I was worried it could be too distracting, to show that every time one enters a directory. Perhaps a user option could be added.


>
>> 2. `C-x v d` recursively lists all "unregistered" files, but
>>     `diff-hl-dired-mode` lists only the entries in current directory.
>>
>>      I would have appreciated an option to do a recursive listing of
>>     files ....
>
> I'm pretty sure the unregistered files are mentioned recursively. But the indicator is put on the containing directory. How else would we do that?


`vc-dired` does what I want, but the annotation added by `vc-dired` `unregistered` etc were too distracting. 

If you look at the screenshots  I shared, you will see that the file names are fontified based on their vc state.

There is also a command to mark files by their state, and I can bulk delete, move or commit the files.

So, task I had is already accomplished with recipes I shared ... and I felt that enhancing `diff-hl-dired` could be generally useful.






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61449; Package emacs. (Sat, 18 Feb 2023 23:26:01 GMT) Full text and rfc822 format available.

Message #26 received at 61449 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Ramesh Nedunchezian <rameshnedunchezian <at> outlook.com>, 61449 <at> debbugs.gnu.org
Subject: Re: bug#61449: 30.0.50; diff-hl-dired: Consider adding a cookie to
 diff-hl-dired overlay
Date: Sun, 19 Feb 2023 01:25:50 +0200
Hi again!

On 13/02/2023 13:19, Ramesh Nedunchezian wrote:
> - `diff-hl-dired-cookie` :: This is added by me, and contains the vc
>    state.
> - `diff-hl` :: This is added by `diff-hl-dired`, and `t` isn't much
>    useful for the task I have hand.
> - `before-string` :: This is added by `diff-hl-dired`, and the vc
>    state is avaiable as a face property.
> 
>    If I have to get to that property, this is the kind of manoeuvre I
>    need to do
> 
>      (->> x
>           (memq 'before-string)
>           cadr
>           (get-text-property 0 'display)
>           car
>           (-filter 'facep)
>           car)
> 
> If you add a cookie, I can do whatever with it.
> 
> Mind you ... I am not saying the relevant information is /not/ there;
> I am only saying that it is buried too deep, and not readily accessible.

Thank you for the extra clarification.

I've added a new overlay property 'diff-hl-dired-type' in 
https://github.com/dgutov/diff-hl/commit/d20f16bf5eadd66e775f215e800f25caddae8cb5.

It the same as you asked, I think, except with a different name.

Due to the version bump, it should be out soon in diff-hl 1.9.2.




This bug report was last modified 1 year and 282 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.