2014-12-13 194 views
1

Emacs新手在这里。我想在打开makefile时在分割窗口中启动eshell。因此,我增加了以下内容我.emacsEmacs意外地将缓冲区切换到临时缓冲区

(add-hook 
    'makefile-mode-hook 
    (lambda() 
    (progn 
     (split-window-right 110) 
     (other-window 1) 
     (eshell) 
     (other-window 1)))) 

我得到的ESHELL按计划进行,但是,从生成文件到临时缓冲区我原来的缓冲开关,原因不明。为什么是这样?另外,如果我省略了eshell调用和最后一个“other-window”,我仍然会得到scratch缓冲区。

回答

0

试试这个代码,我刚刚熟了起来:

(add-hook 'window-configuration-change-hook 
      'makefile-open-eshell) 

(defvar makefile-eshell-in-progress nil) 

(defun makefile-open-eshell() 
    (interactive) 
    (unless makefile-eshell-in-progress 
    (when (memq major-mode 
       '(makefile-mode makefile-gmake-mode)) 
     (let ((dir (file-name-directory (buffer-file-name))) 
      (window (cl-find-if 
        (lambda (window) 
         (with-current-buffer (window-buffer window) 
         (eq major-mode 'eshell-mode))) 
        (window-list)))) 
     (if window 
      (with-current-buffer (window-buffer window) 
       (unless (file-equal-p dir (eshell/pwd)) 
       (eshell/cd dir) 
       (eshell-send-input))) 
      (let ((makefile-eshell-in-progress t)) 
      ;; (delete-other-windows) 
      (split-window-right) 
      (other-window 1) 
      (eshell) 
      (eshell/cd dir) 
      (eshell-send-input) 
      (other-window -1))))))) 

,当你切换到 Makefile中应该始终打开适当ESHELL。

使用此停止疯狂:

​​
+0

这个工程在启动时,但拆分ESHELL窗口时,我从ESHELL退出或试图杀死它的缓冲区中(不良行为),而且更重要的是我还不知道为什么这个工作或为什么我的原始版本不。 – 2014-12-13 16:21:56

+0

你不应该在这个代码的Makefile之前杀死eshell。 无论如何,你的问题的答案是:'(other-window -1)',可能。 – 2014-12-13 16:24:40

+0

'other-window -1'没有帮助。为了澄清事情,我只想打开一个文件并在拆分窗口中打开一个文件夹,我不需要任何更奇特的东西。 – 2014-12-13 17:08:25