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

22 lines
811 B
EmacsLisp

;; Python
(defun python-set-compiler ()
"Returns the value of the shebang if any, `python-shell-interpreter' otherwise."
(let* ((firstline
(save-excursion (goto-char (point-min)) (buffer-substring-no-properties (line-beginning-position) (line-end-position))))
(interpreter
(if (not (string-match "^#!" firstline))
python-shell-interpreter
(substring firstline 2))))
(setq compile-command
(concat interpreter " " (shell-quote-argument buffer-file-name)))))
(add-hook-and-eval 'python-mode-hook 'python-set-compiler)
;; Doc lookup. Requires the python.info file to be installed. See
;; https://bitbucket.org/jonwaltman/pydoc-info/.
;; (add-to-list 'load-path "~/path/to/pydoc-info")
;; (require 'pydoc-info nil t)
(provide 'mode-python)