GNU bug report logs - #28229
26.0.50; outline-minor-mode-hook run twice when reverting buffer

Previous Next

Package: emacs;

Reported by: Kaushal Modi <kaushal.modi <at> gmail.com>

Date: Fri, 25 Aug 2017 12:15:01 UTC

Severity: normal

Found in version 26.0.50

Done: Kaushal Modi <kaushal.modi <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #13 received at 28229-done <at> debbugs.gnu.org (full text, mbox):

From: Kaushal Modi <kaushal.modi <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 28229-done <at> debbugs.gnu.org
Subject: Re: bug#28229: 26.0.50; outline-minor-mode-hook run twice when
 reverting buffer
Date: Fri, 25 Aug 2017 15:06:16 +0000
[Message part 1 (text/plain, inline)]
On Fri, Aug 25, 2017 at 9:08 AM Eli Zaretskii <eliz <at> gnu.org> wrote:

> > From: Kaushal Modi <kaushal.modi <at> gmail.com>
> > Date: Fri, 25 Aug 2017 12:14:23 +0000
> >
> > I recently discovered an anomaly with my outline mode customization and
> it boiled down to this unexplained
> > behavior.. the outline-minor-mode-hook was getting triggered twice on
> doing revert-buffer.
>
> Isn't this expected behavior?  revert-buffer calls normal-mode, which
> first kills all local variables, which involves turning off
> outline-minor-mode by calling
>
>   (outline-minor-mode -1)
>
> And that calls your hook.
>
> The other time is when normal-mode turns outline-minor-mode ON.
>
> The doc string of outline-minor-mode-hook (and any other hook created
> by define-minor-mode) clearly says:
>
>   Hook run after entering or leaving ‘outline-minor-mode’.
>

Hi Eli,

Thanks for reviewing the report. I have now fixed the problem at my end.

Here is an updated MWE to exactly show the problem I was facing:

- I needed to update a local var specific to the major mode.
- The minor mode needed a act a bit differently based on the value of that
local variable.
- The problem was that that local variable was getting wiped out after the
first call of the minor mode hook and it wasn't getting set correctly by
my/text-mode-customization (below example)

=====
(defvar-local my/var 'unknown
  "This var is set to the major mode locally.")

(defun modi/debug ()
  (message "In outline debug")
  (message "buf name: `%S'" (buffer-name))
  (message "major-mode: `%S'" major-mode)
  (message "my/var: `%S'" my/var))
(add-hook 'outline-minor-mode-hook #'modi/debug)
(add-hook 'text-mode-hook #'outline-minor-mode :append)

(defun my/text-mode-customization ()
  (message "In text mode customization")
  (setq-local my/var major-mode))
(remove-hook 'text-mode-hook #'my/text-mode-customization)
(add-hook 'text-mode-hook #'my/text-mode-customization :append) ;Culprit!

(global-set-key (kbd "<f5>") (lambda () (interactive) (revert-buffer)))
=====

On doing C-h v text-mode-hook, I saw:

(outline-minor-mode text-mode-hook-identify my/text-mode-customization)

That explained that the outline-minor-mode's hook ran before
my/text-mode-customization can set the my/var correctly.

The fix was simply to keep the APPEND arg of add-hook at its default value
nil.

The fix was simple but the debug was mind-numbing.. thanks for the help!
-- 

Kaushal Modi
[Message part 2 (text/html, inline)]

This bug report was last modified 7 years and 353 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.