all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How can I remove effects of text properties in 'before-string
@ 2017-10-22  7:25 Amos Bird
  2017-10-22  7:43 ` Amos Bird
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Amos Bird @ 2017-10-22  7:25 UTC (permalink / raw)
  To: help-gnu-emacs


Hi there,

emacs -Q

(set-window-margins (get-buffer-window) 20 0)
(overlay-put (make-overlay (point) (point)) 'before-string 
(propertize "." 'display `((margin left-margin) ,"Hi there!")))
(hl-line-mode)

The string "Hi there!" is also highlighted. How can I disable 
that?

regards,
--
Amos Bird
amosbird@gmail.com


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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22  7:25 Amos Bird
@ 2017-10-22  7:43 ` Amos Bird
  2017-10-22 16:00 ` Emanuel Berg
  2017-10-22 16:02 ` Eli Zaretskii
  2 siblings, 0 replies; 16+ messages in thread
From: Amos Bird @ 2017-10-22  7:43 UTC (permalink / raw)
  To: help-gnu-emacs


I've also post a question at

https://emacs.stackexchange.com/questions/36328/how-can-i-eliminate-the-side-effect-of-left-margin

with some images for better description.


Amos Bird <amosbird@gmail.com> writes:

> Hi there,
>
> emacs -Q
>
> (set-window-margins (get-buffer-window) 20 0)
> (overlay-put (make-overlay (point) (point)) 'before-string 
> (propertize "."
> 'display `((margin left-margin) ,"Hi there!")))
> (hl-line-mode)
>
> The string "Hi there!" is also highlighted. How can I disable 
> that?
>
> regards,


--
Amos Bird
amosbird@gmail.com


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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22  7:25 Amos Bird
  2017-10-22  7:43 ` Amos Bird
@ 2017-10-22 16:00 ` Emanuel Berg
  2017-10-22 17:07   ` Amos Bird
  2017-10-22 16:02 ` Eli Zaretskii
  2 siblings, 1 reply; 16+ messages in thread
From: Emanuel Berg @ 2017-10-22 16:00 UTC (permalink / raw)
  To: help-gnu-emacs

> emacs -Q
>
> (set-window-margins (get-buffer-window) 20 0)
> (overlay-put (make-overlay (point) (point))
> 'before-string (propertize "." 'display
> `((margin left-margin) ,"Hi there!")))
> (hl-line-mode)

I don't know what you're up to but in general
you can use `buffer-substring-no-properties'.

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22  7:25 Amos Bird
  2017-10-22  7:43 ` Amos Bird
  2017-10-22 16:00 ` Emanuel Berg
@ 2017-10-22 16:02 ` Eli Zaretskii
  2017-10-22 17:07   ` Amos Bird
  2 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2017-10-22 16:02 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Amos Bird <amosbird@gmail.com>
> Date: Sun, 22 Oct 2017 15:25:31 +0800
> 
> (set-window-margins (get-buffer-window) 20 0)
> (overlay-put (make-overlay (point) (point)) 'before-string 
> (propertize "." 'display `((margin left-margin) ,"Hi there!")))
> (hl-line-mode)
> 
> The string "Hi there!" is also highlighted. How can I disable 
> that?

Give the string a distinct face.



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

* RE: How can I remove effects of text properties in 'before-string
       [not found] ` <<838tg3b27v.fsf@gnu.org>
@ 2017-10-22 16:33   ` Drew Adams
  2017-10-22 16:50     ` Eli Zaretskii
       [not found]     ` <<837evnazze.fsf@gnu.org>
  0 siblings, 2 replies; 16+ messages in thread
From: Drew Adams @ 2017-10-22 16:33 UTC (permalink / raw)
  To: Eli Zaretskii, help-gnu-emacs

> > (set-window-margins (get-buffer-window) 20 0)
> > (overlay-put (make-overlay (point) (point)) 'before-string
> > (propertize "." 'display `((margin left-margin) ,"Hi there!")))
> > (hl-line-mode)
> >
> > The string "Hi there!" is also highlighted. How can I disable
> > that?
> 
> Give the string a distinct face.

Why doesn't it use the `default' face?  If no `face'
property is given to the string, why would the effective
face be something different from `default'?

Where in the doc do we say that this should use a face
that is used in an overlay placed on some buffer positions?

Is this behavior documented?  I couldn't find anything
about it, but it might well be there somewhere.  I looked
in the doc about overlays and the doc about the margin,
but perhaps it is there and I overlooked or misread it.

Or is this perhaps a bug?  For what reason should the
properties of an overlay on some parts of a buffer
affect the appearance of the margin?



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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22 16:33   ` How can I remove effects of text properties in 'before-string Drew Adams
@ 2017-10-22 16:50     ` Eli Zaretskii
       [not found]     ` <<837evnazze.fsf@gnu.org>
  1 sibling, 0 replies; 16+ messages in thread
From: Eli Zaretskii @ 2017-10-22 16:50 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sun, 22 Oct 2017 09:33:08 -0700 (PDT)
> From: Drew Adams <drew.adams@oracle.com>
> 
> > > The string "Hi there!" is also highlighted. How can I disable
> > > that?
> > 
> > Give the string a distinct face.
> 
> Why doesn't it use the `default' face?  If no `face'
> property is given to the string, why would the effective
> face be something different from `default'?

That's the general way Emacs works: an overlay string which wasn't
specified a face uses the face of the "underlying" text.  You will see
the same if the overlay string is displayed in the text area, and
displaying it in the margins doesn't change this basic fact.

Personally, I think nothing else makes more sense, but that's me.

> Where in the doc do we say that this should use a face
> that is used in an overlay placed on some buffer positions?

The hl-line overlay produces a face for buffer text, and the
before-string is displayed with the same face.

> Is this behavior documented?  I couldn't find anything
> about it, but it might well be there somewhere.  I looked
> in the doc about overlays and the doc about the margin,
> but perhaps it is there and I overlooked or misread it.

It's indirectly documented in "Displaying Faces".

> Or is this perhaps a bug?

Not a bug: the code does this on purpose, and even has comments that
explicitly describe this.  Emacs worked like that since v21.1.



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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22 16:02 ` Eli Zaretskii
@ 2017-10-22 17:07   ` Amos Bird
  2017-10-22 17:15     ` Eli Zaretskii
  0 siblings, 1 reply; 16+ messages in thread
From: Amos Bird @ 2017-10-22 17:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs


Hi, could you show the elisp code that resolves this? I don't 
quite understand how to give a distinct face.

regards,

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Amos Bird <amosbird@gmail.com>
>> Date: Sun, 22 Oct 2017 15:25:31 +0800
>>
>> (set-window-margins (get-buffer-window) 20 0)
>> (overlay-put (make-overlay (point) (point)) 'before-string
>> (propertize "." 'display `((margin left-margin) ,"Hi there!")))
>> (hl-line-mode)
>>
>> The string "Hi there!" is also highlighted. How can I disable
>> that?
>
> Give the string a distinct face.


--
Amos Bird
amosbird@gmail.com


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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22 16:00 ` Emanuel Berg
@ 2017-10-22 17:07   ` Amos Bird
  0 siblings, 0 replies; 16+ messages in thread
From: Amos Bird @ 2017-10-22 17:07 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

Hi, how can I use that to set margin text?

Emanuel Berg <moasen@zoho.com> writes:

>> emacs -Q
>>
>> (set-window-margins (get-buffer-window) 20 0)
>> (overlay-put (make-overlay (point) (point))
>> 'before-string (propertize "." 'display
>> `((margin left-margin) ,"Hi there!")))
>> (hl-line-mode)
>
> I don't know what you're up to but in general
> you can use `buffer-substring-no-properties'.


--
Amos Bird
amosbird@gmail.com


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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22 17:07   ` Amos Bird
@ 2017-10-22 17:15     ` Eli Zaretskii
  2017-10-22 18:08       ` Amos Bird
  0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2017-10-22 17:15 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Amos Bird <amosbird@gmail.com>
> Cc: help-gnu-emacs@gnu.org
> Date: Mon, 23 Oct 2017 01:07:04 +0800
> 
> Hi, could you show the elisp code that resolves this? I don't 
> quite understand how to give a distinct face.

Here, this simple variation of your original recipe will display the
string in the margin using the 'default' face:

  (set-window-margins (get-buffer-window) 20 0)
  (setq ovstring (propertize "Hi, there!" 'face 'default))  <<<<<<<<<<<<<<<
  (overlay-put (make-overlay (point) (point)) 'before-string 
	       (propertize "."
			   'display
			   `((margin left-margin) ,ovstring)))
  (hl-line-mode)

The line marked with "<<<<<" is the main part of the solution.



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

* RE: How can I remove effects of text properties in 'before-string
       [not found]     ` <<837evnazze.fsf@gnu.org>
@ 2017-10-22 17:32       ` Drew Adams
  2017-10-27 14:44         ` Eli Zaretskii
  0 siblings, 1 reply; 16+ messages in thread
From: Drew Adams @ 2017-10-22 17:32 UTC (permalink / raw)
  To: Eli Zaretskii, help-gnu-emacs

> > Is this behavior documented?  I couldn't find anything
> > about it, but it might well be there somewhere.  I looked
> > in the doc about overlays and the doc about the margin,
> > but perhaps it is there and I overlooked or misread it.
> 
> It's indirectly documented in "Displaying Faces".

OK.  The margin-spec `display' property is applied in
this case to a zero-length buffer zone.  And a margin-spec
`display' property is of type "replacing", so the text
in that zone is not shown (which has no effect, since
the zone is empty).

What you say makes sense: face `hl-line-face' is used
for an overlay that covers the empty zone in question,
so that face is active there, so it is visible for the
margin-spec `display' overlay.

Still, I don't think this behavior is obvious, from
the doc.  I'm not sure where it should be pointed out,
but I think it would help to do so, even if it does
follow from what is written now.

Perhaps point this out explicitly in node `Displaying
Faces'.  And perhaps xref that node from node `Display
Margins', since a margin spec is a likely gotcha candidate).

> Not a bug: the code does this on purpose, and even has comments that
> explicitly describe this.  Emacs worked like that since v21.1.

Code comments are one way to make the design and behavior
clear.  The Elisp manual is another way - a better way to
get across something like this to most users.

Thank you for the explanation.  Please consider improving
the doc to make this behavior clearer.



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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22 17:15     ` Eli Zaretskii
@ 2017-10-22 18:08       ` Amos Bird
  2017-10-22 18:24         ` Eli Zaretskii
  2017-10-23 12:57         ` Stefan Monnier
  0 siblings, 2 replies; 16+ messages in thread
From: Amos Bird @ 2017-10-22 18:08 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

Hi, thanks for the code. It works! However, I tried to explicited 
set face to
'((t (:foreground "magenta" :weight bold :inherit default))

which doesn't. Why?

regards,

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Amos Bird <amosbird@gmail.com>
>> Cc: help-gnu-emacs@gnu.org
>> Date: Mon, 23 Oct 2017 01:07:04 +0800
>>
>> Hi, could you show the elisp code that resolves this? I don't
>> quite understand how to give a distinct face.
>
> Here, this simple variation of your original recipe will display 
> the
> string in the margin using the 'default' face:
>
>   (set-window-margins (get-buffer-window) 20 0)
>   (setq ovstring (propertize "Hi, there!" 'face 'default)) 
>   <<<<<<<<<<<<<<<
>   (overlay-put (make-overlay (point) (point)) 'before-string
> 	       (propertize "."
> 			   'display
> 			   `((margin left-margin) ,ovstring)))
>   (hl-line-mode)
>
> The line marked with "<<<<<" is the main part of the solution.


--
Amos Bird
amosbird@gmail.com


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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22 18:08       ` Amos Bird
@ 2017-10-22 18:24         ` Eli Zaretskii
  2017-10-22 19:12           ` Amos Bird
  2017-10-23 12:57         ` Stefan Monnier
  1 sibling, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2017-10-22 18:24 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Amos Bird <amosbird@gmail.com>
> Cc: help-gnu-emacs@gnu.org
> Date: Mon, 23 Oct 2017 02:08:40 +0800
> 
> Hi, thanks for the code. It works! However, I tried to explicited 
> set face to
> '((t (:foreground "magenta" :weight bold :inherit default))
> 
> which doesn't. Why?

Please show the entire recipe, I don't think I understand well enough
what exactly you did.



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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22 18:24         ` Eli Zaretskii
@ 2017-10-22 19:12           ` Amos Bird
  2017-10-22 19:34             ` Eli Zaretskii
  0 siblings, 1 reply; 16+ messages in thread
From: Amos Bird @ 2017-10-22 19:12 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs


Hi,

(set-window-margins (get-buffer-window) 20 0)
(setq ovstring (propertize "Hi, there!" 'face '((t (:foreground 
"magenta" :weight bold :inherit default)))))
(overlay-put (make-overlay (point) (point)) 'before-string 
(propertize "." 'display `((margin left-margin) ,ovstring)))
(hl-line-mode)

The margin text doesn't appear to have the "magenta" color.

regards,

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Amos Bird <amosbird@gmail.com>
>> Cc: help-gnu-emacs@gnu.org
>> Date: Mon, 23 Oct 2017 02:08:40 +0800
>>
>> Hi, thanks for the code. It works! However, I tried to 
>> explicited
>> set face to
>> '((t (:foreground "magenta" :weight bold :inherit default))
>>
>> which doesn't. Why?
>
> Please show the entire recipe, I don't think I understand well 
> enough
> what exactly you did.


--
Amos Bird
amosbird@gmail.com


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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22 19:12           ` Amos Bird
@ 2017-10-22 19:34             ` Eli Zaretskii
  0 siblings, 0 replies; 16+ messages in thread
From: Eli Zaretskii @ 2017-10-22 19:34 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Amos Bird <amosbird@gmail.com>
> Cc: help-gnu-emacs@gnu.org
> Date: Mon, 23 Oct 2017 03:12:55 +0800
> 
> (set-window-margins (get-buffer-window) 20 0)
> (setq ovstring (propertize "Hi, there!" 'face '((t (:foreground 
> "magenta" :weight bold :inherit default)))))
> (overlay-put (make-overlay (point) (point)) 'before-string 
> (propertize "." 'display `((margin left-margin) ,ovstring)))
> (hl-line-mode)
> 
> The margin text doesn't appear to have the "magenta" color.

":inherit default" should appear before the other attributes.

Think about it: you are telling Emacs how to merge the default face
with other attributes, so it should start with the default face,
right?



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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22 18:08       ` Amos Bird
  2017-10-22 18:24         ` Eli Zaretskii
@ 2017-10-23 12:57         ` Stefan Monnier
  1 sibling, 0 replies; 16+ messages in thread
From: Stefan Monnier @ 2017-10-23 12:57 UTC (permalink / raw)
  To: help-gnu-emacs

> Hi, thanks for the code. It works! However, I tried to explicited set face
> to '((t (:foreground "magenta" :weight bold :inherit default))

That's not a face.  You're confusing the face-spec passed to `defface`
with an actual face.

You can use

(setq ovstring
      (propertize "Hi, there!" 'face
                               '((:foreground "magenta" :weight bold) default)))

tho I'd recommend you use one of

    (defface foo-bar
      '((t (:foreground "magenta" :weight bold :inherit default))))
    [...]
      (setq ovstring (propertize "Hi, there!" 'face 'foo-bar))

or

    (defface foo-bar
      '((t (:foreground "magenta" :weight bold))))
    [...]
      (setq ovstring (propertize "Hi, there!" 'face '(foo-bar default)))


-- Stefan




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

* Re: How can I remove effects of text properties in 'before-string
  2017-10-22 17:32       ` Drew Adams
@ 2017-10-27 14:44         ` Eli Zaretskii
  0 siblings, 0 replies; 16+ messages in thread
From: Eli Zaretskii @ 2017-10-27 14:44 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sun, 22 Oct 2017 10:32:20 -0700 (PDT)
> From: Drew Adams <drew.adams@oracle.com>
> 
> Thank you for the explanation.  Please consider improving
> the doc to make this behavior clearer.

Done.



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

end of thread, other threads:[~2017-10-27 14:44 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <<87tvyrabkk.fsf@gmail.com>
     [not found] ` <<838tg3b27v.fsf@gnu.org>
2017-10-22 16:33   ` How can I remove effects of text properties in 'before-string Drew Adams
2017-10-22 16:50     ` Eli Zaretskii
     [not found]     ` <<837evnazze.fsf@gnu.org>
2017-10-22 17:32       ` Drew Adams
2017-10-27 14:44         ` Eli Zaretskii
2017-10-22  7:25 Amos Bird
2017-10-22  7:43 ` Amos Bird
2017-10-22 16:00 ` Emanuel Berg
2017-10-22 17:07   ` Amos Bird
2017-10-22 16:02 ` Eli Zaretskii
2017-10-22 17:07   ` Amos Bird
2017-10-22 17:15     ` Eli Zaretskii
2017-10-22 18:08       ` Amos Bird
2017-10-22 18:24         ` Eli Zaretskii
2017-10-22 19:12           ` Amos Bird
2017-10-22 19:34             ` Eli Zaretskii
2017-10-23 12:57         ` Stefan Monnier
     [not found] <<<87tvyrabkk.fsf@gmail.com>

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.