2014-12-13 195 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