unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Converting C++ data members to a ctor init list
@ 2011-04-13 20:30 Sarir Khamsi
  0 siblings, 0 replies; only message in thread
From: Sarir Khamsi @ 2011-04-13 20:30 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-04-13 20:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-13 20:30 Converting C++ data members to a ctor init list Sarir Khamsi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).