pythonemacspabbrev

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?


Solution

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