2014-09-01 52 views
2

我已經寫了一些函數附加到我的F5和F6鍵,以便按下時,這些函數評估perl或python的緩衝區內容。異步評估整個python或perl緩衝區

;; F5 = perlevaluatie 
(defun perl-eval() 
    "Run whole buffer as Perl code" 
    (interactive) 
    (shell-command-on-region (point-min) (point-max) "perl") ; feeds the region to perl on STDIN 
) 
(global-set-key (kbd "<f5>") 'perl-eval) 

;; F6 = pythonevaluatie 
(defun python-eval() 
    "Run whole buffer as Python code" 
    (interactive) 
    (shell-command-on-region (point-min) (point-max) "python") 
) 
(global-set-key (kbd "<f6>") 'python-eval) 

但是,當我將這些函數用於持續運行很長時間的腳本時,emacs掛起。追加&與shell-command函數無關。有沒有人知道一種方法來使shell-command-on-region異步?

由於提前,

+1

你看看[quickrun]( https://github.com/syohex/emacs-quickrun)?我發現在emacs上測試我的腳本非常方便。 – ale 2014-09-01 07:14:51

+1

您不能在emacs 24.3.1中異步使用'shell-command-on-region'。在那裏,只有使用同步的命令「call-process-region」才能調用shell。要有一個異步命令,你需要'start-process'和sentinels來觀察啓動進程的執行情況。一個有趣的問題是:如果在腳本運行期間修改了輸入區域,會發生什麼情況? – Tobias 2014-09-01 10:24:22

回答

0

我用compile這個:M-x compileperl <file-name>。第一次運行後,您可以使用重新編譯來重新運行它。

稍微有點時間來鍵入文件的名稱,但你會獲得很多好東西,當然它是異步的。

編輯:獎金輔助函數自動使用編譯第一次然後重新編譯:

(defun my-recompile() 
    "Recompile if possible, otherwise compile current buffer." 
    (interactive) 
    ;; If recompile exists do it, else compile 
    (if (fboundp 'recompile) (recompile) 
    (compile "make -k"))) 

,並在適當的鉤綁定類似

(local-set-key (kbd "<f5>") 'my-recompile) 
(local-set-key (kbd "<C-f5>") 'compile) 
+0

我不明白? Perl或python是腳本語言,爲什麼要編譯它們?如果不將緩衝區保存到文件中,它們不能被運行嗎? – MartenBE 2014-09-02 11:17:50

+0

@MartenBE'compile'可能是一個令人誤解的名稱:它可以用來運行任何shell命令。你必須保存它,但我從來沒有發現這是一個問題(因爲你可以設置'compile'來自動保存緩衝區)。 – dshepherd 2014-09-02 12:32:37