From 3cfd44c727903be0de94c5485254b9e6966e6473 Mon Sep 17 00:00:00 2001 From: Jimmy Yuen Ho Wong Date: Tue, 10 Dec 2024 18:00:33 +0000 Subject: [PATCH] Make ignorable commands customizable --- diff-hl-show-hunk-inline.el | 1 + diff-hl-show-hunk.el | 38 +++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/diff-hl-show-hunk-inline.el b/diff-hl-show-hunk-inline.el index ae2704d4..9b2a2de4 100644 --- a/diff-hl-show-hunk-inline.el +++ b/diff-hl-show-hunk-inline.el @@ -222,6 +222,7 @@ to scroll in the popup") (defun diff-hl-show-hunk-inline--post-command-hook () "Called each time a command is executed." (let ((allowed-command (or + (diff-hl-show-hunk-ignorable-command-p this-command) (string-match-p "diff-hl-show-hunk-inline-" (symbol-name this-command)) (diff-hl-show-hunk-inline--ignorable-command-p this-command)))) (unless allowed-command diff --git a/diff-hl-show-hunk.el b/diff-hl-show-hunk.el index bc1ed4da..c23ccb5c 100644 --- a/diff-hl-show-hunk.el +++ b/diff-hl-show-hunk.el @@ -38,6 +38,29 @@ (require 'diff-hl) +(defgroup diff-hl-show-hunk nil + "Show vc diffs in a posframe or popup." + :group 'diff-hl) + +(defcustom diff-hl-show-hunk-ignorable-commands + '(ignore + diff-hl-show-hunk + handle-switch-frame + diff-hl-show-hunk--click) + "Commands that will keep the hunk shown. +Any command not on this list will cause the hunk to be hidden." + :type '(repeat function) + :group 'diff-hl-show-hunk) + +(defcustom diff-hl-show-hunk-function 'diff-hl-show-hunk-inline + "The function used to render the hunk. +The function receives as first parameter a buffer with the +contents of the hunk, and as second parameter the line number +corresponding to the clicked line in the original buffer." + :type '(choice + (const :tag "Show inline" diff-hl-show-hunk-inline) + (const :tag "Show using posframe" diff-hl-show-hunk-posframe))) + (defvar diff-hl-show-hunk-mouse-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd " ") 'diff-hl-show-hunk--click) @@ -65,22 +88,9 @@ (defvar diff-hl-show-hunk--original-overlay nil "Copy of the diff-hl hunk overlay.") -(defgroup diff-hl-show-hunk nil - "Show vc diffs in a posframe or popup." - :group 'diff-hl) - (defconst diff-hl-show-hunk-boundary "^@@.*@@") (defconst diff-hl-show-hunk--no-lines-removed-message (list "<>")) -(defcustom diff-hl-show-hunk-function 'diff-hl-show-hunk-inline - "The function used to render the hunk. -The function receives as first parameter a buffer with the -contents of the hunk, and as second parameter the line number -corresponding to the clicked line in the original buffer." - :type '(choice - (const :tag "Show inline" diff-hl-show-hunk-inline) - (const :tag "Show using posframe" diff-hl-show-hunk-posframe))) - (defvar diff-hl-show-hunk--hide-function nil "Function to call to close the shown hunk.") @@ -111,7 +121,7 @@ corresponding to the clicked line in the original buffer." (defun diff-hl-show-hunk-ignorable-command-p (command) "Decide if COMMAND is a command allowed while showing the current hunk." - (member command '(ignore diff-hl-show-hunk handle-switch-frame diff-hl-show-hunk--click))) + (member command diff-hl-show-hunk-ignorable-commands)) (defun diff-hl-show-hunk--compute-diffs () "Compute diffs using functions of diff-hl.