Emacs M-x外壳在其他窗口中打开外壳

Emacs M-x外壳在其他窗口中打开外壳,emacs,emacs24,Emacs,Emacs24,在以前的emacs中,“M-xshell”在当前窗口中新建了一个shell缓冲区 但最近,我将emacs更新为GNU emacs 26.0.50.2。“M-x外壳”在其他窗口中新建外壳缓冲区。我在谷歌上搜索,找不到答案。 有人知道如何防止这种行为。原因是shell使用(弹出到缓冲区)而不是(切换到缓冲区)。我不知道如何建议函数,所以我不能给你一个合适的答案。但是,如果您只希望shell以您想要的方式工作,那么只需在配置中添加整个函数即可 也许其他人可以用一个建议来代替这个功能。我对这个解决方案很

在以前的emacs中,“M-xshell”在当前窗口中新建了一个shell缓冲区

但最近,我将emacs更新为GNU emacs 26.0.50.2。“M-x外壳”在其他窗口中新建外壳缓冲区。我在谷歌上搜索,找不到答案。
有人知道如何防止这种行为。

原因是
shell
使用
(弹出到缓冲区)
而不是
(切换到缓冲区)
。我不知道如何建议函数,所以我不能给你一个合适的答案。但是,如果您只希望
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)

除非您要自定义shell缓冲区的名称,否则您只需要以下内容:

(添加到列表“显示缓冲区列表”
`(,(regexp引号“*shell”)显示缓冲区同一窗口)
要处理所有shell缓冲区,无论其名称如何,您可以使用以下建议:

(defun shell同一窗口通知(原始fn和可选缓冲区)
“建议让“shell”重用当前窗口。
目的是:围绕建议。”
(let*((缓冲区regexp
(regexp报价)
(cond((bufferp buffer)(buffer name buffer))
((stringp缓冲区)缓冲区)
(:else“*shell*”))
(显示缓冲区列表)
(cons`(,buffer regexp显示buffer同一窗口)
显示缓冲区()
(函数源fn缓冲区)))
(建议添加“shell:about#”shell-same-window-advice)

在.emacs文件中添加此行:

(push (cons "\\*shell\\*" display-buffer--same-window-action) display-buffer-alist)
这个给我修好了。我在Mac电脑上使用eMacs 25.2(9.0),对于在另一个帧中打开外壳,甚至在只有一个帧的情况下打开新帧,我感到非常恼火。
我是从哪里得到这个答案的。

这个答案并不能解释为什么OP以前没有看到同样的行为。Emacs命令
shell
总是使用
pop来缓冲
,至少可以追溯到Emacs 20。实际上,在最近的Emacs版本中
shell
使用
pop来缓冲相同的窗口
。很有趣。也许你可以用
defadvice
或在这种情况下使用的任何东西来编辑答案?尝试将变量
弹出窗口设置为
nil
。这能解决问题吗?对我也有帮助。谢谢