From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Friedrich Dominicus Newsgroups: gmane.emacs.help Subject: Re: How to automate file-opening (derived filename)? Date: 07 Jan 2003 19:19:47 +0100 Organization: Q Software Solutions GmbH Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <87heckhlfg.fsf@fbigm.here> References: <30055c1f.0301070652.62cf0153@posting.google.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1041969500 5637 80.91.224.249 (7 Jan 2003 19:58:20 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 7 Jan 2003 19:58:20 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18Vzre-0001Sn-00 for ; Tue, 07 Jan 2003 20:58:18 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18VzRQ-0006dK-08 for gnu-help-gnu-emacs@m.gmane.org; Tue, 07 Jan 2003 14:31:12 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.online.be!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 65 Original-X-Trace: news.t-online.com 1041963369 01 5765 c5cUEVaSSOA2-O 030107 18:16:09 Original-X-Complaints-To: abuse@t-online.com X-Sender: 320004655587-0001@t-dialin.net User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Military Intelligence) Original-Xref: shelby.stanford.edu gnu.emacs.help:108709 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:5227 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5227 wildernesscat@hotmail.com (Danny Dorfman) writes: > Hi! > > I need to devise an e-lisp macro, that would do the following: > Assume I am now looking at a file named "/a/b/c/ZZZ/d/e.cpp", I'd like > the macro to open "/a/b/c/YYY/d/e.h" for me. The elements a,b,c,d,e > are unknown in advance, while elements ZZZ and YYY are a constant part > of the path. > How do I do this? (My understanding of e-lisp is pretty basic). I have changed the question slightly. I do not think that having a separate source directory makes very much sense, because you wrote "I am now looking at a file ..." That means you have an open buffer with the contents of the file in it. Now what makes sense is having a separate directory for header files. Anyway I do think for one project you won't have diverse header directories but one. With that assumptioins this is my shot (let (hdr-dir) (defun load-proper-header-file (&optional buf-name) (interactive) (unless hdr-dir (setf hdr-dir (read-from-minibuffer "Header directory: " (default-directory)))) (let ((file-name (file-name-sans-extension (if buf-name buf-name (buffer-name))))) (find-file (concat hdr-dir file-name ".h"))))) Emacs Lisp is not lexically scoped therefor hdr-dir can be accesses any time. So the base idea is that you just give it the Header directory once. If you later decide it should be changed you just can reset it with (setf hdr-dir nil) The next time you call load-proper-header-file you will get prompted for the new Header directory, of course you could add something along this lines (defun set-hdr-dir (dir) (interactive "DHeader directory: ") (setf hdr-dir dir)) if you like Now the next simplification I did was that I just drop the extension and replace it with the ".h" prefix. dropping the extension is be done with file-name-sans-extension building the new file name with (concat ... Because I was thinking the way you'll use it will work like this: a) visit a C(PP) file b) you than have that file in a buffer c) you than want to load the appropriate header without getting prompted about the name everytime you prefer just something along M-x load-proper-header-file and the file-name is automatically constructed and loaded. Now with (buffer-name) do I get the name of the current buffer, so this is my "default" value. If that does not work you have to use M-: (load-proper-headerfile "some-cpp-file-name") Regards Friedrich