all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#28229: 26.0.50; outline-minor-mode-hook run twice when reverting buffer
@ 2017-08-25 12:14 Kaushal Modi
  2017-08-25 13:08 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Kaushal Modi @ 2017-08-25 12:14 UTC (permalink / raw)
  To: 28229

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

Hello,

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.

Here is a recipe to recreate that in emacs -Q:

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

(global-set-key (kbd "<f5>") (lambda () (interactive) (revert-buffer
:ignore-auto :noconfirm)))

- Evaluate the above
- Create a foo.txt file and save it.
- Hit F5
- You will notice the modi/debug function called twice.


In GNU Emacs 26.0.50 (build 38, x86_64-pc-linux-gnu, GTK+ Version 2.24.23)
 of 2017-08-24
Repository revision: fa5e63e40412f6152dbe079a766845112d598479
Windowing system distributor 'The X.Org Foundation', version 11.0.60900000
System Description: Red Hat Enterprise Linux Workstation release 6.6
(Santiago)

Recent messages:
buf name: ‘"b.txt"’
major-mode: ‘text-mode’
In outline debug
buf name: ‘"b.txt"’
major-mode: ‘text-mode’
You can run the command ‘revert-buffer’ with M-x rev-b RET
major-mode: ‘text-mode’
Mark activated
next-line: End of buffer
Making completion list...

Configured using:
 'configure --with-modules
 --prefix=/home/kmodi/usr_local/apps/6/emacs/master
 '--program-transform-name=s/^ctags$/ctags_emacs/'
 'CPPFLAGS=-I/home/kmodi/usr_local/6/include -I/usr/include/freetype2
 -I/usr/include' 'CFLAGS=-ggdb3 -O0' 'CXXFLAGS=-ggdb3 -O0'
 'LDFLAGS=-L/home/kmodi/usr_local/6/lib -L/home/kmodi/usr_local/6/lib64
 -ggdb3''

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY
ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK2 X11 MODULES

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=none
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message subr-x puny seq byte-opt gv
bytecomp byte-compile cconv cl-loaddefs cl-lib dired dired-loaddefs
format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg
epg-config gnus-util rmail rmail-loaddefs mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils noutline outline
easy-mmode elec-pair time-date mule-util tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow isearch timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite charscript charprop case-table epa-hook jka-cmpr-hook
help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote dbusbind inotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty
make-network-process emacs)

Memory information:
((conses 16 99816 10196)
 (symbols 48 20978 1)
 (miscs 40 68 180)
 (strings 32 29838 1379)
 (string-bytes 1 811740)
 (vectors 16 15125)
 (vector-slots 8 511402 11453)
 (floats 8 55 306)
 (intervals 56 375 62)
 (buffers 992 14)
 (heap 1024 28574 803))

-- 

Kaushal Modi

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

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

* bug#28229: 26.0.50; outline-minor-mode-hook run twice when reverting buffer
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2017-08-25 13:08 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: 28229

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





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

* bug#28229: 26.0.50; outline-minor-mode-hook run twice when reverting buffer
  2017-08-25 13:08 ` Eli Zaretskii
@ 2017-08-25 15:06   ` Kaushal Modi
  0 siblings, 0 replies; 3+ messages in thread
From: Kaushal Modi @ 2017-08-25 15:06 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 28229-done

[-- 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 --]

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

end of thread, other threads:[~2017-08-25 15:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.