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")))) _______________________________________________ Help-gnu-emacs mailing list Help-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnu-emacs