From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#25571: 24.5; Check if there are hunks before kill or refine a hunk Date: Sun, 29 Jan 2017 20:37:37 +0900 (JST) Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1485689917 22517 195.159.176.226 (29 Jan 2017 11:38:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 29 Jan 2017 11:38:37 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) To: 25571@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jan 29 12:38:30 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXno7-0003VM-L7 for geb-bug-gnu-emacs@m.gmane.org; Sun, 29 Jan 2017 12:38:07 +0100 Original-Received: from localhost ([::1]:54894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXnoC-0000aY-WC for geb-bug-gnu-emacs@m.gmane.org; Sun, 29 Jan 2017 06:38:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXno5-0000aT-Py for bug-gnu-emacs@gnu.org; Sun, 29 Jan 2017 06:38:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cXno2-0007nS-Kp for bug-gnu-emacs@gnu.org; Sun, 29 Jan 2017 06:38:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51534) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cXno2-0007nO-Gv for bug-gnu-emacs@gnu.org; Sun, 29 Jan 2017 06:38:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cXno2-0004cv-Bi for bug-gnu-emacs@gnu.org; Sun, 29 Jan 2017 06:38:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 29 Jan 2017 11:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 25571 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.148568987517770 (code B ref -1); Sun, 29 Jan 2017 11:38:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Jan 2017 11:37:55 +0000 Original-Received: from localhost ([127.0.0.1]:49733 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXnnu-0004cY-KN for submit@debbugs.gnu.org; Sun, 29 Jan 2017 06:37:54 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:43694) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXnnt-0004cL-4G for submit@debbugs.gnu.org; Sun, 29 Jan 2017 06:37:53 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cXnnm-0007k4-GA for submit@debbugs.gnu.org; Sun, 29 Jan 2017 06:37:48 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:54376) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cXnnm-0007jp-CZ for submit@debbugs.gnu.org; Sun, 29 Jan 2017 06:37:46 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXnnk-0000ZI-Ib for bug-gnu-emacs@gnu.org; Sun, 29 Jan 2017 06:37:46 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cXnnh-0007hK-Fb for bug-gnu-emacs@gnu.org; Sun, 29 Jan 2017 06:37:44 -0500 Original-Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:34882) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cXnnh-0007go-7n for bug-gnu-emacs@gnu.org; Sun, 29 Jan 2017 06:37:41 -0500 Original-Received: by mail-pf0-x242.google.com with SMTP id f144so21523419pfa.2 for ; Sun, 29 Jan 2017 03:37:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:subject:message-id:user-agent:mime-version; bh=Y4MgdKHQ3mUkJoxefmUo2vbVeTX/C7LSK/peWBvcQCM=; b=jl5hAizJCYPtyPGCrN14fZzkh6hdihEesgIXWX+vUdSYohO+CEkck66YFIcgTxAUBr sd92fR+yejdUx/0mFtLP8T/20xlVIhbQ3eZJ2EF0szcxH1Ip2OGlIECfMbrsDGeLtZOJ MKIIdfRiofxqfkiSM9xQiOz1esdN7bmlvppgcUGVpdJhXvNnJeXvKkh6oByFbaN5d5r2 x1F1wS/ya7nfS1k96AKrMMgKaYAVIe7d6h6gjjDq4IYz/P9MiHEuMEHcSFb70Ckypj2H utPWsAsQNXN8wE6QifkHN1U8Rugm3UPAoeN4Itp2Y7AN0pWU/uoi0vkCiJpcQ+9qxUrL F4uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:subject:message-id:user-agent :mime-version; bh=Y4MgdKHQ3mUkJoxefmUo2vbVeTX/C7LSK/peWBvcQCM=; b=QjSVFEjXYk/E+wWkXllxefLBXMzyqSmcB4erkWXJHrE3pxgo2l4jgNVZHxnYPIBWNq a9lSKl4WvvEPMrrjH57A2d54wz1REesBAZx0vKWXQlJyQU8KPVsRt5W4dGk0c9OT6IMe /4ldBA6vSowyymMkzjN56HzEp018lv2/cH2VmKFGPntb6wlpGBKp3KowwUwl1M9wq2+P Y4MXaYnBwgkTczsN0Leqpa2y0cx8Ajxg1lWAV5XQkR1dJeDccp6x6gh6BBq0p2mu9h5r 5RjmLF/mHfMZQg5Xsj8UV9vG6cxHpLa+uhG4mkb7aAy1qwip7VHLC82Q8stcGbYhWxv4 G09Q== X-Gm-Message-State: AIkVDXLEI7FhQ0C0ylVmlz2SRH4y/uOnfXqdjCaHk3wN0eP6515TLpkZaCTbJHgiat6eRA== X-Received: by 10.84.209.203 with SMTP id y69mr24774458plh.115.1485689860122; Sun, 29 Jan 2017 03:37:40 -0800 (PST) Original-Received: from calancha-pc (33.94.100.220.dy.bbexcite.jp. [220.100.94.33]) by smtp.gmail.com with ESMTPSA id 66sm24391066pgg.47.2017.01.29.03.37.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Jan 2017 03:37:39 -0800 (PST) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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: 208.118.235.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:128750 Archived-At: emacs -Q: ; Put following content in a buffer in diff-mode: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; START diff --git a/a b/a index 184cbf6..d2d9a24 100644 --- a/a +++ b/a @@ -1,2 +1,2 @@ -I have a foo in my bar. +I have a qux in my bar. Me too. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END >From ed6a10f980bd1eec73982582db7599f936fa5315 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Sun, 29 Jan 2017 20:29:47 +0900 Subject: [PATCH] Check if there are hunks before kill or refine a hunk * lisp/vc/diff-mode.el (diff--some-hunks-p): New predicate. (diff-hunk-kill, diff-file-kill, diff-refine-hunk): Use it (Bug#25571). --- lisp/vc/diff-mode.el | 156 +++++++++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 73 deletions(-) diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index e609ca9f94..4ad03be7f0 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -647,28 +647,35 @@ diff-restrict-view (if arg (diff-bounds-of-file) (diff-bounds-of-hunk))) (set (make-local-variable 'diff-narrowed-to) (if arg 'file 'hunk))) +(defun diff--some-hunks-p () + (save-excursion + (goto-char (point-min)) + (re-search-forward diff-hunk-header-re nil t))) + (defun diff-hunk-kill () "Kill the hunk at point." (interactive) - (let* ((hunk-bounds (diff-bounds-of-hunk)) - (file-bounds (ignore-errors (diff-bounds-of-file))) - ;; If the current hunk is the only one for its file, kill the - ;; file header too. - (bounds (if (and file-bounds - (progn (goto-char (car file-bounds)) - (= (progn (diff-hunk-next) (point)) - (car hunk-bounds))) - (progn (goto-char (cadr hunk-bounds)) - ;; bzr puts a newline after the last hunk. - (while (looking-at "^\n") - (forward-char 1)) - (= (point) (cadr file-bounds)))) - file-bounds - hunk-bounds)) - (inhibit-read-only t)) - (apply 'kill-region bounds) - (goto-char (car bounds)) - (diff-beginning-of-hunk t))) + (if (not (diff--some-hunks-p)) + (error "No more hunks") + (let* ((hunk-bounds (diff-bounds-of-hunk)) + (file-bounds (ignore-errors (diff-bounds-of-file))) + ;; If the current hunk is the only one for its file, kill the + ;; file header too. + (bounds (if (and file-bounds + (progn (goto-char (car file-bounds)) + (= (progn (diff-hunk-next) (point)) + (car hunk-bounds))) + (progn (goto-char (cadr hunk-bounds)) + ;; bzr puts a newline after the last hunk. + (while (looking-at "^\n") + (forward-char 1)) + (= (point) (cadr file-bounds)))) + file-bounds + hunk-bounds)) + (inhibit-read-only t)) + (apply 'kill-region bounds) + (goto-char (car bounds)) + (diff-beginning-of-hunk t)))) (defun diff-beginning-of-file-and-junk () "Go to the beginning of file-related diff-info. @@ -720,9 +727,11 @@ diff-beginning-of-file-and-junk (defun diff-file-kill () "Kill current file's hunks." (interactive) - (let ((inhibit-read-only t)) - (apply 'kill-region (diff-bounds-of-file))) - (diff-beginning-of-hunk t)) + (if (not (diff--some-hunks-p)) + (error "No more hunks") + (let ((inhibit-read-only t)) + (apply 'kill-region (diff-bounds-of-file))) + (diff-beginning-of-hunk t))) (defun diff-kill-junk () "Kill spurious empty diffs." @@ -2000,57 +2009,58 @@ diff-refine-hunk "Highlight changes of hunk at point at a finer granularity." (interactive) (require 'smerge-mode) - (save-excursion - (diff-beginning-of-hunk t) - (let* ((start (point)) - (style (diff-hunk-style)) ;Skips the hunk header as well. - (beg (point)) - (props-c '((diff-mode . fine) (face diff-refine-changed))) - (props-r '((diff-mode . fine) (face diff-refine-removed))) - (props-a '((diff-mode . fine) (face diff-refine-added))) - ;; Be careful to go back to `start' so diff-end-of-hunk gets - ;; to read the hunk header's line info. - (end (progn (goto-char start) (diff-end-of-hunk) (point)))) - - (remove-overlays beg end 'diff-mode 'fine) - - (goto-char beg) - (pcase style - (`unified - (while (re-search-forward "^-" end t) - (let ((beg-del (progn (beginning-of-line) (point))) - beg-add end-add) - (when (and (diff--forward-while-leading-char ?- end) - ;; Allow for "\ No newline at end of file". - (progn (diff--forward-while-leading-char ?\\ end) - (setq beg-add (point))) - (diff--forward-while-leading-char ?+ end) - (progn (diff--forward-while-leading-char ?\\ end) - (setq end-add (point)))) - (smerge-refine-subst beg-del beg-add beg-add end-add - nil 'diff-refine-preproc props-r props-a))))) - (`context - (let* ((middle (save-excursion (re-search-forward "^---"))) - (other middle)) - (while (re-search-forward "^\\(?:!.*\n\\)+" middle t) - (smerge-refine-subst (match-beginning 0) (match-end 0) - (save-excursion - (goto-char other) - (re-search-forward "^\\(?:!.*\n\\)+" end) - (setq other (match-end 0)) - (match-beginning 0)) - other - (if diff-use-changed-face props-c) - 'diff-refine-preproc - (unless diff-use-changed-face props-r) - (unless diff-use-changed-face props-a))))) - (_ ;; Normal diffs. - (let ((beg1 (1+ (point)))) - (when (re-search-forward "^---.*\n" end t) - ;; It's a combined add&remove, so there's something to do. - (smerge-refine-subst beg1 (match-beginning 0) - (match-end 0) end - nil 'diff-refine-preproc props-r props-a)))))))) + (when (diff--some-hunks-p) + (save-excursion + (diff-beginning-of-hunk t) + (let* ((start (point)) + (style (diff-hunk-style)) ;Skips the hunk header as well. + (beg (point)) + (props-c '((diff-mode . fine) (face diff-refine-changed))) + (props-r '((diff-mode . fine) (face diff-refine-removed))) + (props-a '((diff-mode . fine) (face diff-refine-added))) + ;; Be careful to go back to `start' so diff-end-of-hunk gets + ;; to read the hunk header's line info. + (end (progn (goto-char start) (diff-end-of-hunk) (point)))) + + (remove-overlays beg end 'diff-mode 'fine) + + (goto-char beg) + (pcase style + (`unified + (while (re-search-forward "^-" end t) + (let ((beg-del (progn (beginning-of-line) (point))) + beg-add end-add) + (when (and (diff--forward-while-leading-char ?- end) + ;; Allow for "\ No newline at end of file". + (progn (diff--forward-while-leading-char ?\\ end) + (setq beg-add (point))) + (diff--forward-while-leading-char ?+ end) + (progn (diff--forward-while-leading-char ?\\ end) + (setq end-add (point)))) + (smerge-refine-subst beg-del beg-add beg-add end-add + nil 'diff-refine-preproc props-r props-a))))) + (`context + (let* ((middle (save-excursion (re-search-forward "^---"))) + (other middle)) + (while (re-search-forward "^\\(?:!.*\n\\)+" middle t) + (smerge-refine-subst (match-beginning 0) (match-end 0) + (save-excursion + (goto-char other) + (re-search-forward "^\\(?:!.*\n\\)+" end) + (setq other (match-end 0)) + (match-beginning 0)) + other + (if diff-use-changed-face props-c) + 'diff-refine-preproc + (unless diff-use-changed-face props-r) + (unless diff-use-changed-face props-a))))) + (_ ;; Normal diffs. + (let ((beg1 (1+ (point)))) + (when (re-search-forward "^---.*\n" end t) + ;; It's a combined add&remove, so there's something to do. + (smerge-refine-subst beg1 (match-beginning 0) + (match-end 0) end + nil 'diff-refine-preproc props-r props-a))))))))) (defun diff-undo (&optional arg) "Perform `undo', ignoring the buffer's read-only status." -- 2.11.0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.6) of 2017-01-29 Repository revision: 0073223c23749ffd6bd3f882bc30a82cc37efd2a