Charles Coldwell dcc57f
--- rpm-spec-mode.el~	2008-04-22 15:14:40.000000000 -0400
Charles Coldwell dcc57f
+++ rpm-spec-mode.el	2008-04-22 16:19:09.000000000 -0400
Charles Coldwell dcc57f
@@ -63,7 +63,9 @@
Charles Coldwell dcc57f
 
Charles Coldwell dcc57f
 ;;; Code:
Charles Coldwell dcc57f
 
Charles Coldwell dcc57f
-(defconst rpm-spec-mode-version "0.12.1x" "Version of `rpm-spec-mode'.")
Charles Coldwell dcc57f
+(require 'compile)
Charles Coldwell dcc57f
+
Charles Coldwell dcc57f
+(defconst rpm-spec-mode-version "0.12.1x.rh1" "Version of `rpm-spec-mode'.")
Charles Coldwell dcc57f
 
Charles Coldwell dcc57f
 (defgroup rpm-spec nil
Charles Coldwell dcc57f
   "RPM spec mode with Emacs/XEmacs enhancements."
Charles Coldwell dcc57f
@@ -189,11 +191,6 @@
Charles Coldwell dcc57f
   :type 'boolean
Charles Coldwell dcc57f
   :group 'rpm-spec)
Charles Coldwell dcc57f
 
Charles Coldwell dcc57f
-(defcustom rpm-spec-use-compilation-mode t
Charles Coldwell dcc57f
-  "*If non-nil, build in `compilation-mode' if it's available."
Charles Coldwell dcc57f
-  :type 'boolean
Charles Coldwell dcc57f
-  :group 'rpm-spec)
Charles Coldwell dcc57f
-
Charles Coldwell dcc57f
 (defcustom rpm-spec-default-release "1"
Charles Coldwell dcc57f
   "*Default value for the Release tag in new spec files."
Charles Coldwell dcc57f
   :type 'string
Charles Coldwell dcc57f
@@ -225,6 +222,11 @@
Charles Coldwell dcc57f
   :type 'string
Charles Coldwell dcc57f
   :group 'rpm-spec)
Charles Coldwell dcc57f
 
Charles Coldwell dcc57f
+(defcustom rpm-spec-auto-topdir nil
Charles Coldwell dcc57f
+  "*Automatically detect an rpm build directory tree and define _topdir."
Charles Coldwell dcc57f
+  :type 'boolean
Charles Coldwell dcc57f
+  :group 'rpm-spec)
Charles Coldwell dcc57f
+
Charles Coldwell dcc57f
 (defgroup rpm-spec-faces nil
Charles Coldwell dcc57f
   "Font lock faces for `rpm-spec-mode'."
Charles Coldwell dcc57f
   :prefix "rpm-spec-"
Charles Coldwell dcc57f
@@ -1025,20 +1027,30 @@
Charles Coldwell dcc57f
       (setq buildoptions (cons "--nodeps" buildoptions)))
Charles Coldwell dcc57f
   (if (and rpm-spec-sign-gpg (not rpm-no-gpg))
Charles Coldwell dcc57f
       (setq buildoptions (cons "--sign" buildoptions)))
Charles Coldwell dcc57f
-  (save-excursion
Charles Coldwell dcc57f
-    (set-buffer (get-buffer rpm-buffer-name))
Charles Coldwell dcc57f
-    (and rpm-spec-use-compilation-mode
Charles Coldwell dcc57f
-         (fboundp 'compilation-mode)
Charles Coldwell dcc57f
-         (compilation-mode))
Charles Coldwell dcc57f
-    (goto-char (point-max)))
Charles Coldwell dcc57f
-  (let* ((process-environment (cons "EMACS=t" process-environment))
Charles Coldwell dcc57f
-         (process
Charles Coldwell dcc57f
-          (apply 'start-process rpm-spec-build-command rpm-buffer-name
Charles Coldwell dcc57f
-                 rpm-spec-build-command buildoptions)))
Charles Coldwell dcc57f
-    (if (and rpm-spec-sign-gpg (not rpm-no-gpg))
Charles Coldwell dcc57f
-        (let ((rpm-passwd-cache (read-passwd "GPG passphrase: ")))
Charles Coldwell dcc57f
-          (process-send-string process (concat rpm-passwd-cache "\n"))))
Charles Coldwell dcc57f
-    (set-process-filter process 'rpm-command-filter)))
Charles Coldwell dcc57f
+
Charles Coldwell dcc57f
+  (if rpm-spec-auto-topdir
Charles Coldwell dcc57f
+      (if (string-match ".*/SPECS/$" default-directory)
Charles Coldwell dcc57f
+	  (let ((topdir (expand-file-name default-directory)))
Charles Coldwell dcc57f
+	    (setq buildoptions
Charles Coldwell dcc57f
+		  (cons
Charles Coldwell dcc57f
+		   (concat "--define \"_topdir " 
Charles Coldwell dcc57f
+			   (replace-regexp-in-string "/SPECS/$" "" topdir)
Charles Coldwell dcc57f
+			   "\"")
Charles Coldwell dcc57f
+		   buildoptions)))))
Charles Coldwell dcc57f
+
Charles Coldwell dcc57f
+  (progn
Charles Coldwell dcc57f
+    (defun list->string (lst)
Charles Coldwell dcc57f
+      (if (cdr lst)
Charles Coldwell dcc57f
+	  (concat (car lst) " " (list->string (cdr lst)))
Charles Coldwell dcc57f
+	(car lst)))
Charles Coldwell dcc57f
+    (compilation-start (list->string (cons rpm-spec-build-command buildoptions)) 'rpmbuild-mode))
Charles Coldwell dcc57f
+  
Charles Coldwell dcc57f
+  (if (and rpm-spec-sign-gpg (not rpm-no-gpg))
Charles Coldwell dcc57f
+      (let ((build-proc (get-buffer-process
Charles Coldwell dcc57f
+			 (get-buffer
Charles Coldwell dcc57f
+			  (compilation-buffer-name "rpmbuild" nil nil))))
Charles Coldwell dcc57f
+	    (rpm-passwd-cache (read-passwd "GPG passphrase: ")))
Charles Coldwell dcc57f
+	(process-send-string build-proc (concat rpm-passwd-cache "\n")))))
Charles Coldwell dcc57f
 
Charles Coldwell dcc57f
 (defun rpm-build-prepare (&optional arg)
Charles Coldwell dcc57f
   "Run a `rpmbuild -bp'."
Charles Coldwell dcc57f
@@ -1409,5 +1421,8 @@
Charles Coldwell dcc57f
 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.spec\\(\\.in\\)?$" . rpm-spec-mode))
Charles Coldwell dcc57f
 
Charles Coldwell dcc57f
 (provide 'rpm-spec-mode)
Charles Coldwell dcc57f
+;;;###autoload
Charles Coldwell dcc57f
+(define-compilation-mode rpmbuild-mode "RPM build" ""
Charles Coldwell dcc57f
+  (set (make-local-variable 'compilation-disable-input) t))
Charles Coldwell dcc57f
 
Charles Coldwell dcc57f
 ;;; rpm-spec-mode.el ends here