From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: recompile Date: Thu, 14 Mar 2013 10:23:56 +0100 Message-ID: <8738vy9vwz.fsf@rosalinde.fritz.box> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1363253067 12053 80.91.229.3 (14 Mar 2013 09:24:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 14 Mar 2013 09:24:27 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 14 10:24:52 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UG4P6-0005fB-CD for geh-help-gnu-emacs@m.gmane.org; Thu, 14 Mar 2013 10:24:52 +0100 Original-Received: from localhost ([::1]:39311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UG4Oj-0008WE-S3 for geh-help-gnu-emacs@m.gmane.org; Thu, 14 Mar 2013 05:24:29 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:43090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UG4OW-0008Vu-RB for help-gnu-emacs@gnu.org; Thu, 14 Mar 2013 05:24:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UG4OU-0001wZ-74 for help-gnu-emacs@gnu.org; Thu, 14 Mar 2013 05:24:16 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:38540) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UG4OU-0001wT-0R for help-gnu-emacs@gnu.org; Thu, 14 Mar 2013 05:24:14 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UG4Ok-0005MS-Dt for help-gnu-emacs@gnu.org; Thu, 14 Mar 2013 10:24:30 +0100 Original-Received: from i59f55f05.versanet.de ([89.245.95.5]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 14 Mar 2013 10:24:30 +0100 Original-Received: from stephen.berman by i59f55f05.versanet.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 14 Mar 2013 10:24:30 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 35 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: i59f55f05.versanet.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89532 Archived-At: On Wed, 13 Mar 2013 16:17:37 +0100 lode leroy wrote: > I want to define a keyboard macro that does the following: > copy the current line, do a few search-and-replace operations and run it in > a shell... > I haven't done anything non-trivial in elisp, so I need some help... > > something along the lines of: > > (defun recompile-current-line > (beginning-of-line) > (set-mark-command) > (end-of-line) > (copy-region-as-kill) > (shell-command > (replace-regexp "^" "cd ~/build && " > current-kill))) > > can someone give some advice on how to implement this? Although you asked for a keyboard macro, your code example is more like a Lisp function definition, so perhaps you'll be satisfied with an Emacs Lisp command. In that case you can just tack a copy of the current line (which is a substring of the buffer) onto the beginning of your shell command string. Does the following do what you want (call it by typing `M-x recompile-current-line')? (defun recompile-current-line () "Execute current line as shell command after cd'ing to ~/build." (interactive) (let ((curline (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) (shell-command (concat "cd ~/build && " curline)))) Steve Berman