Thursday, May 5, 2011

Emacs Pabbrev and Python

Normally when you hit tab on an empty line in emacs python mode it will cycle through the available tab indentations. When I hit tab when the point is at the deepest indent level I get the pabbrev buffer containing the last best match options. Does anyone else have this problem, is there an easy way around it without writing any elisp?

EDIT: Trey, I want to keep pabbrev working in python mode not turn it off.

So lets say there are 2 indent levels, either none, or 1 level normally if it hit tab 3 times the first would put the point at 4 spaces in (or whatever indent is set to), the second back to 0 spaces, and the third back to 4 spaces.

With pabbrev mode on one indent puts the mark 4 spaces, the second brings up a buffer for autocomplete. This should not happen if there is no letters to the left of my point. Does that make any more sense?

From stackoverflow
  • No elisp? Sure:

    M-x pabbrev-mode
    

    should toggle it off. But, if you don't mind cutting/pasting elisp, you can turn off pabbrev mode in python buffers:

    (add-hook 'python-mode (lambda () (pabbrev-mode -1)))
    
  • In light of the clarified requirements, you need something along the lines of this. I'm pretty sure you can't get away w/out writing some elisp. What's nice (IMO) is that this should work for all modes, not just python mode.

    (defadvice pabbrev-expand-maybe (around pabbrev-expand-maybe-when-not-after-whitespace activate)
      "prevent expansion when only whitespace between point and beginning of line"
      (if (save-match-data
            (save-excursion
              (let ((p (point)))
                (string-match "^\\s-*$" (buffer-substring-no-properties (progn (beginning-of-line) (point)) p)))))
          (let ((last-command (if (eq last-command this-command) (pabbrev-get-previous-binding) last-command))
                (this-command (pabbrev-get-previous-binding)))
            (pabbrev-call-previous-tab-binding))
        ad-do-it))
    
    jacob : I'll try it out, thanks a lot!
    jacob : I havent tried it yet, I am trying to get yasnippet working as well which puts me in a whole new tab hell. hopefully i will be able to integrate your code once i get yasnippet and pabbrev working together.
    Trey Jackson : pretty soon you won't have to do any real typing. :)

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.