2010-08-31 20 views
3

我目前將編譯綁定到C-x c。我知道我可以通過使用C-u C-x c在comint模式下運行編譯,但我更願意直接將它綁定到C-x c。我無法理解如何從compile.el中拷貝整個編譯函數,調整它並綁定它。有沒有更好的辦法?如何使用comint將編譯綁定到組合鍵

編輯:爲了澄清我的草率語言,我不希望在comint模式下綁定C-x c。我希望導致C-x c運行'使用comint模式編譯。我目前有C-x綁定到'編譯。我可以通過輸入C-u C-x c來完成我想要的操作,但我更願意只鍵入C-x c即可。

回答

3

認爲這個工程......

(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) 

的「21」前面加上入載體是CTRL-U前綴鍵,它似乎欺騙編譯功能,以爲它被稱爲Cu Cx c。

編輯:

它沒有工作,但這:

(defun c-w-c() 
    (interactive) 
    (setq current-prefix-arg '(4)) 
    (call-interactively 'compile)) 
+0

完美的作品,正是我一直在尋找的東西。謝謝! – 2010-09-01 10:51:34

3

你可以做這樣的事情:

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

它結合compileC-F5,你想用相同的命令重新編譯爲您在compile給出,只需鍵入F5每次。它的工作原理,你現在是什麼主要的模式

對於你的情況,這樣做:。

(global-set-key [?\C-x ?c] 'compile) 
1

你問這個?

(define-key comint-mode-map (kbd "C-x c") 'compile) 
0

這工作太:

(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))) 

這是醜陋的,因爲它複製了 「互動」 規範從compile命令。

+0

我曾考慮過這個,但忽略它,因爲它涉及剪切和粘貼這麼多的代碼。謝謝。 – 2010-09-01 10:49:37