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

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

RE: recompile


From: Doug Lewan
Subject: RE: recompile
Date: Thu, 14 Mar 2013 13:16:08 +0000

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?



reply via email to

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