From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Masatake YAMATO Newsgroups: gmane.emacs.devel Subject: Re: naming convention based file toggling facility Date: Thu, 25 Sep 2003 16:20:42 +0900 (JST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <20030925.162042.198212664.jet@gyve.org> References: <1064473652.1354.41.camel@lan1> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1064475662 29923 80.91.224.253 (25 Sep 2003 07:41:02 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 25 Sep 2003 07:41:02 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Thu Sep 25 09:41:00 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1A2QkG-0003L5-00 for ; Thu, 25 Sep 2003 09:41:00 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1A2QrK-0001XU-00 for ; Thu, 25 Sep 2003 09:48:18 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.22) id 1A2QQx-0001ls-Mz for emacs-devel@quimby.gnus.org; Thu, 25 Sep 2003 03:21:03 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.22) id 1A2QQj-0001j7-VI for emacs-devel@gnu.org; Thu, 25 Sep 2003 03:20:49 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.22) id 1A2QQh-0001i1-Po for emacs-devel@gnu.org; Thu, 25 Sep 2003 03:20:48 -0400 Original-Received: from [210.130.136.40] (helo=r-maa.spacetown.ne.jp) by monty-python.gnu.org with esmtp (Exim 4.22) id 1A2QQh-0001gR-2N for emacs-devel@gnu.org; Thu, 25 Sep 2003 03:20:47 -0400 Original-Received: from localhost (mx.jp.redhat.com [219.96.218.186]) by r-maa.spacetown.ne.jp (8.11.6) with ESMTP id h8P7Kgs15681; Thu, 25 Sep 2003 16:20:42 +0900 (JST) Original-To: rwa@alumni.princeton.edu In-Reply-To: <1064473652.1354.41.camel@lan1> X-Mailer: Mew version 3.1.52 on Emacs 21.3 / Mule 5.0 (SAKAKI) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:16615 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:16615 > I've had a hackish little elisp function for years that always struck me > as a slightly surprising omission from emacs: the ability to toggle > between files based on a naming convention like: .c and > .h. M-x ff-find-other-file may be useful. I have another implementation. Masatake YAMATO ;; c-alt.el --- Find header file or implementation file ;; Copyright (C) 2000 Masatake YAMATO ;; Author Masatake YAMATO ;; Created: Tue Jun 4 17:00:22 1996 ;; Time-stamp: <00/10/12 20:30:48 masata-y> ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2 of the License, or ;; (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program; if not, write to the Free Software ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ;; Commentary: ;; ;; Put .emacs ;; ;; (add-hook 'c-mode-hook (function (lambda () ;; (define-key c-mode-map "\C-c\C-v" 'c-find-alternative-file)))) ;; (autoload 'c-find-alternative-file "c-alt" "Find .c or .h file" t) ;; Histroy ;; * Thu Oct 12 20:06:36 2000 ;; Added c++ supports (defun c-find-alternative-file (arg) "TODO" (interactive "P") (let* ((fname (buffer-file-name)) (basename (file-name-sans-extension fname)) (afname nil) (baselen (length basename)) (ext (substring fname (1+ baselen)))) (cond ((or (string= ext "c") (string= ext "m") (string= ext "cpp")) (setq afname (concat basename ".h")) (if (file-exists-p afname) (find-file afname) (if arg (find-file afname) (if (y-or-n-p (format "Cannot find! Create %s?: " afname)) (find-file afname) )) )) ((string= ext "h") (if (or (progn (setq afname (concat basename ".m")) (file-exists-p afname)) (progn (setq afname (concat basename ".c")) (file-exists-p afname)) (progn (setq afname (concat basename ".cpp")) (file-exists-p afname))) (find-file afname) (let ((newext (call-interactively 'c-get-alternative-file-name))) (setq afname (concat basename (cond ((eq newext ?+) ".cpp") ((eq newext ?c) ".c") ((eq newext ?m) ".m") ((eq newext ?n) "") ((eq newext ?y) ".c") (t "") ))) (if (not (eq newext ?n)) (if (not (eq baselen (length afname))) (find-file afname) (error "Wrong extension: %c" newext)))))) (t (error "No alternative file for: %c" fname))))) (defun c-get-alternative-file-name (ext) (interactive "cCannot find! Create?(type n(No) c(C), m(ObjC) or +(C++)): ") ext) (provide 'c-alt) ;; c-alt.el ends here.