Emacs: big improvements with python compile functions
parent
4ff79aa35e
commit
d510060929
|
@ -159,3 +159,4 @@ maximum-tabs=0
|
||||||
cookie-expiration=0
|
cookie-expiration=0
|
||||||
tab-width=150
|
tab-width=150
|
||||||
hint-offset-left=0
|
hint-offset-left=0
|
||||||
|
block-insecure-content=false
|
||||||
|
|
|
@ -12,7 +12,7 @@ then it shall return the name of FILE in the current directory,
|
||||||
suitable for creation"
|
suitable for creation"
|
||||||
(let ((root (expand-file-name "/"))) ; the win32 builds should translate this correctly
|
(let ((root (expand-file-name "/"))) ; the win32 builds should translate this correctly
|
||||||
(expand-file-name file
|
(expand-file-name file
|
||||||
(loop
|
(loop
|
||||||
for d = default-directory then (expand-file-name ".." d)
|
for d = default-directory then (expand-file-name ".." d)
|
||||||
if (file-exists-p (expand-file-name file d))
|
if (file-exists-p (expand-file-name file d))
|
||||||
return d
|
return d
|
||||||
|
|
|
@ -2,21 +2,34 @@
|
||||||
;; Python
|
;; Python
|
||||||
;;==============================================================================
|
;;==============================================================================
|
||||||
|
|
||||||
(defcustom python-compiler "python"
|
(defcustom python-compiler ""
|
||||||
"Python compiler."
|
"Python compiler."
|
||||||
:safe 'stringp)
|
: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
|
(add-hook
|
||||||
'python-mode-hook
|
'python-mode-hook
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(defun python-compile ()
|
(set (make-local-variable 'compilation-scroll-output) t)
|
||||||
"Use compile to run python programs."
|
(local-set-key (kbd "<f10>") 'python-compile)) t)
|
||||||
(interactive)
|
|
||||||
(compile (concat python-compiler " \"" buffer-file-name "\""))
|
|
||||||
)
|
|
||||||
(setq compilation-scroll-output t)
|
|
||||||
(local-set-key "\C-c\C-c" 'python-compile)
|
|
||||||
))
|
|
||||||
|
|
||||||
;; Doc lookup. Requires the python.info file to be installed. See
|
;; Doc lookup. Requires the python.info file to be installed. See
|
||||||
;; https://bitbucket.org/jonwaltman/pydoc-info/.
|
;; https://bitbucket.org/jonwaltman/pydoc-info/.
|
||||||
|
|
Loading…
Reference in New Issue