시작시 stdin에서 Emacs 읽기 버퍼를 만드는 방법은 무엇입니까? emacs23 – … Emacs starts with an empty

Vim으로 쉽게 할 수 있습니다

$ echo 123 | vim -

이맥스와 관련이 있습니까?

$ echo 123 | emacs23
... Emacs starts with a Welcome message

$ echo 123 | emacs23 -
... Emacs starts with an empty *scratch* buffer and “Unknown option”

$ echo 123 | emacs23 --insert -
... “No such file or directory”, empty *scratch* buffer

유닉스 파이프에서 버퍼를 읽는 것이 실제로 불가능합니까?

편집 : 솔루션으로 다음과 같은 쉘 래퍼를 작성했습니다 emacspipe.

#!/bin/sh
TMP=$(mktemp) && cat > $TMP && emacs23 $TMP ; rm $TMP



답변

stdin에서 버퍼를 읽는 것은 불가능합니다.

Emacs 정보 페이지에서 stdin에 대한 유일한 언급은 this입니다 .

배치 모드에서, 이맥스는 텍스트를 편집중인 표시되지 않으며, 같은 표준 터미널 인터럽트 문자 C-zC-c정상 영향을 계속한다. 기능 prin1, princprint
출력 stdout대신 에코 영역 반면 message, 오류 메시지를 출력 stderr. 미니 버퍼에서 일반적으로 읽는 함수는 stdin대신 입력을받습니다 .

그리고 read함수는에서 읽을 수 stdin있지만 배치 모드에서만 읽을 수 있습니다 .

따라서 맞춤 elisp를 작성하여이 문제를 해결할 수도 없습니다.


답변

프로세스 대체를 사용할 수 있습니다 .

$ emacs --insert <(echo 123)


답변

파일로 리디렉션 한 다음 파일을 열 수 있습니다. 예 :

echo 123 > temp; emacs temp

jweede는 임시 파일을 자동으로 제거하려면 다음을 수행 할 수 있습니다.

echo 123 > temp; emacs temp; rm temp

Emacsy를 수행하는 방법 은 Emacs에서 shell 명령을 실행하는 것 입니다.

M-! echo 123 RET

그러면 명령 결과와 함께 * Shell Command Output *이라는 버퍼가 제공됩니다.


답변

가능합니다 https : //.com/questions/2879746/idomatic-batch-processing-of-text-in-emacs를 참조 하십시오.

다음은 emacs 스크립트에서 에코입니다 (위 링크에서 복사).

#!/usr/bin/emacs --script
(condition-case nil
    (let (line)
      (while (setq line (read-from-minibuffer ""))
        (princ line)
        (princ "\n")))
  (error nil))

또는 버퍼로 읽어서 한 번에 인쇄

#!/usr/bin/emacs --script
(with-temp-buffer
  (progn
    (condition-case nil
    (let (line)
      (while (setq line (read-from-minibuffer ""))
        (insert line)
        (insert "\n")))
      (error nil))
    (princ (buffer-string))
    ))


답변

그건 간단한 쉘 기능을 만들 수 있습니다 (실제로는 그 읽기 임시 파일에 기록되어 있지만)이 표준 입력에서 읽고으로 작동합니다. 사용중인 코드는 다음과 같습니다.

# The emacs or emacsclient command to use
function _emacsfun
{
    # Replace with `emacs` to not run as server/client
    emacsclient -c -n $@
}

# An emacs 'alias' with the ability to read from stdin
function e
{
    # If the argument is - then write stdin to a tempfile and open the
    # tempfile.
    if [[ $# -ge 1 ]] && [[ "$1" == - ]]; then
        tempfile="$(mktemp emacs-stdin-$USER.XXXXXXX --tmpdir)"
        cat - > "$tempfile"
        _emacsfun --eval "(find-file \"$tempfile\")" \
            --eval '(set-visited-file-name nil)' \
            --eval '(rename-buffer "*stdin*" t))'
    else
        _emacsfun "$@"
    fi
}

emacs의 별칭으로 함수를 사용하면됩니다.

echo "hello world" | e -

또는 파일에서 정상적으로

e hello_world.txt

교체 emacs에 의해 emacsclient기능에하는 것은뿐만 아니라 작동합니다.


답변

이것은 작동합니다 :

echo 123 | emacs --insert <(cat)

그러나 어떤 이유로 든 그래픽 모드 이맥 (Gnome, Konsole, GNU Emacs 23.4.1) 만 사용합니다. 명령 :

echo 123 | emacs -nw --insert <(cat)

’emacs : 표준 입력이 tty가 아닙니다’오류가 발생합니다. 원시 텍스트 콘솔에서 시도 할 때 동일한 오류가 나타납니다.


답변

이전 답변 중 언급되지 않은 또 다른 가능성은 /dev/stdin선택한 유닉스 변형이 있으면 사용 하는 것입니다.

/dev/stdinEmacs가 몇 가지 검사를 한 다음보고하기 때문에 직접 열기 만으로는 작동하지 않습니다 Symbolic link that points to nonexistent file. (그리고 Emacs가 파일을로드하도록 허용했다면 /dev/stdin, 사용자가 예상 한대로 거의하지 않는 것처럼 파일을 다시 저장하려고 시도하십시오 .)

그러나 인수 /dev/stdin와 결합 하면 효과 --insert가 있습니다.

echo 123 | emacs --insert /dev/stdin

이 버전은 X를 사용할 때만 작동합니다. 터미널에서 작동하는 솔루션이 필요한 경우 다른 답변을 참조하십시오 .