ambevar-dotfiles/.emacs.d/lisp/mode-python.el

34 lines
1.1 KiB
EmacsLisp
Raw Normal View History

2013-06-12 23:40:20 +02:00
;; Python
2013-07-04 08:39:35 +02:00
(defun python-version ()
2014-02-26 18:22:47 +01:00
"Returns \"python2\" or \"python3\" according to the shabang.
`python-shell-interpreter' is assumed by default."
(let ((firstline
(car
(split-string (buffer-substring-no-properties 1 (point-max)) "\n"))))
2013-07-04 08:39:35 +02:00
(if (not (string-match "^#!" firstline))
"python"
(cond
((string-match "python2" firstline) "python2")
((string-match "python3" firstline) "python3")
2014-02-26 18:22:47 +01:00
(t python-shell-interpreter)))))
(defun python-set-interpreter ()
"Use compile to run python programs."
(interactive)
2014-02-26 18:22:47 +01:00
(set (make-local-variable 'compile-command)
(concat (python-version) " " (shell-quote-argument buffer-file-name))))
2014-02-26 18:22:47 +01:00
(add-hook-and-eval
2013-06-12 23:40:20 +02:00
'python-mode-hook
(lambda ()
(set (make-local-variable 'compilation-scroll-output) t)
(add-hook 'compilation-before-hook 'python-set-interpreter nil t)))
2013-06-12 23:40:20 +02:00
;; Doc lookup. Requires the python.info file to be installed. See
;; https://bitbucket.org/jonwaltman/pydoc-info/.
2014-02-12 17:37:43 +01:00
;; (add-to-list 'load-path "~/path/to/pydoc-info")
;; (require 'pydoc-info nil t)
2014-02-12 17:48:29 +01:00
2014-02-26 18:22:47 +01:00
(provide 'mode-python)