New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pressing tab to ident sometimes gives tracebacks #20

Closed
epatters opened this Issue Jul 8, 2012 · 6 comments

Comments

Projects
None yet
2 participants
@epatters

epatters commented Jul 8, 2012

The following sequence reliably produces an error (running zeroein on Emacs 23):

  1. Type for i in xrange(10): in an empty cell.
  2. Press Enter.
  3. Press Tab.

No tab is inserted, the cursor leaves the cell, and the following traceback is produced:

part 2 [python-mode]: chu-min=32 chu-max=33 chu-last-bol=nil
apply: Wrong length inserted in mirror [python-mode]: change-beg=10 part=3, chu-max=33, pm=34
Toggling font-lock-mode off; better pass an explicit argument.
@tkf

This comment has been minimized.

Show comment
Hide comment
@tkf

tkf Jul 8, 2012

Owner

Thanks for the report. Yes, I noticed the problem. I think this is because python.el and MuMaMo do not work well in this particular situation. I just type C-o before hitting Tab to avoid this problem. It's lame, but I don't know what is the best way to solve this problem.

Owner

tkf commented Jul 8, 2012

Thanks for the report. Yes, I noticed the problem. I think this is because python.el and MuMaMo do not work well in this particular situation. I just type C-o before hitting Tab to avoid this problem. It's lame, but I don't know what is the best way to solve this problem.

@tkf

This comment has been minimized.

Show comment
Hide comment
@tkf

tkf Jul 8, 2012

Owner

BTW, you are using Fabián E. Gallina's python.el, right? I am using it, so I don't know if it happens in other python modes.

Owner

tkf commented Jul 8, 2012

BTW, you are using Fabián E. Gallina's python.el, right? I am using it, so I don't know if it happens in other python modes.

@epatters

This comment has been minimized.

Show comment
Hide comment
@epatters

epatters Jul 8, 2012

Nope, I am using the vanilla python.el that ships with Emacs. (Although it looks like Gallina's version has just been merged into Emacs trunk, so I will be getting it sooner or later.)

Anyway, the trouble with that workaround is that it breaks my muscle memory. :)

But you've done a great job with the project. I've been hoping for a while that someone would take advantage of IPython's new client-server architecture to make a good Emacs client. Thanks for your hard work!

epatters commented Jul 8, 2012

Nope, I am using the vanilla python.el that ships with Emacs. (Although it looks like Gallina's version has just been merged into Emacs trunk, so I will be getting it sooner or later.)

Anyway, the trouble with that workaround is that it breaks my muscle memory. :)

But you've done a great job with the project. I've been hoping for a while that someone would take advantage of IPython's new client-server architecture to make a good Emacs client. Thanks for your hard work!

@tkf

This comment has been minimized.

Show comment
Hide comment
@tkf

tkf Jul 8, 2012

Owner

OK, I got a super dirty solution!

(defadvice mumamo-indent-line-function
  (around ein-workaround-mumamo-indent-line-function activate)
  (let (m)
    (unwind-protect
        (progn
          (insert "\n")
          (setq m (point-marker))
          (backward-char)
          ad-do-it)
      (save-excursion
        (goto-char m)
        (backward-char)
        (delete-char 1)))))

I will put this in my Emacs init.el for a while and see if it works properly. If it is an OK-solution, I will probably put in EIN and make it possible to optionally enable (or disable).

Yea, I really like IPython's client-server architecture. What is nice about it is that you can share server program with Vim guys. :) I hope many other program languages follow this way.

Owner

tkf commented Jul 8, 2012

OK, I got a super dirty solution!

(defadvice mumamo-indent-line-function
  (around ein-workaround-mumamo-indent-line-function activate)
  (let (m)
    (unwind-protect
        (progn
          (insert "\n")
          (setq m (point-marker))
          (backward-char)
          ad-do-it)
      (save-excursion
        (goto-char m)
        (backward-char)
        (delete-char 1)))))

I will put this in my Emacs init.el for a while and see if it works properly. If it is an OK-solution, I will probably put in EIN and make it possible to optionally enable (or disable).

Yea, I really like IPython's client-server architecture. What is nice about it is that you can share server program with Vim guys. :) I hope many other program languages follow this way.

@tkf

This comment has been minimized.

Show comment
Hide comment
@tkf

tkf Jul 14, 2012

Owner

A bit better version:

(defadvice mumamo-indent-line-function
  (around ein-workaround-mumamo-indent-line-function activate)
  "Workaround the indentation problem when the cursor is at the
end of input area."
  (if (and (looking-at-p "\n")
           (get-char-property (point) 'read-only))
      (let (m)
        ;; The cursor is at the end of input area.
        ;; Indentation does not work as-is.  Here is the workaround:
        (unwind-protect
            (progn
              (insert "\n")
              (setq m (point-marker))
              (backward-char)
              ad-do-it)
          (save-excursion
            (goto-char m)
            (backward-char)
            (delete-char 1))))
    ad-do-it))
Owner

tkf commented Jul 14, 2012

A bit better version:

(defadvice mumamo-indent-line-function
  (around ein-workaround-mumamo-indent-line-function activate)
  "Workaround the indentation problem when the cursor is at the
end of input area."
  (if (and (looking-at-p "\n")
           (get-char-property (point) 'read-only))
      (let (m)
        ;; The cursor is at the end of input area.
        ;; Indentation does not work as-is.  Here is the workaround:
        (unwind-protect
            (progn
              (insert "\n")
              (setq m (point-marker))
              (backward-char)
              ad-do-it)
          (save-excursion
            (goto-char m)
            (backward-char)
            (delete-char 1))))
    ad-do-it))

@tkf tkf closed this in ba16a14 Jul 17, 2012

@tkf

This comment has been minimized.

Show comment
Hide comment
@tkf

tkf Jul 17, 2012

Owner

I added the above workaround code in master.
http://tkf.github.com/emacs-ipython-notebook/#ein:use-mumamo-indent-line-function-workaround

If you are using the above code, you can remove it after updating EIN.

Owner

tkf commented Jul 17, 2012

I added the above workaround code in master.
http://tkf.github.com/emacs-ipython-notebook/#ein:use-mumamo-indent-line-function-workaround

If you are using the above code, you can remove it after updating EIN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment