help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: .cpp, switch to .h


From: Benjamin Rutt
Subject: Re: .cpp, switch to .h
Date: Fri, 13 Feb 2004 23:42:38 -0500
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (usg-unix-v)

Daniel Lidstrom <someone@microsoft.com> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]