X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=python%2Finit_python.el;h=9067c16f37ff2c48ebf4d82ae5602ab03897a513;hb=30a865756f676c2eb476e249d163054152a45e81;hp=da250d8e4a716e999898c645d7800b3a1de5ae2e;hpb=75de9b7e3aa0b2375ed73e0ea729431ab1ccfbe4;p=emacs-init.git diff --git a/python/init_python.el b/python/init_python.el index da250d8..9067c16 100644 --- a/python/init_python.el +++ b/python/init_python.el @@ -35,12 +35,12 @@ nil) (defun python-init-auto-cleanup-imports-on-save () - (add-hook 'write-file-functions 'write-file-py-cleanup-imports nil t)) + (add-hook 'write-contents-functions 'write-file-py-cleanup-imports nil t)) (defun my-flymake-error-at-point () (condition-case nil (flymake-ler-text (car (nth 0 (flymake-find-err-info flymake-err-info - (flymake-current-line-no))))) + (locate-current-line-number))))) (error (error "no flymake error at point")))) (defun my-flymake-show-error () @@ -319,6 +319,15 @@ "Couldn't enable flymake; permission denied on %s" flymake-filename))))) (add-hook 'find-file-hook 'safer-flymake-find-file-hook) +(defun py-skip-few-lines (&optional count) + (if (null count) (setq count 3)) + (let ((blanks 0)) + (while + (and (or (when (eolp) (setq count 0) (incf blanks) t) + (when (> count 0) (decf count) t)) + (< (forward-line 1) 1))) + (> blanks 0))) + (defun py-imports-region () (save-excursion (goto-char (point-min)) @@ -326,6 +335,9 @@ (looking-at "__future__"))) (beginning-of-line) (setq beg (point)) + (while (and (py-skip-few-lines) + (looking-at "import\\s-+\\|from\\s-+")) + (setq beg (point))) (if (not (looking-at "\\(import\\s-+\\|from\\s-+\\)")) (cons beg beg) (while (looking-at "\\(import\\s-+\\|from\\s-+\\)")