How to link compint with comint with keyboard shortcut

I am currently associating compilation with Cx c. I know that I can run comint compilation using Cu Cx c, but I would prefer to just bind it to Cx c directly. I cannot figure out how to do this without copying the entire compilation function from compile.el, without setting it up, and without linking it. Is there a better way?

Edit: To clarify my inaccurate language, I don't want to bind Cx c during comint mode. I want to force Cx c to start compilation using comint mode. I currently have Cx tied to compilation. I can do what I want by typing Cu Cx c, but I would rather just type Cx c to do this.

+3
source share
4 answers

I think it 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" added to the vector is the ctrl-u prefix key, and it seems to be deceiving the compilation function, thinking it was called with Cu Cx c.

Edit:

This did not work, but it does:

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

You can do something like this:

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

It associates compilewith C-f5and every time you want to recompile the same command as you, in compile, just type f5. It works regardless of the main mode you are currently in.

In your case, do the following:

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

?

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

:

(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

Source: https://habr.com/ru/post/1762470/


All Articles