Skip to content

Commit 2cf45ee

Browse files
committed
New option: diff-hl-fallback-to-margin
Resolves #212
1 parent 9b03201 commit 2cf45ee

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ The package also contains auxiliary modes:
1818
* `diff-hl-dired-mode` provides similar functionality in Dired.
1919
* `diff-hl-margin-mode` changes the highlighting function to
2020
use the margin instead of the fringe.
21+
* But if you use a non-graphical terminal, the package will fall back to using
22+
the margins anyway, as long as `diff-hl-fallback-to-margin` is non-nil and the
23+
margin width is non-zero.
2124
* `diff-hl-amend-mode` sets the reference revision to the one before
2225
recent one. Also, you could use `diff-hl-set-reference-rev` to set
2326
it to any revision, see its docstring for details.

diff-hl-margin.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;;; diff-hl-margin.el --- Highlight buffer changes on margins -*- lexical-binding: t -*-
22

3-
;; Copyright (C) 2012-2017 Free Software Foundation, Inc.
3+
;; Copyright (C) 2012-2025 Free Software Foundation, Inc.
44

55
;; This file is part of GNU Emacs.
66

@@ -147,6 +147,7 @@ You probably shouldn't use this function directly."
147147
,(propertize char 'face
148148
(intern (format "diff-hl-margin-%s" type)))))))))
149149

150+
;;;###autoload
150151
(defun diff-hl-highlight-on-margin (ovl type _shape)
151152
(let ((spec (cdr (assoc (cons type diff-hl-side)
152153
(diff-hl-margin-spec-cache)))))

diff-hl.el

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;;; diff-hl.el --- Highlight uncommitted changes using VC -*- lexical-binding: t -*-
22

3-
;; Copyright (C) 2012-2024 Free Software Foundation, Inc.
3+
;; Copyright (C) 2012-2025 Free Software Foundation, Inc.
44

55
;; Author: Dmitry Gutov <dmitry@gutov.dev>
66
;; URL: https://github.com/dgutov/diff-hl
@@ -116,6 +116,14 @@
116116
:group 'diff-hl
117117
:type 'boolean)
118118

119+
(defcustom diff-hl-fallback-to-margin t
120+
"Non-nil to use margin instead of fringe on non-graphic displays.
121+
122+
This requires the corresponding margin width to be >0 already, which is
123+
normally the case on such displays."
124+
:group 'diff-hl
125+
:type 'boolean)
126+
119127
(defcustom diff-hl-highlight-function 'diff-hl-highlight-on-fringe
120128
"Function to highlight the current line. Its arguments are
121129
overlay, change type and position within a hunk."
@@ -500,8 +508,11 @@ It can be a relative expression as well, such as \"HEAD^\" with Git, or
500508
o))
501509

502510
(defun diff-hl-highlight-on-fringe (ovl type shape)
503-
(overlay-put ovl 'before-string (diff-hl-fringe-spec type shape
504-
diff-hl-side)))
511+
(if (and diff-hl-fallback-to-margin
512+
(not (display-graphic-p)))
513+
(diff-hl-highlight-on-margin ovl type shape)
514+
(overlay-put ovl 'before-string (diff-hl-fringe-spec type shape
515+
diff-hl-side))))
505516

506517
(defun diff-hl-remove-overlays (&optional beg end)
507518
(save-restriction

0 commit comments

Comments
 (0)