From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rupert Swarbrick Newsgroups: gmane.emacs.help Subject: Re: Let compilation start in one directory below current one Date: Wed, 22 Oct 2008 21:16:52 +0100 Organization: albasani.net Message-ID: References: <8e2e1f23-1bd1-4e4b-b063-4078aa0f079f@v72g2000hsv.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: ger.gmane.org 1224708064 17895 80.91.229.12 (22 Oct 2008 20:41:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 22 Oct 2008 20:41:04 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Oct 22 22:42:05 2008 connect(): Connection refused Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KskWe-0003tY-KE for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Oct 2008 22:41:52 +0200 Original-Received: from localhost ([127.0.0.1]:46284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KskVZ-0003pr-0P for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Oct 2008 16:40:45 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!goblin1!goblin.stu.neva.ru!news.albasani.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 134 Original-X-Trace: news.albasani.net Iaj5El66f8n/GM5tKbUnbjeRLUoBByi9FMMJoG9PgH8A3rnPNFL/nMUJzbHiFbYriNdQjOsUYTQ0URzByEE5QEijoi10kS4co1RAjZnNwCycsq3X2QSiHnK50GAZ2gCY Original-X-Complaints-To: abuse@albasani.net Original-NNTP-Posting-Date: Wed, 22 Oct 2008 20:16:38 +0000 (UTC) X-User-ID: g+vN72/a+xqyNkmy8Ch9hLC424hm3BdnDZacwjRrF/M= Cancel-Lock: sha1:T4KEMqqxu5/TqfAXvbnAFHlRHII= User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux) X-NNTP-Posting-Host: yYqfFqq/mI6NNdLRRqErwtF1OFpTCVDlwkkVy4BrpRg= Original-Xref: news.stanford.edu gnu.emacs.help:163703 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:59046 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= "stephan.zimmer" writes: > I would like to start my compilation in one directory deeper than the > current. Unfortunately, a local variable specification as > > % -*- ... compile-directory: (concat default-directory ".."); ... -*- > > is not working. Does anyone has an idea (except adding "cd.." to the > compile command)? > > Stephan You might be interested in the following code. I wrote it some time ago, so try not to cringe too much at the horrendous style, but I've been using it since. Basically, it looks upwards from where you start to try and find a configure.ac, which signals the top of an autoconf/automake project. The selection of filenames to stop at is in the top function. Do what you will with the code - it's in the public domain as far as I'm concerned. Rupert --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=compilepkg.el Content-Transfer-Encoding: quoted-printable (defun compile-pkg (&optional command startdir) "Compile a package, moving up to the parent directory containing configure.ac, if it exists. Start in startdir if defined, else start in the current directory." (interactive) (let ((dirname) (dir-buffer nil)) (setq startdir (expand-file-name (if startdir startdir "."))) (setq command (if command command compile-command)) (setq dirname (upward-find-files '("configure.ac" "configure.in") startdir)) (setq dirname (if dirname dirname (upward-find-file "Makefile" startdir= ))) (setq dirname (if dirname dirname (expand-file-name "."))) ; We've now worked out where to sta= rt. Now we need to worry about ; calling compile in the right dire= ctory (save-excursion (setq dir-buffer (find-file-noselect dirname)) (set-buffer dir-buffer) (compile command) (kill-buffer dir-buffer)))) (defun upward-find-files (filenames startdir) "Move up directories until we find one of a list of filenames. If we manage to find one, return the containing directory. Else if we get to the root directory and still can't find it, return nil. Start at startdir." (let ((dirname startdir) (found nil) ; found is set as a flag to leave loop if we find it (top nil)) ; top is set when we get to / so that we only check it once ; While we've neither been at the t= op last time nor have we found ; the file. (while (not (or found top)) ; If we're at / set top flag. (if (string=3D (expand-file-name dirname) "/") (setq top t)) ; Check for the files (dolist (name filenames) (if (file-exists-p (expand-file-name name dirname)) (setq found t))) (if (not found) (setq dirname (expand-file-name ".." dirname)))) ; return statement (if found dirname nil))) (defun upward-find-file (filename &optional startdir) "Move up directories until we find a certain filename. If we manage to find it, return the containing directory. Else if we get to the toplevel directory and still can't find it, return nil. Start at startdir or . if startdir not given" (let ((dirname (expand-file-name (if startdir startdir ".")))) (upward-find-files (cons filename '()) dirname))) (defvar my-compile-command "make" "The compile command used by std-compile to drive compile-pkg.") (defun switch-compile (prefix-arg) "If compile-command =3D \"make\", switch to \"make install\" and vice versa. With a prefix, prompt for a new command." (interactive "P") =20=20 (setf my-compile-command (cond (prefix-arg (read-from-minibuffer "New compile command: ")) ((string=3D my-compile-command "make") "make install") (t "make"))) (message (concat "Compile command: " my-compile-command))) (defun make-tags () "Make etags in source directory by running compile-pkg with make tags as the command" (interactive) (compile-pkg "make tags")) (defun std-compile () "Like 'compile', but uses compile-pkg" (interactive) (compile-pkg my-compile-command)) --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iJwEAQECAAYFAkj/ijUACgkQRtd/pJbYVoaM9AP/ZOEX5y+yIcj29nYHk0r6/9H8 uBASLl41D89xCO04P9Cxp6KLj/IKsggD+TKEsYhlFPKQqm31BwDIDG+njvQB85AK T0UxAiwfG8iRc4IsC1aE9+KEG4HHxvPt/l6JlVmwhauSWhipEtIOMefY3hOUbcst 8nqVi+1cokNbwkG+pX8= =RRys -----END PGP SIGNATURE----- --==-=-=--