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: 26 Jul 2005 15:49:10 -0700 Organization: http://groups.google.com Message-ID: <1122418150.845069.119650@f14g2000cwb.googlegroups.com> References: <1122313927.829340.226930@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: sea.gmane.org 1122418391 31842 80.91.229.2 (26 Jul 2005 22:53:11 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 26 Jul 2005 22:53:11 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jul 27 00:53:02 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DxYI7-0008LU-Fb for geh-help-gnu-emacs@m.gmane.org; Wed, 27 Jul 2005 00:52:51 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DxYKU-0004qV-26 for geh-help-gnu-emacs@m.gmane.org; Tue, 26 Jul 2005 18:55:18 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail Original-Newsgroups: comp.emacs,gnu.emacs.help Original-Lines: 47 Original-NNTP-Posting-Host: 198.74.20.74 Original-X-Trace: posting.google.com 1122418156 27777 127.0.0.1 (26 Jul 2005 22:49:16 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Tue, 26 Jul 2005 22:49:16 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: f14g2000cwb.googlegroups.com; posting-host=198.74.20.74; posting-account=C7LM4w0AAAD23IRuMuUUJVCLQTuHhTK8 Original-Xref: shelby.stanford.edu comp.emacs:89771 gnu.emacs.help:132689 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:28212 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:28212 drkm wrote: > rgb writes: > > > (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"))) > > Or more precisely like this (to use '_Impl.c' instead of '.h'): > > (defun my-open-complementary-file () > "If buffer-file-name ends in _Impl.c open .mdl and vise versa." > (interactive) > (let ((buf (buffer-file-name)) > (mdl-re "\\`\\(.+\\)\\.mdl\\'") > (c-re "\\`\\(.+\\)_Impl\\.c\\'")) > (if buf > (if (string-match mdl-re buf) > (find-file (concat (match-string 1 buf) "_Impl.c")) > (if (string-match c-re buf) > (find-file (concat (match-string 1 buf) ".mdl")) > (error "Filename doesn't end in .mdl or _Impl.c: %s" buf))) > (error "Buffer is not visiting a file")))) > > --drkm I've really been throwing out some slop lately. It's embarrassing. (defun my-open-complementary-file () "If buffer-file-name ends in _Impl.c open .mdl and vise versa." (interactive) (cond ((not buffer-file-name) (message "Buffer is not visiting a file")) ((string-match "\\(\\`.*\\)\\.mdl\\'" buffer-file-name) (find-file (concat (match-string 1 buffer-file-name)"_Impl.c"))) ((string-match "\\(\\`.*\\)_Impl\\.c\\'" buffer-file-name) (find-file (concat (match-string 1 buffer-file-name)".mdl"))) (t (message "Buffer's filename doesn't end in .mdl or _Impl.c"))))