Как включить табуляцию только в режиме term-line-mode

694
godblessfq

У меня установлен режим компании. Когда я нажимаю вкладку в режиме термина, она всегда вызывает компанию завершена. Я пытался отключить режим компании с

(global-company-mode '(not (equal major-mode 'term-mode))) 

Также следующее не работает

(add-hook 'term-mode-hook (lambda() (company-mode 0) (global-unset-key (kbd "<tab>")))) 

Я попробовал другой подход с этим

(defun term-send-tab() (interactive) (term-send-raw-string "\t"))  (define-key term-raw-map (kbd "TAB") 'term-send-tab) (define-key term-raw-map (kbd "<tab>") 'term-send-tab) 

Все не удалось. Любая помощь будет оценена!

2
Ваша первая строка не имеет смысла. Попробуйте `(setq company-global-mode '(не term-mode))`. dgutov 9 лет назад 0
Это отключает режим компании для режима термина. Как включить режим компании только в режиме term-line? godblessfq 9 лет назад 0
Это не тривиально: `term-line-mode` не является основным или второстепенным режимом. dgutov 9 лет назад 0

1 ответ на вопрос

2
godblessfq

I solved it with my customised function my-tab with some code written by phil.I bind tab key to my-tab, it will send a raw tab when in term-char-mode and do complete in other cases, also two quick tab will do yas-expand, by binding yas-next-field to "M-n", tab completion even works inside a snippet expansion.

The problem is when company and yasnnipet has the same prefix, then tab only do completion. Is it possible to set a delay time for company completion after tab key press, make it greater than my-double-key-timeout, so double tab will do yas-expand, if the user want company completion, he can just type one tab and wait. (sovled with sit for)

I don't know why I can't just bind tab to send a raw tab in term-raw-map.

(defvar my-double-key-timeout 0.25 "The number of seconds to wait for a second key press.") (defun my-tab () "Move to the beginning of the current line on the first key stroke, and to the beginning of the buffer if there is a second key stroke within `my-double-key-timeout' seconds." (interactive) (let ((last-called (get this-command 'my-last-call-time)) ) (is-term (string= "term-mode" major-mode))) (if (and is-term (term-in-char-mode)) (term-send-raw-string "\t") (if (and (eq last-command this-command) last-called (<= (time-to-seconds (time-since last-called)) my-double-key-timeout)) (yas-expand) (if (sit-for my-double-key-timeout) (complete-indent-fold))) (put this-command 'my-last-call-time (current-time)))) (defun complete-indent-fold() (interactive) (if (looking-at outline-regexp) (if (equal major-mode 'org-mode) (org-cycle) (my-outline-cycle)) (if (looking-at "\\_>") (company-complete) (indent-for-tab-command)))) 

Please help me make this better. Thank you!

Похожие вопросы