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

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

Re: How to set the Makefile directory in emacs


From: Stefan Monnier
Subject: Re: How to set the Makefile directory in emacs
Date: Sat, 09 Jun 2007 15:36:00 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

> Hi, I am editing a project with source files in many different
> subfolders. I wonder if I can set in emacs the default folder in wich the
> Makefile is, so that when I issue the command "make -k" emacs run it in
> the correct folder no matter where is the file I am editing.

You can try the following:

(defun compilation-find-file-up (regexp)
  "Look up the directory hierarchy for a file matching REGEXP."
  (catch 'found
    (let ((user (nth 2 (file-attributes default-directory)))
          ;; Abbreviate, so as to stop when we cross ~/.
          (dir (abbreviate-file-name default-directory))
          files)
      (while (and dir (equal user (nth 2 (file-attributes dir))))
        (if (setq files (directory-files dir 'full regexp))
            (throw 'found (car files))
          (if (equal dir
                     (setq dir (file-name-directory
                                (directory-file-name dir))))
              (setq dir nil))))
      nil)))

and then

(setq compile-command
  '(let ((mf (compilation-find-file-up "\\`\\(GNU\\)?[Mm]akefile\\'")))
     (if mf (setq mf (file-name-directory mf)))
     (concat (if (and mf (not (equal mf default-directory)))
                 (format "cd %s; "
                         (shell-quote-argument
                          (file-relative-name
                           (directory-file-name mf)))))
             "make -k ")))


-- Stefan


reply via email to

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