From 18857f53018ff035bd1b25f91ffaa3b101427f56 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Wed, 6 Nov 2019 16:44:18 -0600 Subject: [PATCH] Using one monstrous regex for elpy-venv exclusion --- settings.org | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/settings.org b/settings.org index 38e2232..f616bf8 100644 --- a/settings.org +++ b/settings.org @@ -458,14 +458,39 @@ put executables in elpy-rpc-venv in path ;; If the file is remote, don't try and do anything fancy (setq-local pyvenv-workon (emacs-default-venv))) ((let ((buffer-file-name (file-truename buffer-file-name))) - (-any (lambda (file-prefix) - (string-prefix-p file-prefix buffer-file-name)) - (mapcar 'file-truename (list - "/usr/lib/python" - "~/.pyenv/versions/" - (elpy-rpc-get-or-create-virtualenv) - (pyvenv-workon-home))))) - ;; Don't change anything if entering a file in a python install's lib (ie xref) + ;; Don't change anything if entering a file in a python install's lib (ie for a file located with xref) + (if (string-match-p (rx bos (or + ;; Windows + (and letter "/" (one-or-more not-newline) + "/Lib") + ;; Rest of the sane world + (and (or + ;; In the home directory + (and (zero-or-more not-newline) + "/home/" (zero-or-more not-newline) + (or + ;; System python user installed package + "/.local" + ;; In a virtualenv + (and "/.virtualenvs/" (one-or-more (not (any "/")))) + ;; Elpy-rpc venv + (and "/.emacs.d/elpy/rpc-venv") + ;; Using Pyenv + (and "/.pyenv/versions/" + (one-or-more (not (any "/")))))) + ;; System python + (and (zero-or-more not-newline) + "/usr" + (opt "/local"))) + ;; Standard */lib/python3.7/ etc + (or + ;; Standard python + (and "/lib/python" (one-or-more (any digit "."))) + ;; PyPy + (and (or "/lib-python" "/lib_pypy"))))) + (zero-or-more not-newline) + "/" eos) + buffer-file-name))) nil) (t ;; Upon failing all conditions, prompt to create virtual environment if it doesn't exist