Skip to content

Instantly share code, notes, and snippets.

@mcdonc
Created October 30, 2012 02:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcdonc/3977930 to your computer and use it in GitHub Desktop.
Save mcdonc/3977930 to your computer and use it in GitHub Desktop.
Emacs: use f5 to find a tox.ini and run it
(require 'compile)
(defun* get-closest-pathname (&optional (file "tox.ini"))
"Determine the pathname of the first instance of FILE starting
from the current directory towards root. This may not do the
correct thing in presence of links. If it does not find FILE,
then it shall return the name of FILE in the current directory,
suitable for creation"
(let ((root (expand-file-name "/")))
(expand-file-name file
(loop
for d = default-directory then (expand-file-name ".." d)
if (file-exists-p (expand-file-name file d))
return d
if (equal d root)
return nil))))
(add-hook 'python-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(format "tox -c %s" (get-closest-pathname)))))
(global-set-key (kbd "<f5>") 'compile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment