Subject: 23.1.50; image-toggle-display overwrites nxml-mode local key map
From: Brent Goodrick <[email-masked]>
To: [email-masked]
Date: Fri, 27 Nov 2009 16:44:30 -0800

Please write in English if possible, because the Emacs maintainers
usually do not have translators to read other languages for them.

Your bug report will be posted to the [email-masked] mailing list.

Please describe exactly what actions triggered the bug
and the precise symptoms of the bug.  If you can, give
a recipe starting from `emacs -Q':

Insure that you have Emacs 23 built on Debian Squeeze Linux with
librsvg2 library (or similar OS's and libraries), just to get the
image-mode to interact with nxml-mode in its keybindings for a .svg
file which is an XML derivative for SVG files. Then proceed as
follows:

1. Store the following XML content into a file called /tmp/test.svg

--- cut below this line ---
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="400px" height="400px" viewBox="0 0 4000 4000"
     xmlns="http://www.w3.org/2000/svg" version="1.1">
  <title>Sample Title</title>
  <desc>Sample Description</desc>
  <g transform="translate(200,200)">
    <rect x="0" y="0" width="400" height="400"
          fill="none" stroke="blue" stroke-width="10px"/>
    <g transform="translate(50,25)">
      <text x="0" y="0" fill="white" stroke="none">10px</text>
    </g>
  </g>
  <g transform="translate(200,1000)">
    <rect x="0" y="0" width="400" height="400"
          fill="none" stroke="green" stroke-width="10px"/>
    <g transform="translate(50,25)">
      <text x="0" y="0" fill="white" stroke="none">1px</text>
    </g>
  </g>
</svg>
--- cut above this line ---

2. Run emacs -Q and wait for it to load and map into the display.

3. Type C-x C-f /tmp/test.svg and see that the image of the file is
displayed.

4. Type C-c C-c and note that the XML is shown. All correct behavior
so far.

5. Type C-h k C-M-n and notice that the key for C-M-n is bound to
`forward-list' which is not correct because the .svg file is a xml
file, that, by default, should be bound to `nxml-forward-element' by
the defvar for nxml-mode-map inside
share/emacs/23.1.50/lisp/nxml/nxml-mode.el.gz. Notice also that
nxml-mode applies its own local map with this call inside the
`nxml-mode' function:

  (use-local-map nxml-mode-map)

But compare that with `image-toggle-display' where it either calls:

  (use-local-map image-mode-text-map)

or

  (use-local-map image-mode-map)

Neither of which respects the nxml-mode's bindings.

For validation, you can inject a "trampoline" function on
`use-local-map' to show who overwrites the local map, as follows:

(progn
  (defun xx-new-use-local-map (&rest args)
    (message "xx-new-use-local-map called from:\n")
    (backtrace)
    (apply xx-orig-use-local-map args))
  (when (not (boundp 'xx-orig-use-local-map))
    (setq xx-orig-use-local-map (symbol-function 'use-local-map))
    (fset 'use-local-map 'xx-new-use-local-map)))

where the "xx-*" functions were arbitrary for this bug report. Once
xx-new-use-local-map is injected as given above, then use C-h C-e to
see what happens when you first execute C-x C-f /tmp/test.svg, and
then see it again when hitting C-c C-c while in the test.svg
buffer. You will see that image-mode function obliterates the local
map set by the `nxml-mode' function.

I don't know what the correct solution here should be, and many
questions arise:

a. Should image-mode be a minor mode of nxml-mode, or,
b. Should `image-mode' stash a copy of the current buffers
(current-local-map), and restore it afterwards, but also applying the
special binding for C-c C-c, or,
c. Should `image-mode' make the other modes local map be the parent of
its own local map?

I'm thinking (c)?

Thanks to whomever added SVG capabilities to Emacs!

bgoodr

If Emacs crashed, and you have the Emacs process in the gdb debugger,
please include the output from the following gdb commands:
    `bt full' and `xbacktrace'.
For information about debugging Emacs, please read the file
/home/brentg/install/Linux.x86_64/share/emacs/23.1.50/etc/DEBUG.

Emacs did not crash.

In GNU Emacs 23.1.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.18.2)
 of 2009-10-31 on hungover
Windowing system distributor `The X.Org Foundation', version 11.0.10605000
configured using `configure  '--with-x-toolkit' '--with-xft'
'--prefix=/home/brentg/install/Linux.x86_64''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: nXML

Minor modes in effect:
  image-minor-mode: t
  tooltip-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
  global-auto-composition-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
C-x C-f C-v / t m p / C-x h <backspace> C-b C-b C-b
C-g C-x C-f C-SPC M-b C-b <backspace> / t m p C-d C-d
C-d C-d C-d / t e s t . s v g <return> C-v <help-echo>
<help-echo> <help-echo> <down-mouse-2> <mouse-2> C-x
C-s C-x C-v <return> C-c C-c C-h k C-M-n M-x r e p
o r t - e m <tab> <return>

Recent messages:
File mode specification error: (error "Cannot determine image type")
call-interactively: End of buffer
Mark set
Saving file /tmp/test.svg...
Wrote /tmp/test.svg
Using vacuous schema
Type C-c C-c to view the image as text.
Repeat this command to go back to displaying the image
Type C-x 1 to delete the help window.

Load-path shadows:
None found.

Features:
(shadow mail-extr message ecomplete rfc822 mml mml-sec password-cache
mm-decode mm-bodies mm-encode mailcap mail-parse rfc2231 rfc2047 rfc2045
qp ietf-drums mailabbrev nnheader gnus-util netrc time-date mm-util
mail-prsvr gmm-utils wid-edit mailheader canlock sha1 hex-util hashcash
mail-utils emacsbug sendmail help-fns help-mode view nxml-uchnm rng-xsd
xsd-regexp rng-cmpct regexp-opt rng-nxml rng-valid rng-loc rng-uri
rng-parse nxml-parse rng-match rng-dt rng-util rng-pttrn nxml-ns
easymenu nxml-mode nxml-outln nxml-rap nxml-util nxml-glyph nxml-enc
xmltok cl cl-19 jka-compr image-mode tooltip ediff-hook vc-hooks
lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image fringe
lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar
mldrag 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 loaddefs button minibuffer faces cus-face text-properties overlay
md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind gtk
x-toolkit x multi-tty emacs)