unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Call CMD w/ keybinding VS execute-extended-command: redisplay behaviour
@ 2018-03-25  9:32 Tino Calancha
  2018-03-25 10:09 ` Charles A. Roelli
  2018-03-25 12:49 ` Stefan Monnier
  0 siblings, 2 replies; 7+ messages in thread
From: Tino Calancha @ 2018-03-25  9:32 UTC (permalink / raw)
  To: emacs-devel; +Cc: Tino Calancha


Dear Emacs,

I have defined a command (see below snippet code) which updates
the header line in a buffer inheriting from tabulated-list.
The effect on the header line is visible inmediately, i.e.,
the screen is automatically redisplayed, but...

* If I bind this command to 'r', then there is no automatic
  redisplay anymore; I need to push some keys until a
  window redisplay is fired.

* If I call the command and rigth after run `repeat', i.e. `C-x z'
  then the header line is not automatically updated either.

Is there a reason why it is preferable this distintion between
calling a command with a keybinding VS calling
it via `execute-extended-command'?

I wish the keybinding 'r' update the screen as well.
How can I do that?

Note: I don't want to revert the buffer, just redisplay the header line.

To reproduce, create a file foo.el with following content:

--8<-----------------------------cut here---------------start------------->8---
(defvar foo-format
  [("Category" 12 t)
   ("Knight (best friend: hadoken)" 30 t)
   ("Energy" 50 t)]
  "Table format.")

(defvar foo-mode nil "Save status of the `foo-mode'.")

(defun foo-tabulated-list-entries ()
  (setq tabulated-list-entries
        '((1 ["bronze" "Seiya" "98"]) (2 ["bronze" "Shiryu" "95"])))
  (tabulated-list-init-header))

(defun foo ()
  (interactive)
  (let ((foo-buffer (generate-new-buffer "*foo*")))
    (switch-to-buffer foo-buffer)
    (or foo-mode (foo-mode))
    (setq tabulated-list-use-header-line t)
    (foo-tabulated-list-entries)
    (tabulated-list-print)))


(defun foo--new-knight()
  (let ((knights '("Ikki" "Shun" "Hyoga")))
    (nth (random (length knights)) knights)))

(defun foo-update-friend()
  "Update header line with new friend."
  (interactive)
  (let ((regexp "Knight (best friend: \\([^)]+\\))")
        (knight-new (foo--new-knight)))
    (when (string-match regexp header-line-format)
      (let ((knight (match-string 1 header-line-format)))
        (while (string= knight knight-new) (setq knight-new (foo--new-knight)))
        (setq header-line-format
              (replace-match
               knight-new nil nil header-line-format 1))
        (message "Updated knight to: '%s'" knight-new)
        ;; Don't regenerate all rows because it might be expensive;
        ;; just redisplay the header line.
        (redisplay)))))

;;; Foo Mode map
(defvar foo-mode-map
  (let ((map (make-keymap)))
    (define-key map (kbd "r") 'foo-update-friend)
    map))

;;; Define mode
(define-derived-mode foo-mode tabulated-list-mode "Foo"
  (setq tabulated-list-format foo-format))
--8<-----------------------------cut here---------------end--------------->8---

emacs -Q -l foo.el:

M-x foo RET
;; Note the difference between the following:

M-x foo-update-friend RET
;; Updates the knight's friend in the header line, i.e., the name
;; showed in the minibuffer matches the friend name in the header line.

r
;; It doesn't update the knight's friend; you can see that name in the
;; minibuffer doesn't match the one in the header line.  If you input
;; something for example if you use the down arrow, then the header
;; line is updated.



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

* Re: Call CMD w/ keybinding VS execute-extended-command: redisplay behaviour
  2018-03-25 10:09 ` Charles A. Roelli
@ 2018-03-25 10:00   ` Tino Calancha
  2018-03-25 10:19     ` Charles A. Roelli
  2018-03-25 15:35     ` Eli Zaretskii
  0 siblings, 2 replies; 7+ messages in thread
From: Tino Calancha @ 2018-03-25 10:00 UTC (permalink / raw)
  To: Charles A. Roelli; +Cc: emacs-devel



On 03/25/2018 07:09 PM, Charles A. Roelli wrote:
> M-x (`execute-extended-command') calls sit-for, which calls redisplay,
> which probably updates the header line.
Thank you that's sounds like a god explanation for the different behaviour.

What still puzzle me is that I manually call `redisplay' at the end of
`foo-update-friend', but I still don't get a redisplay when using the
keybinding :-(



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

* Re: Call CMD w/ keybinding VS execute-extended-command: redisplay behaviour
  2018-03-25  9:32 Call CMD w/ keybinding VS execute-extended-command: redisplay behaviour Tino Calancha
@ 2018-03-25 10:09 ` Charles A. Roelli
  2018-03-25 10:00   ` Tino Calancha
  2018-03-25 12:49 ` Stefan Monnier
  1 sibling, 1 reply; 7+ messages in thread
From: Charles A. Roelli @ 2018-03-25 10:09 UTC (permalink / raw)
  To: Tino Calancha; +Cc: emacs-devel

M-x (`execute-extended-command') calls sit-for, which calls redisplay,
which probably updates the header line.



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

* Re: Call CMD w/ keybinding VS execute-extended-command: redisplay behaviour
  2018-03-25 10:00   ` Tino Calancha
@ 2018-03-25 10:19     ` Charles A. Roelli
  2018-03-25 15:35     ` Eli Zaretskii
  1 sibling, 0 replies; 7+ messages in thread
From: Charles A. Roelli @ 2018-03-25 10:19 UTC (permalink / raw)
  To: Tino Calancha; +Cc: emacs-devel

> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Sun, 25 Mar 2018 19:00:47 +0900
>
> What still puzzle me is that I manually call `redisplay' at the end of
> `foo-update-friend', but I still don't get a redisplay when using the
> keybinding :-(

Hm, that's weird.  Did you try force-mode-line-update?

force-mode-line-update is a built-in function in ‘src/buffer.c’.

(force-mode-line-update &optional ALL)

Force redisplay of the current buffer’s mode line and header line.
With optional non-nil ALL, force redisplay of all mode lines and
header lines.  This function also forces recomputation of the
menu bar menus and the frame title.



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

* Re: Call CMD w/ keybinding VS execute-extended-command: redisplay behaviour
  2018-03-25  9:32 Call CMD w/ keybinding VS execute-extended-command: redisplay behaviour Tino Calancha
  2018-03-25 10:09 ` Charles A. Roelli
@ 2018-03-25 12:49 ` Stefan Monnier
  1 sibling, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2018-03-25 12:49 UTC (permalink / raw)
  To: emacs-devel

> I have defined a command (see below snippet code) which updates
> the header line in a buffer inheriting from tabulated-list.
> The effect on the header line is visible inmediately, i.e.,

The mode-line or header-line aren't 100% automatically updated, contrary
to the buffer's main text.  You need to call force-mode-line-update
for that.


        Stefan




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

* Re: Call CMD w/ keybinding VS execute-extended-command: redisplay behaviour
  2018-03-25 10:00   ` Tino Calancha
  2018-03-25 10:19     ` Charles A. Roelli
@ 2018-03-25 15:35     ` Eli Zaretskii
  2018-03-26  6:27       ` Tino Calancha
  1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2018-03-25 15:35 UTC (permalink / raw)
  To: Tino Calancha; +Cc: charles, emacs-devel

> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Sun, 25 Mar 2018 19:00:47 +0900
> Cc: emacs-devel@gnu.org
> 
> On 03/25/2018 07:09 PM, Charles A. Roelli wrote:
> > M-x (`execute-extended-command') calls sit-for, which calls redisplay,
> > which probably updates the header line.
> Thank you that's sounds like a god explanation for the different behaviour.
> 
> What still puzzle me is that I manually call `redisplay' at the end of
> `foo-update-friend', but I still don't get a redisplay when using the
> keybinding :-(

That's because the call to 'redisplay' in sit-for is not the reason
you get a redisplay when you type "M-x SOMETHING RET".  If you do that
slowly, you should see that the screen is redrawn as soon as you type
"M-x".  This happens because execute-extended-command reads from the
minibuffer, which enters recursive-editing, and that performs a
thorough redipslay.



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

* Re: Call CMD w/ keybinding VS execute-extended-command: redisplay behaviour
  2018-03-25 15:35     ` Eli Zaretskii
@ 2018-03-26  6:27       ` Tino Calancha
  0 siblings, 0 replies; 7+ messages in thread
From: Tino Calancha @ 2018-03-26  6:27 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel, charles, Tino Calancha



On Sun, 25 Mar 2018, Eli Zaretskii wrote:

>> From: Tino Calancha <tino.calancha@gmail.com>
>> Date: Sun, 25 Mar 2018 19:00:47 +0900
>> Cc: emacs-devel@gnu.org
>>
>> What still puzzle me is that I manually call `redisplay' at the end of
>> `foo-update-friend', but I still don't get a redisplay when using the
>> keybinding :-(
>
> That's because the call to 'redisplay' in sit-for is not the reason
> you get a redisplay when you type "M-x SOMETHING RET".  If you do that
> slowly, you should see that the screen is redrawn as soon as you type
> "M-x".  This happens because execute-extended-command reads from the
> minibuffer, which enters recursive-editing, and that performs a
> thorough redipslay.
I see, totally consistent with the observations.  Thank you!

On Sun, 25 Mar 2018, Charles A. Roelli wrote:
>  Did you try force-mode-line-update?
Excellent!
Using `force-mode-line-update' I get updated the header line
also when I use the `r' keybinding :-)
I will use this in my implementation.
Thank you very much!



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

end of thread, other threads:[~2018-03-26  6:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-25  9:32 Call CMD w/ keybinding VS execute-extended-command: redisplay behaviour Tino Calancha
2018-03-25 10:09 ` Charles A. Roelli
2018-03-25 10:00   ` Tino Calancha
2018-03-25 10:19     ` Charles A. Roelli
2018-03-25 15:35     ` Eli Zaretskii
2018-03-26  6:27       ` Tino Calancha
2018-03-25 12:49 ` 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).