Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frame-local diff-hl-margin-mode? #212

Open
CyberShadow opened this issue Feb 27, 2024 · 1 comment
Open

Frame-local diff-hl-margin-mode? #212

CyberShadow opened this issue Feb 27, 2024 · 1 comment

Comments

@CyberShadow
Copy link

Thank you for this essential package!

I have a question: do you know if it's possible to make diff-hl-margin-mode frame-local? I.e. so that TTY frames have it on, but graphical frames have it off.

Use case: I access my Emacs server locally (graphically) and remotely (over SSH / TTY). Every time I switch, I have to nudge diff-hl to update margin mode (off locally, on remotely). I think ideally it would just be on for TTY frames, if that's possible.

I noticed that there is diff-hl-margin-local-mode, but I don't think that's quite it since that makes it buffer-local, but the same buffer can be open in both a graphical and TTY frame.

Thanks!

@dgutov
Copy link
Owner

dgutov commented Feb 27, 2024

We could do something like this:

diff --git a/diff-hl-margin.el b/diff-hl-margin.el
index c3fffde..a754a43 100644
--- a/diff-hl-margin.el
+++ b/diff-hl-margin.el
@@ -78,6 +78,10 @@
          (set-default symbol value)
          (setq diff-hl-margin-spec-cache nil)))
 
+(defcustom diff-hl-margin-nongraphic-only nil
+  "Only use the margin when a text-only terminal is used."
+  :type 'boolean)
+
 ;;;###autoload
 (define-minor-mode diff-hl-margin-mode
   "Toggle displaying `diff-hl-mode' highlights on the margin."
@@ -147,10 +151,13 @@ You probably shouldn't use this function directly."
                         ,(propertize char 'face
                                      (intern (format "diff-hl-margin-%s" type)))))))))
 
-(defun diff-hl-highlight-on-margin (ovl type _shape)
-  (let ((spec (cdr (assoc (cons type diff-hl-side)
-                          (diff-hl-margin-spec-cache)))))
-    (overlay-put ovl 'before-string spec)))
+(defun diff-hl-highlight-on-margin (ovl type shape)
+  (if (and diff-hl-margin-nongraphic-only
+           (display-graphic-p))
+      (funcall diff-hl-margin-old-highlight-function ovl type shape)
+    (let ((spec (cdr (assoc (cons type diff-hl-side)
+                            (diff-hl-margin-spec-cache)))))
+      (overlay-put ovl 'before-string spec))))
 
 (provide 'diff-hl-margin)
 

Apply the patch, change the variable to t and see the difference.

The only roadbump, I guess, is that the mode also changes the corresponding margin width (from 0 to 1, usually). But if you wanted to use the margin for something else, that shouldn't be a problem.

How make it frame-local isn't obvious, though I suppose the value could be changed on every update. Not sure if there will be any performance implications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants