From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jens Schmidt via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Re: delete lines with overlays [workaround to diff mode] Date: Wed, 30 Aug 2023 13:30:41 +0200 Message-ID: <052ec29e-5293-2cef-673a-2d833319a1e2@vodafonemail.de> References: <89105064-20a7-30e3-6aa9-e2610e9a2c19@vodafonemail.de> Reply-To: Jens Schmidt 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="16574"; 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: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 30 13:31:41 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 1qbJQC-00045v-S0 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 30 Aug 2023 13:31:40 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbJPo-0002I2-2h; Wed, 30 Aug 2023 07:31:16 -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 1qbJPl-0002HM-96 for help-gnu-emacs@gnu.org; Wed, 30 Aug 2023 07:31:13 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbJPf-00007o-H0 for help-gnu-emacs@gnu.org; Wed, 30 Aug 2023 07:31:13 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1qbJPd-0003V6-0K for help-gnu-emacs@gnu.org; Wed, 30 Aug 2023 13:31:05 +0200 X-Injected-Via-Gmane: http://gmane.org/ Content-Language: de-DE-frami, en-US In-Reply-To: Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NICE_REPLY_A=-1.242, 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:145025 Archived-At: 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)))))))