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

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

Re: Emacs lisp programming help


From: Pascal Bourguignon
Subject: Re: Emacs lisp programming help
Date: Thu, 16 Mar 2006 08:47:49 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

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.


reply via email to

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