[comp.emacs] file header program

wsr@lmi-angel.UUCP (Wolfgang Rupprecht) (11/14/86)

Here are two functions that you might find usefull: header and
box-region-for-currant-mode. 

	M-x header makes a header for the currant file.  It uses the
appropriate comment characters for currant mode, and fils in most of
the header for you. It leaves the point and mark around a comment
field that needs filing in.

	M-x box-region-for-currant-mode makes a comment box, according
to the currant buffers' mode.


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;									     ;;
;;	File:     head.el						     ;;
;;	Author:   Wolfgang Rupprecht					     ;;
;;	Created:  Thu Oct  9 14:55:37 EDT 1986				     ;;
;;	Contents: gnuemacs code to make boxes and headers just like this     ;;
;;									     ;;
;;	$Log$								     ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Copyright 1986 Wolfgang Rupprecht

(defvar box-column 80 "last column used when drawing boxes via box command")

(defun c-box-region (start end)
  "draw a box around the current region from POINT to MARK"
  (interactive "r")
  (save-excursion
    (goto-char start)
    (set-mark end)
    (insert "/")
    (let ((count (1- box-column)))
      (while
	  (< 0 (setq count (1- count)))
	(insert ?*)))
    (insert ?\n)
    (while (< (point) (mark))		;note: mark != end anymore
      (insert ?* ?\t)
      (end-of-line 1)
      (indent-to (- box-column 2))
      (insert ?*)
      (forward-line 1))
    (let ((count (1- box-column)))
      (while
	  (< 0 (setq count (1- count)))
	(insert ?*)))
    (insert ?/ ?\n)))

(defun header (start)
  "put a file-header at the current point"  
  (interactive "d")			;value of point as number
    (let ((end start) leave-point leave-mark)
      (goto-char start)
      (insert "\n"
              "File:     " (file-name-nondirectory (buffer-file-name)) "\n"
	      "Author:   " (user-full-name) "\n"
	      "Created:  " (current-time-string) "\n"
	      "Contents: ")
      (setq leave-point (point-marker))
      (insert ">>>Replace this with YOUR description of file contents<<<")
      (setq leave-mark (point-marker))
      (insert "\n\n$Log$\n")		;for RCS log messages
      (box-region-for-current-mode end (point))
      (goto-char (marker-position leave-point))
      (set-mark (marker-position leave-mark))
    ))


(defun box-region-for-current-mode (start end)
  "draw a lisp or C box around region, depending on mode"
  (interactive "r")
  (cond
   ((eq major-mode 'c-mode) (c-box-region start end))
   ((eq major-mode 'text-mode) (lisp-box-region start end ?#)) ;shell or makefile
   ((eq major-mode 'fundamental-mode) (lisp-box-region start end ?#)) ;shell or makefile
   ((eq major-mode 'lisp-mode) (lisp-box-region start end ?\;))
   ((eq major-mode 'emacs-lisp-mode) (lisp-box-region start end ?\;)) 
   (t (lisp-box-region start end nil)))) ;use what-ever is defaulted


(defun lisp-box-region (start end char)
  "draw a lisp box around the current region from POINT to MARK using CHAR
if char is nil default char is \;"
  (interactive "r\nP")
  (save-excursion
    (let ((box-char (or char ?\;)))
      (goto-char start)
      (set-mark end)
      (let ((count box-column))
	(while
	    (< 0 (setq count (1- count)))
	  (insert box-char)))
      (insert ?\n)
      (while (< (point) (mark))		;must be the real mark, since mark != end anymore
	(insert box-char box-char ?\t)
	(end-of-line 1)
	(indent-to (- box-column 3))
	(insert box-char box-char)
	(forward-line 1))
      (let ((count box-column))
	(while
	    (< 0 (setq count (1- count)))
	  (insert box-char)))
      (insert ?\n))))

-- 
Wolfgang Rupprecht	{harvard|decvax!cca|mit-eddie}!lmi-angel!wsr