[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Need help writing file-visiting macro
From: |
rgb |
Subject: |
Re: Need help writing file-visiting macro |
Date: |
25 Jul 2005 10:52:07 -0700 |
User-agent: |
G2/0.2 |
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!