unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Refresh display after changing variable
@ 2021-08-02 16:49 Ken Goldman
  2021-08-02 17:03 ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Ken Goldman @ 2021-08-02 16:49 UTC (permalink / raw)
  To: help-gnu-emacs

I have this to toggle a variable:

(defun kg-toggle-whitespace-line-column ()
   "Toggle whitespace line column between 80 and 101"
   (interactive)
   (setq whitespace-line-column (if (= whitespace-line-column 80) 101 80))
   (font-lock-fontify-buffer))
(global-set-key "\C-cw" 'kg-toggle-whitespace-line-column)

However, the buffer is not refreshed with the different colors.

I also tried (refresh-display) - no success

(revert-buffer) works but seems crude.

What's the correct function?




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

* Re: Refresh display after changing variable
  2021-08-02 16:49 Refresh display after changing variable Ken Goldman
@ 2021-08-02 17:03 ` Eli Zaretskii
  2021-08-02 19:36   ` Ken Goldman
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2021-08-02 17:03 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Ken Goldman <kgoldman@us.ibm.com>
> Date: Mon, 2 Aug 2021 12:49:41 -0400
> 
> I have this to toggle a variable:
> 
> (defun kg-toggle-whitespace-line-column ()
>    "Toggle whitespace line column between 80 and 101"
>    (interactive)
>    (setq whitespace-line-column (if (= whitespace-line-column 80) 101 80))
>    (font-lock-fontify-buffer))
> (global-set-key "\C-cw" 'kg-toggle-whitespace-line-column)
> 
> However, the buffer is not refreshed with the different colors.
> 
> I also tried (refresh-display) - no success
> 
> (revert-buffer) works but seems crude.
> 
> What's the correct function?

This:

  (defun kg-toggle-whitespace-line-column ()
     "Toggle whitespace line column between 80 and 101"
     (interactive)
     (setq whitespace-line-column (if (= whitespace-line-column 80) 101 80))
     (whitespace-mode 1))



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

* Re: Refresh display after changing variable
  2021-08-02 17:03 ` Eli Zaretskii
@ 2021-08-02 19:36   ` Ken Goldman
  2021-08-02 19:40     ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Ken Goldman @ 2021-08-02 19:36 UTC (permalink / raw)
  To: help-gnu-emacs

On 8/2/2021 1:03 PM, Eli Zaretskii wrote:
>> From: Ken Goldman <kgoldman@us.ibm.com>
>> Date: Mon, 2 Aug 2021 12:49:41 -0400
>>
>> I have this to toggle a variable:
>>
>> (defun kg-toggle-whitespace-line-column ()
>>     "Toggle whitespace line column between 80 and 101"
>>     (interactive)
>>     (setq whitespace-line-column (if (= whitespace-line-column 80) 101 80))
>>     (font-lock-fontify-buffer))
>> (global-set-key "\C-cw" 'kg-toggle-whitespace-line-column)
>>
>> However, the buffer is not refreshed with the different colors.
>>
>> I also tried (refresh-display) - no success
>>
>> (revert-buffer) works but seems crude.
>>
>> What's the correct function?
> 
> This:
> 
>    (defun kg-toggle-whitespace-line-column ()
>       "Toggle whitespace line column between 80 and 101"
>       (interactive)
>       (setq whitespace-line-column (if (= whitespace-line-column 80) 101 80))
>       (whitespace-mode 1))
> 
> 
That didn't work.  It seems that, once it's on, turning it on again doesn't
help.  I tried adding a nil first, but it doesn't help.  It
doesn't force redoing the fonts.

This is emacs 26.3 on ubuntu, of that matters.




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

* Re: Refresh display after changing variable
  2021-08-02 19:36   ` Ken Goldman
@ 2021-08-02 19:40     ` Eli Zaretskii
  2021-08-02 20:56       ` Michael Heerdegen
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2021-08-02 19:40 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Ken Goldman <kgoldman@us.ibm.com>
> Date: Mon, 2 Aug 2021 15:36:01 -0400
> 
> >    (defun kg-toggle-whitespace-line-column ()
> >       "Toggle whitespace line column between 80 and 101"
> >       (interactive)
> >       (setq whitespace-line-column (if (= whitespace-line-column 80) 101 80))
> >       (whitespace-mode 1))
> > 
> > 
> That didn't work.

<Shrug> It does here.

> It seems that, once it's on, turning it on again doesn't help.  I
> tried adding a nil first, but it doesn't help.

Turning whitespace-mode off and on doesn't help?

> It doesn't force redoing the fonts.

What do fonts have to do with this?

> This is emacs 26.3 on ubuntu, of that matters.

I tried in Emacs 28, FWIW.



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

* Re: Refresh display after changing variable
  2021-08-02 19:40     ` Eli Zaretskii
@ 2021-08-02 20:56       ` Michael Heerdegen
  2021-08-02 21:26         ` 2QdxY4RzWzUUiLuE
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Heerdegen @ 2021-08-02 20:56 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

> > From: Ken Goldman <kgoldman@us.ibm.com>
> > Date: Mon, 2 Aug 2021 15:36:01 -0400
> > 
> > >    (defun kg-toggle-whitespace-line-column ()
> > >       "Toggle whitespace line column between 80 and 101"
> > >       (interactive)
> > >       (setq whitespace-line-column (if (= whitespace-line-column
> > > 80) 101 80))
> > >       (whitespace-mode 1))
> > > 
> > > 
> > That didn't work.
>
> <Shrug> It does here.

For me that works correctly in master but not in the 27.1 that comes
with Debian.

Michael.




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

* Re: Refresh display after changing variable
  2021-08-02 20:56       ` Michael Heerdegen
@ 2021-08-02 21:26         ` 2QdxY4RzWzUUiLuE
  2021-08-03 15:42           ` Ken Goldman
  0 siblings, 1 reply; 12+ messages in thread
From: 2QdxY4RzWzUUiLuE @ 2021-08-02 21:26 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

On 2021-08-02 at 22:56:41 +0200,
Michael Heerdegen <michael_heerdegen@web.de> wrote:

> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > > From: Ken Goldman <kgoldman@us.ibm.com>
> > > Date: Mon, 2 Aug 2021 15:36:01 -0400
> > > 
> > > >    (defun kg-toggle-whitespace-line-column ()
> > > >       "Toggle whitespace line column between 80 and 101"
> > > >       (interactive)
> > > >       (setq whitespace-line-column (if (= whitespace-line-column
> > > > 80) 101 80))
> > > >       (whitespace-mode 1))
> > > > 
> > > > 
> > > That didn't work.
> >
> > <Shrug> It does here.
> 
> For me that works correctly in master but not in the 27.1 that comes
> with Debian.

FWIW, I have the following snippet in a function I wrote to change
tab-width:

  (let ((w (get-buffer-window (current-buffer))))
    (set-window-start w (window-start w)))

and a note that I stole that snippet from scroll-bar-maybe-window-start
in scroll-bar.el.  That function doesn't exist anymore (in Emacs 27.2),
but scroll-bar-set-window-start in scroll-bar.el does end as follows:

    (set-window-start window (point))))))



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

* Re: Refresh display after changing variable
  2021-08-02 21:26         ` 2QdxY4RzWzUUiLuE
@ 2021-08-03 15:42           ` Ken Goldman
  2021-08-03 15:52             ` Eli Zaretskii
  2021-08-03 17:00             ` 2QdxY4RzWzUUiLuE
  0 siblings, 2 replies; 12+ messages in thread
From: Ken Goldman @ 2021-08-03 15:42 UTC (permalink / raw)
  To: help-gnu-emacs

On 8/2/2021 5:26 PM, 2QdxY4RzWzUUiLuE@potatochowder.com wrote:
> On 2021-08-02 at 22:56:41 +0200,
> Michael Heerdegen <michael_heerdegen@web.de> wrote:
> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>>>> From: Ken Goldman <kgoldman@us.ibm.com>
>>>> Date: Mon, 2 Aug 2021 15:36:01 -0400
>>>>
>>>>>     (defun kg-toggle-whitespace-line-column ()
>>>>>        "Toggle whitespace line column between 80 and 101"
>>>>>        (interactive)
>>>>>        (setq whitespace-line-column (if (= whitespace-line-column
>>>>> 80) 101 80))
>>>>>        (whitespace-mode 1))
> 
> FWIW, I have the following snippet in a function I wrote to change
> tab-width:
> 
>    (let ((w (get-buffer-window (current-buffer))))
>      (set-window-start w (window-start w)))
> 
> and a note that I stole that snippet from scroll-bar-maybe-window-start
> in scroll-bar.el.  That function doesn't exist anymore (in Emacs 27.2),
> but scroll-bar-set-window-start in scroll-bar.el does end as follows:
> 
>      (set-window-start window (point))))))
> 
That line, in the function, yields

kg-toggle-whitespace-line-column: Symbol’s value as variable is void: window





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

* Re: Refresh display after changing variable
  2021-08-03 15:42           ` Ken Goldman
@ 2021-08-03 15:52             ` Eli Zaretskii
  2021-08-03 16:17               ` Ken Goldman
  2021-08-03 17:00             ` 2QdxY4RzWzUUiLuE
  1 sibling, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2021-08-03 15:52 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Ken Goldman <kgoldman@us.ibm.com>
> Date: Tue, 3 Aug 2021 11:42:45 -0400
> 
> >      (set-window-start window (point))))))
> > 
> That line, in the function, yields
> 
> kg-toggle-whitespace-line-column: Symbol’s value as variable is void: window

You did read the doc string of set-window-start and tried to
understand what's the problem, right?



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

* Re: Refresh display after changing variable
  2021-08-03 15:52             ` Eli Zaretskii
@ 2021-08-03 16:17               ` Ken Goldman
  0 siblings, 0 replies; 12+ messages in thread
From: Ken Goldman @ 2021-08-03 16:17 UTC (permalink / raw)
  To: help-gnu-emacs

On 8/3/2021 11:52 AM, Eli Zaretskii wrote:
>> From: Ken Goldman <kgoldman@us.ibm.com>
>> Date: Tue, 3 Aug 2021 11:42:45 -0400
>>
>>>       (set-window-start window (point))))))
>>>
>> That line, in the function, yields
>>
>> kg-toggle-whitespace-line-column: Symbol’s value as variable is void: window
> 
> You did read the doc string of set-window-start and tried to
> understand what's the problem, right?

No, I'm not an elisp programmer.  I just tried the line
that was posted.





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

* Re: Refresh display after changing variable
  2021-08-03 15:42           ` Ken Goldman
  2021-08-03 15:52             ` Eli Zaretskii
@ 2021-08-03 17:00             ` 2QdxY4RzWzUUiLuE
  2021-08-03 17:03               ` Eli Zaretskii
  2021-08-04 20:17               ` Ken Goldman
  1 sibling, 2 replies; 12+ messages in thread
From: 2QdxY4RzWzUUiLuE @ 2021-08-03 17:00 UTC (permalink / raw)
  To: Ken Goldman; +Cc: help-gnu-emacs

On 2021-08-03 at 11:42:45 -0400,
Ken Goldman <kgoldman@us.ibm.com> wrote:

> On 8/2/2021 5:26 PM, 2QdxY4RzWzUUiLuE@potatochowder.com wrote:
> > On 2021-08-02 at 22:56:41 +0200,
> > Michael Heerdegen <michael_heerdegen@web.de> wrote:
> > 
> > > Eli Zaretskii <eliz@gnu.org> writes:
> > > 
> > > > > From: Ken Goldman <kgoldman@us.ibm.com>
> > > > > Date: Mon, 2 Aug 2021 15:36:01 -0400
> > > > > 
> > > > > >     (defun kg-toggle-whitespace-line-column ()
> > > > > >        "Toggle whitespace line column between 80 and 101"
> > > > > >        (interactive)
> > > > > >        (setq whitespace-line-column (if (= whitespace-line-column
> > > > > > 80) 101 80))
> > > > > >        (whitespace-mode 1))
> > 
> > FWIW, I have the following snippet in a function I wrote to change
> > tab-width:
> > 
> >    (let ((w (get-buffer-window (current-buffer))))
> >      (set-window-start w (window-start w)))
> > 
> > and a note that I stole that snippet from scroll-bar-maybe-window-start
> > in scroll-bar.el.  That function doesn't exist anymore (in Emacs 27.2),
> > but scroll-bar-set-window-start in scroll-bar.el does end as follows:
> > 
> >      (set-window-start window (point))))))
> > 
> That line, in the function, yields
> 
> kg-toggle-whitespace-line-column: Symbol’s value as variable is void: window

Yeah, sorry; window (the variable) is extracted near the beginning of
scroll-bar-set-window-start from one of a piece of the scroll bar event
that triggered the function call.

My point was that current Emacs code uses set-window-start to force a
redraw.  Try something like this:

    (set-window-start (get-buffer-window) (point))

(There might be simpler ways to get the current window, and I'm sure
someone will point them out to me, but that should work as a replacement
for your (whitespace-mode 1)).



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

* Re: Refresh display after changing variable
  2021-08-03 17:00             ` 2QdxY4RzWzUUiLuE
@ 2021-08-03 17:03               ` Eli Zaretskii
  2021-08-04 20:17               ` Ken Goldman
  1 sibling, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2021-08-03 17:03 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Tue, 3 Aug 2021 10:00:00 -0700
> From: 2QdxY4RzWzUUiLuE@potatochowder.com
> Cc: help-gnu-emacs@gnu.org
> 
> There might be simpler ways to get the current window

It's all in the doc string, of course.



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

* Re: Refresh display after changing variable
  2021-08-03 17:00             ` 2QdxY4RzWzUUiLuE
  2021-08-03 17:03               ` Eli Zaretskii
@ 2021-08-04 20:17               ` Ken Goldman
  1 sibling, 0 replies; 12+ messages in thread
From: Ken Goldman @ 2021-08-04 20:17 UTC (permalink / raw)
  To: help-gnu-emacs

On 8/3/2021 1:00 PM, 2QdxY4RzWzUUiLuE@potatochowder.com wrote:
> On 2021-08-03 at 11:42:45 -0400,
> Ken Goldman <kgoldman@us.ibm.com> wrote:
> 
>> On 8/2/2021 5:26 PM, 2QdxY4RzWzUUiLuE@potatochowder.com wrote:
>>> On 2021-08-02 at 22:56:41 +0200,
>>> Michael Heerdegen <michael_heerdegen@web.de> wrote:
>>>
>>>> Eli Zaretskii <eliz@gnu.org> writes:
>>>>
>>>>>> From: Ken Goldman <kgoldman@us.ibm.com>
>>>>>> Date: Mon, 2 Aug 2021 15:36:01 -0400
>>>>>>
>>>>>>>      (defun kg-toggle-whitespace-line-column ()
>>>>>>>         "Toggle whitespace line column between 80 and 101"
>>>>>>>         (interactive)
>>>>>>>         (setq whitespace-line-column (if (= whitespace-line-column
>>>>>>> 80) 101 80))
>>>>>>>         (whitespace-mode 1))
>>>
>>> FWIW, I have the following snippet in a function I wrote to change
>>> tab-width:
>>>
>>>     (let ((w (get-buffer-window (current-buffer))))
>>>       (set-window-start w (window-start w)))
>>>
>>> and a note that I stole that snippet from scroll-bar-maybe-window-start
>>> in scroll-bar.el.  That function doesn't exist anymore (in Emacs 27.2),
>>> but scroll-bar-set-window-start in scroll-bar.el does end as follows:
>>>
>>>       (set-window-start window (point))))))
>>>
>> That line, in the function, yields
>>
>> kg-toggle-whitespace-line-column: Symbol’s value as variable is void: window
> 
> Yeah, sorry; window (the variable) is extracted near the beginning of
> scroll-bar-set-window-start from one of a piece of the scroll bar event
> that triggered the function call.
> 
> My point was that current Emacs code uses set-window-start to force a
> redraw.  Try something like this:
> 
>      (set-window-start (get-buffer-window) (point))
> 
> (There might be simpler ways to get the current window, and I'm sure
> someone will point them out to me, but that should work as a replacement
> for your (whitespace-mode 1)).

That scrolls the buffer so that the cursor is at the top of the window.
However, it does not redo the colors.  So far, revert-buffer is
the only function that works.





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

end of thread, other threads:[~2021-08-04 20:17 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-02 16:49 Refresh display after changing variable Ken Goldman
2021-08-02 17:03 ` Eli Zaretskii
2021-08-02 19:36   ` Ken Goldman
2021-08-02 19:40     ` Eli Zaretskii
2021-08-02 20:56       ` Michael Heerdegen
2021-08-02 21:26         ` 2QdxY4RzWzUUiLuE
2021-08-03 15:42           ` Ken Goldman
2021-08-03 15:52             ` Eli Zaretskii
2021-08-03 16:17               ` Ken Goldman
2021-08-03 17:00             ` 2QdxY4RzWzUUiLuE
2021-08-03 17:03               ` Eli Zaretskii
2021-08-04 20:17               ` Ken Goldman

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