;; Filename: coding-standards.el ;; Description: Makes following ruQueue coding standards easier ;; Supported Langauge(s): E-Lisp for Emacs 21 ;; Time-stamp: <2005-05-25 14:45:46 jfulton> ;; -------------------------------------------------------- ;; Put this file in your .emacs ;; Type M-x code-header or M-x function-template (use tab completion) ;; -------------------------------------------------------- (defun line-no-comment () "inserts line (55 -'s) into buffer" (interactive) (insert-string "-------------------------------------------------------- \n")) (defun line () "inserts line into buffer and comments it" (interactive) (let ((pos (point))) (line-no-comment) (comment-region pos (point)))) (add-hook 'write-file-hooks 'time-stamp) (defun code-header () "inserts standard header into buffer for PHP, Perl, or Java" (interactive) (save-excursion (goto-char (point-min)) (if (eq major-mode 'php-mode) (insert-string " \n") (comment-region pos (point))) (if (eq major-mode 'php-mode) (insert-string "\n\n\n?>")) (if (eq major-mode 'perl-mode) (progn (insert-string "\n") (insert-string "use strict;\n") (insert-string "use warnings;\n\n") (insert-string "\n\n\n1"))) (if (eq major-mode 'java-mode) (progn (insert-string "\n") (insert-string "import java.io.*;\n\n") (insert-string "public class ") (insert-string (substring (file-name-nondirectory (buffer-file-name)) 0 -5)) (insert-string " {\n\n\n}"))))) (defun function-template () "creates a template for a function in: PHP or Perl" (interactive) (save-excursion (let ((pos (point))) (line-no-comment) (insert-string "Function: Class::MyFunction\n\n") (insert-string "Description: 1-3 line description of the function\n\n") (insert-string "Type: public\n\n") (insert-string "Parameters:\n") (insert-string " [in] string $url The URL for x\n") (insert-string " [in] array $arr An associative array of y\n") (insert-string " [in] int $num The amount of z\n") (insert-string " (in) boolean $flag An optional flag to do k\n") (insert-string " (Default: false)\n") (insert-string " (in) string $name An optional name\n") (insert-string " (Default: \"Larry\")\n") (insert-string "\n") (insert-string "Return Values: \n") (insert-string " interger -1 if an error occured\n") (insert-string " 0 if authentication failed\n") (insert-string " 1 on sucess\n") (insert-string "\n") (insert-string "Remarks: \n") (insert-string " None \n") (line-no-comment) (comment-region pos (point)) (if (eq major-mode 'php-mode) (progn (insert-string "\nfunction MyFunction() {\n") (insert-string "\n}\n\n"))) (if (eq major-mode 'perl-mode) (progn (insert-string "\nsub MyFunction {\n") (insert-string " my ($param1, $param2, ..., $paramn) = @_;\n\n") (insert-string "\n}\n\n"))) (indent-region pos (point) nil)))) (defun eg-variable () "inserts a sample PHP/Perl variable into the buffer" (interactive) (insert-string "$my_variable")) (defun eg-constant () "inserts a sample PHP/Perl constant into the buffer" (interactive) (insert-string "$MY_CONSTANT")) (defun eg-table () "inserts a sample DB table name into the buffer" (interactive) (insert-string "my_table")) (defun eg-field () "inserts a sample DB field into the buffer" (interactive) (insert-string "my_field")) ;; PHP things you might type a lot (defun php-for-loop () "prints a PHP for loop to save time" (interactive) (insert-string "for ($i = 0; $i < $j; $i++) {\n\n}")) (defun php-get-loop () "prints a PHP GET loop to save time" (interactive) (insert-string "foreach ($_GET as $key => $value) {\n ${$key} = f($value);\n}")) (defun php-post-loop () "prints a PHP POST loop to save time" (interactive) (insert-string "foreach ($_POST as $key => $value) {\n ${$key} = f($value);\n}")) (defun php-mysql-obj-loop () "prints a PHP MySQL result to obj loop to save time" (interactive) (insert-string "while ($row = mysql_fetch_object($result)) {\n\n}")) (defun php-query-builder () "prints a PHP query of variable types to save time" (interactive) (insert-string "$sql .= \"$key=\'$value\', \";")) (defun php-mysql-asoc-loop () "prints a PHP MySQL result to assoc array loop to save time" (interactive) (insert-string "while ($row = mysql_fetch_assoc($result)) {\n\n}")) (defun php-trim-2 () "prints a PHP statment to trim last two (you can change that) chars of $s" (interactive) (insert-string "$s = substr($s, 0, -2); // trim last \", \"")) (defun php-query () "prints a PHP statment to run query and catch error" (interactive) (insert-string "$result = mysql_query($sql) or die(mysql_error());"))