[Top][All Lists]

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

Re: generate methods body (.cpp) from header (.hh)

From: Stefan Reichör
Subject: Re: generate methods body (.cpp) from header (.hh)
Date: Wed, 15 Jun 2005 22:01:18 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Khuong Dinh Pham <address@hidden> writes:

> Where can I find a script where I can generate the methods body from the
> prototypes define the headers?
> Thx in advance

I use the following function to do this:

(defun c++-convert-to-method-body ()
  "Take a function prototype from the class definition and convert it
to the implementation body"
  (let ((class-name)
      (setq doit (looking-at ".+(.*); *$")))
    (if doit
            (re-search-backward "^[^ \t].+\\(\\<\\w+\\>*::\\)")
            (setq class-name (match-string-no-properties 1)))
          (when (looking-at "virtual")
            (message class-name)
            (delete-region (match-beginning 0) (match-end 0)))
          (re-search-forward "(")
          (re-search-backward "[ \t]")
          ;;(forward-char 1)
          (insert " ")
          (insert class-name)
          (delete-region (point) (- (point) 1))
          (insert " {\n\n}\n")
          (next-line 1))
      (message "This line does not contain a valid method declaration"))))

(define-key c++-mode-map [(control c) ?e] 'c++-convert-to-method-body)

Now I copy the function definition from the header file to my cpp file and
hit C-c e.

The function works for most of the method definitions that I use.


reply via email to

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