all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* recompile
@ 2013-03-13 15:17 lode leroy
  2013-03-14  9:23 ` recompile Stephen Berman
  2013-03-14 13:16 ` recompile Doug Lewan
  0 siblings, 2 replies; 3+ messages in thread
From: lode leroy @ 2013-03-13 15:17 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 493 bytes --]

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?

[-- Attachment #2: Type: text/html, Size: 580 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: recompile
  2013-03-13 15:17 recompile lode leroy
@ 2013-03-14  9:23 ` Stephen Berman
  2013-03-14 13:16 ` recompile Doug Lewan
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Berman @ 2013-03-14  9:23 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: recompile
  2013-03-13 15:17 recompile lode leroy
  2013-03-14  9:23 ` recompile Stephen Berman
@ 2013-03-14 13:16 ` Doug Lewan
  1 sibling, 0 replies; 3+ messages in thread
From: Doug Lewan @ 2013-03-14 13:16 UTC (permalink / raw)
  To: lode leroy, help-gnu-emacs@gnu.org

lode leroy,

The following might do roughly what you want.

    (defun recompile-current-line ()
      "Rerun the command on the current line in the ~/build directory."
      (interactive)
      (let* ((line-text (buffer-substring-no-properties 
			 (line-beginning-position)
			 (line-end-position)))
	     (compile-command (concat "cd ~/build && " line-text)))
	(shell-command compile-command)))

There are probably a couple things worth doing if you expect to have more tasks that need automation.

1. Learn emacs lisp. (You've already hinted at this. The next steps should help you with this.)
2. Name, save, study and edit your keyboard macros. (More below.)
3. Read the introduction to emacs lisp, `info "Emacs Lisp Intro"' brings it up. The table of contents alone gives a good idea of what is possible.
4. Use steps 2 & 3 to learn emacs lisp.

Regarding keyboard macros: `C-x C-k e' brings up special buffer for editing keyboard macros. It also contains hints (sometimes wrong unfortunately) about the corresponding lisp functions involved. Here's one that inserts "foo" with some corrections.

    Macro:

    f                   ;; self-insert-command
    ooo                 ;; self-insert-command * 3
    C-b                 ;; backward-char
    C-k                 ;; kill-line
    C-n                 ;; next-line

The corresponding elisp functions are on the right. They suggest the following function definition:

(defun insert-foo-extravagantly ()
  "Insert `foo' extravagantly with some mistakes."
  (interactive)
  (insert "fooo")
  (backward-char)
  (kill-line)
  (next-line))

I hope this helps.


,Douglas
Douglas Lewan
Shubert Ticketing
(201) 489-8600 ext 224

Journalism is printing what someone else does not want printed. Everything else is public relations. - George Orwell

From: help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org [mailto:help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org] On Behalf Of lode leroy
Sent: Wednesday, 2013 March 13 11:18
To: help-gnu-emacs@gnu.org
Subject: recompile

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?



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-03-14 13:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-13 15:17 recompile lode leroy
2013-03-14  9:23 ` recompile Stephen Berman
2013-03-14 13:16 ` recompile Doug Lewan

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.