all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Doug Lewan <dougl@shubertticketing.com>
To: lode leroy <lode.leroy@gmail.com>,
	"help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: RE: recompile
Date: Thu, 14 Mar 2013 13:16:08 +0000	[thread overview]
Message-ID: <155DEC68569B714B86C2C7075F5EDA9828EB07EF@DAKIYA1.pegasus.local> (raw)
In-Reply-To: <CA+N9e5bZWK0qfwdvjR1c0S+G3DwAZEvZ5xgWrcyH97o-e=rSWw@mail.gmail.com>

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?



      parent reply	other threads:[~2013-03-14 13:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-13 15:17 recompile lode leroy
2013-03-14  9:23 ` recompile Stephen Berman
2013-03-14 13:16 ` Doug Lewan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=155DEC68569B714B86C2C7075F5EDA9828EB07EF@DAKIYA1.pegasus.local \
    --to=dougl@shubertticketing.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=lode.leroy@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.