;;; COMMENTIFY-REGION-LISP
;;; 
;;; comment out a region using ";;; "

(defun commentify-region-lisp ()
  (interactive)
  (save-excursion
    (narrow-to-region (min (mark) (point))
		      (- (max (mark) (point)) 1))
    (beginning-of-buffer)
    (replace-regexp "^" ";;; ")
    (widen)))


;;; DE-COMMENTIFY-REGION-LISP
;;; 
;;; strip off the ";;;" or ";;; " at the beginnings of lines

(defun de-commentify-region-lisp ()
  (interactive)
  (save-excursion
    (narrow-to-region (mark) (point))
    (beginning-of-buffer)
    (replace-regexp ";;;[ \t]?" "")
    (widen)))


;;; COMMENTIFY-REGION-C
;;; 
;;;
(defun commentify-region-c ()
  (interactive)
  (save-excursion
    (narrow-to-region (min (mark) (point))
		      (- (max (mark) (point)) 1))
    (beginning-of-buffer)
    (insert-string "#if 0\n")
    (replace-string "\n" "\n * ")
    (end-of-buffer)
    (insert-string "\n#endif\n")
    (widen)))


(defun strip-stars-region ()
  (interactive)
    (narrow-to-region (mark) (point))
    (beginning-of-buffer)
    (replace-string "\n * " "\n")
    (widen))
  


;;; --------------------
;;; ZIPPY-COMMENT-HEADER
;;; --------------------
;;; this is what it does with arg

;;; ZIPPY-COMMENT-HEADER
;;; 
;;; this is what it does with no arg

(defun zippy-comment-header (n)
  (interactive "p")
  (let* ((defname (save-excursion (find-defname)))
	 (namelen (length defname)))
    (unless (= n 1)
      (insert-string ";;; ")
      (insert-n-dashes namelen)
      (insert-string "\n"))
    (insert-string ";;; ")
    (let ((start (point)))
      (insert-string defname)
      (upcase-region start (point)))
    (insert-string "\n")
    (unless (= n 1)
      (insert-string ";;; ")
      (insert-n-dashes namelen)
      (insert-string "\n")))
  (unless (looking-at ";;;")
    (insert-string ";;; ")))
    

;;; INSERT-N-DASHES
;;; boring little function

(defun insert-n-dashes (n)
  (do ((i 0 (+ 1 i)))
      ((= i n))
    (insert-string "-")))


;;; FIND-DEFNAME
;;; position the point at the beginning of the line with the "def..." form
;;; and return the name of the defined thing					

(defun find-defname ()
  (interactive)
  (re-search-forward "([ \n\t]*def")
;;;  (beginning-of-line)
  (save-excursion
    (re-search-forward "[ \n\t(]+")
    (let ((start (point)))
      (re-search-forward "[ \n\t\)]")
      (backward-char)
      (buffer-substring start (point)))))
	
;;; the quick brown fox
;;; 
;;; the quick brown fos mumps the quick brown fos mumps the quick brown
;;; fos mumps the quick brown fos mumps the quick brown fos mumps the
;;; quick brown fos mumps the quick brown fos mumps the quick brown fos
;;; 
;;; mumps the quick brown fos mumps mumps the quick brown fos mumps mumps
;;; the quick brown fos mumps mumps the quick brown fos mumps mumps the
;;; quick brown fos mumps mumps the quick brown fos mumps
;;; 
;;; foo boo



;;; GRIND-COMMENT-PARAGRAPH-LISP
;;; fill the paragraph of text in a lisp comment
;;; a paragraph is delimited by lines shorter than 5 characters

(defun grind-comment-paragraph-lisp ()
  (interactive)
  (re-search-backward "^....\n\\|^...\n\\|^..\n\\|^.\n\\|^\n" 0 t)
  (next-line 1)
  (let ((start (point)))
    (re-search-forward "^....\n\\|^...\n\\|^..\n\\|^.\n\\|^\n")
    (previous-line 1)
    (let ((end (- (point) 1)))
      (narrow-to-region start end)
      (beginning-of-buffer)
      (replace-regexp ";;;[ \t]?" "")
      (fill-paragraph nil)
      (end-of-buffer)(backward-char)
      (if (looking-at "\n") (delete-char 1))
      (beginning-of-buffer)
      (replace-regexp "^" ";;; ")
      (widen))))





(defun make-test-area ()
  (interactive)
  (insert-string 
   ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#|


|#")
  (forward-line -2))
