unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Highlight current line when using gud
@ 2021-06-28 12:43 Zhiwei Chen
  2021-06-29 20:00 ` Condy Chen
  0 siblings, 1 reply; 20+ messages in thread
From: Zhiwei Chen @ 2021-06-28 12:43 UTC (permalink / raw)
  To: emacs-devel; +Cc: condy0919@gmail.com


[-- Attachment #1.1: Type: text/plain, Size: 388 bytes --]

https://www.emacswiki.org/emacs/DebuggingWithEmacs has a good solution for highlighting current line when debugging.

What it looks like:

[cid:68A5EABF-0AC8-40D0-BD6D-6C5B1CDECBAA]

Neat! I’m hoping that it can be installed in Emacs core. And there was already a discussion https://lists.gnu.org/archive/html/help-gnu-emacs/2013-02/msg00056.html in 2013.

--
Zhiwei Chen



[-- Attachment #1.2: Type: text/html, Size: 1879 bytes --]

[-- Attachment #2: PastedGraphic-1.png --]
[-- Type: image/png, Size: 251131 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-06-28 12:43 Highlight current line when using gud Zhiwei Chen
@ 2021-06-29 20:00 ` Condy Chen
  2021-06-30 11:54   ` Lars Ingebrigtsen
  0 siblings, 1 reply; 20+ messages in thread
From: Condy Chen @ 2021-06-29 20:00 UTC (permalink / raw)
  To: Zhiwei Chen; +Cc: emacs-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 592 bytes --]

[image: image.png]
What it looks like in emacs -Q.

Before this patch, dark theme users cannot distinguish the line from the
background even though hl-line-mode is enabled. Personally I can't.
[image: image.png]

Furthermore,  users must set hl-line-sticky-flag to t to enable highlight
in all windows or move the point to the source file buffer, otherwise only
the arrow in fringe is helpful for which line program run to. It's too
restricted in such a situation.

So I propose to add a new overlay of current line to make gud more friendly
and deprecate the old one.

Here is my patch. :-)

[-- Attachment #1.1.2: Type: text/html, Size: 850 bytes --]

[-- Attachment #1.2: image.png --]
[-- Type: image/png, Size: 55153 bytes --]

[-- Attachment #1.3: image.png --]
[-- Type: image/png, Size: 27480 bytes --]

[-- Attachment #2: 0001-lisp-progmodes-gud.el-Highlight-current-line.patch --]
[-- Type: text/x-patch, Size: 2046 bytes --]

From 1b896f5e7f351cabbc43c7ce730e17d43e4dfc7f Mon Sep 17 00:00:00 2001
From: condy <condy0919@gmail.com>
Date: Wed, 30 Jun 2021 03:57:09 +0800
Subject: [PATCH] * lisp/progmodes/gud.el: Highlight current line

---
 lisp/progmodes/gud.el | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el
index 740a6e2581..7f1ec20e47 100644
--- a/lisp/progmodes/gud.el
+++ b/lisp/progmodes/gud.el
@@ -85,6 +85,9 @@ gud
   :group 'processes
   :group 'tools)
 
+(defface gud-highlight-face '((t (:inherit secondary-selection)))
+  "Face to use to highlight current line."
+  :group 'gud)
 
 (defcustom gud-key-prefix "\C-x\C-a"
   "Prefix of all GUD commands valid in C buffers."
@@ -2768,6 +2771,7 @@ gud-filter
 	      (gud-filter proc ""))))))
 
 (defvar gud-minor-mode-type nil)
+(defvar gud-overlay-line nil)
 (defvar gud-overlay-arrow-position nil)
 (add-to-list 'overlay-arrow-variable-list 'gud-overlay-arrow-position)
 
@@ -2791,6 +2795,9 @@ gud-sentinel
 	((memq (process-status proc) '(signal exit))
 	 ;; Stop displaying an arrow in a source file.
 	 (setq gud-overlay-arrow-position nil)
+         ;; Stop displaying the `gud-overlay-line'.
+         (delete-overlay gud-overlay-line)
+         (setq gud-overlay-line nil)
 	 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
 		   'gdbmi)
 	     (gdb-reset)
@@ -2886,6 +2893,11 @@ gud-display-line
 	  (or gud-overlay-arrow-position
 	      (setq gud-overlay-arrow-position (make-marker)))
 	  (set-marker gud-overlay-arrow-position (point) (current-buffer))
+          ;; Update the position of `gud-overlay-line'
+          (unless gud-overlay-line
+            (setq gud-overlay-line (make-overlay (point) (point)))
+            (overlay-put gud-overlay-line 'face 'gud-highlight-face))
+          (move-overlay gud-overlay-line (line-beginning-position) (line-end-position) (current-buffer))
 	  ;; If they turned on hl-line, move the hl-line highlight to
 	  ;; the arrow's line.
 	  (when (featurep 'hl-line)
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-06-29 20:00 ` Condy Chen
@ 2021-06-30 11:54   ` Lars Ingebrigtsen
  2021-06-30 12:27     ` Eli Zaretskii
  2021-06-30 12:53     ` Zhiwei Chen
  0 siblings, 2 replies; 20+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-30 11:54 UTC (permalink / raw)
  To: Condy Chen; +Cc: Zhiwei Chen, emacs-devel

Condy Chen <condy0919@gmail.com> writes:

> Before this patch, dark theme users cannot distinguish the line from the
> background even though hl-line-mode is enabled. Personally I can't.

I'm not sure I understand the problem here -- hl-line-mode works fine
for me when using a dark background.

> Furthermore, users must set hl-line-sticky-flag to t to enable
> highlight in all windows or move the point to the source file buffer,
> otherwise only the arrow in fringe is helpful for which line program
> run to. It's too restricted in such a situation.
>
> So I propose to add a new overlay of current line to make gud more
> friendly and deprecate the old one.

The patch seems to add a new overlay mechanism for gud that's switched
on for all people?  And is "the old one" you want to deprecate
hl-line-mode?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-06-30 11:54   ` Lars Ingebrigtsen
@ 2021-06-30 12:27     ` Eli Zaretskii
  2021-06-30 13:07       ` Zhiwei Chen
  2021-06-30 12:53     ` Zhiwei Chen
  1 sibling, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2021-06-30 12:27 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: condy0919, chenzhiwei03, emacs-devel

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Wed, 30 Jun 2021 13:54:06 +0200
> Cc: Zhiwei Chen <chenzhiwei03@kuaishou.com>, emacs-devel <emacs-devel@gnu.org>
> 
> Condy Chen <condy0919@gmail.com> writes:
> 
> > Before this patch, dark theme users cannot distinguish the line from the
> > background even though hl-line-mode is enabled. Personally I can't.
> 
> I'm not sure I understand the problem here -- hl-line-mode works fine
> for me when using a dark background.

Right, I wondered about that myself.  If some themes make the
highlighted current line hard to see, that's a problem with the face
definition of those themes.

> > Furthermore, users must set hl-line-sticky-flag to t to enable
> > highlight in all windows or move the point to the source file buffer,
> > otherwise only the arrow in fringe is helpful for which line program
> > run to. It's too restricted in such a situation.
> >
> > So I propose to add a new overlay of current line to make gud more
> > friendly and deprecate the old one.
> 
> The patch seems to add a new overlay mechanism for gud that's switched
> on for all people?  And is "the old one" you want to deprecate
> hl-line-mode?

FWIW, I'm not opposed to such a change, but it must be an optional
feature (we could discuss the default value).  I don't think we can
force people to use this overlay.  Especially since on GUI displays
the arrow is shown in the fringe (not to mention the fact that
gud-gdb is deprecated in favor of gdb-mi.el).




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-06-30 11:54   ` Lars Ingebrigtsen
  2021-06-30 12:27     ` Eli Zaretskii
@ 2021-06-30 12:53     ` Zhiwei Chen
  2021-06-30 12:59       ` Zhiwei Chen
  2021-06-30 13:17       ` Eli Zaretskii
  1 sibling, 2 replies; 20+ messages in thread
From: Zhiwei Chen @ 2021-06-30 12:53 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Condy Chen, emacs-devel



> On Jun 30, 2021, at 7:54 PM, Lars Ingebrigtsen <larsi@gnus.org> wrote:
> 
> 
> Condy Chen <condy0919@gmail.com> writes:
> 
>> Before this patch, dark theme users cannot distinguish the line from the
>> background even though hl-line-mode is enabled. Personally I can't.
> 
> I'm not sure I understand the problem here -- hl-line-mode works fine
> for me when using a dark background.

The problem can be categorized into 3 cases. See below.

> 
>> Furthermore, users must set hl-line-sticky-flag to t to enable
>> highlight in all windows or move the point to the source file buffer,
>> otherwise only the arrow in fringe is helpful for which line program
>> run to. It's too restricted in such a situation.
>> 
>> So I propose to add a new overlay of current line to make gud more
>> friendly and deprecate the old one.
> 
> The patch seems to add a new overlay mechanism for gud that's switched
> on for all people?  And is "the old one" you want to deprecate
> hl-line-mode?

Case 1: Users don't use hl-line-mode.
There will be no line highlighted in the source buffer.

Case 2: Users use `hl-line-mode' but set `hl-line-sticky-flag' to nil.
In that case, current line will be highlighted if and only if the point is in the source buffer. But if people type “n”, “bt”, “c” ... in the gud buffer, the line in the source buffer will not be highlighted due to the nil `hl-line-sticky-flag’.

Case 3: Users use `hl-line-mode’ and set `hl-line-sticky-flag’ to t.
It works well except that users should make sure `hl-line-face’ is distinguishable. For me (using doom-one theme), it’s hard to see the highlighted line.

It tries to improve the experience of gud in case 1 and case 2, and gives an another opportunity to customize. 

--
Zhiwei Chen


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-06-30 12:53     ` Zhiwei Chen
@ 2021-06-30 12:59       ` Zhiwei Chen
  2021-06-30 13:18         ` Eli Zaretskii
  2021-06-30 13:17       ` Eli Zaretskii
  1 sibling, 1 reply; 20+ messages in thread
From: Zhiwei Chen @ 2021-06-30 12:59 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Condy Chen, emacs-devel


> On Jun 30, 2021, at 8:53 PM, Zhiwei Chen <chenzhiwei03@kuaishou.com> wrote:
> 
>> 
>>> Furthermore, users must set hl-line-sticky-flag to t to enable
>>> highlight in all windows or move the point to the source file buffer,
>>> otherwise only the arrow in fringe is helpful for which line program
>>> run to. It's too restricted in such a situation.
>>> 
>>> So I propose to add a new overlay of current line to make gud more
>>> friendly and deprecate the old one.
>> 
>> The patch seems to add a new overlay mechanism for gud that's switched
>> on for all people?  And is "the old one" you want to deprecate
>> hl-line-mode?

Yes, this patch adds a new overlay. And I would like to remove the use of hl-line-mode since hl-line-mode only works in a limited situation.

--
Zhiwei Chen




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-06-30 12:27     ` Eli Zaretskii
@ 2021-06-30 13:07       ` Zhiwei Chen
  0 siblings, 0 replies; 20+ messages in thread
From: Zhiwei Chen @ 2021-06-30 13:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Lars Ingebrigtsen, condy0919@gmail.com, emacs-devel@gnu.org


> On Jun 30, 2021, at 8:27 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
> 
>> From: Lars Ingebrigtsen <larsi@gnus.org>
>> Date: Wed, 30 Jun 2021 13:54:06 +0200
>> Cc: Zhiwei Chen <chenzhiwei03@kuaishou.com>, emacs-devel <emacs-devel@gnu.org>
>> 
>> Condy Chen <condy0919@gmail.com> writes:
>> 
>>> Before this patch, dark theme users cannot distinguish the line from the
>>> background even though hl-line-mode is enabled. Personally I can't.
>> 
>> I'm not sure I understand the problem here -- hl-line-mode works fine
>> for me when using a dark background.
> 
> Right, I wondered about that myself.  If some themes make the
> highlighted current line hard to see, that's a problem with the face
> definition of those themes.

Personally for me, hl-line-mode is used for the approximate position. 

> 
>>> Furthermore, users must set hl-line-sticky-flag to t to enable
>>> highlight in all windows or move the point to the source file buffer,
>>> otherwise only the arrow in fringe is helpful for which line program
>>> run to. It's too restricted in such a situation.
>>> 
>>> So I propose to add a new overlay of current line to make gud more
>>> friendly and deprecate the old one.
>> 
>> The patch seems to add a new overlay mechanism for gud that's switched
>> on for all people?  And is "the old one" you want to deprecate
>> hl-line-mode?
> 
> FWIW, I'm not opposed to such a change, but it must be an optional
> feature (we could discuss the default value).  I don't think we can
> force people to use this overlay.  Especially since on GUI displays
> the arrow is shown in the fringe (not to mention the fact that
> gud-gdb is deprecated in favor of gdb-mi.el).
> 

I’m happy to make it opt-in. Yes, I’m using M-x gdb :-)

--
Zhiwei Chen


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-06-30 12:53     ` Zhiwei Chen
  2021-06-30 12:59       ` Zhiwei Chen
@ 2021-06-30 13:17       ` Eli Zaretskii
  2021-06-30 14:26         ` Zhiwei Chen
  1 sibling, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2021-06-30 13:17 UTC (permalink / raw)
  To: Zhiwei Chen; +Cc: larsi, condy0919, emacs-devel

> From: Zhiwei Chen <chenzhiwei03@kuaishou.com>
> Date: Wed, 30 Jun 2021 12:53:08 +0000
> Cc: Condy Chen <condy0919@gmail.com>, emacs-devel <emacs-devel@gnu.org>
> 
> Case 1: Users don't use hl-line-mode.
> There will be no line highlighted in the source buffer.
> 
> Case 2: Users use `hl-line-mode' but set `hl-line-sticky-flag' to nil.
> In that case, current line will be highlighted if and only if the point is in the source buffer. But if people type “n”, “bt”, “c” ... in the gud buffer, the line in the source buffer will not be highlighted due to the nil `hl-line-sticky-flag’.
> 
> Case 3: Users use `hl-line-mode’ and set `hl-line-sticky-flag’ to t.
> It works well except that users should make sure `hl-line-face’ is distinguishable. For me (using doom-one theme), it’s hard to see the highlighted line.

But these are all user preferences, aren't they?  You have your
preferences, others have theirs.  No one said everyone needs to have
the current line highlighted in non-selected windows, even when
debugging.  It's up to the users whether they want it or not.

The question most important to me is: can you, with your preferences,
use hl-line-mode to produce the same effect as the patch you propose
would?  If yes, why do we need yet another user option?  And if you
cannot, can you explain why not?

Thanks.



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-06-30 12:59       ` Zhiwei Chen
@ 2021-06-30 13:18         ` Eli Zaretskii
  0 siblings, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2021-06-30 13:18 UTC (permalink / raw)
  To: Zhiwei Chen; +Cc: larsi, condy0919, emacs-devel

> From: Zhiwei Chen <chenzhiwei03@kuaishou.com>
> Date: Wed, 30 Jun 2021 12:59:21 +0000
> Cc: Condy Chen <condy0919@gmail.com>, emacs-devel <emacs-devel@gnu.org>
> 
> >> The patch seems to add a new overlay mechanism for gud that's switched
> >> on for all people?  And is "the old one" you want to deprecate
> >> hl-line-mode?
> 
> Yes, this patch adds a new overlay. And I would like to remove the use of hl-line-mode since hl-line-mode only works in a limited situation.

Why remove hl-line-mode?  It has gobs of users.



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-06-30 13:17       ` Eli Zaretskii
@ 2021-06-30 14:26         ` Zhiwei Chen
  2021-06-30 15:50           ` Eli Zaretskii
  2021-07-01 11:26           ` Lars Ingebrigtsen
  0 siblings, 2 replies; 20+ messages in thread
From: Zhiwei Chen @ 2021-06-30 14:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Lars Ingebrigtsen, condy0919@gmail.com, emacs-devel@gnu.org


[-- Attachment #1.1: Type: text/plain, Size: 2973 bytes --]


On Jun 30, 2021, at 9:17 PM, Eli Zaretskii <eliz@gnu.org<mailto:eliz@gnu.org>> wrote:


From: Zhiwei Chen <chenzhiwei03@kuaishou.com<mailto:chenzhiwei03@kuaishou.com>>
Date: Wed, 30 Jun 2021 12:53:08 +0000
Cc: Condy Chen <condy0919@gmail.com<mailto:condy0919@gmail.com>>, emacs-devel <emacs-devel@gnu.org<mailto:emacs-devel@gnu.org>>

Case 1: Users don't use hl-line-mode.
There will be no line highlighted in the source buffer.

Case 2: Users use `hl-line-mode' but set `hl-line-sticky-flag' to nil.
In that case, current line will be highlighted if and only if the point is in the source buffer. But if people type “n”, “bt”, “c” ... in the gud buffer, the line in the source buffer will not be highlighted due to the nil `hl-line-sticky-flag’.

Case 3: Users use `hl-line-mode’ and set `hl-line-sticky-flag’ to t.
It works well except that users should make sure `hl-line-face’ is distinguishable. For me (using doom-one theme), it’s hard to see the highlighted line.

But these are all user preferences, aren't they?  You have your
preferences, others have theirs.  No one said everyone needs to have
the current line highlighted in non-selected windows, even when
debugging.  It's up to the users whether they want it or not.

Maybe I’m the victim of vscode.
[cid:65A56DB7-6408-49F7-A911-CCAAF545653E]

I’m making gud more like that, the yellow line is more like the overlay this patch adds.


The question most important to me is: can you, with your preferences,
use hl-line-mode to produce the same effect as the patch you propose
would?  If yes, why do we need yet another user option?  And if you
cannot, can you explain why not?

Thanks.

Personally, hl-line-mode is used to show the approximate position of my point so the face defined in doom-one is fine to me. It needn’t to be too contrast as it hurts my eyes in daily use.
But when debugging, I need to know where the line as if I step over the interesting line I will blame myself. Debugging is more serious than coding/writing, so I would like to
make the line highlighted/contrast.

(defun make-hl-line-face-contrast ()
  (setq-local hl-line-face ‘a-more-contrast-one))
(add-hook gdb-mode-hook #’make-hl-line-face-contrast)

But when I select the source buffer and move the point, forward a page, I can’t tell which line I’m debugging. So I need to seek for the arrow in fringe but it’s too small to be discovered.
I imagine that if there is a sticky overlay what will happen. I will never lose my debug point…

> Why remove hl-line-mode?  It has gobs of users.

Specifically, the 8 lines in gud.el rather than the hl-line-mode itself.

 ;; If they turned on hl-line, move the hl-line highlight to
 ;; the arrow's line.
 (when (featurep 'hl-line)
   (cond
    (global-hl-line-mode
     (global-hl-line-highlight))
    ((and hl-line-mode hl-line-sticky-flag)
     (hl-line-highlight)))))

--
Zhiwei Chen

[-- Attachment #1.2: Type: text/html, Size: 5225 bytes --]

[-- Attachment #2: PastedGraphic-2.png --]
[-- Type: image/png, Size: 79083 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-06-30 14:26         ` Zhiwei Chen
@ 2021-06-30 15:50           ` Eli Zaretskii
  2021-07-01  3:17             ` Zhiwei Chen
  2021-07-01 11:26           ` Lars Ingebrigtsen
  1 sibling, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2021-06-30 15:50 UTC (permalink / raw)
  To: Zhiwei Chen; +Cc: larsi, condy0919, emacs-devel

> From: Zhiwei Chen <chenzhiwei03@kuaishou.com>
> CC: Lars Ingebrigtsen <larsi@gnus.org>,
>         "condy0919@gmail.com"
> 	<condy0919@gmail.com>,
>         "emacs-devel@gnu.org" <emacs-devel@gnu.org>
> Date: Wed, 30 Jun 2021 14:26:33 +0000
> 
> Personally, hl-line-mode is used to show the approximate position of my point so the face defined in
> doom-one is fine to me. It needn’t to be too contrast as it hurts my eyes in daily use.
> But when debugging, I need to know where the line as if I step over the interesting line I will blame myself.
> Debugging is more serious than coding/writing, so I would like to
> make the line highlighted/contrast. 
> 
> (defun make-hl-line-face-contrast ()
>   (setq-local hl-line-face ‘a-more-contrast-one))
> (add-hook gdb-mode-hook #’make-hl-line-face-contrast)
> 
> But when I select the source buffer and move the point, forward a page, I can’t tell which line I’m debugging.
> So I need to seek for the arrow in fringe but it’s too small to be discovered.
> I imagine that if there is a sticky overlay what will happen. I will never lose my debug point…
> 
> > Why remove hl-line-mode?  It has gobs of users.
> 
> Specifically, the 8 lines in gud.el rather than the hl-line-mode itself.
> 
>  ;; If they turned on hl-line, move the hl-line highlight to
>  ;; the arrow's line.
>  (when (featurep 'hl-line)
>    (cond
>     (global-hl-line-mode
>      (global-hl-line-highlight))
>     ((and hl-line-mode hl-line-sticky-flag)
>      (hl-line-highlight)))))

Thanks.  It all looks to me as differences in personal preferences.  I
have no doubt that some of us (myself included) have no problems
finding the current line in the source buffer, and others use
hl-line-mode with the above code and have no problems at all.  So I
wonder what would be the best way of adding the feature you want
without disappointing those who like the existing behavior.



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-06-30 15:50           ` Eli Zaretskii
@ 2021-07-01  3:17             ` Zhiwei Chen
  0 siblings, 0 replies; 20+ messages in thread
From: Zhiwei Chen @ 2021-07-01  3:17 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Lars Ingebrigtsen, condy0919@gmail.com, emacs-devel@gnu.org


[-- Attachment #1.1: Type: text/plain, Size: 859 bytes --]


> On Jun 30, 2021, at 11:50 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>
> Thanks.  It all looks to me as differences in personal preferences.  I
> have no doubt that some of us (myself included) have no problems
> finding the current line in the source buffer, and others use
> hl-line-mode with the above code and have no problems at all.  So I
> wonder what would be the best way of adding the feature you want
> without disappointing those who like the existing behavior.

> FWIW, I'm not opposed to such a change, but it must be an optional
feature (we could discuss the default value).  I don't think we can
force people to use this overlay.  Especially since on GUI displays
the arrow is shown in the fringe (not to mention the fact that
gud-gdb is deprecated in favor of gdb-mi.el).

A user option is introduced.



--
Zhiwei Chen

[-- Attachment #1.2: Type: text/html, Size: 1381 bytes --]

[-- Attachment #2: 0001-lisp-progmodes-gud.el-Highlight-current-line.patch --]
[-- Type: application/octet-stream, Size: 2286 bytes --]

From 654f3c2728741117642c8b762fb6a9fa78ff7309 Mon Sep 17 00:00:00 2001
From: condy <condy0919@gmail.com>
Date: Thu, 1 Jul 2021 11:11:04 +0800
Subject: [PATCH] * lisp/progmodes/gud.el: Highlight current line

---
 lisp/progmodes/gud.el | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el
index 740a6e2581..57bb610287 100644
--- a/lisp/progmodes/gud.el
+++ b/lisp/progmodes/gud.el
@@ -85,6 +85,14 @@ gud
   :group 'processes
   :group 'tools)
 
+(defface gud-highlight-face '((t (:inherit secondary-selection)))
+  "Face to use to highlight current line."
+  :group 'gud)
+
+(defcustom gud-highlight-line nil
+  "If non-nil, highlight the current line when debugging."
+  :group 'gud
+  :type 'boolean)
 
 (defcustom gud-key-prefix "\C-x\C-a"
   "Prefix of all GUD commands valid in C buffers."
@@ -2768,6 +2776,7 @@ gud-filter
 	      (gud-filter proc ""))))))
 
 (defvar gud-minor-mode-type nil)
+(defvar gud-overlay-line nil)
 (defvar gud-overlay-arrow-position nil)
 (add-to-list 'overlay-arrow-variable-list 'gud-overlay-arrow-position)
 
@@ -2791,6 +2800,10 @@ gud-sentinel
 	((memq (process-status proc) '(signal exit))
 	 ;; Stop displaying an arrow in a source file.
 	 (setq gud-overlay-arrow-position nil)
+         ;; Stop displaying the `gud-overlay-line'.
+         (when gud-highlight-line
+           (delete-overlay gud-overlay-line)
+           (setq gud-overlay-line nil))
 	 (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
 		   'gdbmi)
 	     (gdb-reset)
@@ -2886,6 +2899,12 @@ gud-display-line
 	  (or gud-overlay-arrow-position
 	      (setq gud-overlay-arrow-position (make-marker)))
 	  (set-marker gud-overlay-arrow-position (point) (current-buffer))
+          ;; Update the position of `gud-overlay-line'
+          (when gud-highlight-line
+            (unless gud-overlay-line
+              (setq gud-overlay-line (make-overlay (point) (point)))
+              (overlay-put gud-overlay-line 'face 'gud-highlight-face))
+            (move-overlay gud-overlay-line (line-beginning-position) (line-end-position) (current-buffer)))
 	  ;; If they turned on hl-line, move the hl-line highlight to
 	  ;; the arrow's line.
 	  (when (featurep 'hl-line)
-- 
2.30.1 (Apple Git-130)


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-06-30 14:26         ` Zhiwei Chen
  2021-06-30 15:50           ` Eli Zaretskii
@ 2021-07-01 11:26           ` Lars Ingebrigtsen
  2021-07-01 11:35             ` Zhiwei Chen
  2021-07-01 18:25             ` Zhiwei Chen
  1 sibling, 2 replies; 20+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-01 11:26 UTC (permalink / raw)
  To: Zhiwei Chen; +Cc: Eli Zaretskii, condy0919@gmail.com, emacs-devel@gnu.org

Zhiwei Chen <chenzhiwei03@kuaishou.com> writes:

> Personally, hl-line-mode is used to show the approximate position of
> my point so the face defined in doom-one is fine to me. It needn’t to
> be too contrast as it hurts my eyes in daily use.
>
> But when debugging, I need to know where the line as if I step over the
> interesting line I will blame myself. Debugging is more serious than
> coding/writing, so I would like to
> make the line highlighted/contrast. 

So, Doom has customised the hi-line face to be less perceptible, so you
want to introduce a new highlighting mechanism to make it more
perceptible again, but only in gud buffers?

This can be done with `face-remapping-alist' -- it's a buffer-local
variable that's used to display a different face in certain buffers.
Would using that variable in gud buffers solve your problems?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-07-01 11:26           ` Lars Ingebrigtsen
@ 2021-07-01 11:35             ` Zhiwei Chen
  2021-07-01 17:27               ` Condy Chen
  2021-07-01 18:25             ` Zhiwei Chen
  1 sibling, 1 reply; 20+ messages in thread
From: Zhiwei Chen @ 2021-07-01 11:35 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, condy0919@gmail.com, emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1249 bytes --]


On Jul 1, 2021, at 7:26 PM, Lars Ingebrigtsen <larsi@gnus.org<mailto:larsi@gnus.org>> wrote:

Zhiwei Chen <chenzhiwei03@kuaishou.com<mailto:chenzhiwei03@kuaishou.com>> writes:

Personally, hl-line-mode is used to show the approximate position of
my point so the face defined in doom-one is fine to me. It needn’t to
be too contrast as it hurts my eyes in daily use.

But when debugging, I need to know where the line as if I step over the
interesting line I will blame myself. Debugging is more serious than
coding/writing, so I would like to
make the line highlighted/contrast.

So, Doom has customised the hi-line face to be less perceptible, so you
want to introduce a new highlighting mechanism to make it more
perceptible again, but only in gud buffers?

This can be done with `face-remapping-alist' -- it's a buffer-local
variable that's used to display a different face in certain buffers.
Would using that variable in gud buffers solve your problems?


Another problem it can’t solve is the debugging line will be lost if I select the source buffer and move the point since the highlighted line uses hl-line-mode.
And I think the new mechanism can supersede the use of hl-line-mode almost.

--
Zhiwei Chen


[-- Attachment #2: Type: text/html, Size: 2820 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-07-01 11:35             ` Zhiwei Chen
@ 2021-07-01 17:27               ` Condy Chen
  0 siblings, 0 replies; 20+ messages in thread
From: Condy Chen @ 2021-07-01 17:27 UTC (permalink / raw)
  To: Zhiwei Chen; +Cc: Lars Ingebrigtsen, Eli Zaretskii, emacs-devel@gnu.org


[-- Attachment #1.1: Type: text/plain, Size: 1820 bytes --]

On Thu, Jul 1, 2021 at 7:35 PM Zhiwei Chen <chenzhiwei03@kuaishou.com>
wrote:

>
> On Jul 1, 2021, at 7:26 PM, Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
> Zhiwei Chen <chenzhiwei03@kuaishou.com> writes:
>
> Personally, hl-line-mode is used to show the approximate position of
> my point so the face defined in doom-one is fine to me. It needn’t to
> be too contrast as it hurts my eyes in daily use.
>
> But when debugging, I need to know where the line as if I step over the
> interesting line I will blame myself. Debugging is more serious than
> coding/writing, so I would like to
> make the line highlighted/contrast.
>
>
> So, Doom has customised the hi-line face to be less perceptible, so you
> want to introduce a new highlighting mechanism to make it more
> perceptible again, but only in gud buffers?
>
> This can be done with `face-remapping-alist' -- it's a buffer-local
> variable that's used to display a different face in certain buffers.
> Would using that variable in gud buffers solve your problems?
>
>
> Another problem it can’t solve is the debugging line will be lost if I
> select the source buffer and move the point since the highlighted line uses
> hl-line-mode.
> And I think the new mechanism can supersede the use of hl-line-mode almost.
>
>
Why do I introduce a new overlay in gud buffer?
Because it's used to show the line where the debugger stops at. The
position of the gud overlay is controlled by the debugger, not by users. So
using hl-line-mode in such a situation is not the proper way.

See the pic below.
[image: image.png]
gdb stops at line 4 (see the arrow in left fringe). But after I select the
source buffer and move 3 lines down, the line 7 is highlighted. Does it
mean that gdb stops at line 7? It's too confusing to users.

[-- Attachment #1.2: Type: text/html, Size: 3015 bytes --]

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 188731 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-07-01 11:26           ` Lars Ingebrigtsen
  2021-07-01 11:35             ` Zhiwei Chen
@ 2021-07-01 18:25             ` Zhiwei Chen
  2021-07-02 11:01               ` Lars Ingebrigtsen
  1 sibling, 1 reply; 20+ messages in thread
From: Zhiwei Chen @ 2021-07-01 18:25 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, Zhiwei Chen, emacs-devel@gnu.org

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Zhiwei Chen <chenzhiwei03@kuaishou.com> writes:
>
>> Personally, hl-line-mode is used to show the approximate position of
>> my point so the face defined in doom-one is fine to me. It needn’t to
>> be too contrast as it hurts my eyes in daily use.
>>
>> But when debugging, I need to know where the line as if I step over the
>> interesting line I will blame myself. Debugging is more serious than
>> coding/writing, so I would like to
>> make the line highlighted/contrast. 
>
> So, Doom has customised the hi-line face to be less perceptible, so you
> want to introduce a new highlighting mechanism to make it more
> perceptible again, but only in gud buffers?
>
> This can be done with `face-remapping-alist' -- it's a buffer-local
> variable that's used to display a different face in certain buffers.
> Would using that variable in gud buffers solve your problems?

Why do I introduce a new overlay in gud buffer? Because it's used to
show the line where the debugger stops at. The position of the gud
overlay is controlled by the debugger, not by users. So using
hl-line-mode in such a situation is not the proper way.

See the pic below.

https://fars.ee/j5l_

gdb stops at line 4 (see the arrow in left fringe). But after I select
the source buffer and move 3 lines down, the line 7 is highlighted. Does
it mean that gdb stops at line 7? It's too confusing to users.

Seems like gmail failed to send this mail, resend.

-- 
Zhiwei Chen



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-07-01 18:25             ` Zhiwei Chen
@ 2021-07-02 11:01               ` Lars Ingebrigtsen
  2021-07-02 11:39                 ` Eli Zaretskii
  0 siblings, 1 reply; 20+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-02 11:01 UTC (permalink / raw)
  To: Zhiwei Chen; +Cc: Eli Zaretskii, Zhiwei Chen, emacs-devel@gnu.org

Zhiwei Chen <condy0919@gmail.com> writes:

> Why do I introduce a new overlay in gud buffer? Because it's used to
> show the line where the debugger stops at. The position of the gud
> overlay is controlled by the debugger, not by users. So using
> hl-line-mode in such a situation is not the proper way.

Hm, I see...

I rarely use gud, and I never use any line-based highlighting, so I
don't really have any opinion about this.  Anybody else?

Looking at the patch, it looks good to me, but I wonder whether the
`gud-overlay-line' variable should be buffer-local in case there's more
than one gud buffer?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-07-02 11:01               ` Lars Ingebrigtsen
@ 2021-07-02 11:39                 ` Eli Zaretskii
  2021-07-04  0:12                   ` Zhiwei Chen
  0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2021-07-02 11:39 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: condy0919, chenzhiwei03, emacs-devel

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: Zhiwei Chen <chenzhiwei03@kuaishou.com>,  Eli Zaretskii <eliz@gnu.org>,
>   "emacs-devel@gnu.org" <emacs-devel@gnu.org>
> Date: Fri, 02 Jul 2021 13:01:38 +0200
> 
> Zhiwei Chen <condy0919@gmail.com> writes:
> 
> > Why do I introduce a new overlay in gud buffer? Because it's used to
> > show the line where the debugger stops at. The position of the gud
> > overlay is controlled by the debugger, not by users. So using
> > hl-line-mode in such a situation is not the proper way.
> 
> Hm, I see...
> 
> I rarely use gud, and I never use any line-based highlighting, so I
> don't really have any opinion about this.  Anybody else?

I think this should be an integral part of the overlay-arrow display,
not an independent add-on.  IOW, I'd like to see it implemented via
new properties that can be put on variables which are members of
overlay-arrow-variable-list.



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-07-02 11:39                 ` Eli Zaretskii
@ 2021-07-04  0:12                   ` Zhiwei Chen
  2021-07-04  4:30                     ` Eli Zaretskii
  0 siblings, 1 reply; 20+ messages in thread
From: Zhiwei Chen @ 2021-07-04  0:12 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Lars Ingebrigtsen, chenzhiwei03, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Lars Ingebrigtsen <larsi@gnus.org>
>> Cc: Zhiwei Chen <chenzhiwei03@kuaishou.com>,  Eli Zaretskii <eliz@gnu.org>,
>>   "emacs-devel@gnu.org" <emacs-devel@gnu.org>
>> Date: Fri, 02 Jul 2021 13:01:38 +0200
>> 
>> Zhiwei Chen <condy0919@gmail.com> writes:
>> 
>> > Why do I introduce a new overlay in gud buffer? Because it's used to
>> > show the line where the debugger stops at. The position of the gud
>> > overlay is controlled by the debugger, not by users. So using
>> > hl-line-mode in such a situation is not the proper way.
>> 
>> Hm, I see...
>> 
>> I rarely use gud, and I never use any line-based highlighting, so I
>> don't really have any opinion about this.  Anybody else?
>
> I think this should be an integral part of the overlay-arrow display,
> not an independent add-on.  IOW, I'd like to see it implemented via
> new properties that can be put on variables which are members of
> overlay-arrow-variable-list.
>
>

Ok, let me see how to implement it. BTW, the manual[1] says
overlay-arrow has nothing to do with overlays.

[1]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Overlay-Arrow.html

-- 
Zhiwei Chen



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Highlight current line when using gud
  2021-07-04  0:12                   ` Zhiwei Chen
@ 2021-07-04  4:30                     ` Eli Zaretskii
  0 siblings, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2021-07-04  4:30 UTC (permalink / raw)
  To: Zhiwei Chen; +Cc: larsi, chenzhiwei03, emacs-devel

> From: Zhiwei Chen <condy0919@gmail.com>
> Cc: Lars Ingebrigtsen <larsi@gnus.org>,  chenzhiwei03@kuaishou.com,
>   emacs-devel@gnu.org
> Date: Sun, 04 Jul 2021 08:12:20 +0800
> 
> > I think this should be an integral part of the overlay-arrow display,
> > not an independent add-on.  IOW, I'd like to see it implemented via
> > new properties that can be put on variables which are members of
> > overlay-arrow-variable-list.
> 
> Ok, let me see how to implement it.

Thanks in advance.

> BTW, the manual[1] says overlay-arrow has nothing to do with
> overlays.

Indeed, and the manual is correct.



^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-07-04  4:30 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-28 12:43 Highlight current line when using gud Zhiwei Chen
2021-06-29 20:00 ` Condy Chen
2021-06-30 11:54   ` Lars Ingebrigtsen
2021-06-30 12:27     ` Eli Zaretskii
2021-06-30 13:07       ` Zhiwei Chen
2021-06-30 12:53     ` Zhiwei Chen
2021-06-30 12:59       ` Zhiwei Chen
2021-06-30 13:18         ` Eli Zaretskii
2021-06-30 13:17       ` Eli Zaretskii
2021-06-30 14:26         ` Zhiwei Chen
2021-06-30 15:50           ` Eli Zaretskii
2021-07-01  3:17             ` Zhiwei Chen
2021-07-01 11:26           ` Lars Ingebrigtsen
2021-07-01 11:35             ` Zhiwei Chen
2021-07-01 17:27               ` Condy Chen
2021-07-01 18:25             ` Zhiwei Chen
2021-07-02 11:01               ` Lars Ingebrigtsen
2021-07-02 11:39                 ` Eli Zaretskii
2021-07-04  0:12                   ` Zhiwei Chen
2021-07-04  4:30                     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).