(define-key ropemacs-local-keymap "\M-/" 'hippie-expand)
+(global-unset-key "\C-xpn")
+
(defun write-file-py-cleanup-imports ()
(save-excursion
(condition-case nil
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 ()
(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
(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-+\\)")