unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* overlays and movement
@ 2022-06-28  9:17 Manuel Giraud
  2022-06-28 10:39 ` Tassilo Horn
  0 siblings, 1 reply; 12+ messages in thread
From: Manuel Giraud @ 2022-06-28  9:17 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I'd like to have some overlays (just 2 in fact) that have to be updated
each time I'm moving into the buffer. What is the prefered way to do
this?

I have tried to add a hook on `post-command-hook'. It kind of works but
it seems to lag sometimes and the docstring says that this is a bad idea
anyway.

Best regards,
-- 
Manuel Giraud



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

* Re: overlays and movement
  2022-06-28  9:17 overlays and movement Manuel Giraud
@ 2022-06-28 10:39 ` Tassilo Horn
  2022-06-28 12:12   ` Manuel Giraud
  2022-06-28 15:56   ` Manuel Giraud
  0 siblings, 2 replies; 12+ messages in thread
From: Tassilo Horn @ 2022-06-28 10:39 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: help-gnu-emacs

Manuel Giraud <manuel@ledu-giraud.fr> writes:

Hi Manuel,

> I'd like to have some overlays (just 2 in fact) that have to be
> updated each time I'm moving into the buffer.

What does that mean exactly?  Do you mean "the position of point changes
in that buffer" or "the buffer becomes shown in a window"?  If it's the
former, I'd use a buffer-local post-command-hook checking if point moved
by comparing to the former value and recording that.  If it's the
latter, a buffer-local window-configuration-change-hook.

If you only need to update the overlays when the buffer contents have
changed, then after-change-functions are your friend.

> I have tried to add a hook on `post-command-hook'. It kind of works
> but it seems to lag sometimes and the docstring says that this is a
> bad idea anyway.

It says it's a bad idea for expensive functions.  But when you can
cheaply detect that nothing has to be done in most of the cases and you
do it buffer-locally, it won't be too bad, I guess.

Bye,
Tassilo



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

* Re: overlays and movement
  2022-06-28 10:39 ` Tassilo Horn
@ 2022-06-28 12:12   ` Manuel Giraud
  2022-06-28 15:56   ` Manuel Giraud
  1 sibling, 0 replies; 12+ messages in thread
From: Manuel Giraud @ 2022-06-28 12:12 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

Tassilo Horn <tsdh@gnu.org> writes:

>> I'd like to have some overlays (just 2 in fact) that have to be
>> updated each time I'm moving into the buffer.
>
> What does that mean exactly?  Do you mean "the position of point changes
> in that buffer" or "the buffer becomes shown in a window"?

Hi Tassilo,

Sorry, I was not clear. It is the former. I'll stick to
post-command-hook then but try to reduce the amount of
computing. Thanks.
-- 
Manuel Giraud



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

* Re: overlays and movement
  2022-06-28 10:39 ` Tassilo Horn
  2022-06-28 12:12   ` Manuel Giraud
@ 2022-06-28 15:56   ` Manuel Giraud
  2022-06-28 16:13     ` Emanuel Berg
  2022-06-28 19:22     ` Tassilo Horn
  1 sibling, 2 replies; 12+ messages in thread
From: Manuel Giraud @ 2022-06-28 15:56 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

Hi,

FWIW, here is what I wanted to do. It is not super fast but quite
usable.
--8<---------------cut here---------------start------------->8---
;; Fog
(defvar up-fog nil)
(defvar down-fog nil)
(defvar fog-distance 10)

(defun up-fog-end ()
  (save-excursion
    (if	(zerop (forward-line (- (+ fog-distance 1))))
	(progn (end-of-line)
	       (point))
      (point-min))))

(defun down-fog-start ()
  (save-excursion
    (forward-line (+ fog-distance 1))
    (beginning-of-line)
    (point)))

(defface fog
  '((t :foreground "grey90" :background "grey95"))
  "Fog face.")

(defun maybe-move-fog ()
  (while-no-input
    (redisplay)
    (let ((new-end (up-fog-end))
	  (new-start (down-fog-start)))
      (when (or (/= (overlay-end up-fog) new-end)
		(/= (overlay-start down-fog) new-start))
	(move-overlay up-fog (point-min) new-end)
	(move-overlay down-fog new-start (point-max))))))

(defun fog-on ()
  (maybe-move-fog)
  (overlay-put up-fog 'face 'fog)
  (overlay-put down-fog 'face 'fog))

(defun fog-off ()
  (overlay-put up-fog 'face nil)
  (overlay-put down-fog 'face nil))

(define-minor-mode fog-mode
  "Minor fog mode"
  :lighter " fog"
  (if fog-mode
      (progn
	(setq up-fog (make-overlay 1 1)
	      down-fog (make-overlay 1 1))
	(fog-on)
	(add-hook 'post-command-hook 'maybe-move-fog 0 t))
    (fog-off)
    (remove-hook 'post-command-hook 'maybe-move-fog t)
    (delete-overlay up-fog)
    (delete-overlay down-fog)
    (setq up-fog nil down-fog nil)))
--8<---------------cut here---------------end--------------->8---
-- 
Manuel Giraud



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

* Re: overlays and movement
  2022-06-28 15:56   ` Manuel Giraud
@ 2022-06-28 16:13     ` Emanuel Berg
  2022-06-29  7:12       ` Manuel Giraud
  2022-06-28 19:22     ` Tassilo Horn
  1 sibling, 1 reply; 12+ messages in thread
From: Emanuel Berg @ 2022-06-28 16:13 UTC (permalink / raw)
  To: help-gnu-emacs

Manuel Giraud wrote:

> FWIW, here is what I wanted to do. It is not super fast but
> quite usable.

Good code!

Add ;;; -*- lexical-binding: t -*-

You could add `1+' and #'function ...

> ;; Fog
> (defvar up-fog nil)
> (defvar down-fog nil)
> (defvar fog-distance 10)

You can get away with these global with let closures, won't
improve performance tho LOL :)

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: overlays and movement
  2022-06-28 15:56   ` Manuel Giraud
  2022-06-28 16:13     ` Emanuel Berg
@ 2022-06-28 19:22     ` Tassilo Horn
  2022-06-29  7:23       ` Manuel Giraud
  1 sibling, 1 reply; 12+ messages in thread
From: Tassilo Horn @ 2022-06-28 19:22 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: help-gnu-emacs

Manuel Giraud <manuel@ledu-giraud.fr> writes:

Hi Manuel,

> FWIW, here is what I wanted to do. It is not super fast but quite
> usable.

Interesting.  What purpose does it serve?  :-)

Bye,
Tassilo



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

* Re: overlays and movement
  2022-06-28 16:13     ` Emanuel Berg
@ 2022-06-29  7:12       ` Manuel Giraud
  2022-06-29  7:34         ` tomas
  2022-06-30  6:11         ` Emanuel Berg
  0 siblings, 2 replies; 12+ messages in thread
From: Manuel Giraud @ 2022-06-29  7:12 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <incal@dataswamp.org> writes:

> Manuel Giraud wrote:
>
>> FWIW, here is what I wanted to do. It is not super fast but
>> quite usable.
>
> Good code!

Thanks!

> Add ;;; -*- lexical-binding: t -*-

You mean to use variables into closures?
-- 
Manuel Giraud



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

* Re: overlays and movement
  2022-06-28 19:22     ` Tassilo Horn
@ 2022-06-29  7:23       ` Manuel Giraud
  2022-06-30  4:51         ` Tassilo Horn
  2022-06-30  6:14         ` Emanuel Berg
  0 siblings, 2 replies; 12+ messages in thread
From: Manuel Giraud @ 2022-06-29  7:23 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

Tassilo Horn <tsdh@gnu.org> writes:

> Manuel Giraud <manuel@ledu-giraud.fr> writes:
>
> Hi Manuel,
>
>> FWIW, here is what I wanted to do. It is not super fast but quite
>> usable.
>
> Interesting.  What purpose does it serve?  :-)

😅 the purpose I wanted to use that for is to have this mode on when
viewing a file full of passwords. This way only some passwords + context
will be visible at a time. A simple/weird shoulder surfing protection if
you will.

I know that package like hidepw does this better but this seems fun and
a way to play with overlays.
-- 
Manuel Giraud



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

* Re: overlays and movement
  2022-06-29  7:12       ` Manuel Giraud
@ 2022-06-29  7:34         ` tomas
  2022-06-30  6:11         ` Emanuel Berg
  1 sibling, 0 replies; 12+ messages in thread
From: tomas @ 2022-06-29  7:34 UTC (permalink / raw)
  To: help-gnu-emacs

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

On Wed, Jun 29, 2022 at 09:12:25AM +0200, Manuel Giraud wrote:
> Emanuel Berg <incal@dataswamp.org> writes:
> 
> > Manuel Giraud wrote:
> >
> >> FWIW, here is what I wanted to do. It is not super fast but
> >> quite usable.
> >
> > Good code!
> 
> Thanks!
> 
> > Add ;;; -*- lexical-binding: t -*-
> 
> You mean to use variables into closures?

Besides, the compiler can do more nice things to your
code.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* Re: overlays and movement
  2022-06-29  7:23       ` Manuel Giraud
@ 2022-06-30  4:51         ` Tassilo Horn
  2022-06-30  6:14         ` Emanuel Berg
  1 sibling, 0 replies; 12+ messages in thread
From: Tassilo Horn @ 2022-06-30  4:51 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: help-gnu-emacs

Manuel Giraud <manuel@ledu-giraud.fr> writes:

Hi Manuel,

>>> FWIW, here is what I wanted to do. It is not super fast but quite
>>> usable.
>>
>> Interesting.  What purpose does it serve?  :-)
>
> 😅 the purpose I wanted to use that for is to have this mode on when
> viewing a file full of passwords. This way only some passwords +
> context will be visible at a time. A simple/weird shoulder surfing
> protection if you will.

Ah, I see.  I was thinking it was about focusing on just some specific
part of the buffer where I would have suggested to be a more specific
(like current function in code or current sentence/paragraph in prose).

> I know that package like hidepw does this better but this seems fun
> and a way to play with overlays.

That's of course always an excellent reason. :-)

Bye,
Tassilo



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

* Re: overlays and movement
  2022-06-29  7:12       ` Manuel Giraud
  2022-06-29  7:34         ` tomas
@ 2022-06-30  6:11         ` Emanuel Berg
  1 sibling, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2022-06-30  6:11 UTC (permalink / raw)
  To: help-gnu-emacs

Manuel Giraud wrote:

>>> FWIW, here is what I wanted to do. It is not super fast
>>> but quite usable.
>>
>> Good code!
>
> Thanks!
>
>> Add ;;; -*- lexical-binding: t -*-
>
> You mean to use variables into closures?

Always do that first thing for Elisp for several reasons
including that (if you intend to do it).

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: overlays and movement
  2022-06-29  7:23       ` Manuel Giraud
  2022-06-30  4:51         ` Tassilo Horn
@ 2022-06-30  6:14         ` Emanuel Berg
  1 sibling, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2022-06-30  6:14 UTC (permalink / raw)
  To: help-gnu-emacs

Manuel Giraud wrote:

>> Interesting.  What purpose does it serve? 
>
> the purpose I wanted to use that for is to have this mode on
> when viewing a file full of passwords. This way only some
> passwords + context will be visible at a time.
> A simple/weird shoulder surfing protection if you will.

Ikr Tassilo? Straight DGSE :)

Any other ideas for Emacs Mr. Giraud?

-- 
underground experts united
https://dataswamp.org/~incal




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

end of thread, other threads:[~2022-06-30  6:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-28  9:17 overlays and movement Manuel Giraud
2022-06-28 10:39 ` Tassilo Horn
2022-06-28 12:12   ` Manuel Giraud
2022-06-28 15:56   ` Manuel Giraud
2022-06-28 16:13     ` Emanuel Berg
2022-06-29  7:12       ` Manuel Giraud
2022-06-29  7:34         ` tomas
2022-06-30  6:11         ` Emanuel Berg
2022-06-28 19:22     ` Tassilo Horn
2022-06-29  7:23       ` Manuel Giraud
2022-06-30  4:51         ` Tassilo Horn
2022-06-30  6:14         ` Emanuel Berg

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