Emacs: big improvements with python compile functions

master
Pierre Neidhardt 2013-07-03 20:14:06 +02:00
parent 4ff79aa35e
commit d510060929
3 changed files with 24 additions and 10 deletions

View File

@ -159,3 +159,4 @@ maximum-tabs=0
cookie-expiration=0
tab-width=150
hint-offset-left=0
block-insecure-content=false

View File

@ -12,7 +12,7 @@ then it shall return the name of FILE in the current directory,
suitable for creation"
(let ((root (expand-file-name "/"))) ; the win32 builds should translate this correctly
(expand-file-name file
(loop
(loop
for d = default-directory then (expand-file-name ".." d)
if (file-exists-p (expand-file-name file d))
return d

View File

@ -2,21 +2,34 @@
;; Python
;;==============================================================================
(defcustom python-compiler "python"
(defcustom python-compiler ""
"Python compiler."
:safe 'stringp)
(defun is-python3-p () "Check whether we're running Python 2 or
3. Python is assumed by default."
(let ((firstline (car (split-string (buffer-string) "\n" t))))
(let ((firstword (car (split-string firstline nil t))))
(let ((version (if (string-match "/bin/env" firstword)
(car (cdr (split-string firstline nil t)))
firstword)))
(if (string-match "python2" version) nil t)))))
(defun python-compile ()
"Use compile to run python programs."
(interactive)
(let ((py-compiler
(if (equal python-compiler "")
(if (is-python3-p)
"python3" "python2")
python-compiler)))
(compile (concat py-compiler " '" buffer-file-name "'"))))
(add-hook
'python-mode-hook
(lambda ()
(defun python-compile ()
"Use compile to run python programs."
(interactive)
(compile (concat python-compiler " \"" buffer-file-name "\""))
)
(setq compilation-scroll-output t)
(local-set-key "\C-c\C-c" 'python-compile)
))
(set (make-local-variable 'compilation-scroll-output) t)
(local-set-key (kbd "<f10>") 'python-compile)) t)
;; Doc lookup. Requires the python.info file to be installed. See
;; https://bitbucket.org/jonwaltman/pydoc-info/.