Last active
April 25, 2017 03:20
-
-
Save autosquid/acdd732f836b001ffe622c89847d36ad to your computer and use it in GitHub Desktop.
simple way to find package name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; autopyimport.el --- Import python packages automatically | |
;; Copyright(C) 2017 CAPG Lab., Zhejiang University. | |
;; Author: Z. Wang <[email protected]> | |
;; Version: 1.0 | |
;; Package-Requires: (()) | |
;; Keywords: python, import | |
;; URL: http://blog.mightu.cc/autopyimport | |
;;; Commentary: | |
;; This package is used to fix (simply) python auto import.el | |
(defvar packageregex "\\([A-Za-z0-9]+\\)\\.") | |
(defun find-imports (buffer-content) | |
(let ((start-position 0) (candidates nil)) | |
(while (string-match packageregex buffer-content start-position) | |
(let* ((package-name-start (nth 2 (match-data))) | |
(package-name-end (nth 3 (match-data))) | |
(next-start (match-end 0)) | |
(potential-name (substring buffer-content package-name-start package-name-end))) | |
(unless (or (assoc potential-name candidates) | |
(string-match potential-name (substring buffer-content 0 package-name-start))) | |
(push (cons potential-name package-name-start) | |
candidates)) | |
(setq start-position next-start))) | |
candidates)) | |
(defun fix-imports (buffer) | |
(interactive "bfile to fix:") | |
(with-current-buffer buffer | |
(message "%s" (find-imports (buffer-string)))) | |
) | |
(provide 'fix-imports) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks, @jlf.