From cb4c371e5ce68ba89afce0ae020e6b6f4161d237 Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Wed, 30 Aug 2023 21:44:39 +0200 Subject: [PATCH] Add function to generate a date ranged diff for the current buffer --- gists.org | 12 ++++++++++++ gists/magit-diff-range-current-buffer.el | 7 +++++++ 2 files changed, 19 insertions(+) create mode 100644 gists/magit-diff-range-current-buffer.el diff --git a/gists.org b/gists.org index f790533..b3ad908 100644 --- a/gists.org +++ b/gists.org @@ -701,6 +701,18 @@ Based on an answer at the [[https://emacs.stackexchange.com/a/77480/34645][Emacs (apply-partially #'my/buffer-has-major-mode-p mode)))) #+end_src +* Magit: show diff of current buffer since a given date/time :emacs:magit: + +#+begin_src elisp :tangle gists/magit-diff-range-current-buffer.el + (defun my/magit-diff-since (&optional since) + "Shows the diff for the current file SINCE the given date/time." + (interactive "sSince (default 24 hours ago): ") + (let* ((revisionA (format "HEAD@{%s}" (or (and (not (string-empty-p since)) since) "24 hours ago"))) + (revisionB "{worktree}") + (range (string-join (list revisionA ".." revisionB)))) + (magit-diff-range range () (list (buffer-file-name))))) +#+end_src + * Meta ** License diff --git a/gists/magit-diff-range-current-buffer.el b/gists/magit-diff-range-current-buffer.el new file mode 100644 index 0000000..2b40732 --- /dev/null +++ b/gists/magit-diff-range-current-buffer.el @@ -0,0 +1,7 @@ +(defun my/magit-diff-since (&optional since) + "Shows the diff for the current file SINCE the given date/time." + (interactive "sSince (default 24 hours ago): ") + (let* ((revisionA (format "HEAD@{%s}" (or (and (not (string-empty-p since)) since) "24 hours ago"))) + (revisionB "{worktree}") + (range (string-join (list revisionA ".." revisionB)))) + (magit-diff-range range () (list (buffer-file-name)))))