unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How do I give an overlay a priority lower to that of hl-line-mode?
@ 2016-05-31  4:46 Clément Pit--Claudel
  2016-05-31 20:28 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Clément Pit--Claudel @ 2016-05-31  4:46 UTC (permalink / raw)
  To: Emacs developers


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

Hi emacs-dev,

A mode that I contribute to uses overlays to highlight certain lines. The added overlays typically cover (point-at-bol) .. (1+ (point-at-eol)), which unfortunately does not play nicely with hl-line-mode: my overlays hide the one added by hl-line-mode.

Demo:

(with-current-buffer (get-buffer-create "*hl*")
  (erase-buffer)
  (fundamental-mode)
  (hl-line-mode)
  (dotimes (_ 5) (insert "AAAAAAAAAA\n"))
  (goto-char 25)
  (let ((ov (make-overlay (point-at-bol) (1+ (point-at-eol)))))
    (overlay-put ov 'face '(:background "red")))
  (pop-to-buffer (current-buffer)))

Of course, the temptation is great to add a little (overlay-put ov 'priority -100), but it's explicitly a bad idea:

> This property’s value determines the priority of the overlay. If you
> want to specify a priority value, use either nil (or zero), or a
> positive integer. Any other value has undefined behavior.

What alternatives do I have? (In fact, do I have any?)

Thanks!


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: How do I give an overlay a priority lower to that of hl-line-mode?
  2016-05-31  4:46 How do I give an overlay a priority lower to that of hl-line-mode? Clément Pit--Claudel
@ 2016-05-31 20:28 ` Stefan Monnier
  2016-05-31 20:46   ` Clément Pit--Claudel
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2016-05-31 20:28 UTC (permalink / raw)
  To: emacs-devel

> What alternatives do I have? (In fact, do I have any?)

Alternatives:
- use text-properties instead of overlays.
- undocumented and tentatively added in recentish Emacsen you can use
  a priority of the form (nil . -100).  Which means: normal priority nil
  in general, but priority -100 when the normal priority rules (which
  look at the relative size of overlays) don't have a preference
  use -100.
- use a negative priority.


        Stefan




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

* Re: How do I give an overlay a priority lower to that of hl-line-mode?
  2016-05-31 20:28 ` Stefan Monnier
@ 2016-05-31 20:46   ` Clément Pit--Claudel
  2016-06-01  2:29     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Clément Pit--Claudel @ 2016-05-31 20:46 UTC (permalink / raw)
  To: emacs-devel


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

On 2016-05-31 16:28, Stefan Monnier wrote:
>> What alternatives do I have? (In fact, do I have any?)
> 
> Alternatives:

Thanks Stefan!

> - use text-properties instead of overlays.

Could work, indeed. Though adding and removing faces in text properties is trickier.

> - undocumented and tentatively added in recentish Emacsen you can use
>   a priority of the form (nil . -100).  Which means: normal priority nil
>   in general, but priority -100 when the normal priority rules (which
>   look at the relative size of overlays) don't have a preference
>   use -100.

Oh, neat :) Do you know in which version this was introduced?

> - use a negative priority.

Does this just behave like positive priorities, in practice?

Clément.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: How do I give an overlay a priority lower to that of hl-line-mode?
  2016-05-31 20:46   ` Clément Pit--Claudel
@ 2016-06-01  2:29     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2016-06-01  2:29 UTC (permalink / raw)
  To: emacs-devel

>> - undocumented and tentatively added in recentish Emacsen you can use
>> a priority of the form (nil . -100).  Which means: normal priority nil
>> in general, but priority -100 when the normal priority rules (which
>> look at the relative size of overlays) don't have a preference
>> use -100.
> Oh, neat :) Do you know in which version this was introduced?

IIRC it was added for the overlay-based region-highlight, so it should
be in 24.4.

>> - use a negative priority.
> Does this just behave like positive priorities, in practice?

Yes.  But these priorities are always tricky to use (no matter what
priority you choose, they'll always end up wrong at some point), in
my experience.  So positive or negative, they tend to suck.


        Stefan




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

end of thread, other threads:[~2016-06-01  2:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-31  4:46 How do I give an overlay a priority lower to that of hl-line-mode? Clément Pit--Claudel
2016-05-31 20:28 ` Stefan Monnier
2016-05-31 20:46   ` Clément Pit--Claudel
2016-06-01  2:29     ` Stefan Monnier

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).