2012-02-23 25 views
1

我想在emacs中開始使用eshell來代替bash,但是我非常依賴多年來我寫的bash函數。我想配置eshell來調用bash,只要有一個「command not found」條件發生,以防有問題的命令作爲bash函數實現。如何爲emacs定義一個替代命令eshell

有一個變量引人入勝地命名爲eshell-alternate-command-hook,聽起來像它是爲了排序,但我缺乏elisp技能是干擾我的成功,我認爲。

這是我最大的努力:

(add-hook 'eshell-alternate-command-hook 'invoke-bash t t) 
(defun invoke-bash (command args) 
    (throw 'eshell-replace-command 
    (list "bash -c" command args))) 

但是當我測試了一下,這是行不通的:

c:/temp $ lsd 
Wrong number of arguments: (lambda (command args) (throw (quote eshell-replace-command) (list "bash -c" command args))), 1 
c:/temp $ 

回答

1

這是我終於想出了:

(defun invoke-bash (command) 
(progn 
    (setq invoke-bash-cmd (concat "bash -c \"" command " " (mapconcat 'identity eshell-last-arguments " ") "\"")) 
    (message invoke-bash-cmd) 
    (throw 'eshell-replace-command 
    (eshell-parse-command invoke-bash-cmd)))) 
+0

嘗試這樣的:https://gist.github.com/1903146,雖然我沒有嘗試過 –

+0

謝謝,我看到,預測是退化和沒有必要的,雖然它似乎並沒有工作,當我用'讓'而不是'setq'。 (也許我做錯了) – wytten

+0

奇怪的是,'let'不適合你。 'let'的主要目的是在本地環境中創建變量。在你的代碼中,因爲'invoke-bash-cmd'沒有在本地上下文中聲明,所以它將是全局變量 –

0

我不是ESHELL大師,但在地方,這個鉤子我看到它只接收一個參數 - 命令,你試圖執行,所以你的代碼可能看起來像

(add-hook 'eshell-alternate-command-hook 'invoke-bash) 
(defun invoke-bash (command) 
    (throw 'eshell-replace-command 
    (list "bash -c" command))) 

但是它不起作用,因爲你需要返回elisp函數,而不是命令的名稱(根據文檔)。如果你想運行bash,那麼你需要返回字符串的完整路徑,但我還沒有找到如何將其他參數傳遞給bash。也許你可以在corresponding section on Emacs Wiki找到更多信息?

+0

這幫助;我已經得到了進一步,但再次被卡住了:'(defun invoke-bash(command) (throw'eshell-replace-command (eshell-parse-command(concat「bash -c」command eshell-last-arguments) )) ' 如果參數是「pom.xml」,我得到消息'錯誤類型參數:字符',pom.xml'',所以我覺得我現在已經很近了。 – wytten

相關問題