Automatic minor modes?

classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Automatic minor modes?

Lars Ingebrigtsen
I was going to write a mode for ~/.authinfo and ~/.netrc that would
cover up the passwords visually so that things are slightly less "eek"
if somebody should happen to walk behind you while you're editing that
file.

But then it was suggested that this should be a minor mode, and that
makes sense: There might well be other kinds of files where you'd rather
cover stuff up, and the minor mode could allow hooks to define syntaxes
and stuff.

But then back to the original remit: ~/.authinfo.  So I now have to
write a major mode for ~/.authinfo that will basically do nothing else
than switch this new minor mode on...  er...  `hide-passwords-mode',
let's call it.

Do we have a method for this?  That is, a way to say "this major mode
will activate these minor modes, unless the user has disabled that"?

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


Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Charles A. Roelli
> From: Lars Ingebrigtsen <[hidden email]>
> Date: Sat, 14 Apr 2018 16:56:55 +0200
>
> I was going to write a mode for ~/.authinfo and ~/.netrc that would
> cover up the passwords visually so that things are slightly less "eek"
> if somebody should happen to walk behind you while you're editing that
> file.

Could it build on hs-minor-mode?

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Yuri Khan-2
In reply to this post by Lars Ingebrigtsen
On Sat, Apr 14, 2018 at 9:56 PM, Lars Ingebrigtsen <[hidden email]> wrote:
> I was going to write a mode for ~/.authinfo and ~/.netrc that would
> cover up the passwords visually so that things are slightly less "eek"
> if somebody should happen to walk behind you while you're editing that
> file.

Could be just a few regexen for prettify-symbols-mode. Comes with an
ability to unmask the one the point is on.

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Lars Ingebrigtsen
Yuri Khan <[hidden email]> writes:

> Could be just a few regexen for prettify-symbols-mode. Comes with an
> ability to unmask the one the point is on.

It's similar, yes, but it should have commands to allow
unmasking/remasking a single password, I think?

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

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Clément Pit-Claudel
In reply to this post by Lars Ingebrigtsen
On 2018-04-14 10:56, Lars Ingebrigtsen wrote:
> Do we have a method for this?  That is, a way to say "this major mode
> will activate these minor modes, unless the user has disabled that"?

The way it's usually done is with a globalized minor mode.  The major mode then sets a variable (eldoc-documentation-function, or prettify-symbols-alist), and the minor mode turns itself on based on that variable.

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Lars Ingebrigtsen
Clément Pit-Claudel <[hidden email]> writes:

> On 2018-04-14 10:56, Lars Ingebrigtsen wrote:
>> Do we have a method for this?  That is, a way to say "this major mode
>> will activate these minor modes, unless the user has disabled that"?
>
> The way it's usually done is with a globalized minor mode.  The major
> mode then sets a variable (eldoc-documentation-function, or
> prettify-symbols-alist), and the minor mode turns itself on based on
> that variable.

Ah, I see.  So `hide-password-mode' would be a globalized minor mode
that's on by default, and the ~/.authinfo major mode would set a
`hide-password-alist' (or something) buffer-local variable to signal
that it should do its work in that buffer?

That makes sense.

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

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Clément Pit-Claudel
On 2018-04-14 11:45, Lars Ingebrigtsen wrote:

> Clément Pit-Claudel <[hidden email]> writes:
>
>> On 2018-04-14 10:56, Lars Ingebrigtsen wrote:
>>> Do we have a method for this?  That is, a way to say "this major mode
>>> will activate these minor modes, unless the user has disabled that"?
>>
>> The way it's usually done is with a globalized minor mode.  The major
>> mode then sets a variable (eldoc-documentation-function, or
>> prettify-symbols-alist), and the minor mode turns itself on based on
>> that variable.
>
> Ah, I see.  So `hide-password-mode' would be a globalized minor mode
> that's on by default, and the ~/.authinfo major mode would set a
> `hide-password-alist' (or something) buffer-local variable to signal
> that it should do its work in that buffer?

That's how I would do it, yup.

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Lars Ingebrigtsen
In reply to this post by Charles A. Roelli
[hidden email] (Charles A. Roelli) writes:

> Could it build on hs-minor-mode?

Hm, I hadn't seen that one before...  I just played with it for a minute
or so, and it seems a bit heavy...

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

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Ted Zlatanov
In reply to this post by Lars Ingebrigtsen
On Sat, 14 Apr 2018 17:27:43 +0200 Lars Ingebrigtsen <[hidden email]> wrote:

LI> Yuri Khan <[hidden email]> writes:
>> Could be just a few regexen for prettify-symbols-mode. Comes with an
>> ability to unmask the one the point is on.

LI> It's similar, yes, but it should have commands to allow
LI> unmasking/remasking a single password, I think?

prettify-symbols-mode has built-in the perfect tool for what
you're describing, `prettify-symbols-unprettify-at-point':

prettify-symbols-unprettify-at-point is a variable defined in ‘prog-mode.el’.
Its value is ‘right-edge’
Original value was nil

Documentation:
If non-nil, show the non-prettified version of a symbol when point is on it.
If set to the symbol ‘right-edge’, also unprettify if point
is immediately after the symbol.  The prettification will be
reapplied as soon as point moves away from the symbol.  If
set to nil, the prettification persists even when point is
on the symbol.

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Lars Ingebrigtsen
Ted Zlatanov <[hidden email]> writes:

>>> Could be just a few regexen for prettify-symbols-mode. Comes with an
>>> ability to unmask the one the point is on.
>
> LI> It's similar, yes, but it should have commands to allow
> LI> unmasking/remasking a single password, I think?
>
> prettify-symbols-mode has built-in the perfect tool for what
> you're describing, `prettify-symbols-unprettify-at-point':
>
> prettify-symbols-unprettify-at-point is a variable defined in ‘prog-mode.el’.
> Its value is ‘right-edge’

Ah, cool, then we should perhaps just activate that minor mode in
.authino/.netrc buffers?  (With the appropriate regexps to hide the
"passwd" token.)

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

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Clément Pit-Claudel
On 2018-07-22 08:26, Lars Ingebrigtsen wrote:

> Ted Zlatanov <[hidden email]> writes:
>
>>>> Could be just a few regexen for prettify-symbols-mode. Comes with an
>>>> ability to unmask the one the point is on.
>>
>> LI> It's similar, yes, but it should have commands to allow
>> LI> unmasking/remasking a single password, I think?
>>
>> prettify-symbols-mode has built-in the perfect tool for what
>> you're describing, `prettify-symbols-unprettify-at-point':
>>
>> prettify-symbols-unprettify-at-point is a variable defined in ‘prog-mode.el’.
>> Its value is ‘right-edge’
>
> Ah, cool, then we should perhaps just activate that minor mode in
> .authino/.netrc buffers?  (With the appropriate regexps to hide the
> "passwd" token.)

Even better would be to move the "unmask-at-point" feature out of prettify-symbols-mode, so that more complex hiding could use it too (prettify-symbols-mode is fairly strict in its inputs).

As a concrete example, company-coq prettifies abc__hijk as abcₕᵢⱼₖ (notice the hidden "__"), and I had to reimplement the unmasking feature.

Clément.

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Stefan Monnier
> Even better would be to move the "unmask-at-point" feature out of
> prettify-symbols-mode, so that more complex hiding could use it too
> (prettify-symbols-mode is fairly strict in its inputs).

How 'bout adding it to `reveal-mode`?


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Clément Pit-Claudel
On 2018-07-22 15:01, Stefan Monnier wrote:
>> Even better would be to move the "unmask-at-point" feature out of
>> prettify-symbols-mode, so that more complex hiding could use it too
>> (prettify-symbols-mode is fairly strict in its inputs).
>
> How 'bout adding it to `reveal-mode`?

Maybe ? But bonus points if each type of revealing can be turned on or off separately; maybe something like buffer-invisibility-spec? (I think currently you can disable revealing for some overlays, but not the other way around? basically I'd like my minor mode to be able to turn on revealing, but only for the overlays it created)

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Ted Zlatanov
On Sun, 22 Jul 2018 16:06:01 -0400 Clément Pit-Claudel <[hidden email]> wrote:

CP> On 2018-07-22 15:01, Stefan Monnier wrote:
>>> Even better would be to move the "unmask-at-point" feature out of
>>> prettify-symbols-mode, so that more complex hiding could use it too
>>> (prettify-symbols-mode is fairly strict in its inputs).
>>
>> How 'bout adding it to `reveal-mode`?

CP> Maybe ? But bonus points if each type of revealing can be turned on or off
CP> separately; maybe something like buffer-invisibility-spec? (I think currently
CP> you can disable revealing for some overlays, but not the other way around?
CP> basically I'd like my minor mode to be able to turn on revealing, but only for
CP> the overlays it created)

Any ideas here? This is still a feature worth having, I think. But
Clément and Stefan's comments have confused me so I don't know if it's
waiting for something and if there's a "right" way to do it?

Ted


Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Stefan Monnier
> Any ideas here? This is still a feature worth having, I think. But
> Clément and Stefan's comments have confused me so I don't know if it's
> waiting for something and if there's a "right" way to do it?

IIUC there are many different right ways.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Ted Zlatanov
On Mon, 08 Oct 2018 10:57:23 -0400 Stefan Monnier <[hidden email]> wrote:

>> Any ideas here? This is still a feature worth having, I think. But
>> Clément and Stefan's comments have confused me so I don't know if it's
>> waiting for something and if there's a "right" way to do it?

SM> IIUC there are many different right ways.

Stefan, can you recommend one? We all trust your expertise and you did a
lot of the work on prettify-symbols-mode that would apply here :)

Thanks
Ted

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Ted Zlatanov
On Tue, 09 Oct 2018 19:44:05 +0000 Ted Zlatanov <[hidden email]> wrote:

TZ> On Mon, 08 Oct 2018 10:57:23 -0400 Stefan Monnier <[hidden email]> wrote:
>>> Any ideas here? This is still a feature worth having, I think. But
>>> Clément and Stefan's comments have confused me so I don't know if it's
>>> waiting for something and if there's a "right" way to do it?

SM> IIUC there are many different right ways.

TZ> Stefan, can you recommend one? We all trust your expertise and you did a
TZ> lot of the work on prettify-symbols-mode that would apply here :)

I found several other threads about this, asking more or less the same
things "how to I use prettify-symbols-mode with strings/regexps"

https://emacs.stackexchange.com/questions/36572/prettify-symbols-mode-and-multi-character-replacements?noredirect=1&lq=1
https://emacs.stackexchange.com/questions/34808/using-prettify-symbols-with-strings-instead-of-characters?noredirect=1&lq=1

and "how do I hide secrets in Emacs"

https://www.reddit.com/r/emacs/comments/9ncypp/hide_copy_and_edit_secrets_in_gpg_encrypted_file/

The users are asking for this--it's not just us here. From my side, I
wanted to add support for it to JSON mode (for authinfo.json users) and
a netrc minor mode or something.

So... I looked at several things:

`reveal-mode`: the docs are simply unclear about how to use it:

;; Reveal mode is a minor mode that makes sure that text around point
;; is always visible.  When point enters a region of hidden text,
;; `reveal-mode' temporarily makes it visible.
...
;; It only works with packages that hide text using overlays.

...but no explanation of how to use it, practically, just references to
other packages which don't explain it either. It all seems custom-fitted
together in a way that's hard to reuse.

Then I looked at "(elisp) Replacing Specs" which let me to "(elisp)
Other Display Specs" and "(elisp) Overlay Properties" and... it was
not easy to follow when I just wanted to use reveal-mode. OK, I can make
overlays with special display properties... but how do I hook that with
font-lock and why do I have to know these details?

I then looked at the hideshow and outline modes, and they didn't have
generic functionality either, and it wasn't clear to me how to use them.

I looked at prettify-symbols-mode but extending it for strings and
regexps seems a bit inconsistent with how it was designed. I could hack
it probably.

Thus I was not able to make progress on this one. Maybe someone else
will, or be able to help me.

Ted

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Eli Zaretskii
> From: Ted Zlatanov <[hidden email]>
> Date: Sun, 14 Oct 2018 03:59:29 +0000
> Cc: [hidden email]
>
> Thus I was not able to make progress on this one. Maybe someone else
> will, or be able to help me.

It is very hard to follow a discussion that is spread over several
months, and each month produces a about 3 messages.  I personally long
ago lost focus of the thread; in particular, I no longer remember what
prettify-symbols-mode and/or reveal-mode have to do with the subject
of this discussion.

So I think it would help if you summarize the issue, and then let's
try finishing this discussion in less than a month ;-)

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Ted Zlatanov
On Sun, 14 Oct 2018 17:44:33 +0300 Eli Zaretskii <[hidden email]> wrote:

>> From: Ted Zlatanov <[hidden email]>
>> Date: Sun, 14 Oct 2018 03:59:29 +0000
>> Cc: [hidden email]
>>
>> Thus I was not able to make progress on this one. Maybe someone else
>> will, or be able to help me.

EZ> It is very hard to follow a discussion that is spread over several
EZ> months, and each month produces a about 3 messages.  I personally long
EZ> ago lost focus of the thread; in particular, I no longer remember what
EZ> prettify-symbols-mode and/or reveal-mode have to do with the subject
EZ> of this discussion.

I'll try to summarize. Sorry for the long lapses.

EZ> So I think it would help if you summarize the issue, and then let's
EZ> try finishing this discussion in less than a month ;-)

When I open a file such as authinfo.json.gpg, the passwords are clearly
visible to anyone that can see my screen. I'd like to hide them
visually. Ideally in a way that reveals them when I move inside them,
like `prettify-symbols-mode` does. Stefan suggested `reveal-mode` may be
the right place to do this work, so I investigated a little.

I think Lars was also interested in this, and I posted several URLs
where people are looking for more or less the same thing.

Ted

Reply | Threaded
Open this post in threaded view
|

Re: Automatic minor modes?

Eli Zaretskii
> From: Ted Zlatanov <[hidden email]>
> Cc: [hidden email],  [hidden email]
> Date: Sun, 14 Oct 2018 15:48:22 +0000
>
> When I open a file such as authinfo.json.gpg, the passwords are clearly
> visible to anyone that can see my screen. I'd like to hide them
> visually. Ideally in a way that reveals them when I move inside them,
> like `prettify-symbols-mode` does. Stefan suggested `reveal-mode` may be
> the right place to do this work, so I investigated a little.

OK, but what, if anything, does that have to do with "automatic minor
modes", something that sounds like a much more general subject?

12