Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (26 sloc) 1.09 KB
(defun add-semicolon (string)
(if (string-match ";" string)
(concat string ";")))
(defun add-use ()
"Add a new perl use statement after the existing use statements."
(let ((module (read-with-default "Module" (thing-at-point 'perl-module)
"You must specify a module to use!"))
after statement before space)
(condition-case nil
(while (re-search-forward "^\\(?:class\\|role\\)[^{]+{" nil t)
(setq after (match-string 0)))
(while (re-search-forward "^\\([[:space:]]*\\)use [A-Za-z][[:alnum:]:]+\;" nil t)
(setq space (match-string 1))
(setq after (match-string 0))))
(error (goto-char (point-min))))
(setq statement (concat space "use " (add-semicolon module)))
(insert (concat "\n" statement))
(indent-region (line-beginning-position)
(message (format "Added '%s' after '%s'" statement after)))))
(provide 'cperl-use)
Jump to Line
Something went wrong with that request. Please try again.