emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/why-this 88ee5f9746 27/59: Add Mercurial backend


From: ELPA Syncer
Subject: [nongnu] elpa/why-this 88ee5f9746 27/59: Add Mercurial backend
Date: Sun, 27 Nov 2022 16:02:51 -0500 (EST)

branch: elpa/why-this
commit 88ee5f974693a04a19ab76f731dae221146af33a
Author: Akib Azmain Turja <akib@disroot.org>
Commit: Akib Azmain Turja <akib@disroot.org>

    Add Mercurial backend
---
 why-this.el | 53 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 49 insertions(+), 4 deletions(-)

diff --git a/why-this.el b/why-this.el
index 72761fc673..d5df6905bc 100644
--- a/why-this.el
+++ b/why-this.el
@@ -1,4 +1,4 @@
-;;; why-this.el --- Minor mode for showing why the current line was changed 
-*- lexical-binding: t -*-
+;;; why-this.el --- Show why the current line contains this -*- 
lexical-binding: t -*-
 
 ;; Copyright (C) 2022 Akib Azmain Turja.
 
@@ -25,7 +25,10 @@
 
 ;;; Commentary:
 
-;; Show the when and why the current line was last changed.
+;; why-this shows when and why the current line was last changed.  Enable
+;; with M-x why-this-mode.  Or see why a line was change without enabling
+;; with M-x why-this.  See editing history of whole file with heat map with
+;; M-x why-this-annotate.
 
 ;;; Code:
 
@@ -39,7 +42,8 @@
   :link '(url-link "https://codeberg.org/akib/emacs-why-this";)
   :prefix "why-this-")
 
-(defcustom why-this-backends '(why-this-backend-git)
+(defcustom why-this-backends '(why-this-git
+                               why-this-hg)
   "List of enabled backends."
   :type '(repeat (function :tag "Backend"))
   :package-version '(why-this "1.0")
@@ -545,7 +549,7 @@ Actually the supported backend is returned."
   :group 'why-this
   (add-to-invisibility-spec '(ellipsis . t)))
 
-(defun why-this-backend-git (cmd &rest args)
+(defun why-this-git (cmd &rest args)
   "Git backend for Why-This mode.
 
 Do CMD with ARGS."
@@ -625,5 +629,46 @@ Do CMD with ARGS."
            (funcall add-uncommitted))
          line-data)))))
 
+(defun why-this-hg (cmd &rest args)
+  "Mercurial backend for Why-This mode.
+
+Do CMD with ARGS."
+  (pcase cmd
+    ('supported-p
+     (and (buffer-file-name)
+          (string= "t" (shell-command-to-string
+                        (format "hg annotate \"%s\" --template \"t\""
+                                (buffer-file-name))))))
+    ('line-data
+     (when (> (- (nth 1 args) (nth 0 args)) 0)
+       (let ((output
+              (car
+               (read-from-string
+                (shell-command-to-string
+                 (format
+                  (concat
+                   "hg annotate \"%s\" --template \"({lines %% '(:id"
+                   " {rev} :author \\\"{person(user)}\\\" :time"
+                   " ({hgdate(date)}) :message \\\"{sub(\\\"\\\\\\\"\\\","
+                   " \\\"\\\\\\\\\\\\\\\"\\\", sub(\\\"\\n.*\\\","
+                   " \\\"\\\", desc))}\\\") '})\"")
+                  (buffer-file-name))))))
+             data)
+         (dolist (i (number-sequence (1- (nth 1 args)) (nth 0 args) -1))
+           (if (<= i (length output))
+               (let ((plist (nth (1- i) output)))
+                 (plist-put plist :time (time-convert
+                                         (car (plist-get plist :time))))
+                 (push plist data))
+             (setq data
+                   (append data
+                           (list
+                            (list
+                             :id nil
+                             :author user-full-name
+                             :time (current-time)
+                             :message "Uncommitted changes"))))))
+         data)))))
+
 (provide 'why-this)
 ;;; why-this.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]