質問

GNOMEターミナルでは、Bashはスマートな自動補完を行います。例

apt-get in<TAB>

なる

apt-get install

Emacsシェルモードでは、 / etc / bash_completion を明示的にソースした後でも、この自動補完は機能しません。上記の例は、有効な apt-get コマンドオプションではなく、現在のディレクトリ内のファイル名で in またはオートコンプリートのままです。おそらく、これはEmacsがTabキーの押下をインターセプトしているためです。 shell-mode でスマート自動補完を有効にするにはどうすればよいですか?

役に立ちましたか?

解決

この質問は3年前のものですが、解決にも興味があります。 Web検索により、Emacsにシェルモードでの補完にbashを使用させるelispの一部に導かれました。いずれにせよ、私にとってはうまくいきます。

https://github.com/szermatt/emacs-bash-completion で確認してください。

他のヒント

emacsシェルでは、bashではなくemacsが実際に自動補完を実行します。シェルとemacsが同期していない場合(pushd、popd、またはシェルの現在のディレクトリを変更するbashユーザー関数を使用するなど)、自動補完は動作を停止します。

これを修正するには、シェルに「dirs」と入力するだけで、同期が取れます。

.emacsには次のものもあります:

(global-set-key "\M-\r" 'shell-resync-dirs)

Esc-returnキーを押すと、オートコンプリートが再同期されます。

これに対する答えはわかりません。しかし、期待どおりに動作しない理由は、おそらくemacsシェルでの補完が内部的に(comint-dynamic-complete関数によって)emacsによって処理され、それらのスマートな補完関数が組み込まれていないためです。 / p>

修正するのは簡単なことではないようです。

編集:njsfによるterm-modeの使用の提案は、おそらくそれと同じくらい良いでしょう。

M-x term
で開始します これは標準のemacsディストリビューションに含まれています(少なくともUbuntuとDebianのemacs21-commonまたはemacs22-commonにあります)。

マトリのように、bashは--noeditingで開始され、TABはcomint-dynamic-completeにバインドされているため、簡単なタスクではありません。

おそらく、tabをlocal-set-keyを使用してshell-comand-hookのself-insert-commandに再バインドできます M-x customize-variable RET explicit-bash-argsによる--noeditingでシェルモードが開始されないようにしますが、他のすべての編集ではうまく動作しないと思われます。

term-modeを試してみたいと思うかもしれませんが、他の通常のキーバインドのいくつかはterm-modeに取って代わられるため、別の一連の問題があります。

編集:他の通常のキービッドがterm-modeに取って代わることで、バッファーを切り替えることができるエスケープとなるC-c以外のすべてを意味します。したがって、バッファを殺すためにC-x kの代わりにC-c C-x kをしなければなりません。または、別のバッファー「C-c C-x o」または「C-c C-x 2」に切り替えるには

別のモード Mx term を検討してください。2011年に問題が発生したときにこれを行いました。 。しかし、 term-mode に直面して代替案を発見したので、 eshell を試してさえいません。

これは完全なターミナルエミュレータであるため、Midnight Commanderのように内部でインタラクティブなプログラムを実行できます。または、 zsh の完了に切り替えて、Emacsの設定に時間がかからないようにします。

無料でbashでTAB補完を取得します。しかし、さらに重要なのは、インクリメンタルまたはプレフィックス付きコマンド検索のような完全なReadlineパワーを取得することです。このセットアップをより便利にするには、 .inputrc 。bashrc 。emacs

.inputrc の必須部分:

# I like this!
set editing-mode emacs

# Don't strip characters to 7 bits when reading.
set input-meta on

# Allow iso-latin1 characters to be inserted rather than converted to
# prefix-meta sequences.
set convert-meta off

# Display characters with the eighth bit set directly rather than as
# meta-prefixed characters.
set output-meta on

# Ignore hidden files.
set match-hidden-files off

# Ignore case (on/off).
set completion-ignore-case on

set completion-query-items 100

# First tab suggests ambiguous variants.
set show-all-if-ambiguous on

# Replace common prefix with ...
set completion-prefix-display-length 1

set skip-completed-text off

# If set to 'on', completed directory names have a slash appended. The default is 'on'.
set mark-directories on
set mark-symlinked-directories on

# If set to 'on', a character denoting a file's type is appended to the
# filename when listing possible completions. The default is 'off'.
set visible-stats on

set horizontal-scroll-mode off

$if Bash
"\C-x\C-e": edit-and-execute-command
$endif

# Define my favorite Emacs key bindings.
"\C-@": set-mark
"\C-w": kill-region
"\M-w": copy-region-as-kill

# Ctrl+Left/Right to move by whole words.
"\e[1;5C": forward-word
"\e[1;5D": backward-word
# Same with Shift pressed.
"\e[1;6C": forward-word
"\e[1;6D": backward-word

# Ctrl+Backspace/Delete to delete whole words.
"\e[3;5~": kill-word
"\C-_": backward-kill-word

# UP/DOWN filter history by typed string as prefix.
"\e[A": history-search-backward
"\C-p": history-search-backward
"\eOA": history-search-backward
"\e[B": history-search-forward
"\C-n": history-search-forward
"\eOB": history-search-forward

# Bind 'Shift+TAB' to complete as in Python TAB was need for another purpose.
"\e[Z": complete
# Cycling possible completion forward and backward in place.
"\e[1;3C": menu-complete                    # M-Right
"\e[1;3D": menu-complete-backward           # M-Left
"\e[1;5I": menu-complete                    # C-TAB

.bashrc (YEA!〜/ .bash_history の任意の単語からBashにdabbrevがあります):

set -o emacs

if [[ $- == *i* ]]; then
  bind '"\e/": dabbrev-expand'
  bind '"\ee": edit-and-execute-command'
fi
用語バッファーでのナビゲーションを快適にする

.emacs

(setq term-buffer-maximum-size (lsh 1 14))

(eval-after-load 'term
  '(progn
    (defun my-term-send-delete-word-forward () (interactive) (term-send-raw-string "\ed"))
    (defun my-term-send-delete-word-backward () (interactive) (term-send-raw-string "\e\C-h"))
    (define-key term-raw-map [C-delete] 'my-term-send-delete-word-forward)
    (define-key term-raw-map [C-backspace] 'my-term-send-delete-word-backward)
    (defun my-term-send-forward-word () (interactive) (term-send-raw-string "\ef"))
    (defun my-term-send-backward-word () (interactive) (term-send-raw-string "\eb"))
    (define-key term-raw-map [C-left] 'my-term-send-backward-word)
    (define-key term-raw-map [C-right] 'my-term-send-forward-word)
    (defun my-term-send-m-right () (interactive) (term-send-raw-string "\e[1;3C"))
    (defun my-term-send-m-left () (interactive) (term-send-raw-string "\e[1;3D"))
    (define-key term-raw-map [M-right] 'my-term-send-m-right)
    (define-key term-raw-map [M-left] 'my-term-send-m-left)
    ))

(defun my-term-mode-hook ()
  (goto-address-mode 1))
(add-hook 'term-mode-hook #'my-term-mode-hook)

C-x o などの通常のコマンドがターミナルエミュレーションモードで機能しないので、キーマップを次のように拡張しました。

(unless
    (ignore-errors
      (require 'ido)
      (ido-mode 1)
      (global-set-key [?\s-d] #'ido-dired)
      (global-set-key [?\s-f] #'ido-find-file)
      t)
  (global-set-key [?\s-d] #'dired)
  (global-set-key [?\s-f] #'find-file))

(defun my--kill-this-buffer-maybe-switch-to-next ()
  "Kill current buffer. Switch to next buffer if previous command
was switching to next buffer or this command itself allowing
sequential closing of uninteresting buffers."
  (interactive)
  (let ( (cmd last-command) )
    (kill-buffer (current-buffer))
    (when (memq cmd (list 'next-buffer this-command))
      (next-buffer))))
(global-set-key [s-delete] 'my--kill-this-buffer-maybe-switch-to-next)
(defun my--backward-other-window ()
  (interactive)
  (other-window -1))
(global-set-key [s-up] #'my--backward-other-window)
(global-set-key [s-down] #'other-window)
(global-set-key [s-tab] 'other-window)

super キーを使用しているため、 term-raw-map およびその他のキーマップがキーバインディングと競合しないことに注意してください。左の Win キーから super キーを作成するには、 .xmodmaprc を使用します:

! To load this config run:
!   $ xmodmap .xmodmaprc

! Win key.
clear mod3
clear mod4

keycode 133 = Super_L
keycode 134 = Hyper_R
add mod3 = Super_L
add mod4 = Hyper_R

2つのコマンドを覚えておく必要があります。 Cc Cj -通常のEmacs編集モード(バッファーテキストでのコピーまたはgrepの入力)、 Cc Ck -に戻る端末エミュレーションモード。

マウス選択と Shift-Insert は、 xterm と同様に機能します。

Preludeを使用し、Meta + Tabを押すと完了します。

また、Ctrl + iは同じことをするようです。

ヘルムモードを使用します。この機能があります(&quot; TAB&quot;を押した後): ここに画像の説明を入力してください

emacsの専門家であると主張することはありませんが、これで問題が解決するはずです:

作成:〜/ .emacs

追加:

( 'shell-commandが必要) (shell-command-completion-mode)

Emacsがシェルを引き継ぐので、BASH設定は引き継がれません。これにより、EMACS自体の自動補完が設定されます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top