Add function to generate a date ranged diff for the current buffer

This commit is contained in:
Bram Schoenmakers 2023-08-30 21:44:39 +02:00
parent aab960a989
commit cb4c371e5c
2 changed files with 19 additions and 0 deletions

View File

@ -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

View File

@ -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)))))