Permalink
Browse files

Initial import

  • Loading branch information...
0 parents commit e9b6c25d0bd75bfc15d19b39b06fc332fb15d5b4 @wfarr committed Apr 22, 2009
Showing with 46 additions and 0 deletions.
  1. +46 −0 add-import.el
@@ -0,0 +1,46 @@
+;;; Original Author: Jonathon Rockway
+
+(require 'thingatpt)
+
+(defun bounds-of-module-at-point ()
+ "Determine where a module name starts for (thing-at-point 'perl-module)"
+ (save-excursion
+ (skip-chars-backward "[:alpha:]:\\->") ; skip to F in Foo::Bar->
+ (if (looking-at "[[:alpha:]:]+") ; then get Foo::Bar
+ (cons (point) (match-end 0))
+ nil)))
+
+
+; allow (thing-at-point 'perl-module)
+(put 'perl-module 'bounds-of-thing-at-point 'bounds-of-module-at-point)
+
+
+(defun read-with-default (string &optional default error)
+ (let ((read (read-string
+ (if default
+ (format "%s (default %s): " string default)
+ (format "%s: " string)))))
+ (if (equal read "") (setq read nil))
+ (if (and (not read) (not default)) (error error))
+ (if (not read) (setq read default))
+ read))
+
+
+(defun add-semicolon (string)
+ (if (string-match ";" string)
+ string
+ (concat string ";")))
+
+
+(defun add-use ()
+ "Add a new perl use statement after the existing use statements."
+ (interactive)
+ (let ((module (read-with-default "Module" (thing-at-point 'perl-module)
+ "You must specify a module to use!")))
+ (save-excursion
+ (goto-char (point-max))
+ (condition-case nil
+ (re-search-backward "^\\(use .+;\\)")
+ (error (goto-char 0)))
+ (end-of-line)
+ (insert (concat "\nuse " (add-semicolon module))))))

0 comments on commit e9b6c25

Please sign in to comment.