tags:

views:

86

answers:

4

I currently bind compile to C-x c. I know I can run compile in comint mode by using C-u C-x c but I'd prefer to just bind it to C-x c directly. I can't fathom how to do this without copying the whole of the compile function from compile.el, tweaking it and binding that. Is there a better way?

Edit: To clarify my sloppy language, I don't wish to bind C-x c whilst in comint mode. I wish to cause C-x c to run 'compile using comint mode. I currently have C-x bound to 'compile. I can do what I want by typing C-u C-x c but I'd prefer to just be able to type C-x c to do that.

A: 

You can do something like this :

(global-set-key [(C-f5)] 'compile)
(global-set-key [(f5)] 'recompile)

It binds compile to C-f5 and each time you want to recompile with the same command as you've given in compile, just type f5. It works whatever the major mode you're currently in.

For your case, do like this :

(global-set-key [?\C-x ?c] 'compile)
Jérôme Radix
+1  A: 

Are you asking for this?

(define-key comint-mode-map (kbd "C-x c") 'compile)
Trey Jackson
+1  A: 

I think this works...

(defun c-w-c ()
  (interactive)
  (call-interactively 'compile t (vector 21 (this-command-keys-vector))))

(global-set-key (kbd "C-x c") 'c-w-c)

the '21' prepended into the vector is the ctrl-u prefix key, and it seems to fool the compile function into thinking it was called with C-u C-x c.

Edit:

It didn't work, but this does:

(defun c-w-c ()
  (interactive)
  (setq current-prefix-arg '(4))
  (call-interactively 'compile))
NikkiA
That works perfectly and is exactly the type of thing I was looking for. Thanks!
Mike Crowe
A: 

This works too:

(define-key comint-mode-map (kbd "C-x c")
  (lambda (command)
    (interactive
     (list
      (let ((command (eval compile-command)))
        (if (or compilation-read-command current-prefix-arg)
            (compilation-read-command command)
          command))))
    (compile command t)))

It's ugly because it duplicates the "interactive" spec from the compile command.

offby1
I'd considered this one but disregarded it because it involved cutting and pasting so much code. Thanks.
Mike Crowe