From unknown Tue Jun 17 01:36:38 2025 X-Loop: help-debbugs@gnu.org Subject: bug#25571: 24.5; Check if there are hunks before kill or refine a hunk 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: To: 25571@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.148568987517770 (code B ref -1); Sun, 29 Jan 2017 11:38:02 +0000 Received: (at submit) by debbugs.gnu.org; 29 Jan 2017 11:37:55 +0000 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 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 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 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 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 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 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 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 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) 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) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Sun, 29 Jan 2017 20:37:37 +0900 (JST) X-X-Sender: calancha@calancha-pc Message-ID: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII 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-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) 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 From unknown Tue Jun 17 01:36:38 2025 X-Loop: help-debbugs@gnu.org Subject: bug#25571: 24.5; Check if there are hunks before kill or refine a hunk Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 29 Jan 2017 11:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25571 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 25571@debbugs.gnu.org Cc: Tino Calancha Received: via spool by 25571-submit@debbugs.gnu.org id=B25571.148569037818572 (code B ref 25571); Sun, 29 Jan 2017 11:47:01 +0000 Received: (at 25571) by debbugs.gnu.org; 29 Jan 2017 11:46:18 +0000 Received: from localhost ([127.0.0.1]:49738 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXnw2-0004pU-Lr for submit@debbugs.gnu.org; Sun, 29 Jan 2017 06:46:18 -0500 Received: from mail-pf0-f170.google.com ([209.85.192.170]:33472) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXnw1-0004pF-9b for 25571@debbugs.gnu.org; Sun, 29 Jan 2017 06:46:17 -0500 Received: by mail-pf0-f170.google.com with SMTP id y143so83798598pfb.0 for <25571@debbugs.gnu.org>; Sun, 29 Jan 2017 03:46:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version; bh=oqLDWlhLOd3ka/5jhm50G6MYb/T0/a6iFwOw46WzWMY=; b=NO6LAd7JJ5R22r0Mofc6M/A7VE62Yd9rEW4nXFjVrAUWBHxvQfYm/5rm/lVCd08BR9 fSL/wPYkpQPhhw19HJZPeNJaK2Yube6tU3c+ypms7KTQUhZYD9etv9fyyuzq/OFaohjO /9+ngt13hiW2eeYopQZFD85vb1nMPPxUeOmPU3FTeU6nULTfXC54EPdy4BG2kxSPSJJt Dvu+HrjYHgA/dEdpuJUlJ4ivo2dyXf+eoUQ3cAF4OVEcCvuHfgc70xb4IEkBXuAGSa+p H86fTIBAh6v/Sz/7z0M5alZBfEYZ1lGsLlOzE9RKanXUxfzsFb2EJwbpe7ZJaTbe1PZ5 DOaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :user-agent:date:message-id:mime-version; bh=oqLDWlhLOd3ka/5jhm50G6MYb/T0/a6iFwOw46WzWMY=; b=OijVU7SbOgnh8tGf/pqK5fZ7ya6pIVXW+SEBttQYSfcRROH1Vxvs+SA/42HNeDjFV6 1p7qYFKe9M45a/maqwQqmHtnzVY3IVFj4djViAe3qngId70mEDyWYHqCrOcxn9T1vFbT 0mMIs23BgRVZU+y4N2A6yQzzDccweeuHXyHl30WqY+OCfXUsaRymj+oYImSd6auNlY4x 4gbuCUgwbsqtcb+IbQHOZTBoXdXwQmGGf4VhkDmXUtw03hpMvzdBdd67LYAT3kGwsh35 MzicZW5Ik9U5c9M2vr+FiEySEeRwy52Gmo+9r6DUGJmTA37ROxI/dcr1rMQ/Eku5BlRH bYMQ== X-Gm-Message-State: AIkVDXJfX/K2c6+i453CY9Rbllg9p473iKyc8utp2vxqhv+0bSZHgUFoE0L/sHnitWD6XQ== X-Received: by 10.84.137.165 with SMTP id 34mr25110305pln.24.1485690371397; Sun, 29 Jan 2017 03:46:11 -0800 (PST) Received: from calancha-pc (33.94.100.220.dy.bbexcite.jp. [220.100.94.33]) by smtp.gmail.com with ESMTPSA id l25sm24395848pfb.24.2017.01.29.03.46.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Jan 2017 03:46:10 -0800 (PST) From: Tino Calancha In-Reply-To: (Tino Calancha's message of "Sun, 29 Jan 2017 20:37:37 +0900 (JST)") References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Date: Sun, 29 Jan 2017 20:46:06 +0900 Message-ID: <87bmuqum0x.fsf@calancha-pc> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.3 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) Tino Calancha writes: > 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 I forgot the receipt; do the following: < ; Go to beginning of buffer M-n M-k M-n ; Shows: 'No next hunk'. M-k ; Shows: "Can't find the beginning of the file". ;; It would be more clear a message like: 'No more hunks'. From unknown Tue Jun 17 01:36:38 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Tino Calancha Subject: bug#25571: closed (Re: bug#25571: 24.5; Check if there are hunks before kill or refine a hunk) Message-ID: References: <87mve47m3d.fsf@calancha-pc> X-Gnu-PR-Message: they-closed 25571 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 25571@debbugs.gnu.org Date: Thu, 02 Feb 2017 13:35:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1486042502-17790-1" This is a multi-part message in MIME format... ------------=_1486042502-17790-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #25571: 24.5; Check if there are hunks before kill or refine a hunk which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 25571@debbugs.gnu.org. --=20 25571: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D25571 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1486042502-17790-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 25571-done) by debbugs.gnu.org; 2 Feb 2017 13:34:41 +0000 Received: from localhost ([127.0.0.1]:53845 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZHX7-0004cE-9d for submit@debbugs.gnu.org; Thu, 02 Feb 2017 08:34:41 -0500 Received: from mail-pf0-f181.google.com ([209.85.192.181]:36216) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZHX5-0004c0-Nd for 25571-done@debbugs.gnu.org; Thu, 02 Feb 2017 08:34:39 -0500 Received: by mail-pf0-f181.google.com with SMTP id 189so5515040pfu.3 for <25571-done@debbugs.gnu.org>; Thu, 02 Feb 2017 05:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version; bh=AcWVB9GnSbQzIssiv6ODvyo+V/O/EmTx2vyLzGL3bL4=; b=CPEcMNLZxqYi/Ss71oKxxIfs/CYPJjFLoH85HZV9ZQM5DsLKMdFcOSR60sbCuR7TjT O6Sz5rZ/DgMfkFqOwHcGFpwHkLd/VpcBcXHNzLZtefO8iaaxhCCyTQwGdIsCTXQcQOAb Yah/IqX1kc4GBUbsiPENh92P6UKeIX/Uq0J36XOBKngZ69tgjLSJUjoDzxTko7uMTGpK rloLYv6kcMztCW9dye+rXfP8dzMdTq/oxxk/KctR6yVky587etsjCfxgmThHPZX9kq74 ngAy9IFN8tiOl635hMAp3xNg8WK/z/GMWuuURLSfJmleoMG40aU8DOPChdx9xCh8W4NZ BoCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=AcWVB9GnSbQzIssiv6ODvyo+V/O/EmTx2vyLzGL3bL4=; b=peY7jkgjEPF2Yq7ZGGqUjaFXMyJtUVJ1EO71aqJ8fefSw2sLaAQyBDOVlH81ApOoNC o456ipXbsUUKcts+R5d1zuDJX7XZ6ewyvMHjlU2gOlex7rosnFnViq6VGCCUAtrfm1Gu XtWy3T5nNiNG0DXvHswCA618R5tQnm8P7rron8ew624ti11AQ75FKLusgiY4k++1G8h4 WHeuer5Zyxn8XsV/Tk4fiqh48FiJu9sikCJAB5z0W/1xMHNciglpVFaBGX9qSWMrSwtZ 9nEgioMFkXifNZvGWzBZGczEtWADUlqTo/6Sbv31cALFgDaDHzUpiMP0RaEPSwa2xUml VUBQ== X-Gm-Message-State: AIkVDXJlfx/1SICoPGqGWvPCWJghMo+R1dlQmZvREceiy27prKMH/4L+vDNGcFObpPdzcQ== X-Received: by 10.84.179.99 with SMTP id a90mr12505596plc.139.1486042473615; Thu, 02 Feb 2017 05:34:33 -0800 (PST) Received: from calancha-pc (104.81.147.124.dy.bbexcite.jp. [124.147.81.104]) by smtp.gmail.com with ESMTPSA id z77sm58749927pfk.47.2017.02.02.05.34.32 for <25571-done@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Feb 2017 05:34:33 -0800 (PST) From: Tino Calancha To: 25571-done@debbugs.gnu.org Subject: Re: bug#25571: 24.5; Check if there are hunks before kill or refine a hunk References: <87bmuqum0x.fsf@calancha-pc> Date: Thu, 02 Feb 2017 22:34:30 +0900 In-Reply-To: <87bmuqum0x.fsf@calancha-pc> (Tino Calancha's message of "Sun, 29 Jan 2017 20:46:06 +0900") Message-ID: <87mve47m3d.fsf@calancha-pc> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.6 (/) X-Debbugs-Envelope-To: 25571-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.6 (/) Tino Calancha writes: > Tino Calancha writes: > >> 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 > < ; Go to beginning of buffer > M-n M-k > M-n ; Shows: 'No next hunk'. > M-k ; Shows: "Can't find the beginning of the file". > ;; It would be more clear a message like: 'No more hunks'. Push fix to master branch as commit a362b56b51f49963dbb63cd318967bca9b9fef74 ------------=_1486042502-17790-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 29 Jan 2017 11:37:55 +0000 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 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 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 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 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 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 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 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 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) 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) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Sun, 29 Jan 2017 20:37:37 +0900 (JST) X-X-Sender: calancha@calancha-pc To: bug-gnu-emacs@gnu.org Subject: 24.5; Check if there are hunks before kill or refine a hunk Message-ID: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII 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-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) 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 ------------=_1486042502-17790-1--