如何使用comint将绑定编译到键组合中

3
我目前将编译绑定到C-x c。我知道可以使用C-u C-x c在comint模式下运行编译,但我更喜欢直接将其绑定到C-x c。我无法想象如何在不复制整个compile函数并进行微调和绑定的情况下完成此操作。有更好的方法吗?
编辑:为澄清我的口头表达不准确,我不希望在comint模式下绑定C-x c。我希望使C-x c运行“使用comint模式编译”。我目前已将C-x绑定到'compile。我可以通过输入C-u C-x c来实现所需的功能,但我更喜欢只需键入C-x c即可完成。
4个回答

3
你可以像这样做:

你可以这样做:

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

它将compile绑定到C-f5,每次您想要使用与您在compile中给出的相同命令重新编译时,只需键入f5。无论您当前处于哪种主模式下,它都可以正常工作。

对于您的情况,请按照以下步骤操作:

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

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前缀键,它似乎欺骗了编译函数,使其认为使用了C-u C-x c调用。

编辑:

这种方法不起作用,但是以下方法可以:

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

那个完美地运作,并且正是我所寻找的类型。谢谢! - Mike Crowe

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命令中复制了“交互式”规范。


我曾考虑过这个方案,但因为涉及到大量的剪切和粘贴代码而放弃了。谢谢。 - Mike Crowe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接