From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gabriel do Nascimento Ribeiro Newsgroups: gmane.emacs.bugs Subject: bug#45946: [PATCH] Re: bug#45946: 28.0.50; hl-line-sticky-flag not working Date: Fri, 22 Jan 2021 23:22:21 -0300 Message-ID: References: <83bldi74yn.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27595"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: 45946@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 23 03:38:22 2021 Return-path: Envelope-to: geb-bug-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 1l38of-00074A-Uh for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 23 Jan 2021 03:38:22 +0100 Original-Received: from localhost ([::1]:33084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l38oe-0007HY-Sk for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 Jan 2021 21:38:20 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l38oM-0007HA-5Q for bug-gnu-emacs@gnu.org; Fri, 22 Jan 2021 21:38:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50168) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l38oL-0000Q8-U8 for bug-gnu-emacs@gnu.org; Fri, 22 Jan 2021 21:38:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l38oL-00015g-R4 for bug-gnu-emacs@gnu.org; Fri, 22 Jan 2021 21:38:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Gabriel do Nascimento Ribeiro Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 23 Jan 2021 02:38:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45946 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16113694584161 (code B ref -1); Sat, 23 Jan 2021 02:38:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 23 Jan 2021 02:37:38 +0000 Original-Received: from localhost ([127.0.0.1]:33481 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l38nx-000152-FS for submit@debbugs.gnu.org; Fri, 22 Jan 2021 21:37:38 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:54646) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l38nt-00014s-2X for submit@debbugs.gnu.org; Fri, 22 Jan 2021 21:37:35 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l38ns-0006vO-Qz for bug-gnu-emacs@gnu.org; Fri, 22 Jan 2021 21:37:32 -0500 Original-Received: from mail-mw2nam10olkn2030.outbound.protection.outlook.com ([40.92.42.30]:46176 helo=NAM10-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l38nq-0000H1-Ha for bug-gnu-emacs@gnu.org; Fri, 22 Jan 2021 21:37:32 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FVehs/5JmiUJTKSWzSr3jMN8IemTiOjriCifFToWzezU9ZUoUv7J6aSJP35lWwPmWPSxYfc2ylUQEwDGAchhpdZj6MYKs4ExR2NAC1mRJ/pQMFUATFs4ouct004RWzP+Jisr8Aa6vFfBrxTo8cGGRQYpTl8iamZYzx6/IZbkyEAgAxvzXxdn+m1oeHIxw1WDflT27dYx3ISJwdxybRv8faP7Ddn/gtarT4tnlyuhTYmLcTot0FsArbor1IcbER4yics0aNU97D49FEQW/8fOiJeGCN53FqkDPKBoo8nF69dfqQXbfsXFaWwfuTNaiOutPx252B42rlnwzmJ8IJVT0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=upLb+nBqYrulzKAcMAlhS8cYLFxwPTZYkooe9k6NJWQ=; b=ObzAQBGSGbVM0dimuA6Z+qsFZmzl9mOJ8yyz2tpN6BSL3CGOvlb9wFSkKMz0ukXdkIrnPCT6inNvWERRYAcOUAAAzbHqWXd+VTBMAPN4l8ELHSdEu0KbwNYXWIej808oS9nwlJjnCwnJiskc2zoBahpkgwC7QjC5whngNqGHmkIVdwQ3bTza8ZT07nLY9p4XtAg7wHwGQ8ZE393bJfdLSUYO482tQnw9XOO116u9mRikgcooHIvgddCSHg5iR6tA7B2PMNBx9HtNUFUpi2VFtN5aKLDB7vr/cNb3yYqQv2/bRHvGE1oIbTucBVZGCwh6Z1U0DJ1dLwAs8BlvXbmw7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=upLb+nBqYrulzKAcMAlhS8cYLFxwPTZYkooe9k6NJWQ=; b=QrJT9Z6VHnF5dzl3iqF6hdIx+WafW3r7wVTAIIeFjyiTXQvrH6GVYVtMgtXP41QuObHyVRpMML8epT2DPVuinZMsGMxpmtkXjkpzXb8hsQNiJGHCNapDX51tFf4FLs4WDEZqi6YIyDiH3RmvmBS0cUt2/ECZcN5eGwC3ZnWoMpyD3xqXPw6a2tLzSMBc5M5RA8kvhntmcr+igjoGi8Zv1JlV1pExNc4q5uKTx2SoEBwvhEgt5O+HUb0UKyUxnudeHmexz5Hd9sSUt/S1tj6+jm/DzHzVobynAN7pqwjIJQOCuHKZYL2U2JHsPsjKr4MzfXORr0G4S0MNtchTKgRIIQ== Original-Received: from DM6NAM10FT020.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::42) by DM6NAM10HT119.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::333) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11; Sat, 23 Jan 2021 02:22:27 +0000 Original-Received: from CH2PR01MB5879.prod.exchangelabs.com (2a01:111:e400:7e86::45) by DM6NAM10FT020.mail.protection.outlook.com (2a01:111:e400:7e86::115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Sat, 23 Jan 2021 02:22:27 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:EC4DA1F55829060D9596B3E8D8BCD15712B843733AF2B9AFD9F5B5C89D11F988; UpperCasedChecksum:3D061C663327EBAFF3680CD1378A13DDF418E3314683CB44BD0E996A6BF449B1; SizeAsReceived:7656; Count:45 Original-Received: from CH2PR01MB5879.prod.exchangelabs.com ([fe80::d51d:8cbe:370a:39ac]) by CH2PR01MB5879.prod.exchangelabs.com ([fe80::d51d:8cbe:370a:39ac%7]) with mapi id 15.20.3763.014; Sat, 23 Jan 2021 02:22:27 +0000 In-Reply-To: <83bldi74yn.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 21 Jan 2021 16:13:52 +0200") X-TMN: [mnMGt7bqu2/QZhGjk2vMqduNbiLT0nm5oNK6yVM8th/UQ6LN26utlxJ/aJl3S7Ld] X-ClientProxiedBy: CPYP284CA0006.BRAP284.PROD.OUTLOOK.COM (2603:10d6:103:68::11) To CH2PR01MB5879.prod.exchangelabs.com (2603:10b6:610:3c::12) X-Microsoft-Original-Message-ID: <8735yspf36.fsf_-_@hotmail.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from precision5540 (2804:431:c7f3:76d5:a5da:d562:8946:2579) by CPYP284CA0006.BRAP284.PROD.OUTLOOK.COM (2603:10d6:103:68::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.12 via Frontend Transport; Sat, 23 Jan 2021 02:22:25 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 45 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 6ff95599-2652-4e73-d374-08d8bf45b9e5 X-MS-TrafficTypeDiagnostic: DM6NAM10HT119: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: N1Rj0tJpYA6icX5xmuSeMHxxMtoZ5DCrd7VTZcyLVeAM1YNwiAEREYxRuDcbwoECTQNp3uxhNOG3j/BAB8m3GBnxdsMWxBEjOJtr8VLpw1E5OHnSc99qEygQ7DtMt2D6nU+ppMTKQX6GJlyYh03+fEhm4EmHfcx/zn2IScyalPFYx7XVx/loza/sWis9/jRdIfF2SUOoh1+I23uc3oNbb8uVcsnIbgVzZ9s1wSpGnQbGsODsyGUS4mCX19VhZK7x X-MS-Exchange-AntiSpam-MessageData: OdsgcswFLZujvAOGo1Optr2G56Etd3O3PIRfSWj9EM7POddey8fmNvlBtro68twxelpV8I1NvXbpjdUK/NTSG4bFunXjrEBAcCgJhczw50Z67B9455HWQg0BZFjer3WfWxWZWb/ZO8bh/3A2ceMXvp7JZK158zqRqoEpmP/j/3lb62cKjiHyxCEIFRHY8tJXiTuos3ynE463byglrGoFUg== X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ff95599-2652-4e73-d374-08d8bf45b9e5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jan 2021 02:22:27.2786 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DM6NAM10FT020.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM10HT119 Received-SPF: pass client-ip=40.92.42.30; envelope-from=gabriel376@hotmail.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:198418 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Gabriel do Nascimento Ribeiro >> Date: Wed, 20 Jan 2021 22:07:33 -0300 >> >> Here is a proposal of patch for this bug. It seems to work well in all >> cases I have tested, but maybe I am missing some edge case. Suggestions >> are welcome. > > Thanks. > > While at that, would it be possible to fix some code there that I at > least consider strange? E.g., it calls delete-overlay, but doesn't > assign nil to the variable, so the overlayp predicate still returns > non-nil for the resulting invalid overlay. Also, it puts 2 functions > on the post-command-hook, but it looks like the code subtly depends on > the order of their execution (should hl-line-highlight run before or > after hl-line-maybe-unhighlight?). Hi Eli, Thanks for your suggestions. Please find attached a new patch that uses a single post-command-hook function and some other minor changes. The original issue is fixed. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Use-single-post-command-hook-on-hl-line.patch >From 980504403e41164fef79806781eff84e05760463 Mon Sep 17 00:00:00 2001 From: Gabriel do Nascimento Ribeiro Date: Fri, 22 Jan 2021 23:05:17 -0300 Subject: [PATCH] Use single post-command-hook on hl-line --- lisp/hl-line.el | 58 +++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/lisp/hl-line.el b/lisp/hl-line.el index 73870f9579..82952e934b 100644 --- a/lisp/hl-line.el +++ b/lisp/hl-line.el @@ -45,11 +45,7 @@ ;; An overlay is used. In the non-sticky cases, this overlay is ;; active only on the selected window. A hook is added to ;; `post-command-hook' to activate the overlay and move it to the line -;; about point. To get the non-sticky behavior, `hl-line-unhighlight' -;; is added to `pre-command-hook' as well. This function deactivates -;; the overlay unconditionally in case the command changes the -;; selected window. (It does so rather than keeping track of changes -;; in the selected window). +;; about point. ;; You could make variable `global-hl-line-mode' buffer-local and set ;; it to nil to avoid highlighting specific buffers, when the global @@ -91,9 +87,9 @@ hl-line-face (set symbol value) (dolist (buffer (buffer-list)) (with-current-buffer buffer - (when hl-line-overlay + (when (overlayp hl-line-overlay) (overlay-put hl-line-overlay 'face hl-line-face)))) - (when global-hl-line-overlay + (when (overlayp global-hl-line-overlay) (overlay-put global-hl-line-overlay 'face hl-line-face)))) (defcustom hl-line-sticky-flag t @@ -141,9 +137,7 @@ hl-line-mode `hl-line-highlight' on `post-command-hook' in this case. When `hl-line-sticky-flag' is nil, Hl-Line mode highlights the -line about point in the selected window only. In this case, it -uses the function `hl-line-maybe-unhighlight' in -addition to `hl-line-highlight' on `post-command-hook'." +line about point in the selected window only." :group 'hl-line (if hl-line-mode (progn @@ -151,12 +145,10 @@ hl-line-mode (add-hook 'change-major-mode-hook #'hl-line-unhighlight nil t) (hl-line-highlight) (setq hl-line-overlay-buffer (current-buffer)) - (add-hook 'post-command-hook #'hl-line-highlight nil t) - (add-hook 'post-command-hook #'hl-line-maybe-unhighlight nil t)) + (add-hook 'post-command-hook #'hl-line-highlight nil t)) (remove-hook 'post-command-hook #'hl-line-highlight t) (hl-line-unhighlight) - (remove-hook 'change-major-mode-hook #'hl-line-unhighlight t) - (remove-hook 'post-command-hook #'hl-line-maybe-unhighlight t))) + (remove-hook 'change-major-mode-hook #'hl-line-unhighlight t))) (defun hl-line-make-overlay () (let ((ol (make-overlay (point) (point)))) @@ -168,17 +160,19 @@ hl-line-highlight "Activate the Hl-Line overlay on the current line." (if hl-line-mode ; Might be changed outside the mode function. (progn - (unless hl-line-overlay + (unless (overlayp hl-line-overlay) (setq hl-line-overlay (hl-line-make-overlay))) ; To be moved. (overlay-put hl-line-overlay 'window (unless hl-line-sticky-flag (selected-window))) - (hl-line-move hl-line-overlay)) + (hl-line-move hl-line-overlay) + (hl-line-maybe-unhighlight)) (hl-line-unhighlight))) (defun hl-line-unhighlight () "Deactivate the Hl-Line overlay on the current line." - (when hl-line-overlay - (delete-overlay hl-line-overlay))) + (when (overlayp hl-line-overlay) + (delete-overlay hl-line-overlay) + (setq hl-line-overlay nil))) (defun hl-line-maybe-unhighlight () "Maybe deactivate the Hl-Line overlay on the current line. @@ -191,8 +185,7 @@ hl-line-maybe-unhighlight (not (eq curbuf hlob)) (not (minibufferp))) (with-current-buffer hlob - (when (overlayp hl-line-overlay) - (delete-overlay hl-line-overlay)))) + (hl-line-unhighlight))) (when (and (overlayp hl-line-overlay) (eq (overlay-buffer hl-line-overlay) curbuf)) (setq hl-line-overlay-buffer curbuf)))) @@ -205,8 +198,8 @@ global-hl-line-mode highlights the line about the current buffer's point in all live windows. -Global-Hl-Line mode uses the functions `global-hl-line-highlight' -and `global-hl-line-maybe-unhighlight' on `post-command-hook'." +Global-Hl-Line mode uses the function `global-hl-line-highlight' +on `post-command-hook'." :global t :group 'hl-line (if global-hl-line-mode @@ -214,25 +207,24 @@ global-hl-line-mode ;; In case `kill-all-local-variables' is called. (add-hook 'change-major-mode-hook #'global-hl-line-unhighlight) (global-hl-line-highlight-all) - (add-hook 'post-command-hook #'global-hl-line-highlight) - (add-hook 'post-command-hook #'global-hl-line-maybe-unhighlight)) + (add-hook 'post-command-hook #'global-hl-line-highlight)) (global-hl-line-unhighlight-all) (remove-hook 'post-command-hook #'global-hl-line-highlight) - (remove-hook 'change-major-mode-hook #'global-hl-line-unhighlight) - (remove-hook 'post-command-hook #'global-hl-line-maybe-unhighlight))) + (remove-hook 'change-major-mode-hook #'global-hl-line-unhighlight))) (defun global-hl-line-highlight () "Highlight the current line in the current window." (when global-hl-line-mode ; Might be changed outside the mode function. (unless (window-minibuffer-p) - (unless global-hl-line-overlay + (unless (overlayp global-hl-line-overlay) (setq global-hl-line-overlay (hl-line-make-overlay))) ; To be moved. (unless (member global-hl-line-overlay global-hl-line-overlays) (push global-hl-line-overlay global-hl-line-overlays)) (overlay-put global-hl-line-overlay 'window (unless global-hl-line-sticky-flag (selected-window))) - (hl-line-move global-hl-line-overlay)))) + (hl-line-move global-hl-line-overlay) + (global-hl-line-maybe-unhighlight)))) (defun global-hl-line-highlight-all () "Highlight the current line in all live windows." @@ -243,8 +235,9 @@ global-hl-line-highlight-all (defun global-hl-line-unhighlight () "Deactivate the Global-Hl-Line overlay on the current line." - (when global-hl-line-overlay - (delete-overlay global-hl-line-overlay))) + (when (overlayp global-hl-line-overlay) + (delete-overlay global-hl-line-overlay) + (setq global-hl-line-overlay nil))) (defun global-hl-line-maybe-unhighlight () "Maybe deactivate the Global-Hl-Line overlay on the current line. @@ -256,9 +249,8 @@ global-hl-line-maybe-unhighlight (bufferp ovb) (not (eq ovb (current-buffer))) (not (minibufferp))) - (with-current-buffer ovb - (when (overlayp global-hl-line-overlay) - (delete-overlay global-hl-line-overlay)))))) + (with-current-buffer ovb + (global-hl-line-unhighlight))))) global-hl-line-overlays)) (defun global-hl-line-unhighlight-all () -- 2.27.0 --=-=-=--