2016-10-28 4 views
4

以前のemacsでは、 "M-xシェル"は現在のウィンドウ内のシェルバッファを新しくしました。他のウィンドウのM-xシェルオープンシェル

しかし、最近、EmacsをGNU Emacs 26.0.50.2にアップデートします。 "M-x shell"は他のウィンドウにシェルバッファを追加しました。私はGoogleを検索し、答えを見つけることができませんでした。 誰もこの動作を防ぐ方法を知っていません。

+0

変数 'pop-up-windows'を' nil'に設定してみてください。これで問題は解決しますか? – Drew

答えて

1

shellは、(switch-to-buffer buffer)の代わりに(pop-to-buffer buffer)を使用しているためです。私はどのように機能を助言するのか分からないので、私はあなたに適切な答えを与えることはできません。しかし、あなたが望むようにshellを働かせたいだけなら、あなたの設定に関数全体を加えることができます。

多分、他の誰かがこの機能をアドバイスに置き換えることができます。私はその解決策に興味があります。

(defun shell (&optional buffer) 
    "Run an inferior shell, with I/O through BUFFER (which defaults to `*shell*'). 
Interactively, a prefix arg means to prompt for BUFFER. 
If `default-directory' is a remote file name, it is also prompted 
to change if called with a prefix arg. 

If BUFFER exists but shell process is not running, make new shell. 
If BUFFER exists and shell process is running, just switch to BUFFER. 
Program used comes from variable `explicit-shell-file-name', 
or (if that is nil) from the ESHELL environment variable, 
or (if that is nil) from `shell-file-name'. 
If a file `~/.emacs_SHELLNAME' exists, or `~/.emacs.d/init_SHELLNAME.sh', 
it is given as initial input (but this may be lost, due to a timing 
error, if the shell discards input when it starts up). 
The buffer is put in Shell mode, giving commands for sending input 
and controlling the subjobs of the shell. See `shell-mode'. 
See also the variable `shell-prompt-pattern'. 

To specify a coding system for converting non-ASCII characters 
in the input and output to the shell, use \\[universal-coding-system-argument] 
before \\[shell]. You can also specify this with \\[set-buffer-process-coding-system] 
in the shell buffer, after you start the shell. 
The default comes from `process-coding-system-alist' and 
`default-process-coding-system'. 

The shell file name (sans directories) is used to make a symbol name 
such as `explicit-csh-args'. If that symbol is a variable, 
its value is used as a list of arguments when invoking the shell. 
Otherwise, one argument `-i' is passed to the shell. 

\(Type \\[describe-mode] in the shell buffer for a list of commands.)" 
    (interactive 
    (list 
    (and current-prefix-arg 
     (prog1 
      (read-buffer "Shell buffer: " 
          ;; If the current buffer is an inactive 
          ;; shell buffer, use it as the default. 
          (if (and (eq major-mode 'shell-mode) 
            (null (get-buffer-process (current-buffer)))) 
           (buffer-name) 
          (generate-new-buffer-name "*shell*"))) 
      (if (file-remote-p default-directory) 
       ;; It must be possible to declare a local default-directory. 
       ;; FIXME: This can't be right: it changes the default-directory 
       ;; of the current-buffer rather than of the *shell* buffer. 
       (setq default-directory 
        (expand-file-name 
         (read-directory-name 
         "Default directory: " default-directory default-directory 
         t nil)))))))) 
    (setq buffer (if (or buffer (not (derived-mode-p 'shell-mode)) 
         (comint-check-proc (current-buffer))) 
        (get-buffer-create (or buffer "*shell*")) 
       ;; If the current buffer is a dead shell buffer, use it. 
       (current-buffer))) 

    ;; On remote hosts, the local `shell-file-name' might be useless. 
    (if (and (called-interactively-p 'any) 
      (file-remote-p default-directory) 
      (null explicit-shell-file-name) 
      (null (getenv "ESHELL"))) 
     (with-current-buffer buffer 
     (set (make-local-variable 'explicit-shell-file-name) 
      (file-remote-p 
       (expand-file-name 
       (read-file-name 
       "Remote shell path: " default-directory shell-file-name 
       t shell-file-name)) 
       'localname)))) 

    ;; The buffer's window must be correctly set when we call comint (so 
    ;; that comint sets the COLUMNS env var properly). 
    (switch-to-buffer buffer) 
    (unless (comint-check-proc buffer) 
    (let* ((prog (or explicit-shell-file-name 
        (getenv "ESHELL") shell-file-name)) 
      (name (file-name-nondirectory prog)) 
      (startfile (concat "~/.emacs_" name)) 
      (xargs-name (intern-soft (concat "explicit-" name "-args")))) 
     (unless (file-exists-p startfile) 
     (setq startfile (concat user-emacs-directory "init_" name ".sh"))) 
     (apply 'make-comint-in-buffer "shell" buffer prog 
      (if (file-exists-p startfile) startfile) 
      (if (and xargs-name (boundp xargs-name)) 
       (symbol-value xargs-name) 
       '("-i"))) 
     (shell-mode))) 
    buffer) 
+0

ありがとう、私は関数を更新しようとします。 – yuandaxing

+0

この回答は、OPが以前と同じ動作をしなかった理由を説明していません。 Emacsのコマンド 'shell'は常に' pop-to-buffer'を使って少なくともEmacs 20に戻ります。 – Drew

+1

実際、最近のEmacsのバージョンでは 'shell'は' pop-to-buffer-same-window'を使用しています。 – Drew

5

あなたのシェルバッファの名前をカスタマイズしている場合を除き、これはあなたが必要とするすべてのようになります。

(add-to-list 'display-buffer-alist 
      `(,(regexp-quote "*shell") display-buffer-same-window)) 

すべてのシェルバッファを処理するには、何でも自分の名前、あなたはこのアドバイスを使用することができます。

(defun shell-same-window-advice (orig-fn &optional buffer) 
    "Advice to make `shell' reuse the current window. 

Intended as :around advice." 
    (let* ((buffer-regexp 
      (regexp-quote 
      (cond ((bufferp buffer) (buffer-name buffer)) 
       ((stringp buffer) buffer) 
       (:else    "*shell*")))) 
     (display-buffer-alist 
      (cons `(,buffer-regexp display-buffer-same-window) 
       display-buffer-alist))) 
    (funcall orig-fn buffer))) 

(advice-add 'shell :around #'shell-same-window-advice) 
4

あなたの.emacsファイルに次の行を追加します。

(push (cons "\\*shell\\*" display-buffer--same-window-action) display-buffer-alist) 

これは私のために修正されました。私はMacでeMacs 25.2(9.0)を使用していて、別のフレームで開いているシェル、または1つしかなかったときには新しいフレームであっても、本当に迷惑になりました。 This is the sourceここから私はこの答えを得ました。

+1

私のために働いた。ありがとう! –

関連する問題