2

I am using (global-company-mode 1) but using remote shell it is annoyingly slow.

How can I disable company mode when I open a shell buffer, but only if it's a remote shell?

The problem manifests when I SSH to a remote server using C-x f /ssh:root@server.com:/ and then M-x shell.

4
  • 1
    This is somewhere between a statement and a description. What's the question? Also, please clarify the description "using remote shell" (especially "using" is unclear and "remote shell" is also a bit vague). – Stefan Jan 20 '20 at 19:56
  • I use find-file and open M-x shell on that location – phoxd Jan 20 '20 at 20:17
  • 1
    I believe I was able to parse out your actual question @phoxd, but in the future, please put a specific question in the body of your question rather than using the title to add the necessary details. A simple "How can I disable company-mode in a shell when it is remote?" would ensure your question is answered and people don't skip over it. – Jordon Biondo Jan 20 '20 at 21:30
  • @JordonBiondo: If you think the question shouldn't be closed, because it's clear to you and it and answers will help others, please edit the question to make it clear. Thx. – Drew Jan 20 '20 at 23:42
1

In order to know that a buffer represents a remote connection, you can use file-remote-p.

You can read about this function Here

For example, in a shell buffer, (file-remote-p default-directory) will allow you to differentiate between a local shell and a remote shell.

In order to toggle company-mode, you can call the company-mode function with a parameter of -1 (negative one).

To perform actions only in a shell buffer, you can add a function hook to the shell-mode-hook list. You can read about what hooks are and how to use them Here

Putting it all together:

  1. Write a function that disables company mode in the current buffer only when it is remote:
(defun my-shell-mode-setup-function () 
  (when (and (fboundp 'company-mode)
             (file-remote-p default-directory))
    (company-mode -1)))
  1. Add this function to your shell-mode-hooks
(add-hook 'shell-mode-hook 'my-shell-mode-setup-function)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.