unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Update `minibuffer-line' on buffer switches
@ 2015-06-27 14:22 Alexander Shukaev
  2015-06-27 15:43 ` Michael Heerdegen
  0 siblings, 1 reply; 12+ messages in thread
From: Alexander Shukaev @ 2015-06-27 14:22 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

Recently Stefan has introduced the `minibuffer-line' package.  I find it
very handy, especially for displaying the full path to either the
`default-directory' or `buffer-file-name'.  Previously, I used
`frame-title-format' for this like so:

(setq-default frame-title-format
              '((:eval
                 (list (user-login-name)
                       "@"
                       (system-name)
                       ":"
                       (abbreviate-file-name (or (buffer-file-name)
                                                 (file-name-as-directory
                                                  default-directory)))))))

and it behaved very well since when one switches buffers, the title is
automatically updated.  The same is true for `mode-line-format'.  Both
variables come from the C source code.  I'm not sure how automatic updating
is implemented for those, but obviously, to make this work with
`minibuffer-line', I'd have to attach `minibuffer-line--update' to some
hook which runs when buffers are switched.  Is there such a hook?  Are
there alternative implementations for this?  Thanks.

Kind regards,
Alexander


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

* Re: Update `minibuffer-line' on buffer switches
  2015-06-27 14:22 Alexander Shukaev
@ 2015-06-27 15:43 ` Michael Heerdegen
  2015-06-27 21:59   ` Stefan Monnier
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Heerdegen @ 2015-06-27 15:43 UTC (permalink / raw)
  To: help-gnu-emacs

Alexander Shukaev <haroogan@gmail.com> writes:

> `minibuffer-line', I'd have to attach `minibuffer-line--update' to some
> hook which runs when buffers are switched.

Indeed, there is only a timer for refreshing.  You must handle updating
yourself if you want it happen automatically in certain situations.

> Is there such a hook?  Are there alternative implementations for this?

There are no hooks in the package defined.  However, for your use case,
`window-configuration-change-hook' seems appropriate.  Of course there
is `post-command-hook' as well.  time-consuming calculations should not
go there of course.

The mode-line etc. are refreshed as part of redisplay.  That can't be
controlled from Lisp.


Regards,

Michael.




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

* Re: Update `minibuffer-line' on buffer switches
  2015-06-27 15:43 ` Michael Heerdegen
@ 2015-06-27 21:59   ` Stefan Monnier
  2015-06-28 17:19     ` Alexander Shukaev
  0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2015-06-27 21:59 UTC (permalink / raw)
  To: help-gnu-emacs

> The mode-line etc. are refreshed as part of redisplay.  That can't be
> controlled from Lisp.

Actually, you could do:

   (add-function :after pre-redisplay-function #'minibuffer-line--update)

which should re-compute the minibuffer-line before every redisplay.


        Stefan




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

* Re: Update `minibuffer-line' on buffer switches
  2015-06-27 21:59   ` Stefan Monnier
@ 2015-06-28 17:19     ` Alexander Shukaev
  2015-06-28 17:38       ` Alexander Shukaev
       [not found]       ` <mailman.5854.1435513096.904.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 12+ messages in thread
From: Alexander Shukaev @ 2015-06-28 17:19 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

On Sat, Jun 27, 2015 at 11:59 PM, Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> > The mode-line etc. are refreshed as part of redisplay.  That can't be
> > controlled from Lisp.
>
> Actually, you could do:
>
>    (add-function :after pre-redisplay-function #'minibuffer-line--update)
>
> which should re-compute the minibuffer-line before every redisplay.
>
>
>         Stefan
>
>
>
​Thanks, Stefan, but I keep receiving

Error during redisplay: (#[128 "\300\302\x02\"\300\301\x03\"\210\207" [apply
minibuffer-line--update #[128 "\300\301\x02\"\210\300\302\x02\"\207" [apply
redisplay--pre-redisplay-functions ignore nil] 4 nil nil] nil] 5 nil nil]
nil) signaled (wrong-number-of-arguments (0 . 0) 1) [30 times]
​
Any ideas?

Regards,
Alexander


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

* Re: Update `minibuffer-line' on buffer switches
  2015-06-28 17:19     ` Alexander Shukaev
@ 2015-06-28 17:38       ` Alexander Shukaev
       [not found]       ` <mailman.5854.1435513096.904.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 12+ messages in thread
From: Alexander Shukaev @ 2015-06-28 17:38 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Looks like the correct solution is

  (add-function :after pre-redisplay-function #'(lambda
                                                    (windows)

(minibuffer-line--update)))

Anyway, it would be nice to have some native support for such updates...
Similar to mode line and frame title.  The potential problem that I see is
that this redisplay is called quite a lot, and I have not only path
information in minibuffer line but also time information, and I assume that
this time information is obtained via system calls, which are inherently
very expensive.  Furthermore, it would be nice to have hook(s)
corresponding to buffer switching, e.g. tracking an event of entering
(transferring focus) to another buffer.  Wouldn't Emacs 25 benefit the
flexibility offered by such hooks?  What do you think Stefan?

Regards,
Alexander


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

* Re: Update `minibuffer-line' on buffer switches
       [not found]       ` <mailman.5854.1435513096.904.help-gnu-emacs@gnu.org>
@ 2015-06-29  3:36         ` Stefan Monnier
  2015-06-29 16:31           ` Alexander Shukaev
  0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2015-06-29  3:36 UTC (permalink / raw)
  To: help-gnu-emacs

> very expensive.  Furthermore, it would be nice to have hook(s)
> corresponding to buffer switching, e.g. tracking an event of entering
> (transferring focus) to another buffer.

These are actually fairly tricky to define in a way that corresponds to
your intuitive understanding.

But you might get partway there, by doing something like

  (add-function :after pre-redisplay-function
                (lambda (windows)
                  ;; Only recompute if we've switched window, or if
                  ;; (force-mode-line-update t) has been called.
                  (unless (and (consp windows) (null (cdr windows)))
                    (minibuffer-line--update))))

> Wouldn't Emacs 25 benefit the flexibility offered by such hooks?
> What do you think Stefan?

"switching buffer" already has a hook: window-configuration-change-hook.
Changing which window is selected does not have a hook, OTOH.

Adding a hook to `select-window' could work, but could be a bit tricky
since this function is sometimes used internally at places which don't
correspond to something which the end-user would consider as relevant.

I guess we could synthesize such a hook with pre-redisplay-function by
comparing the current selected-window with the window that was selected
last time pre-redisplay-function was run (or the same could be done with
post-command-hook).  Not sure how often that would be useful.


        Stefan


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

* Re: Update `minibuffer-line' on buffer switches
  2015-06-29  3:36         ` Stefan Monnier
@ 2015-06-29 16:31           ` Alexander Shukaev
  2015-06-29 17:00             ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Alexander Shukaev @ 2015-06-29 16:31 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Would `window-configuration-change-hook' work in case when a buffer is
switched in-place (i.e. all windows stay intact and the selected window is
not changed but only the displayed buffer inside this window is switched)?

Adding a hook to `select-window' could work, but could be a bit tricky
> since this function is sometimes used internally at places which don't
> correspond to something which the end-user would consider as relevant.


This again seems not to take into account the above scenario.  In other
words, really the buffer switching event is needed (regardless of what's
going on with windows).

Not sure how often that would be useful.


​To be honest it's not the first time that I find myself in a situation
when I simply need to hook the event of buffer (focus) switching and/or
window (focus) switching​, etc.

Regards,
Alexander


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

* Re: Update `minibuffer-line' on buffer switches
  2015-06-29 16:31           ` Alexander Shukaev
@ 2015-06-29 17:00             ` Eli Zaretskii
  2015-06-29 19:02               ` Alexander Shukaev
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2015-06-29 17:00 UTC (permalink / raw)
  To: Alexander Shukaev; +Cc: help-gnu-emacs, monnier

> Date: Mon, 29 Jun 2015 18:31:25 +0200
> From: Alexander Shukaev <haroogan@gmail.com>
> Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
> 
> Would `window-configuration-change-hook' work in case when a buffer is
> switched in-place (i.e. all windows stay intact and the selected window is
> not changed but only the displayed buffer inside this window is switched)?

From the ELisp manual:

 -- Variable: window-configuration-change-hook
     A normal hook that is run every time you change the window
     configuration of an existing frame.  This includes splitting or
     deleting windows, changing the sizes of windows, or displaying a
     different buffer in a window.                       ^^^^^^^^^^^^
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^



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

* Re: Update `minibuffer-line' on buffer switches
@ 2015-06-29 17:15 martin rudalics
  2015-06-29 19:00 ` Alexander Shukaev
  0 siblings, 1 reply; 12+ messages in thread
From: martin rudalics @ 2015-06-29 17:15 UTC (permalink / raw)
  To: haroogan; +Cc: help-gnu-emacs

 > Would `window-configuration-change-hook' work in case when a buffer is
 > switched in-place (i.e. all windows stay intact and the selected window is
 > not changed but only the displayed buffer inside this window is switched)?

  -- Variable: window-configuration-change-hook
      A normal hook that is run every time you change the window
      configuration of an existing frame.  This includes splitting or
      deleting windows, changing the sizes of windows, or displaying a
                                                          ^^^^^^^^^^^^
      different buffer in a window.
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 > ​To be honest it's not the first time that I find myself in a situation
 > when I simply need to hook the event of buffer (focus) switching and/or
 > window (focus) switching​, etc.

  -- Variable: buffer-list-update-hook
      This is a normal hook run whenever the buffer list changes.
      Functions (implicitly) running this hook are `get-buffer-create'
      (*note Creating Buffers::), `rename-buffer' (*note Buffer Names::),
      `kill-buffer' (*note Killing Buffers::), `bury-buffer' (see above)
      and `select-window' (*note Selecting Windows::).
           ^^^^^^^^^^^^^

martin




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

* Re: Update `minibuffer-line' on buffer switches
  2015-06-29 17:15 Update `minibuffer-line' on buffer switches martin rudalics
@ 2015-06-29 19:00 ` Alexander Shukaev
  0 siblings, 0 replies; 12+ messages in thread
From: Alexander Shukaev @ 2015-06-29 19:00 UTC (permalink / raw)
  To: martin rudalics; +Cc: help-gnu-emacs

>
>  -- Variable: buffer-list-update-hook
>      This is a normal hook run whenever the buffer list changes.
>      Functions (implicitly) running this hook are `get-buffer-create'
>      (*note Creating Buffers::), `rename-buffer' (*note Buffer Names::),
>      `kill-buffer' (*note Killing Buffers::), `bury-buffer' (see above)
>      and `select-window' (*note Selecting Windows::).
>           ^^^^^^^^^^^^^
>
> martin
>
>
​Would be nice to use this one, but I've just checked that unfortunately,
for instance, doing `next-buffer' does not entail this hook.​

Regards,
Alexander


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

* Re: Update `minibuffer-line' on buffer switches
  2015-06-29 17:00             ` Eli Zaretskii
@ 2015-06-29 19:02               ` Alexander Shukaev
  2015-06-29 19:50                 ` Alexander Shukaev
  0 siblings, 1 reply; 12+ messages in thread
From: Alexander Shukaev @ 2015-06-29 19:02 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs, Stefan Monnier

>
>  -- Variable: window-configuration-change-hook
>      A normal hook that is run every time you change the window
>      configuration of an existing frame.  This includes splitting or
>      deleting windows, changing the sizes of windows, or displaying a
>      different buffer in a window.                       ^^^^^^^^^^^^
>      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>

​This one seems to come very close, yet still very general.  However, it
seems there is no other alternative to narrow down to the needed subset of
events.  Thanks, Eli.

Regards,
Alexander​


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

* Re: Update `minibuffer-line' on buffer switches
  2015-06-29 19:02               ` Alexander Shukaev
@ 2015-06-29 19:50                 ` Alexander Shukaev
  0 siblings, 0 replies; 12+ messages in thread
From: Alexander Shukaev @ 2015-06-29 19:50 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: michael_heerdegen, rudalics, Stefan Monnier

After some trial I've found out that the comprehensive solution which takes
into account both window and buffer switching is a combination of two hooks:

  (add-hook 'buffer-list-update-hook          #'minibuffer-line--update)
  (add-hook 'window-configuration-change-hook #'minibuffer-line--update)

Hope this helps somebody in future.  Thanks a lot to everybody who
participated.

Kind regards,
Alexander


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

end of thread, other threads:[~2015-06-29 19:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-29 17:15 Update `minibuffer-line' on buffer switches martin rudalics
2015-06-29 19:00 ` Alexander Shukaev
  -- strict thread matches above, loose matches on Subject: below --
2015-06-27 14:22 Alexander Shukaev
2015-06-27 15:43 ` Michael Heerdegen
2015-06-27 21:59   ` Stefan Monnier
2015-06-28 17:19     ` Alexander Shukaev
2015-06-28 17:38       ` Alexander Shukaev
     [not found]       ` <mailman.5854.1435513096.904.help-gnu-emacs@gnu.org>
2015-06-29  3:36         ` Stefan Monnier
2015-06-29 16:31           ` Alexander Shukaev
2015-06-29 17:00             ` Eli Zaretskii
2015-06-29 19:02               ` Alexander Shukaev
2015-06-29 19:50                 ` Alexander Shukaev

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