
Vim을 사용하면 쉽게 할 수 있습니다
$ echo 123 | vim -
Emacs로 할 수 있나요?
$ 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
답변1
맞습니다. stdin에서 버퍼를 읽는 것은 불가능합니다.
Emacs 정보 페이지에서 stdin에 대한 유일한 언급은 다음과 같습니다.이것, 내용은 다음과 같습니다.
배치 모드에서 Emacs는 편집 중인 텍스트를 표시하지 않으며 및 같은 표준 터미널 인터럽트 문자는
C-z
계속C-c
해서 정상적인 효과를 나타냅니다. 함수prin1
및 출력은 에코 영역 대신에 출력princ
되고 , 오류 메시지는 에 출력됩니다 . 일반적으로 미니버퍼에서 읽는 함수는 대신 미니버퍼에서 입력을 받습니다.stdout
message
stderr
stdin
그리고read
함수는 에서 읽을 수 있지만 stdin
배치 모드에서만 읽을 수 있습니다.
따라서 사용자 정의 elisp를 작성하여 이 문제를 해결할 수도 없습니다.
답변2
당신은 사용할 수 있습니다프로세스 대체:
$ emacs --insert <(echo 123)
답변3
파일로 리디렉션한 다음 파일을 열 수 있습니다. 예를 들어
echo 123 > temp; emacs temp
jweede는 임시 파일을 자동으로 제거하려면 다음을 수행할 수 있다고 말합니다.
echo 123 > temp; emacs temp; rm temp
이를 수행하는 Emacsy 방법은 다음과 같습니다.Emacs에서 쉘 명령을 실행하려면.
M-! echo 123 RET
그러면 명령 결과가 포함된 *Shell Command Output*이라는 버퍼가 제공됩니다.
답변4
그것은간단한 쉘 함수 생성 가능이는 stdin에서 읽는 것처럼 작동합니다(실제로는 임시 파일에 쓴 다음 이를 읽습니다). 내가 사용하는 코드는 다음과 같습니다.
# 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
by로 바꾸는 것도 작동합니다.emacsclient