Skip to content

Instantly share code, notes, and snippets.

@jplindstrom
Last active August 29, 2015 14:16
Show Gist options
  • Save jplindstrom/59f5e9450ad449633918 to your computer and use it in GitHub Desktop.
Save jplindstrom/59f5e9450ad449633918 to your computer and use it in GitHub Desktop.
PS copy package name from file name
(defun ps/project-buffer-file-name ()
"Return the current buffer file name, relative to the project
root dir."
(let* ((full-file-name (buffer-file-name))
(project-dir (or (ps/project-dir) (error "Not in a PerlySense project.")))
(project-file-name
(replace-regexp-in-string (regexp-quote (format "%s/" project-dir)) "" full-file-name))
)
project-file-name
)
)
(defun ps/edit-copy-package-name-from-file-name ()
"Copy (put in the kill-ring) the name of the current file name
as if it was a package name, and display it in the echo area"
(interactive)
(let* (
(project-file-name (ps/project-buffer-file-name))
(lib-file-name
(replace-regexp-in-string ".*?/?lib/" "" project-file-name))
(package-file-name (replace-regexp-in-string "/" "::" lib-file-name))
(package-name (replace-regexp-in-string "\\.pm$" "" package-file-name))
)
(kill-new package-name)
(message "Copied package name '%s'" package-name)
)
)
(global-set-key (kbd "C-o e c P") 'ps/edit-copy-package-name-from-file-name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment