bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#61449: 30.0.50; diff-hl-dired: Consider adding a cookie to diff-hl-d


From: Ramesh Nedunchezian
Subject: bug#61449: 30.0.50; diff-hl-dired: Consider adding a cookie to diff-hl-dired overlay
Date: Sun, 12 Feb 2023 11:02:16 +0530
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0

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))))))




Attachment: M-x diff-hl-dired-mark-vc-states.png
Description: PNG image

Attachment: M-x diff-hl-dired-fontify.png
Description: PNG image


reply via email to

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