summaryrefslogtreecommitdiff
path: root/lisp/vc-annotate-lens-mode.el
blob: 830f568705c477c4e6ad5d0ac3634f35c9232c21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

;;; Code:

(make-variable-buffer-local
 (defvar vc-annotate-lens-cursor-position 0
   "Holds the cursor position from the last run of post-command-hooks."))

(defun do-stuff-if-moved-post-command ()
  "Show version control history of the current line in a flash."
  (unless (equal (line-number-at-pos) vc-annotate-lens-cursor-position)
    (remove-overlays)
    (overlay-put (make-overlay (point-at-eol) (+ 3 (point-at-eol))) 'display "Hello world\n")
    (let* ((lfrom (line-number-at-pos (point) t))
           (lto   (line-number-at-pos (1- (point)) t))
           (file buffer-file-name)
           (backend (vc-backend file))
           (buf (get-buffer-create "*VC_LENS*")))
      
      (vc-call region-history (buffer-file-name) buf lfrom lto)
      (with-current-buffer buf
        (save-restriction
          (widen)
          (buffer-substring-no-properties (point-min) (point-max))))
      )
    )
  (setq vc-annotate-lens-cursor-position (line-number-at-pos)))

(define-minor-mode vc-annotate-lens-mode
  "Show 'vc-annotate' information when you move to a line."
  :lighter " vc-annotate-lens"
  )

(add-hook 'vc-annotate-lens-mode-on-hook (lambda () (add-hook 'post-command-hook #'do-stuff-if-moved-post-command)))
(add-hook 'vc-annotate-lens-mode-off-hook (lambda () (remove-hook 'post-command-hook #'do-stuff-if-moved-post-command)))

(provide 'vc-annotate-lens-mode)
;;; vc-annotate-lens-mode.el ends here.