diff options
author | Kyle Meyer <kyle@kyleam.com> | 2018-04-28 21:34:56 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2018-04-28 21:34:56 -0400 |
commit | 1ae0c1009b595b9ad66d488e7a1c442bd42b6f72 (patch) | |
tree | 81a22923c767564472605ac3f95778b9b793de1a /lisp | |
parent | 031f48e3726f51686c0525afe5d42f42dad17ded (diff) | |
download | emacs.d-1ae0c1009b595b9ad66d488e7a1c442bd42b6f72.tar.gz |
projectile: Add command to copy Python module name
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/km-projectile.el | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/lisp/km-projectile.el b/lisp/km-projectile.el index 169db8b..9107af7 100644 --- a/lisp/km-projectile.el +++ b/lisp/km-projectile.el @@ -84,21 +84,39 @@ names separated by a space." (if (listp fname) fname (list fname)) " ")))) +(defun km/projectile-project-filename () + (or (km/project-filename-at-point) + (and buffer-file-name + (file-relative-name buffer-file-name + (projectile-project-root))))) + ;;;###autoload (defun km/projectile-copy-project-filename-as-kill () "Copy name of project file. If point is on a file, copy this as the file name. Otherwise, use the name of the current file." (interactive) - (-when-let (fname (or (km/project-filename-at-point) - (and buffer-file-name - (file-relative-name buffer-file-name - (projectile-project-root))))) + (-when-let (fname (km/projectile-project-filename)) (if (eq last-command 'kill-region) (kill-append fname nil) (kill-new fname)) (message "%s" fname))) +;;;###autoload +(defun km/projectile-copy-project-module-as-kill () + "Copy name of project file, transformed into a project module. +Currently, only Python mode is supported." + (interactive) + (when (derived-mode-p 'python-mode) + (-when-let* ((fname (km/projectile-project-filename)) + (module (--> fname + (replace-regexp-in-string "/" "." it nil t) + (replace-regexp-in-string "\\.py" "" it t t)))) + (if (eq last-command 'kill-region) + (kill-append module nil) + (kill-new module)) + (message "%s" module)))) + (defvar km/projectile-project-saved-thing nil "Property list of saved thing for projects. The keys are project roots (strings), so use `lax-plist-put' and |