;; $Id: DONperl.el,v 2.0 2000/11/11 09:55:03 tag Exp $ ;; Version $Name: R2_0_1 $ ;; ;; DONperl.el - Perl-mode hook for DON Lab usage ;; by T.A. Gonsalves, 17-9-97 ;; TAG, 3-10-98: ;; Added statement templates ;; TAG, 18-9-99: perl-file-comment calls c-file-comment ;; ;; Last modified: Sat 11-Nov-2000 15:19:09 by tag ;; Get stmt templates etc from DONc: c-do-while-loop c-if-then-else ;; c-for-loop c-if-then c-switch c-while-loop ;; insert-relative-buffer-file-name ;; DONc-statement-block c-file-comment (require 'DONc) (defconst perl-interpreter "/usr/bin/perl") ; system-dependant ;;; ;;; perl-file-comment - setup a comment block template at the top of the file ;;; (defun perl-file-comment () "Sets up a comment template at the top of the file" (interactive "*") (save-match-data (goto-char (point-min)) (forward-line 1) (if (not (search-backward (concat "#!" perl-interpreter) () t)) (progn (goto-char (point-min)) (insert (concat "#!" perl-interpreter "\n")))) (setq c-comment-prefix "#") (setq c-comment-block-start "#**************************************************************************") (setq c-comment-block-end "#**************************************************************************") (setq c-file-comment-start-line 2) (setq c-file-comment-body-hook 'perl-file-comment-body) (c-file-comment))) (defun perl-file-comment-body () (insert "use strict;\n") (insert "use vars qw();\n") (insert "use subs qw();\n\n") (insert "#******************************* Constants ******************************\n\n") (insert "#******************************* Functions ******************************\n\n") (insert "#******************************* Main Code ******************************\n") (newline-and-indent) (insert "my ();") (indent-for-comment) (insert "variables local to the main code") (beginning-of-line) (insert "#") ; Perl doesn't like my (); (end-of-line)) (defun perl-function-comment () "Sets up a comment template at the start of a function" (interactive "*") (let ((funName) (args) (argp)) (setq funName (read-string "Enter function name: ")) (setq args (read-string (concat "Arguments for " funName " (e.g. $a, $b...): "))) (setq argp (not (string-equal args ""))) (if (not (bolp)) (end-of-line)) (insert "\n#-------------------------------------------------------------------------\n") (insert "# " funName " -- ") (save-excursion (save-match-data (insert "\n# Args:\t") (if argp (insert args) (insert "None")) (insert "\n# Returns:\t\n") (insert "# Bugs:\t\n") (insert "#-------------------------------------------------------------------------\n\n") (insert "sub " funName "(" args ")") (DONc-statement-block) (search-backward "{") (forward-char) (if argp (progn (newline-and-indent) (insert "my (" args ") = @_;"))) (newline-and-indent) (insert "my ();") (indent-for-comment) (insert "variables local to this function") (beginning-of-line) (insert "#") ; Perl doesn't like my (); (end-of-line) (newline-and-indent) (insert "local ();") (indent-for-comment) (insert "localized global variables") (search-forward "}") (insert "\t" comment-start " End of " funName "\t\tEnd of " funName " " comment-end) (if (not c-auto-newline) (newline-and-indent)))))) (defun DONperl-setup () "Set indentation style a la DONLab and bind keys" (add-hook 'write-file-hooks 'time-stamp) (setq perl-indent-level 2) (setq perl-continued-statement-offset 4) (setq perl-continued-brace-offset -4) (setq perl-brace-offset 2) (setq perl-brace-imaginary-offset 2) (setq perl-label-offset -2) (define-key perl-mode-map "\C-cd" 'c-do-while-loop) (define-key perl-mode-map "\C-ce" 'c-if-then-else) (define-key perl-mode-map "\C-cf" 'c-for-loop) (define-key perl-mode-map "\C-ci" 'c-if-then) (define-key perl-mode-map "\C-cs" 'c-switch) (define-key perl-mode-map "\C-cw" 'c-while-loop) (define-key perl-mode-map "\C-ct" 'perl-file-comment) (define-key perl-mode-map "\C-cu" 'perl-function-comment) (c-set-local-variables) ) (provide 'DONperl) ;;;---------------------------------------------------------------- ;;; $Log: DONperl.el,v $ ;;; Revision 2.0 2000/11/11 09:55:03 tag ;;; Made DONel into a module, added README and INSTALL files ;;; ;;; Revision 1.5 2000/11/10 11:36:43 tag ;;; Added Version tag to DON\*.el ;;; ;;; Revision 1.4 2000/11/10 11:27:42 tag ;;; Modified to handle javadoc-style comments ;;; ;;; Revision 1.3 1999/09/18 06:26:11 tag ;;; Modified perl-file-comment to call c-file-comment ;;; ;;; Revision 1.2 1998/10/27 10:38:52 tag ;;; Fixed problem in CVS keywords that appear in the code ;;; ;;; Revision 1.1 1998/10/16 06:25:57 tag ;;; Templates for DONlab coding style ;;; ;;; Local Variables: ;;; time-stamp-active: t ;;; time-stamp-line-limit: 20 ;;; time-stamp-start: "Last modified:[ ]+" ;;; time-stamp-format: "%3a %:d-%3b-%:y %02H:%02M:%02S by %u" ;;; time-stamp-end: "$" ;;; End: ;;; End of DONperl.el --------------------------------------------