Error when major mode changes for html.erb files

Bug #898670 reported by Jorge Dias
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
nXhtml
In Progress
Medium
Unassigned

Bug Description

Editing a file with erb snippets like:

<html>
  some html
  <%= ruby code %>
  more html
  <% ruby code %>
</html>

When I move around and go in and out of the ruby snippet I start to get this error:

Wrong type argument: stringp, nil
- Please try M-: (mumamo-post-command-1) to see what happened.

this is the output of (mumamo-post-command-1)

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  mumamo-set-major(nil nil)
  mumamo-set-major-post-command()
  mumamo-post-command-1()
  eval((mumamo-post-command-1) nil)
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp nil nil)

I don't know why but after that when inside a ruby snippet it's unable to set the mode as: Ruby/eruby-html, it stays as:

Mumamo border/eruby-html

I'm using this version: https://github.com/emacsmirror/nxhtml with the latest commit

Revision history for this message
lborgman (lennart-borgman) wrote :

Thanks for the bug report, Jorge. However I can not reproduce this. I guess the git mirror is updated?

What version of Emacs are you using? (I have not had time to test with Emacs 24 pretest yet.)

Changed in nxhtml:
importance: Undecided → Medium
status: New → In Progress
Revision history for this message
Jorge Dias (dias-jorge) wrote :

I'm using emacs "GNU Emacs 24.0.91.1 (i386-apple-darwin10.8.0, NS apple-appkit-1038.36) of 2011-11-22

Although it was happening with a previous build of emacs 24 too, I actually updated to see if it would go away.

The git mirror is with the commits of Nov 03.

Revision history for this message
Jorge Dias (dias-jorge) wrote :

Any idea how I could help you out with this one? I've tried the latest version but it still happens, so I can't really use it for my erb files :( so now I use rhtml-mode but I still liked this one better.

Revision history for this message
lborgman (lennart-borgman) wrote :

I think I have to try Emacs 24 myself first to see. (However you are of course free to dig into the nXhtml sources if you like to!)

Revision history for this message
Jorge Dias (dias-jorge) wrote :

Finally I found the cause of the bug. It's not an nxhtml-bug itself but here's my description:

The problem occurred within the mumamo-fetch-local-map:

I had a hook that was giving an error when switching to ruby mode with the "temporary buffer", so when it did:

(with-current-buffer temp-buf
      (let ((mumamo-fetching-major t))
        (funcall major))
        ....

When it called ruby-mode, then one of the hooks would blow up.

It was very hard to track and debug, although I think I understand mumamo so much more right now, so not a complete lost ;)

Would it be possible to provide a more detailed backtrace when an error happens here?

Also may I suggest that we rewrite this function to use (with-temp-buffer) I think it would greatly simplify it. I could provide you with a patch although I don't know if it's done like this because some older emacs versions don't support this function. In this case maybe we could backport it? what versions of emacs do you support?

Greetings

Revision history for this message
lborgman (lennart-borgman) wrote :

Thanks Jorge! :-)

with-temp-buffer can't be used ... eh, forgot the reason exactly, but the major mode was not set as I expected when I tried that (long ago).

Yes, those things used to be awfully difficult to track down sometimes. Sorry for that.

The error must have happened in mumamo-find-chunks, or at least I believe so. I have struggled a bit with error handling there. In some cases you can use mumamo-condition-case. Please take a look at the doc for that macro.

I am leaving the bug open for now, since I think better error checking in mumamo-find-chunks-1 would be good. Perhaps you can tell what would have helped there?

Revision history for this message
Jorge Dias (dias-jorge) wrote :

In the patch I just surrounded the call with mumamo-condition-case. At least it would help you narrow down where this kind of bugs would happen.

Although I don't think this would be a good solution at least would save some debugging time in case of an error. Another alternative would be to return an empty keymap if there's an error and giving just a warning.

What do you think?

Revision history for this message
lborgman (lennart-borgman) wrote :

I can't see how this should help here. Can you please explain?

Revision history for this message
Jorge Dias (dias-jorge) wrote :

In my case it would help since the problem was when turning on the major mode inside this temp buffer.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.