From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Konstantin Kharlamov Newsgroups: gmane.emacs.bugs Subject: bug#37395: [PATCH v4] diff-mode.el: take into account patch separators Date: Tue, 8 Oct 2019 22:34:20 +0300 Message-ID: <20191008193420.193239-1-Hi-Angel@yandex.ru> References: <1568323985.28657.0@yandex.ru> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="2687"; mail-complaints-to="usenet@blaine.gmane.org" To: 37395@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Oct 08 21:38:07 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iHvJ8-0000bS-KY for geb-bug-gnu-emacs@m.gmane.org; Tue, 08 Oct 2019 21:38:06 +0200 Original-Received: from localhost ([::1]:33848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHvJ7-0005dO-4h for geb-bug-gnu-emacs@m.gmane.org; Tue, 08 Oct 2019 15:38:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46655) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHvGB-00045c-Pz for bug-gnu-emacs@gnu.org; Tue, 08 Oct 2019 15:35:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHvGA-00078p-G1 for bug-gnu-emacs@gnu.org; Tue, 08 Oct 2019 15:35:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42724) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHvGA-00078h-8U for bug-gnu-emacs@gnu.org; Tue, 08 Oct 2019 15:35:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iHvGA-0002qI-44 for bug-gnu-emacs@gnu.org; Tue, 08 Oct 2019 15:35:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <1568323985.28657.0@yandex.ru> Resent-From: Konstantin Kharlamov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 08 Oct 2019 19:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37395 X-GNU-PR-Package: emacs Original-Received: via spool by 37395-submit@debbugs.gnu.org id=B37395.157056328010888 (code B ref 37395); Tue, 08 Oct 2019 19:35:02 +0000 Original-Received: (at 37395) by debbugs.gnu.org; 8 Oct 2019 19:34:40 +0000 Original-Received: from localhost ([127.0.0.1]:51545 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iHvFo-0002pY-43 for submit@debbugs.gnu.org; Tue, 08 Oct 2019 15:34:40 -0400 Original-Received: from forward100j.mail.yandex.net ([5.45.198.240]:56956) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iHvFj-0002pE-8Y for 37395@debbugs.gnu.org; Tue, 08 Oct 2019 15:34:38 -0400 Original-Received: from forward102q.mail.yandex.net (forward102q.mail.yandex.net [IPv6:2a02:6b8:c0e:1ba:0:640:516:4e7d]) by forward100j.mail.yandex.net (Yandex) with ESMTP id 9A81650E03A5 for <37395@debbugs.gnu.org>; Tue, 8 Oct 2019 22:34:27 +0300 (MSK) Original-Received: from mxback10q.mail.yandex.net (mxback10q.mail.yandex.net [IPv6:2a02:6b8:c0e:1b4:0:640:b6ef:cb3]) by forward102q.mail.yandex.net (Yandex) with ESMTP id 947397F20017 for <37395@debbugs.gnu.org>; Tue, 8 Oct 2019 22:34:27 +0300 (MSK) Original-Received: from vla5-63eb7479a3c9.qloud-c.yandex.net (vla5-63eb7479a3c9.qloud-c.yandex.net [2a02:6b8:c18:3411:0:640:63eb:7479]) by mxback10q.mail.yandex.net (nwsmtp/Yandex) with ESMTP id scSyZydX9a-YRIW7YeQ; Tue, 08 Oct 2019 22:34:27 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1570563267; bh=4Ol1viYtRtNIqN1z/FgAGmSPi0rCp84NFWO+dd2A3cY=; h=Subject:To:From:Date:Message-Id; b=IBu6V28ez8sqTdxNE5JiKWyyvwO3+cwRYri1Uh9HS69pyoUdAui8p2dz6k7hLrjec 1Cg1lECGs3439ClzhBMgxLhPYWEg8qxNPUQAbKubhLiirgOeXc9mfEeQtzYROA5mmx g8JfNwz+9cIqH6k2mVwQbTok6Ps5EHXgzRBx3lRE= Authentication-Results: mxback10q.mail.yandex.net; dkim=pass header.i=@yandex.ru Original-Received: by vla5-63eb7479a3c9.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA id A2PCPZJIvS-YQrmqrBb; Tue, 08 Oct 2019 22:34:26 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Mailer: git-send-email 2.23.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:168680 Archived-At: * 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