From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: drkm Newsgroups: gmane.emacs.help Subject: Re: Need help writing file-visiting macro Date: Mon, 25 Jul 2005 23:02:45 +0200 Organization: None Message-ID: References: <1122313927.829340.226930@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1122325814 21020 80.91.229.2 (25 Jul 2005 21:10:14 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 25 Jul 2005 21:10:14 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 25 23:10:12 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DxAD0-00032D-Ne for geh-help-gnu-emacs@m.gmane.org; Mon, 25 Jul 2005 23:09:59 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DxAFJ-0006dl-Tr for geh-help-gnu-emacs@m.gmane.org; Mon, 25 Jul 2005 17:12:21 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!newsfeed.gamma.ru!Gamma.RU!skynet.be!newspost001!tjb!not-for-mail Original-Newsgroups: comp.emacs,gnu.emacs.help User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/22.0.50 (windows-nt) Cancel-Lock: sha1:m66tpgPPtWPHNLVo8s0ptI+9A40= Original-Lines: 31 Original-NNTP-Posting-Host: 8f145054.news.skynet.be Original-X-Trace: 1122325370 news.skynet.be 2328 81.247.184.219:2089 Original-X-Complaints-To: usenet-abuse@skynet.be Original-Xref: shelby.stanford.edu comp.emacs:89761 gnu.emacs.help:132663 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:28184 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:28184 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