(defvar comment-char ?*)
(defvar make-target "")
(defvar make-directory nil)
(defvar make-window-height 25)
(defun make (arg)
  (interactive "P")
  (if (and
       (boundp 'compilation-process)
       (processp compilation-process))
      (delete-process compilation-process))
  (if (and (buffer-file-name) 
	   (progn 
	     (save-buffer) 
	     (save-excursion 
	       (goto-char (point-min))
	       (if (search-forward "compile-command" 512 t)
		   (progn (compile (read (current-buffer))) t)))))
      nil
    (progn
      (if arg
	  (progn
	    (setq make-target
		  (read-string "Make target: " make-target))
	    (setq make-directory
		  (expand-file-name
		   (read-file-name "Make directory: " default-directory default-directory)))
	    (or (equal (substring make-directory (1- (length make-directory))) "/")
		(setq make-directory (concat make-directory "/")))))
      (or make-directory
	  (setq make-directory default-directory))
      (let ((b (get-buffer "*compilation*")))
	(if b (kill-buffer b)))
      (let ((default-directory make-directory))
	(compile (format "make %s" make-target))
	)))
  (select-window (get-buffer-window "*compilation*"))
  (shrink-window (- (window-height) make-window-height))
  (other-window 1))

(setq star-column 79)
(defun star-line (arg)
  (interactive "p")
  (while (> arg 0)
    (beginning-of-line)
    (if (not (looking-at "\\*"))
	(insert "*"))
    (end-of-line)
    (let ((spaces (- star-column (current-column))))
      (if (> spaces 0)
	  (insert-char ?  spaces))
      (end-of-line)
      (while (> (current-column) star-column)
	(backward-char 1))
      (insert "*"))
    (next-line 1)
    (beginning-of-line)
    (setq arg (1- arg))))


(defun comment-pp ()
  (interactive)
  (save-excursion
    (let ((comment-start comment-start)
	  (comment-end comment-end))
      (string-match "[ \t]*\\([^ \t]*\\)" comment-start)
      (setq comment-start (substring comment-start (match-beginning 1) (match-end 1)))
      (string-match "[ \t]*\\([^ \t]*\\)" comment-end)
      (setq comment-end (substring comment-end (match-beginning 1) (match-end 1)))
      (if (re-search-backward "^[ \t]*$" (point-min) t)
	  (forward-line 1)
	(goto-char (point-min)))
      (insert comment-start)
      (insert-char comment-char (- 75 (length comment-start)))
      (setq end-col (1- (current-column)))
      (insert "\n")
      (insert-char comment-char 1)
      (indent-to-column end-col)
      (insert-char comment-char 1)
      (insert "\n")
      (while (and (< (point) (point-max))
		  (not (looking-at "^[ \t]*$")))
	(insert-char comment-char 1)
	(insert " ")
	(end-of-line)
	(indent-to-column end-col)
	(insert-char comment-char 1)
	(forward-line 1))
      (insert-char comment-char 1)
      (indent-to-column end-col)
      (insert-char comment-char 1)
      (insert "\n")
      (insert-char comment-char (- 75 (length comment-end)))
      (insert comment-end)
      (insert "\n"))))
