2013-04-10 3 views
2

기존 eshell 버퍼에 명령을 보내고 명령이 끝날 때까지 기다리고 다른 명령을 보내는 elisp 기능을 작성했습니다. 예를 들어, 내가 보내려 :eslip에서 eshell로 명령 보내기

python 
2+3 

를 지금까지 내가 실패, 다음을 시도 :

process-send-stringaccept-process-output 사용하는 eshell 과정을 1.Getting :

(process-send-string eshell-proc "python") 
(accept-process-output eshell-proc 100) 

을하지만, 나는 eshell 프로세스를 얻을 수 없습니다. (get-buffer-process (current-buffer))은 현재 버퍼가 eshell 인 경우 nil을 반환합니다.

, 버퍼에 명령을 2.Inserting (eshell-send-input)을 사용하고 다음 명령을 전송하기 전에 조금 자고 :

(progn 
(insert "python") 
(eshell-send-input) 
(sleep-for 1) 
(insert "2+3") 
(eshell-send-input)) 

이 방법의 문제는 "+ 3 2"는 이전에 보내지는 것입니다 파이썬 하위 프로세스가 시작되었습니다. 이것은 내가 잠자고있는 시간에 관계없이 발생합니다. 잠자는 동안 이맥스의 모든 하위 프로세스가 정지 된 것 같습니다.

3.Using eshell-gather-process-output : 내가 사용하는 경우 다음 중 하나를

(eshell-gather-process-output "/usr/bin/python" nil) 

또는

내가 할
(eshell-gather-process-output "/usr/bin/python" (list "somearg")) 

Debugger entered--Lisp error: (wrong-type-argument arrayp nil)

하지만 사용하는 경우 :

(eshell-gather-process-output "/usr/bin/python" (vector "somearg")) 

내가 얻을 Debugger entered--Lisp error: (wrong-type-argument listp ["somearg"])

그래서 나는이 명령이 예상하는 인수의 유형에 관해서 정말로 혼란 스럽다. 이 명령의 사용 예를 한 번도 찾을 수 없었습니다.

왜 이렇게 간단한 것이 그렇게 복잡합니까? 어떤 입력을 주셔서 감사합니다

+0

1 - eshell이 ​​외부 프로세스를 시작하지 않으므로이 프로세스가 작동하지 않습니다. 보낼 프로세스가 없습니다. 2 나를 위해 작동합니다. – Tyler

+0

2는 매우 약한 솔루션입니다. 시스템의로드에 따라 하위 프로세스를 시작하는 데 걸리는 시간이 달라집니다. 이 솔루션에서는 필자가 만날 것으로 예상되는 최대로드 시간을 하드 코딩하고 매번이 시간을 기다리는 것으로 제한됩니다.이것이 제가 대안을 원한다는 이유입니다. – erjoalgo

답변

1

나는 당신이 말하는 것을 보았습니다. 그러나 이것은 실제로 "이맥스"일을하는 것처럼 보이지 않습니다. 파이썬 모드로 버퍼를 열고 파이썬 인터프리터에 2 + 2라고 말하는 영역을 보낼 수 있습니다. 이 과정은 당신이 명령을 보낼 프로세스 인터페이스를위한 유사합니다

(defun python-shell-send-string (string &optional process msg) 
    "Send STRING to inferior Python PROCESS. 
When MSG is non-nil messages the first line of STRING." 
    (interactive "sPython command: ") 
    (let ((process (or process (python-shell-get-or-create-process))) 
     (lines (split-string string "\n" t))) 
    (and msg (message "Sent: %s..." (nth 0 lines))) 
    (if (> (length lines) 1) 
     (let* ((temporary-file-directory 
      (if (file-remote-p default-directory) 
       (concat (file-remote-p default-directory) "/tmp") 
       temporary-file-directory)) 
      (temp-file-name (make-temp-file "py")) 
      (file-name (or (buffer-file-name) temp-file-name))) 
     (with-temp-file temp-file-name 
     (insert string) 
     (delete-trailing-whitespace)) 
     (python-shell-send-file file-name process temp-file-name)) 
    (comint-send-string process string) 
    (when (or (not (string-match "\n$" string)) 
      (string-match "\n[ \t].*\n?$" string)) 
    (comint-send-string process "\n"))))) 

: 또는 당신은 특히,이 기능을

(python-shell-send-string "2 + 2") 

을하거나 파이썬 모드의 소스 좀 걸릴 수 있습니다 에서 이맥스에게. 위의 함수 코드를 살펴보면 파이썬 모드가 필요한 프로세스를 가져 오거나 시작하는 것을 볼 수 있습니다.이 경우에는 파이썬 인터프리터입니다.