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: 09 Jan 2003 07:39:01 +0100 Organization: Q Software Solutions GmbH Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <87r8bm6d4q.fsf@fbigm.here> References: <30055c1f.0301070652.62cf0153@posting.google.com> <30055c1f.0301080505.26e1d8d2@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 1042094463 25442 80.91.224.249 (9 Jan 2003 06:41:03 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 9 Jan 2003 06:41:03 +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 18WWNA-0006bw-00 for ; Thu, 09 Jan 2003 07:41:00 +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 18WWMm-0005t3-05 for gnu-help-gnu-emacs@m.gmane.org; Thu, 09 Jan 2003 01:40:36 -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: 57 Original-X-Trace: news.t-online.com 1042094118 00 19413 a04UEFKES-YzYU 030109 06:35:18 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:108760 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:5289 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5289 wildernesscat@hotmail.com (Danny Dorfman) writes: > The thing is, there is no ONE header directory. There are several > header directories, and it would be impractical to feed the directory > every time I switch from one module to another. The macro must find > the path automatically by doing some sort of "search & replace" on the > full pathname (e.g. */src/* -> */inc/*) . I'm sorry, but I'm really > bad at e-lisp, otherwise I would have changed your macro somehow to > make it work for me... Ok I suggest using an association list than. (defvar *dir-match-alist* '(("~/programming/C/" . "~programming/C/") ("/some/path/" . "/some/path/include")) "Asscociation lisp which maps source pathes to appropriate header paths.") (defun load-proper-header-file (&optional buf-name) (interactive) (let* ((src-dir (default-directory)) (hdr-dir (cdr (assoc src-dir *dir-match-alist*))) (file-name (file-name-sans-extension (if buf-name buf-name (buffer-name))))) (find-file (concat hdr-dir file-name ".h")))) This works as follows the first variable is a mapping from one path to another (please do not forget to append the trailing / it should be a dirctory. And you can read it like this: All files in HOME/programming/C will find their header files in the same directory all files in /some/path/ have their header files in /some/path/include The function load-proper-header-file works like this: It tries to figure our in which directory it was called after that it looks through the *dir-match-alist* association list for a matching directory. assoc yield the whole line therefor we take the second element (cdr), which it the directory path to the header files. After that the file-name is build from the buffer name and in the end we load the file which is the concatenation of the header directory part the file name and ".h". This works as intented, but is not very "user-friendly", but it's a starting ground ... Adding elements to the association list can be done with push or acons removing elements with remassoc Regards Friedrich