Skip to content

Instantly share code, notes, and snippets.

@imakado
Forked from yappo/gist:176111
Created August 27, 2009 07:19
Show Gist options
  • Save imakado/176153 to your computer and use it in GitHub Desktop.
Save imakado/176153 to your computer and use it in GitHub Desktop.
(defun perl-get-package-string ()
(interactive)
(require 'perl-completion)
(let ((lib-path (plcmp--get-lib-path)))
(when (and lib-path buffer-file-truename)
(let* ((s (replace-regexp-in-string
(rx-to-string `(and bol ,lib-path (? "/")))
""
(expand-file-name buffer-file-truename)))
(s (file-name-sans-extension (replace-regexp-in-string (rx "/") "::" (replace-regexp-in-string "^.+/lib/" "" s)))))
s))))
(defun perl-insert-package ()
(interactive)
(let ((s (perl-get-package-string)))
(when s
(insert "package " s ";"))))
;; my config for autoinsert.el
(require 'autoinsert)
(setq auto-insert-query nil)
(add-hook 'find-file-hook 'auto-insert)
(setq auto-insert-alist
'(
(cperl-mode lambda ()
(when (perl-get-package-string)
(perl-insert-package)
(insert "\n"))
(insert "use strict;\n")
(insert "use warnings;\n")
(insert "use utf8;\n")
;; insert "1;" end of buf if new buffer is under lib dir and extension is .pm
(when (and (perl-get-package-string)
(string= "pm" (file-name-extension buffer-file-truename)))
(insert "\n\n" "1;" "\n")))
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment