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

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

Re: build-and-save-all


From: Kevin Rodgers
Subject: Re: build-and-save-all
Date: Thu, 02 Dec 2004 15:00:20 -0700
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

[Please don't top-post.]

Rodrigo Canellas wrote:
> Well, I know that the name of file is 'makefile', so I understand is
> the name of the buffer. I believe there is a function in 'emacs' that
> returns a list of the name of the buffers, and I hope there is another
> one that returns a reference to a buffer given its name, and finally
> another one that makes a buffer the current one, given a reference to
> it.

Actually, buffer-list returns a list of buffers (not their names, nor
"references", which don't exist in Lisp).  And set-buffer is used to
select it.

But none of that is needed, especially since it requires the user to
have already explicitly visited the Makefile, which should not be
necessary.  What I meant was: where in the file system is the project
"makefile", relative to any source file?

For example, here's an implementation that assumes you've created a
"project.dir" symbolic link in each source directory that points to the
project directory:

(defun compile-project ()
  "Compile the project to which this source file belongs."
  (interactive)
  ;; ./project.dir must be a symbolic link to the project directory:
  (let ((default-directory (file-truename "project.dir")))
    (compile "make")))

And here's an implementation that checks the current directory, then its
parent, and so on until it finds a "makefile":

(defun compile-project ()
  "Compile the project to which this source file belongs."
  (interactive)
  ;; The project directory is the closest ancestor directory containing
  ;; a makefile:
  (let* ((default-directory default-directory))
    (while (not (file-exists-p (expand-file-name "makefile"
                                                 default-directory)))
      (when (equal default-directory "/")
        (error "No ancestor \"makefile\" found"))
      (setq default-directory
(directory-file-name (expand-file-name ".." default-directory))))
    (compile "make")))

--
Kevin Rodgers


reply via email to

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