[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/eldoc-diffstat e954a705f1 2/6: Address review comments (on
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/eldoc-diffstat e954a705f1 2/6: Address review comments (on emacs-devel) |
Date: |
Sat, 14 Dec 2024 19:00:48 -0500 (EST) |
branch: elpa/eldoc-diffstat
commit e954a705f1e34fbb42c62fe5a067c2413b685c30
Author: Johann Klähn <johann@jklaehn.de>
Commit: Johann Klähn <johann@jklaehn.de>
Address review comments (on emacs-devel)
Cf. https://lists.gnu.org/archive/html/emacs-devel/2024-12/msg00369.html
Suggested-by: Philip Kaludercic <philipk@posteo.net>
Suggested-by: Tassilo Horn <tsdh@gnu.org>
---
.elpaignore | 2 ++
README.md | 11 +++++++++-
eldoc-diffstat.el | 63 +++++++++++++++++++++++++++++++------------------------
3 files changed, 48 insertions(+), 28 deletions(-)
diff --git a/.elpaignore b/.elpaignore
new file mode 100644
index 0000000000..daa22c07ac
--- /dev/null
+++ b/.elpaignore
@@ -0,0 +1,2 @@
+.gitignore
+screenshot.webp
diff --git a/README.md b/README.md
index 5279e15a8a..732407ac2b 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,16 @@ It supports Git and Mercurial repositories.
![A screenshot showing diffstat information in the echo area of a magit-log
buffer.](screenshot.webp "diffstat information is available in the echo area.")
-To use, call `eldoc-diffstat-setup` in the desired buffer or mode hook.
+To use, call `eldoc-diffstat-setup` in the desired buffer or mode hook, e.g.:
+
+```elisp
+(add-hook 'git-rebase-mode-hook #'eldoc-diffstat-setup)
+(add-hook 'log-view-mode-hook #'eldoc-diffstat-setup)
+(add-hook 'magit-log-mode-hook #'eldoc-diffstat-setup)
+(add-hook 'magit-status-mode-hook #'eldoc-diffstat-setup)
+(add-hook 'vc-annotate-mode-hook #'eldoc-diffstat-setup)
+```
+
You might also want to add the following to your config:
```elisp
diff --git a/eldoc-diffstat.el b/eldoc-diffstat.el
index a9dcc41854..04636a906c 100644
--- a/eldoc-diffstat.el
+++ b/eldoc-diffstat.el
@@ -61,6 +61,23 @@ a property to the process object.")
"--stat" "--rev"))
"Alist mapping VCS backend to the command to use for computing the
diffstat.")
+(defconst eldoc-diffstat--output-regex
+ (rx buffer-start
+ ;; 1: commit author and date
+ ;; 2: newline between author info and subject (will be removed)
+ (group-n 1 (+ not-newline)) (group-n 2 ?\n)
+ ;; subject / first line of commit message
+ (+ not-newline) ?\n
+ ;; 3: point after subject / before diffstat (shortstat will be moved
here)
+ (group-n 3)
+ ;; diffstat for individual files
+ (+? anything)
+ ;; 4: shortstat, i.e., total # of modified files + added/deleted lines
+ (group-n 4 (+ not-newline) ?\n)
+ (* space) buffer-end)
+ "Regular expression used to rewrite and apply faces to diffstat output.
+Has to match `eldoc-diffstat--commands'.")
+
;;;###autoload
(defun eldoc-diffstat-setup ()
"Configure eldoc buffer-locally to display diffstat for revision at point."
@@ -77,7 +94,7 @@ Intended for `eldoc-documentation-functions'."
(backend (car info))
(revision (cdr info))
(command (alist-get backend eldoc-diffstat--commands)))
- (if-let ((result (eldoc-diffstat--get-cache info)))
+ (if-let* ((result (eldoc-diffstat--get-cache info)))
(funcall callback result)
(eldoc-diffstat--docstring-1 (append command (list revision)) callback
info))))
@@ -87,11 +104,11 @@ The returned record should be a cons cell of the form
(BACKEND . REVISION) where
BACKEND is a symbol representing the version control system and REVISION is
a string identifying the specific revision."
(cond
- ((when-let (((fboundp 'magit-stash-at-point))
- (revision (magit-stash-at-point)))
+ ((when-let* (((fboundp 'magit-stash-at-point))
+ (revision (magit-stash-at-point)))
(cons 'Git revision)))
- ((when-let (((fboundp 'magit-commit-at-point))
- (revision (magit-commit-at-point)))
+ ((when-let* (((fboundp 'magit-commit-at-point))
+ (revision (magit-commit-at-point)))
(cons 'Git revision)))
((and (derived-mode-p 'git-rebase-mode)
(fboundp 'git-rebase-current-line)
@@ -154,35 +171,27 @@ caching the result, see `eldoc-diffstat--get-cache' for
details."
(funcall callback result)))))
(defun eldoc-diffstat--format-output-buffer ()
- "Format the diffstat output."
+ "Format the diffstat output in the current buffer."
;; Translate color control sequences into text properties.
(let ((ansi-color-apply-face-function
(lambda (beg end face)
(put-text-property beg end 'face face))))
(ansi-color-apply-on-region (point-min) (point-max)))
- ;; Delete trailing blank lines.
- (goto-char (point-max))
- (delete-blank-lines)
-
- ;; Make first line bold.
(goto-char (point-min))
- (put-text-property (point)
- (line-end-position)
- 'face 'bold)
-
- ;; Join second line.
- (forward-line)
- (join-line)
-
- ;; Move summary to the top and make it italic.
- (forward-line)
- (reverse-region (point) (point-max))
- (put-text-property (point)
- (line-end-position)
- 'face 'italic)
- (forward-line)
- (reverse-region (point) (point-max)))
+ (when (looking-at eldoc-diffstat--output-regex)
+ ;; Make commit author and date bold.
+ (put-text-property
+ (match-beginning 1) (match-end 1) 'face 'bold)
+
+ ;; Join the first two lines.
+ (replace-match " " nil nil nil 2)
+
+ ;; Move summary to the second line and make it italic.
+ (let ((summary (delete-and-extract-region
+ (match-beginning 4) (match-end 4))))
+ (replace-match
+ (propertize summary 'face 'italic) nil nil nil 3))))
(provide 'eldoc-diffstat)
;;; eldoc-diffstat.el ends here
- [nongnu] elpa/eldoc-diffstat updated (99b49c9793 -> 33aa6d7ee5), ELPA Syncer, 2024/12/14
- [nongnu] elpa/eldoc-diffstat 98e0e18a41 1/6: Fix potential race condition, ELPA Syncer, 2024/12/14
- [nongnu] elpa/eldoc-diffstat 0481f4f5a7 3/6: Add minor mode, ELPA Syncer, 2024/12/14
- [nongnu] elpa/eldoc-diffstat e954a705f1 2/6: Address review comments (on emacs-devel),
ELPA Syncer <=
- [nongnu] elpa/eldoc-diffstat bd7fcae4c1 5/6: Always register magit commands with eldoc, ELPA Syncer, 2024/12/14
- [nongnu] elpa/eldoc-diffstat 33aa6d7ee5 6/6: Release version 1.0, ELPA Syncer, 2024/12/14
- [nongnu] elpa/eldoc-diffstat 50c1c5ebb8 4/6: Add option to truncate / pad output, ELPA Syncer, 2024/12/14