X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=python%2Finit_python.el;h=9067c16f37ff2c48ebf4d82ae5602ab03897a513;hb=30a865756f676c2eb476e249d163054152a45e81;hp=d45a25acdc39a6a16b3d631cf74add99f9e82924;hpb=91d47f5fe8bd7404cdd373e8e8558cb32da52c76;p=emacs-init.git diff --git a/python/init_python.el b/python/init_python.el index d45a25a..9067c16 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,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 + (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 () @@ -74,6 +76,12 @@ (flymake-goto-next-error) (my-flymake-show-error)) +(defun my-flymake-goto-prev-error () + (interactive) + (my-flymake-check-and-wait) + (flymake-goto-prev-error) + (my-flymake-show-error)) + (defun py-find-file (errormark filename defaultdir) (let ((fullname (expand-file-name filename defaultdir))) (or (and (not (file-exists-p fullname)) @@ -117,6 +125,8 @@ (progn (set (make-local-variable 'py-eshell-last-error) (point)) (set (make-local-variable 'py-eshell-prefix) (or (match-string 1) "")) + (if (string-match "Original $" py-eshell-prefix) + (setq py-eshell-prefix (substring py-eshell-prefix 0 (match-beginning 0)))) (if example (forward-line 2) (while (and (< (forward-line 1) 1) (looking-at (concat py-eshell-prefix " "))))) @@ -207,6 +217,7 @@ (define-key python-mode-map "\C-ci" 'my-pyflymake-add-import-from-error) (define-key python-mode-map "\C-ce" 'my-flymake-show-error) (define-key python-mode-map "\C-cn" 'my-flymake-goto-next-error) + (define-key python-mode-map "\C-cp" 'my-flymake-goto-prev-error) (define-key python-mode-map "\C-cI" 'py-cleanup-imports) ) @@ -292,10 +303,30 @@ (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) + (message "flymake init pyflakes %s" local-file) (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 @@ -304,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-+\\)")