From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Pascal Bourguignon Newsgroups: gmane.emacs.help Subject: Re: Emacs lisp programming help Date: Thu, 16 Mar 2006 08:47:49 +0100 Organization: Informatimago Message-ID: <871wx2g7a2.fsf@thalassa.informatimago.com> References: <1142493303.498132.243470@z34g2000cwc.googlegroups.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1142495436 15333 80.91.229.2 (16 Mar 2006 07:50:36 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 16 Mar 2006 07:50:36 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 16 08:50:32 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FJnFf-0007JG-PZ for geh-help-gnu-emacs@m.gmane.org; Thu, 16 Mar 2006 08:50:32 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FJnFf-00057q-A8 for geh-help-gnu-emacs@m.gmane.org; Thu, 16 Mar 2006 02:50:31 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 39 Original-X-Trace: individual.net 85mEua46ZxI7O+Q4K6IKFggdYgvLIlfqm7wHtzrEGWv5epayMV Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:ErGewKq6fWITLVt0+zlHr0ddy3c= Original-Xref: shelby.stanford.edu gnu.emacs.help:138209 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:33820 Archived-At: yeogirl@gmail.com writes: > Can anyone write me a short emacs list programming which changes its > buffer to corresponding .h or .cc files? > > For example, if I work on a buffer, foo.cc and I want to switch to > buffer foo.h, I like to use a hot key such as meta-h to change to > foo.h. I can also do the same hot key change back to foo.cc. I used to > have the feature in my old machine...but I misplaced the code! > > Anyhelp would be greatly appreciated!! Thank you!! (require 'cl) (defvar *c-sources-extensions* '("cc" "c" "m" "c++" "C")) (defun* swap-h-c () (interactive) (let* ((name (buffer-file-name)) (exte (file-name-extension name))) (cond ((string= "h" exte) (dolist (ext *c-sources-extensions*) (let ((other (format "%s.%s" (file-name-sans-extension name) ext))) (when (file-exists-p other) (find-file other) (return-from swap-h-c)))) (find-file (format "%s.%s" (file-name-sans-extension name) (first *c-sources-extensions*)))) ((member* exte *c-sources-extensions* :test (function string=)) (find-file (format "%s.%s" (file-name-sans-extension name) "h"))) (t (beep))))) -- __Pascal Bourguignon__ http://www.informatimago.com/ This is a signature virus. Add me to your signature and help me to live.