Emacs Pabbrev and Python

Usually, when you click a tab on an empty line in emacs python mode, it will cycle through the available tabs. When I click the tab when the point is at the deepest level of the indentation, I get a pabbrev buffer containing the latest best match options. Does anyone else have this problem, is there an easy way around this without writing elisp?

EDIT: Trey, I want pabbrev to work in python mode without disconnecting it.

So, let's say that there are two levels of indentation, none, not 1 level, if he typed a tab 3 times, the first will put a dot in 4 spaces (or any other indent), the second in 0 spaces, and the third in 4 spaces.

In pabbrev mode, it places 4 spaces on one indent, the second calls the buffer for autofill. This should not happen if there are no letters to the left of my point. It makes sense?

+3
source share
3 answers

In light of the specified requirements, you need something like that. I am pretty sure that you will not be able to get away from writing some kind of elisp. What a 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))
+3
source

How is this for a late reply?

This should work out of the box now, thanks to a patch from Trey. The tab binding is that pabbrev.el is somewhat naughty, but what do you do if you want a quick extension.

+1
source

elisp? :

M-x pabbrev-mode

. / elisp, pabbrev python:

(add-hook 'python-mode (lambda () (pabbrev-mode -1)))
0

Source: https://habr.com/ru/post/1707631/


All Articles