[PATCH/RFC] git-blame.el: Use eldoc-mode to display current commit.

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

 



I think this is a better way to display the current commit.  However,
I'm not sure whether to rely on eldoc, or create my own timer.

regards,
Nikolaj Schumacher


>From 4bbd50ab1ae26ca154c20d140edfa187c9124959 Mon Sep 17 00:00:00 2001
From: Nikolaj Schumacher <git@xxxxxxxxx>
Date: Mon, 30 Jun 2008 11:44:46 +0200
Subject: [PATCH] git-blame.el: Use eldoc-mode to display current commit.

Previously, the current commit was displayed on every point movement using
text properties.  These properties stick to copied text, so that an error is
thrown once it is pasted in a different buffer.  Additionally, there is no
way to turn them off.  Using a configurable timer solves these problems.
Since eldoc already provides such functionality, hand off the work to it.
---
 contrib/emacs/git-blame.el |   27 +++++++++++----------------
 1 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/contrib/emacs/git-blame.el b/contrib/emacs/git-blame.el
index 9f92cd2..c13e445 100644
--- a/contrib/emacs/git-blame.el
+++ b/contrib/emacs/git-blame.el
@@ -40,7 +40,7 @@
 ;; turn it on while viewing a file, the editor buffer will be updated by
 ;; setting the background of individual lines to a color that reflects
 ;; which commit it comes from.  And when you move around the buffer, a
-;; one-line summary will be shown in the echo area.
+;; one-line summary will be shown in the echo area if `eldoc-mode' is on.
 
 ;;; Installation:
 ;;
@@ -195,6 +195,7 @@ See also function `git-blame-mode'."
       (setq git-blame-colors git-blame-light-colors)))
   (setq git-blame-cache (make-hash-table :test 'equal))
   (setq git-blame-mode t)
+  (setq eldoc-documentation-function 'git-blame-identify)
   (git-blame-run))
 
 (defun git-blame-mode-off ()
@@ -354,15 +355,7 @@ See also function `git-blame-mode'."
             (overlay-put ovl 'git-blame info)
             (overlay-put ovl 'help-echo hash)
             (overlay-put ovl 'face (list :background
-                                         (cdr (assq 'color (nthcdr 5 info)))))
-            ;; the point-entered property doesn't seem to work in overlays
-            ;;(overlay-put ovl 'point-entered
-            ;;             `(lambda (x y) (git-blame-identify ,hash)))
-            (let ((modified (buffer-modified-p)))
-              (put-text-property (if (= start 1) start (1- start)) (1- end)
-                                 'point-entered
-                                 `(lambda (x y) (git-blame-identify ,hash)))
-              (set-buffer-modified-p modified))))
+                                         (cdr (assq 'color (nthcdr 5 info)))))))
         (setq num-lines (1- num-lines))))))
 
 (defun git-blame-add-info (key value)
@@ -383,14 +376,16 @@ See also function `git-blame-mode'."
                   hash)
     (buffer-substring (point-min) (1- (point-max)))))
 
-(defvar git-blame-last-identification nil)
-(make-variable-buffer-local 'git-blame-last-identification)
 (defun git-blame-identify (&optional hash)
   (interactive)
-  (let ((info (gethash (or hash (git-blame-current-commit)) git-blame-cache)))
-    (when (and info (not (eq info git-blame-last-identification)))
-      (message "%s" (nth 4 info))
-      (setq git-blame-last-identification info))))
+  (condition-case err
+      (let ((info (nth 4 (gethash (or hash (git-blame-current-commit))
+                                  git-blame-cache))))
+        (when info
+          (when (interactive-p)
+            (message "%s" info))
+          info))
+    (error nil)))
 
 ;; (defun git-blame-after-save ()
 ;;   (when git-blame-mode
-- 
1.5.5.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux