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

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

Re: recompile


From: Stephen Berman
Subject: Re: recompile
Date: Thu, 14 Mar 2013 10:23:56 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

On Wed, 13 Mar 2013 16:17:37 +0100 lode leroy <lode.leroy@gmail.com> 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




reply via email to

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