[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is this correct?
From: |
Tim X |
Subject: |
Re: Is this correct? |
Date: |
Sun, 27 Feb 2011 09:38:14 +1100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Eli Zaretskii <eliz@gnu.org> writes:
>> Date: Sat, 26 Feb 2011 12:44:15 +0000
>> From: Uday Reddy <uDOTsDOTreddy@cs.bham.ac.uk>
>>
>> On 2/26/2011 6:54 AM, Tim X wrote:
>>
>> >
>> > (defun force-mode-line-update (&optional all)
>> > (if all (with-current-buffer (other-buffer)))
>> > (set-buffer-modified-p (buffer-modified-p)))
>> >
>> > The bit that doesn't look quite right to me is
>> >
>> > (if all (with-current-buffer (other-buffer)))
>> >
>> > I'm assuming that by calling with-current-buffer, this will temporarily
>> > make 'other-buffer' active and as a side effect, the mode-line etc will get
>> > updated.
>>
>> That would be quite magical if it were true.
>
> ??
>
>> My guess is that the parentheses have been misplaced.
>
> ????? Doesn't force-mode-line-update work for you?
>
>> It should have been
>>
>> (if all (with-current-buffer (other-buffer)
>> (set-buffer-modified-p (buffer-modified-p)))
>> (set-buffer-modified-p (buffer-modified-p))
>>
>> This doesn't make it right of course. The "other-buffer" doesn't equate
>> to "all" buffers, and pretty often, the "other-buffer" is an invisible
>> buffer. It is not guaranteed that the current-buffer is a visible
>> buffer either. So, this code would seem to be wrong at many levels!
>
> I gets better: `(set-buffer-modified-p (buffer-modified-p))'
> apparently does nothing, because it sets the buffer's modified flag to
> the same value it has already. So this function actually does nothing
> at all, right?
>
I looked at the C code that implements set-buffer-modified-p at it seems
to me (who freely admits not understanding the low C level of emacs!)
that as a side effect, the function updates mode-lines etc regardless of
the setting/value for buffer-modified-p. Therefore, my interpretation
was that this would call the function without actually changing the
state of the modified flag and by side effect, result in an update of
the mode-line.
I do agree it doesn't look right and personally don't like code which
does something via a non-intuitive/obvious side effect. While possibly
convenient, from a maintenance standpoint, it would be better if it was
more deliberate/obvious IMO.
Tim
--
tcross (at) rapttech dot com dot au
- Re: Is this correct?, (continued)
Re: Is this correct?, Uday Reddy, 2011/02/26
Message not available