unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "rgb" <rbielaws@i1.net>
Subject: Re: Need help writing file-visiting macro
Date: 26 Jul 2005 15:49:10 -0700	[thread overview]
Message-ID: <1122418150.845069.119650@f14g2000cwb.googlegroups.com> (raw)
In-Reply-To: <ud5p6zjii.fsf@fgeorges.org>

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"))))

  reply	other threads:[~2005-07-26 22:49 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
2005-07-26 22:49     ` rgb [this message]
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=1122418150.845069.119650@f14g2000cwb.googlegroups.com \
    --to=rbielaws@i1.net \
    /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).