Skip to content

Instantly share code, notes, and snippets.

@Wilfred
Created April 24, 2013 13:18
Show Gist options
  • Select an option

  • Save Wilfred/5452053 to your computer and use it in GitHub Desktop.

Select an option

Save Wilfred/5452053 to your computer and use it in GitHub Desktop.
(defun* virtualenv-search--dwim-at-point ()
"If there's an active selection, return that.
Otherwise, get the symbol at point and return a search term for its definition."
(when (use-region-p)
(return (buffer-substring-no-properties (region-beginning) (region-end))))
(-when-let* ((symbol (symbol-at-point))
(symbol-name (symbol-name symbol)))
(return (format "%s %s" (if (s-lowercase? symbol-name) "def" "class") symbol-name)))) ;; return should be return-from virtualenv-search--dwim-at-point
(defun virtualenv-search ()
"Search the source code in the current virtualenv for
a specific search string."
(interactive)
(unless python-shell-virtualenv-path
(error "Need to set `python-shell-virtualenv-path', see `virtualenv-workon'"))
(let ((search-term (read-from-minibuffer "Search virtualenv for: "
(virtualenv-search--dwim-at-point)))
(libraries-path
(file-path-join python-shell-virtualenv-path "lib/python2.7/site-packages")))
(ag/search search-term libraries-path)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment