all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Redisplaying text in both display margins?
@ 2021-01-19  9:27 pwr--- via Users list for the GNU Emacs text editor
  2021-01-19 15:16 ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: pwr--- via Users list for the GNU Emacs text editor @ 2021-01-19  9:27 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I would like to use font-lock and display text properties to redisplay a 
regular expression group for a heading number in both display margins. 
n.b. "Margins" here may be ambiguous; I refer to the display margins 
(info "(elisp) Display Margins") and not the text margins (info "(elisp) 
Margins").

My intent is to redisplay the string marked here:

        HEADING. FOOBAR   #5-A#
                       ^^^^^^^^
as:

   5-A  HEADING. FOOBAR                            5-A

So far clarity, in this particular major mode, a heading may end with an 
arbitrary string between two '#' characters (e.g. "5-A"). This string 
should be redisplayed in the display margins (without the '#' 
characters).

At the moment I'm happily redisplaying the heading number in the right 
margin with the following code (where group 7 is the preceding space, 
group 8 is the first '#', group 9 is the string to redisplay, and gropu 
10 is the second '#'):

    (put-text-property (match-beginning 7) (match-end 10)
        'display (list '(margin right-margin)
                    (match-string-no-properties 9)))

There are a couple of things I can't figure out:

1. How to put multiple display text properties on the same text, so that 
it may redisplay group 9 in both margins.

2. When redisplaying a string in the left margin, how to right-align it, 
ideally padded with a couple of spaces away from the body text.

I have read over (info "(elisp) Display Property") a few times, but 
haven't been able to quite grok it for this specific problem.

Any help would be much appreciated. Thank you in advance,

-- 
Paul W. Rankin
https://bydasein.com

The single best thing you can do for the world is to delete your social 
media accounts.



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

* Re: Redisplaying text in both display margins?
  2021-01-19  9:27 Redisplaying text in both display margins? pwr--- via Users list for the GNU Emacs text editor
@ 2021-01-19 15:16 ` Eli Zaretskii
  2021-01-25  8:28   ` pwr--- via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2021-01-19 15:16 UTC (permalink / raw)
  To: help-gnu-emacs

> Feedback-ID: 791:353:null:purelymail
> Date: Tue, 19 Jan 2021 19:27:34 +1000
> From: pwr--- via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
> 
> My intent is to redisplay the string marked here:
> 
>         HEADING. FOOBAR   #5-A#
>                        ^^^^^^^^
> as:
> 
>    5-A  HEADING. FOOBAR                            5-A
> 
> So far clarity, in this particular major mode, a heading may end with an 
> arbitrary string between two '#' characters (e.g. "5-A"). This string 
> should be redisplayed in the display margins (without the '#' 
> characters).
> 
> At the moment I'm happily redisplaying the heading number in the right 
> margin with the following code (where group 7 is the preceding space, 
> group 8 is the first '#', group 9 is the string to redisplay, and gropu 
> 10 is the second '#'):
> 
>     (put-text-property (match-beginning 7) (match-end 10)
>         'display (list '(margin right-margin)
>                     (match-string-no-properties 9)))
> 
> There are a couple of things I can't figure out:
> 
> 1. How to put multiple display text properties on the same text, so that 
> it may redisplay group 9 in both margins.

You can't, not directly: each text property of a given character can
have only one value in Emacs.  But perhaps you could do that with 2
overlay strings, if you put the overlays on the same text?

> 2. When redisplaying a string in the left margin, how to right-align it, 
> ideally padded with a couple of spaces away from the body text.
> 
> I have read over (info "(elisp) Display Property") a few times, but 
> haven't been able to quite grok it for this specific problem.

I think the node "Pixel Specification" there should tell you how to
accomplish that, but if you already read that, please ask more
specific questions, and/or show the code you tried that didn't work.



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

* Re: Redisplaying text in both display margins?
  2021-01-19 15:16 ` Eli Zaretskii
@ 2021-01-25  8:28   ` pwr--- via Users list for the GNU Emacs text editor
  2021-01-27 15:59     ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: pwr--- via Users list for the GNU Emacs text editor @ 2021-01-25  8:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On 2021-01-20 01:16, Eli Zaretskii wrote:
>> Feedback-ID: 791:353:null:purelymail
>> 2. When redisplaying a string in the left margin, how to right-align 
>> it,
>> ideally padded with a couple of spaces away from the body text.
>> 
>> I have read over (info "(elisp) Display Property") a few times, but
>> haven't been able to quite grok it for this specific problem.
> 
> I think the node "Pixel Specification" there should tell you how to
> accomplish that, but if you already read that, please ask more
> specific questions, and/or show the code you tried that didn't work.

Thanks for the help. I had another read through and after some trial and 
error got something working how I like. However I've run into some 
behaviour that confuses me. I'll describe this first but this will be 
clearer with the example below.

To achieve the desired result of a string in the left display margin 
aligned with the body text I've put display text properties onto two 
regions of text, one a space to fill most of the margin, and then the 
string to display. However, when inserting enough body text to cause 
these regions to wrap, the space in the margin begins to shrink.

To reproduce:

emacs -Q
(erase-buffer)
(set-window-margins nil 20)
(insert "foobarbaz")
(put-text-property 4 7 'display '((margin left-margin) (space :width (- 
left-margin 2))))
(put-text-property 7 10 'display '((margin left-margin) "1"))

This should result in a window with something like:

           1 foo

Then assuming a frame of 80 columns and `truncate-lines' is nil (or 
visual-line-mode is enabled):

(goto-char (point-min))
(insert (make-string 45 ?x))

The "1" will appear to get pushed towards the left as more text is added 
until the line wraps the window:

So my question becomes, how should I apply these display text properties 
such that they will not be affected by line wrapping?

Thanks!



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

* Re: Redisplaying text in both display margins?
  2021-01-25  8:28   ` pwr--- via Users list for the GNU Emacs text editor
@ 2021-01-27 15:59     ` Eli Zaretskii
  2021-01-27 18:02       ` Alan Third
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2021-01-27 15:59 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Mon, 25 Jan 2021 18:28:11 +1000
> From: "Paul W. Rankin" <pwr@bydasein.com>
> Cc: help-gnu-emacs@gnu.org
> 
> emacs -Q
> (erase-buffer)
> (set-window-margins nil 20)
> (insert "foobarbaz")
> (put-text-property 4 7 'display '((margin left-margin) (space :width (- 
> left-margin 2))))
> (put-text-property 7 10 'display '((margin left-margin) "1"))
> 
> This should result in a window with something like:
> 
>            1 foo
> 
> Then assuming a frame of 80 columns and `truncate-lines' is nil (or 
> visual-line-mode is enabled):
> 
> (goto-char (point-min))
> (insert (make-string 45 ?x))
> 
> The "1" will appear to get pushed towards the left as more text is added 
> until the line wraps the window:
> 
> So my question becomes, how should I apply these display text properties 
> such that they will not be affected by line wrapping?

It's a bug.  Two bugs, actually.  And from the looks of that, it
sounds like no one has ever tried to display stretches of whitespace
in the display margins.

I've now fixed that on the master branch, see commit ff03411.

Alan, could you please see if something similar is needed in nsterm.m
(my reading of the code indicates that it is already okay, but I'm not
sure).  The symptom of the problem I fixed in xterm.c and w32term.c is
that when you execute the first part of the recipe in a single progn,
the first 2 lines are not cleared in the left margin area, you still
see portions of the comment originally displayed in the *scratch*
buffer.

Thanks.



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

* Re: Redisplaying text in both display margins?
  2021-01-27 15:59     ` Eli Zaretskii
@ 2021-01-27 18:02       ` Alan Third
  2021-02-01  7:04         ` pwr--- via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 9+ messages in thread
From: Alan Third @ 2021-01-27 18:02 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Wed, Jan 27, 2021 at 05:59:23PM +0200, Eli Zaretskii wrote:
> 
> Alan, could you please see if something similar is needed in nsterm.m
> (my reading of the code indicates that it is already okay, but I'm not
> sure).  The symptom of the problem I fixed in xterm.c and w32term.c is
> that when you execute the first part of the recipe in a single progn,
> the first 2 lines are not cleared in the left margin area, you still
> see portions of the comment originally displayed in the *scratch*
> buffer.

It looks OK here. I don't see what you describe.
-- 
Alan Third



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

* Re: Redisplaying text in both display margins?
  2021-01-27 18:02       ` Alan Third
@ 2021-02-01  7:04         ` pwr--- via Users list for the GNU Emacs text editor
  2021-02-01 15:02           ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: pwr--- via Users list for the GNU Emacs text editor @ 2021-02-01  7:04 UTC (permalink / raw)
  To: Alan Third; +Cc: help-gnu-emacs

On 2021-01-28 04:02, Alan Third wrote:
> On Wed, Jan 27, 2021 at 05:59:23PM +0200, Eli Zaretskii wrote:
>> 
>> Alan, could you please see if something similar is needed in nsterm.m
>> (my reading of the code indicates that it is already okay, but I'm not
>> sure).  The symptom of the problem I fixed in xterm.c and w32term.c is
>> that when you execute the first part of the recipe in a single progn,
>> the first 2 lines are not cleared in the left margin area, you still
>> see portions of the comment originally displayed in the *scratch*
>> buffer.
> 
> It looks OK here. I don't see what you describe.

Thank you gentlemen. Everything appears to work as expected on Emacs 
from master, 28.0.50 on macOS 10.13.6.

Can I work on the assumption this commit will be included in `(<= 28 
emacs-major-version)'?

Is there likely to be any workaround or alternate approach to make a 
string display similarly aligned in the left display margin in Emacs < 
28? I'm trying to keep as much functionality as possible all the way 
back to 24.4.

(Btw I am off-list, if you can reply-all I would much appreciate it!)



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

* Re: Redisplaying text in both display margins?
  2021-02-01  7:04         ` pwr--- via Users list for the GNU Emacs text editor
@ 2021-02-01 15:02           ` Eli Zaretskii
  2021-02-01 15:44             ` pwr--- via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2021-02-01 15:02 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: Paul W. Rankin

> Date: Mon, 01 Feb 2021 17:04:34 +1000
> From: "Paul W. Rankin" <pwr@bydasein.com>
> Cc: Eli Zaretskii <eliz@gnu.org>, help-gnu-emacs@gnu.org
> 
> Can I work on the assumption this commit will be included in `(<= 28 
> emacs-major-version)'?

Yes.  What is now the master branch will become Emacs 28.1.

> Is there likely to be any workaround or alternate approach to make a 
> string display similarly aligned in the left display margin in Emacs < 
> 28? I'm trying to keep as much functionality as possible all the way 
> back to 24.4.

The only way I know of is to make sure the text on which you put the
display property is never too close to the right edge of the window.
The bug was that the display engine considered the X coordinate of the
buffer text in the text area when it made the decision whether to
decrease the width of the string displayed in the margin.

> (Btw I am off-list, if you can reply-all I would much appreciate it!)

I will try to remember, but I cannot promise, as I always reply only
to the list in this case, without thinking.  (I almost blew it this
time.)



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

* Re: Redisplaying text in both display margins?
  2021-02-01 15:02           ` Eli Zaretskii
@ 2021-02-01 15:44             ` pwr--- via Users list for the GNU Emacs text editor
  2021-02-01 16:10               ` moasenwood--- via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 9+ messages in thread
From: pwr--- via Users list for the GNU Emacs text editor @ 2021-02-01 15:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On 2021-02-02 01:02, Eli Zaretskii wrote:
> The only way I know of is to make sure the text on which you put the
> display property is never too close to the right edge of the window.
> The bug was that the display engine considered the X coordinate of the
> buffer text in the text area when it made the decision whether to
> decrease the width of the string displayed in the margin.
> 
>> (Btw I am off-list, if you can reply-all I would much appreciate it!)
> 
> I will try to remember, but I cannot promise, as I always reply only
> to the list in this case, without thinking.  (I almost blew it this
> time.)

Thanks! Sorry I only meant for this thread -- the onus is on me to make 
clear when I'm writing in from off-list, which this time I forgot to do. 
(Can't expect anyone to keep in their heads who is/isn't subscribed.)



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

* Re: Redisplaying text in both display margins?
  2021-02-01 15:44             ` pwr--- via Users list for the GNU Emacs text editor
@ 2021-02-01 16:10               ` moasenwood--- via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 9+ messages in thread
From: moasenwood--- via Users list for the GNU Emacs text editor @ 2021-02-01 16:10 UTC (permalink / raw)
  To: help-gnu-emacs

pwr--- via Users list for the GNU Emacs text editor wrote:

> Thanks! Sorry I only meant for this thread -- the onus is on
> me to make clear when I'm writing in from off-list, which
> this time I forgot to do. (Can't expect anyone to keep in
> their heads who is/isn't subscribed.)

Doesn't that happen automagically? I for one _never_ think who
subscribes or not. There should be mane ways to read,
furthermore. There were even a Usenet group (gnu.emacs.help)
and a gateway here but I think it (the gateway) isn't
operational anymore. More, I use Emacs Gnus and Gmane, so this
is gmane.emacs.help for me. When the Usenet group was
gatewayed there were also Google groups. There is the web
archive [1] and even tho I don't think Gmane has an
interface/archive up ATM I'm pretty sure that was the case
sometimes. Plus the way to read and send that I'm unaware
of...

[1] https://lists.gnu.org/archive/html/help-gnu-emacs/

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

end of thread, other threads:[~2021-02-01 16:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-19  9:27 Redisplaying text in both display margins? pwr--- via Users list for the GNU Emacs text editor
2021-01-19 15:16 ` Eli Zaretskii
2021-01-25  8:28   ` pwr--- via Users list for the GNU Emacs text editor
2021-01-27 15:59     ` Eli Zaretskii
2021-01-27 18:02       ` Alan Third
2021-02-01  7:04         ` pwr--- via Users list for the GNU Emacs text editor
2021-02-01 15:02           ` Eli Zaretskii
2021-02-01 15:44             ` pwr--- via Users list for the GNU Emacs text editor
2021-02-01 16:10               ` moasenwood--- via Users list for the GNU Emacs text editor

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.