From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jens Schmidt Newsgroups: gmane.emacs.help Subject: Re: delete lines with overlays [workaround to diff mode] Date: Wed, 30 Aug 2023 18:25:20 +0200 Message-ID: References: <89105064-20a7-30e3-6aa9-e2610e9a2c19@vodafonemail.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5212"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Cc: help-gnu-emacs@gnu.org To: Samuel Wales Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 30 18:26:18 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qbO1J-0001BI-RI for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 30 Aug 2023 18:26:17 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbO0o-0003wO-DE; Wed, 30 Aug 2023 12:25:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbO0m-0003va-JY for help-gnu-emacs@gnu.org; Wed, 30 Aug 2023 12:25:44 -0400 Original-Received: from mr6.vodafonemail.de ([145.253.228.166]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbO0j-0006fa-Mm for help-gnu-emacs@gnu.org; Wed, 30 Aug 2023 12:25:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vodafonemail.de; s=vfde-mb-mr2-21dec; t=1693412739; bh=dAm4mByzHIlamZVmzpan8ZFCzSZnY1nr1UL8c8lSsS4=; h=Message-ID:Date:User-Agent:From:Subject:To:References: Content-Language:In-Reply-To:Content-Type:From; b=IkWM85xxD36Z+HnhqMv3lerZ2444LQiX6TU66FSNjkOVwjo5XW4oISTAwkzn+Y0d7 AI+k77sH7Of389HqzS+c9AsSlHkTIhR10eeL9qjYDlA9KfSo1K/R2kP0uNtInIAjcR SiR8ULd8weAcYQdKm/FAa3Zs4iGP/cQjMVoETQFg= Original-Received: from smtp.vodafone.de (unknown [10.0.0.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mr6.vodafonemail.de (Postfix) with ESMTPS id 4RbV5b1DB3z1xwq; Wed, 30 Aug 2023 16:25:39 +0000 (UTC) Original-Received: from [192.168.0.138] (unknown [86.33.72.162]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp.vodafone.de (Postfix) with ESMTPSA id 4RbV5R2KpCz9s6F; Wed, 30 Aug 2023 16:25:28 +0000 (UTC) X-Mozilla-News-Host: news://news.gmane.io Content-Language: de-DE-frami, en-US In-Reply-To: X-purgate-type: clean X-purgate: clean X-purgate-size: 4608 X-purgate-ID: 155817::1693412735-377FFE22-C684CEC6/0/0 Received-SPF: pass client-ip=145.253.228.166; envelope-from=jschmidt4gnu@vodafonemail.de; helo=mr6.vodafonemail.de X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-1.242, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:145028 Archived-At: [Internet sucks at my current place, sorry for the split sends/resends.] On 2023-08-30 07:07, Samuel Wales wrote: > currently 27 How convenient ... having that around here as well. As Dmitry has noted in your bug#61396, the diff refinement machinery probably already has what you are looking for, but without ready-made switches to turn it on. You might want to try whether the following modified function `diff--refine-hunk' does what you need. Not sure how proficient you are in Elisp hacking, so I provide full instructions to get it activated. 1. Start Emacs as "emacs -Q" to get reproducible results. (This is required only for the initial tests.) 2. M-x load-library diff-mode RET to load the original library 3. Paste below function definition into *scratch* and press C-M-x with point in or after the definition to evaluate the modified function definition. 4. Then check whether the result matches your expectation. The only lines I modified in the function are these: - (smerge-refine-regions beg-del beg-add beg-add end-add - nil #'diff-refine-preproc props-r props-a))))) I replaced that by: + (smerge-refine-regions beg-del beg-add beg-add end-add + props-c nil nil nil))))) Comments: - `props-c' is responsible for highlighting changes in yellow (compared to `props-r' for removals, `props-a' for additions) - Function `diff-refine-preproc' referenced in the original function strips off the leading '-' and '+' chars from the diffs to avoid getting them highlighted as refined diffs. When replacing the reference to that function by nil, these leading chars get processed by the refinement as well and are highlighted as changes if needed. Hopefully, they did at least in the samples I checked. You might also want to try: + (smerge-refine-regions beg-del beg-add beg-add end-add + props-c nil props-r props-a))))) Anyway, here is the full modified function: (defun diff--refine-hunk (start end) (require 'smerge-mode) (goto-char start) (let* ((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)))) (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-regions beg-del beg-add beg-add end-add props-c nil nil nil))))) ('context (let* ((middle (save-excursion (re-search-forward "^---" end))) (other middle)) (while (re-search-forward "^\\(?:!.*\n\\)+" middle t) (smerge-refine-regions (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-regions beg1 (match-beginning 0) (match-end 0) end nil #'diff-refine-preproc props-r props-a)))))))