From: Konstantin Kharlamov <Hi-Angel@yandex.ru>
To: 37395@debbugs.gnu.org
Subject: bug#37395: [PATCH v4] diff-mode.el: take into account patch separators
Date: Tue, 8 Oct 2019 22:34:20 +0300 [thread overview]
Message-ID: <20191008193420.193239-1-Hi-Angel@yandex.ru> (raw)
In-Reply-To: <1568323985.28657.0@yandex.ru>
* lisp/vc/diff-mode.el (diff-prev-line-if-patch-separator):
A function to return prev. line if it has git-format-patch
separator.
(diff-end-of-hunk): Make use of
diff-prev-line-if-patch-separator
diff-buffer-type: whether a buffer is a git-diff
(define-derived-mode): set diff-buffer-type to appropriate
value
---
v4:
* replace defsubst with defun
* define diff-buffer-type with defvar and set with setq-local
* call `setq-local` just once
lisp/vc/diff-mode.el | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 19f9c802d4..1cc3cd3d4d 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -511,6 +511,19 @@ diff-hunk-style
(goto-char (match-end 0)))
style)
+(defun diff-prev-line-if-patch-separator ()
+ "Return previous line if it has patch separator as produced by git."
+ (pcase diff-buffer-type
+ ('git
+ (save-excursion
+ (let ((old-point (point)))
+ (previous-line)
+ (beginning-of-line)
+ (if (looking-at "^-- $")
+ (point)
+ old-point))))
+ (_ (point))))
+
(defun diff-end-of-hunk (&optional style donttrustheader)
"Advance to the end of the current hunk, and return its position."
(let (end)
@@ -561,7 +574,8 @@ diff-end-of-hunk
(goto-char (or end (point-max)))
(while (eq ?\n (char-before (1- (point))))
(forward-char -1)
- (setq end (point)))))
+ (setq end (point))))
+ (setq end (diff-prev-line-if-patch-separator)))
;; The return value is used by easy-mmode-define-navigation.
(goto-char (or end (point-max)))))
@@ -1425,6 +1439,7 @@ diff--font-lock-cleanup
(defvar whitespace-style)
(defvar whitespace-trailing-regexp)
+(defvar diff-buffer-type nil)
;;;###autoload
(define-derived-mode diff-mode fundamental-mode "Diff"
@@ -1491,7 +1506,12 @@ diff-mode
(add-function :filter-return (local 'filter-buffer-substring-function)
#'diff--filter-substring)
(unless buffer-file-name
- (hack-dir-local-variables-non-file-buffer)))
+ (hack-dir-local-variables-non-file-buffer))
+ (save-excursion
+ (setq-local diff-buffer-type
+ (if (re-search-forward "^diff --git" nil t)
+ 'git
+ nil))))
;;;###autoload
(define-minor-mode diff-minor-mode
--
2.23.0
next prev parent reply other threads:[~2019-10-08 19:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-12 21:33 bug#37395: Diff-mode doesn't take into account patch-separators as produced by git-format-patch Konstantin Kharlamov
2019-09-12 21:34 ` bug#37395: [PATCH] diff-mode.el: take into account patch separators Konstantin Kharlamov
2019-09-13 6:14 ` Eli Zaretskii
2019-09-13 6:58 ` Konstantin Kharlamov
2019-09-16 20:31 ` Konstantin Kharlamov
2019-09-13 9:19 ` bug#37395: [PATCH v2] " Konstantin Kharlamov
2019-09-16 20:26 ` bug#37395: [PATCH v3] " Konstantin Kharlamov
2019-10-07 4:39 ` Lars Ingebrigtsen
2019-10-07 23:04 ` Konstantin Kharlamov
2019-10-07 23:12 ` Konstantin Kharlamov
2019-10-08 15:59 ` Lars Ingebrigtsen
2019-10-08 20:08 ` Konstantin Kharlamov
2019-10-08 19:34 ` Konstantin Kharlamov [this message]
2019-10-09 19:36 ` bug#37395: [PATCH v4] " Lars Ingebrigtsen
2019-10-09 20:08 ` Konstantin Kharlamov
2019-10-09 20:07 ` bug#37395: [PATCH v5] " Konstantin Kharlamov
2019-10-13 3:53 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191008193420.193239-1-Hi-Angel@yandex.ru \
--to=hi-angel@yandex.ru \
--cc=37395@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).