[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/diff-hl ab2f4f0 13/25: Merge pull request #140 from moo
From: |
Dmitry Gutov |
Subject: |
[elpa] externals/diff-hl ab2f4f0 13/25: Merge pull request #140 from mookid/fix-indirect-buffers |
Date: |
Sun, 20 Dec 2020 05:07:02 -0500 (EST) |
branch: externals/diff-hl
commit ab2f4f0db9b0c3484db837252ce2dc75f4696b1d
Merge: a625033 ba6cf44
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: GitHub <noreply@github.com>
Merge pull request #140 from mookid/fix-indirect-buffers
Fix commands for indirect buffers.
---
.gitignore | 1 +
Makefile | 23 +++++++++
diff-hl.el | 22 ++++++---
test/diff-hl-test.el | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++
test/empty | 10 ++++
5 files changed, 177 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c531d98
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.elc
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..fb3ec5e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,23 @@
+EMACS ?= emacs
+SOURCES=
+SOURCES+=diff-hl-amend.el
+SOURCES+=diff-hl-dired.el
+SOURCES+=diff-hl-flydiff.el
+SOURCES+=diff-hl-margin.el
+
+ARTIFACTS=$(patsubst %.el, %.elc, $(SOURCES))
+
+RM ?= rm -f
+
+all: test
+
+test:
+ $(EMACS) -batch -L . -l test/diff-hl-test.el -f diff-hl-run-tests
+
+compile:
+ $(EMACS) -batch -f batch-byte-compile $(SOURCES)
+
+clean:
+ $(RM) $(ARTIFACTS)
+
+.PHONY: all test compile plain clean
diff --git a/diff-hl.el b/diff-hl.el
index f504ddf..2dcff96 100644
--- a/diff-hl.el
+++ b/diff-hl.el
@@ -1,6 +1,6 @@
;;; diff-hl.el --- Highlight uncommitted changes using VC -*- lexical-binding:
t -*-
-;; Copyright (C) 2012-2019 Free Software Foundation, Inc.
+;; Copyright (C) 2012-2020 Free Software Foundation, Inc.
;; Author: Dmitry Gutov <dgutov@yandex.ru>
;; URL: https://github.com/dgutov/diff-hl
@@ -376,9 +376,7 @@ the end position as its only argument."
(unless (buffer-modified-p)
(diff-hl-update))))
-(defun diff-hl-diff-goto-hunk ()
- "Run VC diff command and go to the line corresponding to the current."
- (interactive)
+(defun diff-hl-diff-goto-hunk-1 ()
(vc-buffer-sync)
(let* ((line (line-number-at-pos))
(buffer (current-buffer)))
@@ -388,6 +386,12 @@ the end position as its only argument."
(diff-hl-diff-skip-to ,line)
(setq vc-sentinel-movepoint (point))))))
+(defun diff-hl-diff-goto-hunk ()
+ "Run VC diff command and go to the line corresponding to the current."
+ (interactive)
+ (with-current-buffer (or (buffer-base-buffer) (current-buffer))
+ (diff-hl-diff-goto-hunk-1)))
+
(defun diff-hl-diff-skip-to (line)
"In `diff-mode', skip to the hunk and line corresponding to LINE
in the source file, or the last line of the hunk above it."
@@ -421,9 +425,7 @@ in the source file, or the last line of the hunk above it."
'diff-hl-reverted-hunk-highlight)
(forward-line 1)))))
-(defun diff-hl-revert-hunk ()
- "Revert the diff hunk with changes at or above the point."
- (interactive)
+(defun diff-hl-revert-hunk-1 ()
(save-restriction
(widen)
(vc-buffer-sync)
@@ -475,6 +477,12 @@ in the source file, or the last line of the hunk above it."
(message "Hunk reverted"))))
(quit-windows-on diff-buffer t)))))
+(defun diff-hl-revert-hunk ()
+ "Revert the diff hunk with changes at or above the point."
+ (interactive)
+ (with-current-buffer (or (buffer-base-buffer) (current-buffer))
+ (diff-hl-revert-hunk-1)))
+
(defun diff-hl-hunk-overlay-at (pos)
(cl-loop for o in (overlays-in pos (1+ pos))
when (overlay-get o 'diff-hl-hunk)
diff --git a/test/diff-hl-test.el b/test/diff-hl-test.el
new file mode 100644
index 0000000..b94c316
--- /dev/null
+++ b/test/diff-hl-test.el
@@ -0,0 +1,128 @@
+;;; diff-hl-test.el --- tests for diff-hl -*- lexical-binding: t -*-
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; Author: Nathan Moreau <nathan.moreau@m4x.org>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'diff-hl)
+(require 'subr-x) ;; string-trim
+(require 'ert)
+
+(defvar diff-hl-test-source-file
+ (expand-file-name (concat (file-name-directory (locate-library "diff-hl"))
+ "test/empty")))
+
+(defvar diff-hl-test-initial-content nil)
+
+(defmacro diff-hl-test-in-source (&rest body)
+ `(save-window-excursion
+ (find-file diff-hl-test-source-file)
+ ,@body))
+(put 'diff-hl-test-in-source 'lisp-indent-function 0)
+
+(defun diff-hl-test-init ()
+ (diff-hl-test-in-source
+ (setq diff-hl-test-initial-content (buffer-string)))
+ t)
+
+(defun diff-hl-test-teardown ()
+ (diff-hl-test-in-source
+ (erase-buffer)
+ (insert diff-hl-test-initial-content)
+ (save-buffer)))
+
+(defun diff-hl-test-compute-diff-lines ()
+ (diff-hl-test-in-source
+ (save-buffer)
+ (let ((vc-diff-switches "-w"))
+ (diff-hl-diff-goto-hunk))
+ (switch-to-buffer "*vc-diff*")
+ (let ((lines nil)
+ (previous-line (point-min)))
+ (goto-char (point-min))
+ (while (< (point) (point-max))
+ (forward-line 1)
+ (push (string-trim (buffer-substring-no-properties previous-line
(point))) lines)
+ (setq previous-line (point)))
+ (delq nil (nreverse lines)))))
+
+(defmacro diff-hl-deftest (name &rest body)
+ `(ert-deftest ,name ()
+ (diff-hl-test-init)
+ (unwind-protect
+ (progn ,@body)
+ (diff-hl-test-teardown))))
+(put 'diff-hl-deftest 'lisp-indent-function 'defun)
+
+(diff-hl-deftest diff-hl-insert ()
+ (diff-hl-test-in-source
+ (goto-char (point-max))
+ (insert "added\n")
+ (should (equal "+added"
+ (car (last (diff-hl-test-compute-diff-lines)))))))
+
+(diff-hl-deftest diff-hl-remove ()
+ (diff-hl-test-in-source
+ (delete-region (point-min) (point-max))
+ (should (equal "-last line"
+ (car (last (diff-hl-test-compute-diff-lines)))))))
+
+(diff-hl-deftest diff-hl-indirect-buffer-insert ()
+ (diff-hl-test-in-source
+ (narrow-to-region (point-min) (point-max))
+ (goto-char (point-max))
+ (insert "added\n")
+ (should (equal "+added"
+ (car (last (diff-hl-test-compute-diff-lines)))))))
+
+(diff-hl-deftest diff-hl-indirect-buffer-remove ()
+ (diff-hl-test-in-source
+ (narrow-to-region (point-min) (point-max))
+ (goto-char (point-min))
+ (delete-region (point) (point-max))
+ (should (equal "-last line"
+ (car (last (diff-hl-test-compute-diff-lines)))))))
+
+(diff-hl-deftest diff-hl-indirect-buffer-move ()
+ (diff-hl-test-in-source
+ (narrow-to-region (point-min) (point-max))
+ (goto-char (point-min))
+ (kill-whole-line 3)
+ (goto-char (point-max))
+ (insert "added\n")
+ (save-buffer)
+ (diff-hl-mode 1)
+ (diff-hl-previous-hunk)
+ (should (looking-at "added"))
+ (diff-hl-previous-hunk)
+ (should (looking-at "function2"))
+ (should-error (diff-hl-previous-hunk) :type 'user-error)
+ (diff-hl-next-hunk)
+ (should (looking-at "added"))
+ (should-error (diff-hl-next-hunk) :type 'user-error)))
+
+(defun diff-hl-run-tests ()
+ (ert-run-tests-batch))
+
+(provide 'diff-hl-test)
+
+;;; diff-hl-test.el ends here
diff --git a/test/empty b/test/empty
new file mode 100644
index 0000000..8fa2495
--- /dev/null
+++ b/test/empty
@@ -0,0 +1,10 @@
+function1 () {
+}
+
+function2 () {
+}
+
+function3 () {
+}
+
+last line
- [elpa] externals/diff-hl 1f35974 01/25: Fix windows getting messed up (Issue #125), (continued)
- [elpa] externals/diff-hl 1f35974 01/25: Fix windows getting messed up (Issue #125), Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl ccf89ec 02/25: Fix #128, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl 9c1c95c 03/25: Fix typo, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl f95d123 04/25: Merge pull request #129 from tarsiiformes/typo, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl 3418630 05/25: diff-hl-flydiff-buffer-with-head: Honor diff-hl-reference-revision, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl fb9eb1c 06/25: Merge pull request #127 from m-cat/diff-apply-hunk, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl 2cf8b48 07/25: Avoid the "args out of range error", Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl bc02c99 08/25: Add variable to ask for confirmation when reverting a hunk, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl ba6cf44 12/25: Add tests., Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl 7fce94f 09/25: Merge pull request #137 from erickgnavar/feature/ask-for-confirmation-on-revert-hunk, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl ab2f4f0 13/25: Merge pull request #140 from mookid/fix-indirect-buffers,
Dmitry Gutov <=
- [elpa] externals/diff-hl 2281a89 17/25: Update docstring and untabify, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl a625033 10/25: Update Magit bridge to use the recommended approach, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl f3b2d15 11/25: diff-hl-diff-goto-hunk, diff-hl-revert-hunk: handle indirect buffers., Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl 176f931 14/25: Support buffers in 'conflict' state as well, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl 165a30f 16/25: Merge pull request #143 from walseb/master, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl c58098c 15/25: Added option to not automatically enable diff-hl in certain major-modes, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl d1b9a2b 18/25: Add global-diff-hl-amend-mode to diff-hl custom group, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl c31af59 20/25: Don't hook into after-revert-hook, Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl 8ed1120 22/25: Revert "Don't hook into after-revert-hook", Dmitry Gutov, 2020/12/20
- [elpa] externals/diff-hl f6244ab 19/25: Merge pull request #150 from tarsiiformes/custom-group, Dmitry Gutov, 2020/12/20