From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "rgb" Newsgroups: gmane.emacs.help Subject: Re: Need help writing file-visiting macro Date: 25 Jul 2005 10:52:07 -0700 Organization: http://groups.google.com Message-ID: <1122313927.829340.226930@z14g2000cwz.googlegroups.com> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: sea.gmane.org 1122314022 14560 80.91.229.2 (25 Jul 2005 17:53:42 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 25 Jul 2005 17:53:42 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 25 19:53:41 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Dx792-0007Cf-2p for geh-help-gnu-emacs@m.gmane.org; Mon, 25 Jul 2005 19:53:40 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dx7BK-0006ti-P1 for geh-help-gnu-emacs@m.gmane.org; Mon, 25 Jul 2005 13:56:02 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail Original-Newsgroups: comp.emacs,gnu.emacs.help Original-Lines: 24 Original-NNTP-Posting-Host: 198.74.20.73 Original-X-Trace: posting.google.com 1122313933 15274 127.0.0.1 (25 Jul 2005 17:52:13 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Mon, 25 Jul 2005 17:52:13 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=198.74.20.73; posting-account=C7LM4w0AAAD23IRuMuUUJVCLQTuHhTK8 Original-Xref: shelby.stanford.edu comp.emacs:89757 gnu.emacs.help:132646 Original-To: help-gnu-emacs@gnu.org 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:28165 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:28165 Roy Smith wrote: > I'm working in a software development system which has classes defined > in foo.mdl files, with the corresponding implementation code in > foo_Impl.c files I want to write a macro or function which lets you > flip back and forth between the two. If I'm looking at a .mdl file, I > want it to construct the corresponding _Impl.c filename and visit that > file. Is that possible? > > I'm using GNU Emacs 21.3.1. (defun my-open-complementary-file () "If buffer-file-name ends in .h open .mdl and vise versa." (interactive) (if buffer-file-name (if (string-match "\\(\\`.*\\.\\)mdl\\'" (buffer-file-name)) (find-file (concat (match-string 1 (buffer-file-name))"h")) (if (string-match ".*\\.h\\'" (buffer-file-name)) (find-file (concat (match-string 1 (buffer-file-name))"mdl")) (message "Buffer's filename doesn't end in .mdl or .h"))) (message "Buffer is not visiting a file"))) Don't expect to get this kind of service all the time!