From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joseph Brenner Newsgroups: gmane.emacs.help Subject: Re: Making code more Emacs Lisp-like Date: Mon, 02 Nov 2009 12:05:51 -0800 Message-ID: <871vkgzo80.fsf@kzsu.stanford.edu> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1257194452 22965 80.91.229.12 (2 Nov 2009 20:40:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 2 Nov 2009 20:40:52 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 02 21:40:45 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1N53hi-0006vs-LB for geh-help-gnu-emacs@m.gmane.org; Mon, 02 Nov 2009 21:40:42 +0100 Original-Received: from localhost ([127.0.0.1]:45548 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N53hi-000187-8A for geh-help-gnu-emacs@m.gmane.org; Mon, 02 Nov 2009 15:40:42 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!postnews.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.rawbandwidth!news.posted.rawbandwidth.POSTED!not-for-mail Original-NNTP-Posting-Date: Mon, 02 Nov 2009 14:05:50 -0600 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) Cancel-Lock: sha1:KM85RaMOHbpJxpVJpUVu0ge2Png= Original-Lines: 46 X-Usenet-Provider: http://www.giganews.com Original-NNTP-Posting-Host: 198.144.208.84 Original-X-Trace: sv3-zAdOpQyM5mLVX5K16cziazO/OoP2js7pjgxEuPilajbYn+qwtc3q5JVhKS/vqdiCDCB4G7hVfhwtMid!fIKTBHJQ4DBR8QeI5N96lUXgTRa4qZFsAj77wax1lPxafI/n2FWSaGVSuMACcKFED32TnYs/2kE= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Original-Xref: news.stanford.edu gnu.emacs.help:174330 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:69411 Archived-At: Sarir Khamsi writes: > I wrote this function > > (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 > (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 "*" > (set-mark (+ (point) 1)) ; save the current position > (beginning-of-line) > (kill-region (point) (mark)) > (c-indent-command)) > (next-line 1)) > > to take a region that containers C++ code for member variable > declarations and convert it to a constructor's member init list. Is > there a better (or a more ELisp) way than this approach? Thanks. If you look up the Help screen for each function (using the default bindings: cursor to the function, and do a "f1 f"), you'll often see hints on better ways of doing things from inside of elisp. For example, if you look up "set-mark", there's an example that's easily adapted to what you're doing here: > (set-mark (+ (point) 1)) ; save the current position > (beginning-of-line) > (kill-region (point) (mark)) Would become: (let ((beg (point))) (beginning-of-line) (delete-region beg (point))) The goal there is to avoid messing with the kill-ring or the mark history if that's not necessary. Otherwise you may surprise the user with the unwanted side-effects.