branch: externals/diff-hl commit 2cf45ee48705609ae9954d299104308797bda752 Author: Dmitry Gutov <dmi...@gutov.dev> Commit: Dmitry Gutov <dmi...@gutov.dev>
New option: `diff-hl-fallback-to-margin` Resolves #212 --- README.md | 3 +++ diff-hl-margin.el | 3 ++- diff-hl.el | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ae05e358c7..c1446bbeb2 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ The package also contains auxiliary modes: * `diff-hl-dired-mode` provides similar functionality in Dired. * `diff-hl-margin-mode` changes the highlighting function to use the margin instead of the fringe. +* But if you use a non-graphical terminal, the package will fall back to using + the margins anyway, as long as `diff-hl-fallback-to-margin` is non-nil and the + margin width is non-zero. * `diff-hl-amend-mode` sets the reference revision to the one before recent one. Also, you could use `diff-hl-set-reference-rev` to set it to any revision, see its docstring for details. diff --git a/diff-hl-margin.el b/diff-hl-margin.el index c3fffde14e..0a39608d21 100644 --- a/diff-hl-margin.el +++ b/diff-hl-margin.el @@ -1,6 +1,6 @@ ;;; diff-hl-margin.el --- Highlight buffer changes on margins -*- lexical-binding: t -*- -;; Copyright (C) 2012-2017 Free Software Foundation, Inc. +;; Copyright (C) 2012-2025 Free Software Foundation, Inc. ;; This file is part of GNU Emacs. @@ -147,6 +147,7 @@ You probably shouldn't use this function directly." ,(propertize char 'face (intern (format "diff-hl-margin-%s" type))))))))) +;;;###autoload (defun diff-hl-highlight-on-margin (ovl type _shape) (let ((spec (cdr (assoc (cons type diff-hl-side) (diff-hl-margin-spec-cache))))) diff --git a/diff-hl.el b/diff-hl.el index f06f318e66..4c6b965a0f 100644 --- a/diff-hl.el +++ b/diff-hl.el @@ -1,6 +1,6 @@ ;;; diff-hl.el --- Highlight uncommitted changes using VC -*- lexical-binding: t -*- -;; Copyright (C) 2012-2024 Free Software Foundation, Inc. +;; Copyright (C) 2012-2025 Free Software Foundation, Inc. ;; Author: Dmitry Gutov <dmi...@gutov.dev> ;; URL: https://github.com/dgutov/diff-hl @@ -116,6 +116,14 @@ :group 'diff-hl :type 'boolean) +(defcustom diff-hl-fallback-to-margin t + "Non-nil to use margin instead of fringe on non-graphic displays. + +This requires the corresponding margin width to be >0 already, which is +normally the case on such displays." + :group 'diff-hl + :type 'boolean) + (defcustom diff-hl-highlight-function 'diff-hl-highlight-on-fringe "Function to highlight the current line. Its arguments are 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 o)) (defun diff-hl-highlight-on-fringe (ovl type shape) - (overlay-put ovl 'before-string (diff-hl-fringe-spec type shape - diff-hl-side))) + (if (and diff-hl-fallback-to-margin + (not (display-graphic-p))) + (diff-hl-highlight-on-margin ovl type shape) + (overlay-put ovl 'before-string (diff-hl-fringe-spec type shape + diff-hl-side)))) (defun diff-hl-remove-overlays (&optional beg end) (save-restriction