X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=python%2Finit_python.el;h=e66e6a1707ce59f8a0b2c2813625e442bd1dc68e;hb=d44024a9086ffc06430329b40841aa0015668e21;hp=11458f582803c106382e0bde8be2453785e35b41;hpb=5f3c695024b3619e7239e9177cca2a07792f9876;p=emacs-init.git diff --git a/python/init_python.el b/python/init_python.el index 11458f5..e66e6a1 100644 --- a/python/init_python.el +++ b/python/init_python.el @@ -25,6 +25,8 @@ (define-key ropemacs-local-keymap "\M-/" 'hippie-expand) +(global-unset-key "\C-xpn") + (defun write-file-py-cleanup-imports () (save-excursion (condition-case nil @@ -33,10 +35,10 @@ 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 + (condition-case nil (flymake-ler-text (car (nth 0 (flymake-find-err-info flymake-err-info (flymake-current-line-no))))) (error (error "no flymake error at point")))) @@ -305,7 +307,26 @@ (list "pyflakes" (list local-file)))) (add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pyflakes-init))) -(add-hook 'find-file-hook 'flymake-find-file-hook) + +(defun safer-flymake-find-file-hook () + "Don't barf if we can't open this flymake file" + (let ((flymake-filename + (flymake-create-temp-inplace (buffer-file-name) "flymake"))) + (if (file-writable-p flymake-filename) + (flymake-find-file-hook) + (message + (format + "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 @@ -314,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-+\\)")