-
-
Save imakado/176153 to your computer and use it in GitHub Desktop.
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
(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