unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* mode line construct question
@ 2024-08-28  9:18 Joost Kremers
  2024-08-28  9:30 ` Joost Kremers
  0 siblings, 1 reply; 2+ messages in thread
From: Joost Kremers @ 2024-08-28  9:18 UTC (permalink / raw)
  To: gnu-emacs-help

Hi list,

I'm trying to prettify my mode line a bit, but am running into a strange
issue.

Specifically, I'm trying to modify the way pyvenv.el[1] displays the
virtual environment in the mode line. The package itself defines a variable
`pyvenv-mode-line-indicator`:

```
(defvar pyvenv-mode-line-indicator '(pyvenv-virtual-env-name
                                     ("[" pyvenv-virtual-env-name "] ")))
```

Then it adds the following to `mode-line-misc-info`:

```
(add-to-list 'mode-line-misc-info '(pyvenv-mode pyvenv-mode-line-indicator))
```

This works, but because my virtual environment names contain a hash for the
project's directory path, they are rather long and ugly. So I was hoping to
redefine `pyvenv-mode-line-indicator` to something like this:

```
(setq pyvenv-mode-line-indicator
      '(pyvenv-virtual-env-name
        ("[" (:eval (jk-pyvenv-prettify-name pyvenv-virtual-env-name)) "] ")))
```

Where the function `jk-pyvenv-prettify-name` takes the venv's name (which
is just a string) and returns a prettified version of it.

Problem is, this doesn't work... As soon as I add an `:eval` construct to
the value of `pyvenv-mode-line-indicator`, it stops working. All I see in
the mode line are the square brackets "[]" that surround the `:eval`.

What's even more surprising to me is that if put the value of
`pyvenv-mode-line-indicator` in `mode-line-misc-info` directly, it *does*
work:

```
(add-to-list 'mode-line-misc-info
             '(pyvenv-mode
               (pyvenv-virtual-env-name
                ("[" (:eval (jk-pyvenv-prettify-name pyvenv-virtual-env-name)) "] "))))
```

Is there anyone who can shed some light on this? Why is it possible to put
`pyvenv-mode-line-construct` in `mode-line-misc-info` when it has its
original value, but not when I redefine it to something that works fine
when used directly as part of `mode-line-misc-info`?

TIA

Joost



Footnotes:
[1]  https://github.com/jorgenschaefer/pyvenv

-- 
Joost Kremers
Life has its moments



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

* Re: mode line construct question
  2024-08-28  9:18 mode line construct question Joost Kremers
@ 2024-08-28  9:30 ` Joost Kremers
  0 siblings, 0 replies; 2+ messages in thread
From: Joost Kremers @ 2024-08-28  9:30 UTC (permalink / raw)
  To: gnu-emacs-help

On Wed, Aug 28 2024, Joost Kremers wrote:
> I'm trying to prettify my mode line a bit, but am running into a strange
> issue.

And of course, less than five minutes after sending my message, I find the
solution myself...

As the doc string for `mode-line-format` says:

,----
| [...] unless the symbol has a non-nil
|  ‘risky-local-variable’ property, all properties in any strings, as
|  well as all :eval and :propertize forms in the value, are ignored.
`----

So a simple

```
(put 'pyvenv-mode-line-indicator 'risky-local-variable t)
```

solves my problem...


-- 
Joost Kremers
Life has its moments



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

end of thread, other threads:[~2024-08-28  9:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-28  9:18 mode line construct question Joost Kremers
2024-08-28  9:30 ` Joost Kremers

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