unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#22272: 24.5; nonfunctional Emacs with a bad global mode (post-command-hook).
@ 2015-12-30  7:28 brubar.cs
  2015-12-30 18:04 ` Eli Zaretskii
  2015-12-31 20:33 ` bug#22272: Close 22272 Michael Heerdegen
  0 siblings, 2 replies; 7+ messages in thread
From: brubar.cs @ 2015-12-30  7:28 UTC (permalink / raw)
  To: 22272

Hi,

This report is about a possible improvement. The "bug" arises only after
a programming mistake.

Please find attached a recipe to reproduce a stupid thing I've done.

I was trying to define a new global minor mode. I ended up placing a
function that raises an unhandled error in `post-command-hook'.

Then, I had to kill my Emacs; I found no other way to recover control.

As the `post-command-hook' documentation says, Emacs could probably
do better here by discarding my non-working code.

To reproduce and *KILL YOUR EMACS*, launch a *NEW* Emacs like that:

   emacs -Q --load test-kill-your-emacs-with-global-mode.el A-NEW-FILE.txt --eval '(insert "modified")' --funcall BAD-global-mode 

I'm reporting this only to improve Emacs. I obviously fixed my code and
Emacs is awesome again!

Thanks,

Bruno.


In GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.14.9)
 of 2015-09-22 on tosh-laptop
Windowing system distributor `The X.Org Foundation', version 11.0.11704000
Configured using:
 `configure --prefix=/usr --build=x86_64-pc-linux-gnu
 --host=x86_64-pc-linux-gnu --mandir=/usr/share/man
 --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc
 --localstatedir=/var/lib --disable-dependency-tracking
 --disable-silent-rules --libdir=/usr/lib64 --program-suffix=-emacs-24
 --infodir=/usr/share/info/emacs-24 --localstatedir=/var
 --enable-locallisppath=/etc/emacs:/usr/share/emacs/site-lisp
 --with-gameuser=:gamestat --without-compress-install
 --with-file-notification=inotify --enable-acl --with-dbus
 --without-gnutls --without-gpm --without-hesiod --without-kerberos
 --without-kerberos5 --with-xml2 --without-selinux --without-wide-int
 --with-zlib --with-sound=alsa --with-x --without-ns --without-gconf
 --without-gsettings --without-toolkit-scroll-bars --without-gif
 --with-jpeg --with-png --with-rsvg --without-tiff --with-xpm
 --with-imagemagick --with-xft --without-libotf --without-m17n-flt
 --with-x-toolkit=gtk3 GENTOO_PACKAGE=app-editors/emacs-24.5 'CFLAGS=-O2
 -pipe -march=native' CPPFLAGS= 'LDFLAGS=-Wl,-O1 -Wl,--as-needed''

Important settings:
  value of $LC_CTYPE: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Emacs-Lisp

Minor modes in effect:
  tooltip-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

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Making completion list...

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
help-fns mail-prsvr mail-utils help-mode easymenu time-date tooltip
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode prog-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
abbrev minibuffer 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 make-network-process
dbusbind inotify dynamic-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty emacs)

Memory information:
((conses 16 73069 6963)
 (symbols 48 17625 0)
 (miscs 40 44 138)
 (strings 32 9420 4003)
 (string-bytes 1 259885)
 (vectors 16 8991)
 (vector-slots 8 384143 17302)
 (floats 8 64 195)
 (intervals 56 372 4)
 (buffers 960 13)
 (heap 1024 36263 750))

===File
~/WorkingDirectory/Community/Emacs/Gnu-Emacs/test-kill-your-emacs-with-global-mode.el===
;; WARNING WARNING WARNING WARNING 
;; 
;;   Make your Emacs *UNUSABLE*
;; 
;; WARNING WARNING WARNING WARNING 
;; 
;; BUG report: nonfunctional Emacs with a bad global mode (post-command-hook).
;; 
;; What follows is a recipe to reproduce a stupid thing I've done.
;; The problem is that I had to kill my emacs; I found no other way to
;; recover control.
;; 
;; The following code reproduces the problem: it ends up placing a
;; function that raises an unhandled error in `post-command-hook'.
;; 
;; As the `post-command-hook' documentation says, Emacs could probably
;; do better here by discarding my stupid code.
;; 
;; Do not use like this:
;; 
;;    emacs -Q --load test-kill-your-emacs-with-global-mode.el A-NEW-FILE.txt --eval '(insert "modified")' --funcall BAD-global-mode 
;; 
;; 
;; 
(define-minor-mode BAD-minor-mode
  "BAD minor mode."
  )


(define-globalized-minor-mode BAD-global-mode
  BAD-minor-mode
  identity
  "BAD global mode."
  )
============================================================





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

* bug#22272: 24.5; nonfunctional Emacs with a bad global mode (post-command-hook).
  2015-12-30  7:28 bug#22272: 24.5; nonfunctional Emacs with a bad global mode (post-command-hook) brubar.cs
@ 2015-12-30 18:04 ` Eli Zaretskii
  2015-12-30 19:02   ` Bruno BARBIER
  2015-12-31 20:33 ` bug#22272: Close 22272 Michael Heerdegen
  1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2015-12-30 18:04 UTC (permalink / raw)
  To: brubar.cs; +Cc: 22272

> From: brubar.cs@gmail.com
> Date: Wed, 30 Dec 2015 08:28:04 +0100
> 
> This report is about a possible improvement. The "bug" arises only after
> a programming mistake.
> 
> Please find attached a recipe to reproduce a stupid thing I've done.
> 
> I was trying to define a new global minor mode. I ended up placing a
> function that raises an unhandled error in `post-command-hook'.
> 
> Then, I had to kill my Emacs; I found no other way to recover control.
> 
> As the `post-command-hook' documentation says, Emacs could probably
> do better here by discarding my non-working code.
> 
> To reproduce and *KILL YOUR EMACS*, launch a *NEW* Emacs like that:
> 
>    emacs -Q --load test-kill-your-emacs-with-global-mode.el A-NEW-FILE.txt --eval '(insert "modified")' --funcall BAD-global-mode 
> 
> I'm reporting this only to improve Emacs. I obviously fixed my code and
> Emacs is awesome again!

Thanks.

The current ELisp manual says:

     Quitting is suppressed while running `pre-command-hook' and
  `post-command-hook'.  If an error happens while executing one of these
  hooks, it does not terminate execution of the hook; instead the error
  is silenced and the function in which the error occurred is removed
  from the hook.

Are you saying that this is inaccurate, and what actually happens is
something else?





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

* bug#22272: 24.5; nonfunctional Emacs with a bad global mode (post-command-hook).
  2015-12-30 18:04 ` Eli Zaretskii
@ 2015-12-30 19:02   ` Bruno BARBIER
  2015-12-30 20:28     ` Michael Heerdegen
  0 siblings, 1 reply; 7+ messages in thread
From: Bruno BARBIER @ 2015-12-30 19:02 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 22272

On Wed, Dec 30, 2015 at 08:04:56PM +0200, Eli Zaretskii wrote:
> > From: brubar.cs@gmail.com
> > Date: Wed, 30 Dec 2015 08:28:04 +0100
> > 

...

> > To reproduce and *KILL YOUR EMACS*, launch a *NEW* Emacs like that:
> > 
> >    emacs -Q --load test-kill-your-emacs-with-global-mode.el A-NEW-FILE.txt --eval '(insert "modified")' --funcall BAD-global-mode 
> > 
> > I'm reporting this only to improve Emacs. I obviously fixed my code and
> > Emacs is awesome again!
> 
> Thanks.
 
> The current ELisp manual says:
> 
>      Quitting is suppressed while running `pre-command-hook' and
>   `post-command-hook'.  If an error happens while executing one of these
>   hooks, it does not terminate execution of the hook; instead the error
>   is silenced and the function in which the error occurred is removed
>   from the hook.
> 
> Are you saying that this is inaccurate, and what actually happens is
> something else?
>

I was referring to the documentation for the variable
`post-command-hook' (sorry I wasn't clear about what documentation I
was talking about), but it pretty much says the same:

   | If an unhandled error happens in running this hook, the function
   | in which the error occurred is unconditionally removed, since
   | otherwise the error might happen repeatedly and make Emacs
   | nonfunctional.

What is happening to me when running my recipe above on Emacs 24.5:

   1. the error is not silenced,

   2. and the function is not removed.

Thus, the error is constantly raised rendering Emacs
nonfunctional. That's why I had to ask the OS to kill my Emacs.  

So, I'm saying Emacs could be slightly improved by following what the
documentation says. 

Am I wrong ? 

Did the recipe fail to reproduce the behavior on your own Emacs ?

Thanks for your prompt reply and for looking into this.


Bruno.






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

* bug#22272: 24.5; nonfunctional Emacs with a bad global mode (post-command-hook).
  2015-12-30 19:02   ` Bruno BARBIER
@ 2015-12-30 20:28     ` Michael Heerdegen
  2015-12-31  6:40       ` Bruno BARBIER
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Heerdegen @ 2015-12-30 20:28 UTC (permalink / raw)
  To: Bruno BARBIER; +Cc: 22272

Bruno BARBIER <brubar.cs@gmail.com> writes:

>    1. the error is not silenced,
>
>    2. and the function is not removed.
>
> Thus, the error is constantly raised rendering Emacs
> nonfunctional. That's why I had to ask the OS to kill my Emacs.  
>
> So, I'm saying Emacs could be slightly improved by following what the
> documentation says. 
>
> Am I wrong ? 

Emacs behaves as documented, but the situation is more complicated as
you expect - See the code `define-globalized-minor-mode':

Turning on a globalized minor mode pushes a function to
change-major-mode-hook that adds a function to post-command-hook - and
that's the one that fails.  So the cited behavior of Emacs removing the
erroneous function from post-command-hook doesn't solve the problem
permanently.


Michael.





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

* bug#22272: 24.5; nonfunctional Emacs with a bad global mode (post-command-hook).
  2015-12-30 20:28     ` Michael Heerdegen
@ 2015-12-31  6:40       ` Bruno BARBIER
  2015-12-31 20:31         ` Michael Heerdegen
  0 siblings, 1 reply; 7+ messages in thread
From: Bruno BARBIER @ 2015-12-31  6:40 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: 22272

On Wed, Dec 30, 2015 at 09:28:31PM +0100, Michael Heerdegen wrote:
> Bruno BARBIER <brubar.cs@gmail.com> writes:
> 
> >    1. the error is not silenced,
> >
> >    2. and the function is not removed.
> >
> > Thus, the error is constantly raised rendering Emacs
> > nonfunctional. That's why I had to ask the OS to kill my Emacs.  
> >
> > So, I'm saying Emacs could be slightly improved by following what the
> > documentation says. 
> >
> > Am I wrong ? 
> 
> Emacs behaves as documented, but the situation is more complicated as
> you expect - See the code `define-globalized-minor-mode':
> 
> Turning on a globalized minor mode pushes a function to
> change-major-mode-hook that adds a function to post-command-hook - and
> that's the one that fails.  So the cited behavior of Emacs removing the
> erroneous function from post-command-hook doesn't solve the problem
> permanently.

Ok. I see. Not that simple indeed and I was wrong: the error is
silenced and the function removed (but `change-major-mode-hook' pushes
it back into `post-command-hook' as instructed by
`define-globalized-minor-mode').

The simplest solution is probably to use a spare Emacs when
developping a new global mode and to catch errors in it; that makes
sense.


I guess this non bug should be closed. Sorry for the noise.

Thanks Eli and Michael for your prompt reply and your time.

Bruno.
 
> 
> Michael.
> 






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

* bug#22272: 24.5; nonfunctional Emacs with a bad global mode (post-command-hook).
  2015-12-31  6:40       ` Bruno BARBIER
@ 2015-12-31 20:31         ` Michael Heerdegen
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Heerdegen @ 2015-12-31 20:31 UTC (permalink / raw)
  To: Bruno BARBIER; +Cc: 22272

Bruno BARBIER <brubar.cs@gmail.com> writes:

> The simplest solution is probably to use a spare Emacs when
> developping a new global mode and to catch errors in it; that makes
> sense.

Also compile your code before loading it:

In BAD-global-mode:
bad.el:30:31:Warning: identity called with 0 args, but requires 1
bad.el:32:3:Warning: identity called with 0 arguments, but requires 1

The byte compiler finds most of such obvious errors.


Michael.





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

* bug#22272: Close 22272
  2015-12-30  7:28 bug#22272: 24.5; nonfunctional Emacs with a bad global mode (post-command-hook) brubar.cs
  2015-12-30 18:04 ` Eli Zaretskii
@ 2015-12-31 20:33 ` Michael Heerdegen
  1 sibling, 0 replies; 7+ messages in thread
From: Michael Heerdegen @ 2015-12-31 20:33 UTC (permalink / raw)
  To: 22272-done

Nothing to do here; Emacs behaves as expected.  Closing.


Thanks,

Michael.





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

end of thread, other threads:[~2015-12-31 20:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-30  7:28 bug#22272: 24.5; nonfunctional Emacs with a bad global mode (post-command-hook) brubar.cs
2015-12-30 18:04 ` Eli Zaretskii
2015-12-30 19:02   ` Bruno BARBIER
2015-12-30 20:28     ` Michael Heerdegen
2015-12-31  6:40       ` Bruno BARBIER
2015-12-31 20:31         ` Michael Heerdegen
2015-12-31 20:33 ` bug#22272: Close 22272 Michael Heerdegen

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