From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Benjamin Rutt Newsgroups: gmane.emacs.help Subject: Re: .cpp, switch to .h Date: Fri, 13 Feb 2004 23:42:38 -0500 Organization: The Ohio State University Dept. of Computer and Info. Science Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1076733975 5476 80.91.224.253 (14 Feb 2004 04:46:15 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 14 Feb 2004 04:46:15 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Feb 14 05:46:07 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Arrgt-0004Mm-00 for ; Sat, 14 Feb 2004 05:46:07 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1ArrgP-0000Px-3V for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Feb 2004 23:45:37 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!bloom-beacon.mit.edu!129.250.16.78.MISMATCH!peer1.stngva01.us.to.verio.net!news.verio.net!news.maxwell.syr.edu!news.cis.ohio-state.edu!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 22 Original-NNTP-Posting-Host: mu.cis.ohio-state.edu Mail-Copies-To: nobody User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (usg-unix-v) Cancel-Lock: sha1:ZtB2FN8RMkOWvZz/k9MnXwZA3xE= Original-Xref: shelby.stanford.edu gnu.emacs.help:120893 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:16842 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:16842 Daniel Lidstrom writes: > Hello, > > I would like a script that I can bind to Ctrl-Shift-h that will switch > from a .cpp file to the associated .h file, if there is one. For example, > if I have Hash.cpp opened and press the selected keys, emacs switches to > Hash.h. If there is no Hash.h nothing is done. Any help appreciated. > Thanks! Looks only in the same directory as the .cpp file: (defun my-goto-h-file () (interactive) (when (string-match "\\.cpp$" (buffer-file-name)) (let* ((h-file (format "%s.h" (file-name-sans-extension (buffer-file-name))))) (when (file-exists-p h-file) (find-file h-file))))) (define-key c++-mode-map (kbd "C-S-h") 'my-goto-h-file) -- Benjamin