Skip to content

Instantly share code, notes, and snippets.

View con-cat's full-sized avatar

Caitlin White con-cat

  • Melbourne, Australia
View GitHub Profile
@con-cat
con-cat / get-python-import-statement.el
Last active July 2, 2024 03:56
Emacs lisp function to return an import statement for a Python file or object
(defun con-cat/get-python-path (root-in-project)
"Return a list of parts of the path to a Python file or object.
root-in-project is the optional path to a directory inside the project that the path should be relative to,
e.g. 'src' if your project is in ~/myproject and your Python files are in ~/myproject/src"
(unless (and (projectile-project-root) buffer-file-name (string= "py" (file-name-extension buffer-file-name)))
(user-error "Buffer isn't visiting a Python file in a Projectile project."))
(let*
;; Get the path of the file relative to projectile-project-root and root-in-project
((file-path (file-relative-name buffer-file-name (expand-file-name root-in-project (projectile-project-root))))