From: drkm <usenet@fgeorges.org>
Subject: Re: Need help writing file-visiting macro
Date: Mon, 25 Jul 2005 23:02:45 +0200 [thread overview]
Message-ID: <ud5p6zjii.fsf@fgeorges.org> (raw)
In-Reply-To: 1122313927.829340.226930@z14g2000cwz.googlegroups.com
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
next prev parent reply other threads:[~2005-07-25 21:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-25 13:58 Need help writing file-visiting macro Roy Smith
2005-07-25 15:33 ` Thien-Thi Nguyen
2005-07-25 16:45 ` Roy Smith
2005-07-25 17:44 ` drkm
2005-07-25 16:50 ` Sergei Organov
2005-07-25 17:52 ` rgb
2005-07-25 21:02 ` drkm [this message]
2005-07-26 22:49 ` rgb
2005-07-25 18:05 ` Kevin Rodgers
2005-07-25 21:38 ` Martin Slouf
2005-07-26 15:52 ` Kevin Rodgers
2005-07-26 18:24 ` Martin Slouf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ud5p6zjii.fsf@fgeorges.org \
--to=usenet@fgeorges.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).