;; Author: Dmitry Gutov <dgutov@yandex.ru>\r
;; URL: https://github.com/dgutov/diff-hl\r
;; Keywords: vc, diff\r
-;; Version: 1.3.6\r
+;; Version: 1.4.0\r
;; Package-Requires: ((cl-lib "0.2"))\r
\r
;; This file is not part of GNU Emacs.\r
,body))\r
\r
(defun diff-hl-changes ()\r
- (let* ((buf-name " *diff-hl* ")\r
- (file buffer-file-name)\r
- (backend (vc-backend file))\r
- res)\r
- (when (and backend (eq (vc-state file backend) 'edited))\r
- (diff-hl-with-diff-switches\r
- (vc-call-backend backend 'diff (list file) nil nil buf-name))\r
- (with-current-buffer buf-name\r
- (goto-char (point-min))\r
- (unless (eobp)\r
- (diff-beginning-of-hunk t)\r
- (while (looking-at diff-hunk-header-re-unified)\r
- (let ((line (string-to-number (match-string 3)))\r
- (len (let ((m (match-string 4)))\r
- (if m (string-to-number m) 1)))\r
- (beg (point)))\r
- (diff-end-of-hunk)\r
- (let* ((inserts (diff-count-matches "^\\+" beg (point)))\r
- (deletes (diff-count-matches "^-" beg (point)))\r
- (type (cond ((zerop deletes) 'insert)\r
- ((zerop inserts) 'delete)\r
- (t 'change))))\r
- (push (list line len type) res)))))))\r
- (nreverse res)))\r
+ (let* ((file buffer-file-name)\r
+ (backend (vc-backend file)))\r
+ (when backend\r
+ (cl-case (vc-state file backend)\r
+ (edited\r
+ (let* ((buf-name " *diff-hl* ")\r
+ res)\r
+ (diff-hl-with-diff-switches\r
+ (vc-call-backend backend 'diff (list file) nil nil buf-name))\r
+ (with-current-buffer buf-name\r
+ (goto-char (point-min))\r
+ (unless (eobp)\r
+ (diff-beginning-of-hunk t)\r
+ (while (looking-at diff-hunk-header-re-unified)\r
+ (let ((line (string-to-number (match-string 3)))\r
+ (len (let ((m (match-string 4)))\r
+ (if m (string-to-number m) 1)))\r
+ (beg (point)))\r
+ (diff-end-of-hunk)\r
+ (let* ((inserts (diff-count-matches "^\\+" beg (point)))\r
+ (deletes (diff-count-matches "^-" beg (point)))\r
+ (type (cond ((zerop deletes) 'insert)\r
+ ((zerop inserts) 'delete)\r
+ (t 'change))))\r
+ (when (eq type 'delete)\r
+ (setq len 1)\r
+ (cl-incf line))\r
+ (push (list line len type) res))))))\r
+ (nreverse res)))\r
+ (added\r
+ `((1 ,(line-number-at-pos (point-max)) insert)))\r
+ (removed\r
+ `((1 ,(line-number-at-pos (point-max)) delete)))))))\r
\r
(defun diff-hl-update ()\r
(let ((changes (diff-hl-changes))\r
(goto-char (point-min))\r
(dolist (c changes)\r
(cl-destructuring-bind (line len type) c\r
- (when (eq type 'delete)\r
- (setq len 1)\r
- (cl-incf line))\r
(forward-line (- line current-line))\r
(let ((hunk-beg (point)))\r
(forward-line len)\r