Coder Social home page Coder Social logo

Comments (4)

dgutov avatar dgutov commented on August 15, 2024 1

Hi again!

I've though about this some more, and there are several ways you can have some improved behavior. The first one is simply having that git diff basically run in full whenever Emacs is idle, to update the selected buffer. The patch will look like this:

diff --git a/diff-hl-flydiff.el b/diff-hl-flydiff.el
index e366eec..56be107 100644
--- a/diff-hl-flydiff.el
+++ b/diff-hl-flydiff.el
@@ -36,6 +36,13 @@
   "The idle delay in seconds before highlighting is updated."
   :type 'number)
 
+(defcustom diff-hl-flydiff-always-check t
+  "Non-nil to always run the full status check of the current file.
+
+This will make it always pick up changes in HEAD even when commit is made
+outside of Emacs (e.g. in terminal) before any changes to buffers are made."
+  :type 'boolean)
+
 (defvar diff-hl-flydiff-modified-tick nil)
 (defvar diff-hl-flydiff-timer nil)
 (make-variable-buffer-local 'diff-hl-flydiff-modified-tick)
@@ -47,14 +54,16 @@
 (defun diff-hl-flydiff-update ()
   (unless (or
            (not diff-hl-mode)
-           (eq diff-hl-flydiff-modified-tick (buffer-chars-modified-tick))
+           (unless diff-hl-flydiff-always-check
+             (eq diff-hl-flydiff-modified-tick (buffer-chars-modified-tick)))
            (not buffer-file-name)
            (file-remote-p default-directory)
            (not (file-exists-p buffer-file-name)))
     (diff-hl-update)))
 
 (defun diff-hl-flydiff/modified-p (_state)
-  (buffer-modified-p))
+  (or diff-hl-flydiff-always-check
+      (buffer-modified-p)))
 
 ;;;###autoload
 (define-minor-mode diff-hl-flydiff-mode

Please go ahead and test it when you have the time. The downside is it will produce somewhat wasteful work, and in larger repositories git diff can take a fair amount of time (up to 200ms in my testing). Whether it will translate in visible stutters sometimes or not, depends on the size of the projects and the speed of the machine.

Another approach would be to use after-focus-change-function. Then, if you switch to a different window (terminal) and then back, diff-hl-flydiff could notice that and update all the buffers in visible windows. The main downside is that not all scenarios will be covered: e.g. if you have a tiling WM and want to have Emacs and the terminal side-by-side, make a commit in the terminal and see the contents updated in Emacs more-or-less synchronously, this won't happen. But it will happen when you bring the focus to Emacs again, so maybe it can be a good compromise.

Let me know if you're still around and interesting in trying out the patches -- I will do one for the second option as well.

from diff-hl.

dgutov avatar dgutov commented on August 15, 2024

Hi! This actually seems to work fine for me.

Do you have some non-default settings maybe? Try writing a step-by-step reproduction scenario.

from diff-hl.

wanghaiqiangk avatar wanghaiqiangk commented on August 15, 2024

My settings

(use-package diff-hl
  :config
  (global-diff-hl-mode)
  (diff-hl-flydiff-mode)
  (if (not (display-graphic-p))
      (diff-hl-margin-mode t)))

Instead of writing a textual description, a gif may give a better demonstration.

Peek 2022-05-16 09-55

So, after saving and committing, the indicators are still there until I run vc-diff, or revert-buffer thingy

from diff-hl.

dgutov avatar dgutov commented on August 15, 2024

I can see it now. Is that a real nuisance? Do you know if similar editors have this behavior?

Something like VS Code aside, which likely plugs into inotify, which I'm not sure we can do. Not easily, at least.

The alternative would be running the equivalent of git status on a timer, to see if it changed, and update whenever that happens. Which feels a little wasteful (I don't know) when you can just make an edit and revert to see the updated fringe. But I get the comfort of always seeing up-to-date indicators. Another common problem (which git status wouldn't solve), is having the file updated after git checkout. But having global-auto-revert-mode enabled should take care of that.

from diff-hl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.