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

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

Converting C++ data members to a ctor init list


From: Sarir Khamsi
Subject: Converting C++ data members to a ctor init list
Date: Tue, 24 May 2011 20:00:54 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (windows-nt)

I have some elisp code that converts a C++ data member declaration to a
constructor's member initialization list. It kinda brute force so I'm
looking for suggestions on making it "more better" or more lispy. :-)

(defun sk-convert-to-ctor-init-list ()
  "Convert a C++ member variable declaration to a ctor init list line.
To use this, copy all member variable declarations into the constructor's 
member initialization list area and execute this command on each line. At the 
end of this command, it moves you to the next line setting it up for a key 
binding."
  (interactive)
  (save-excursion
    (save-match-data
      (comment-kill 1) ; delete the comment on the line, if there is one
      (previous-line)
      (delete-blank-lines)
      (end-of-line)
      (delete-horizontal-space)     ; delete whitespace at end of line
      (backward-delete-char-untabify 1) ; delete the ";"
      (insert "(),")
      (search-backward-regexp "[\t *&]") ; look for whitespace, "&" or "*"
      (let ((beg (+ 1 (point)))) ; set start 1 char forward
        (beginning-of-line)
        (delete-region beg (point)))
      (c-indent-command)))
  (next-line 1))

Comments are welcome. Thanks.

Sarir

-- 
Sarir Khamsi
sarir.khamsi@raytheon.com


reply via email to

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