unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 28229-done@debbugs.gnu.org
Subject: bug#28229: 26.0.50; outline-minor-mode-hook run twice when reverting buffer
Date: Fri, 25 Aug 2017 15:06:16 +0000	[thread overview]
Message-ID: <CAFyQvY2EwWkxwHeM837rixm0VCNpsMmcX9MaBaJY56sLqEExZw@mail.gmail.com> (raw)
In-Reply-To: <83o9r37q32.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2509 bytes --]

On Fri, Aug 25, 2017 at 9:08 AM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Kaushal Modi <kaushal.modi@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

[-- Attachment #2: Type: text/html, Size: 3529 bytes --]

      reply	other threads:[~2017-08-25 15:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-25 12:14 bug#28229: 26.0.50; outline-minor-mode-hook run twice when reverting buffer Kaushal Modi
2017-08-25 13:08 ` Eli Zaretskii
2017-08-25 15:06   ` Kaushal Modi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFyQvY2EwWkxwHeM837rixm0VCNpsMmcX9MaBaJY56sLqEExZw@mail.gmail.com \
    --to=kaushal.modi@gmail.com \
    --cc=28229-done@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).