help-emacs-windows
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[h-e-w] Help with defadvice


From: Ben Key
Subject: [h-e-w] Help with defadvice
Date: Wed, 18 Jun 2003 09:41:36 -0400

I am trying to  modify Emacs to use a more intelligent method of setting the
value of compile command.

I have defined a function that calculates the compile command and I am
trying to get compile to call the function prior to displaying the
compile-command prompt using defadvice.  For some reason it is not working.
What am I doing wrong?

(defun bk-set-compile-command ()
 "Attempts to sets compile-command so that the project contained in the
directory
associated with the current buffer may be built successfully."
 (interactive)
 (message "bk-set-compile-command")
 (if (memq system-type '(windows-nt))
   (progn
    (make-variable-buffer-local 'bk-current-compile-command)
    (make-variable-buffer-local 'compile-command)
    (let (
       (dsw-file nil)
       (dsp-file nil)
       (project-name nil)
       (msvc-make-file nil)
       )
     (setq dsw-file
        (or
         (car-safe
         (directory-files
          (file-name-directory (buffer-file-name))
          t
          "\\.dsw$"))
         (car-safe
         (directory-files
          (expand-file-name (concat (file-name-directory (buffer-file-name))
"../"))
          t
          "\\.dsw$"))
         )
        )
     (setq dsp-file
        (car-safe
         (directory-files
         (file-name-directory (buffer-file-name))
         t
         "\\.dsp$"))
        )
     (setq msvc-make-file
        (car-safe
         (directory-files
         (file-name-directory (buffer-file-name))
         t
         "MSVCMakeFile"))
        )
     (if (not msvc-make-file)
       (setq msvc-make-file
          (car-safe
           (directory-files
           (file-name-directory (buffer-file-name))
           t
           "makefile.msvc"))
          )
      )
     (if (and dsw-file dsp-file)
       (progn
        (setq project-name (file-name-sans-extension (file-name-nondirectory
dsp-file)))
        (setq compile-command
           (format "msdev %s /MAKE \"%s - Win32 \"" dsw-file project-name))
        (setq msdev-current-compile-command compile-command)
        (message "compile-command is now '%s'" compile-command)
        )
      (if msvc-make-file
        (progn
         (setq compile-command
            (format "nmake -f %s" msvc-make-file))
         (setq msdev-current-compile-command compile-command)
         (message "compile-command is now '%s'" compile-command)
         )
       )
      )
     )
    )
  )
 )

(if (fboundp 'defadvice)
  (progn
   (defadvice compile (before bk-set-compile-command-advice activate)
    (bk-set-compile-command)
    )
   (ad-enable-advice 'compile 'before 'bk-set-compile-command-advice)
   (ad-activate 'compile)
   )
 )




reply via email to

[Prev in Thread] Current Thread [Next in Thread]