Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to push text from another application into the current buffer of Emacs?

Tags:

emacs

I want to make a command-line app that can be used like this:

$push_to_emacs_buffer "some text"

Then the current running Emacs will append some text into its current active buffer.

Any idea on how to achieve that?

like image 349
TomCaps Avatar asked Jun 06 '12 07:06

TomCaps


People also ask

How do I navigate between buffers in Emacs?

To move between the buffers, type C-x b. Emacs shows you a default buffer name. Press Enter if that's the buffer you want, or type the first few characters of the correct buffer name and press Tab. Emacs fills in the rest of the name.

How do you yank text in Emacs?

Kill (Cut), Copy, and Yank (Paste) Commands in Emacs To cut, or kill, the text, you can use the keys Ctrl + k to kill a particular line, or the Ctrl + w command to kill the entire selected region. To paste, or yank, the text, press the keys Ctrl + y.

How do you select all in current buffer in Emacs?

C-x h will select the entire buffer. You can search for help within Emacs using the built-in help system.

What is an Emacs buffer?

Buffers in Emacs editing are objects that have distinct names and hold text that can be edited. Buffers appear to Lisp programs as a special data type. You can think of the contents of a buffer as a string that you can extend; insertions and deletions may occur in any part of the buffer.


1 Answers

Try

emacsclient -e '(with-current-buffer (window-buffer (selected-window)) (insert "some text"))'

On Linux, push-to-emacs-buffer can be implemented like this:

#!/bin/sh

emacsclient -e "(with-current-buffer (window-buffer (selected-window)) \
                  (insert \"$@\"))"
like image 193
huaiyuan Avatar answered Nov 15 '22 08:11

huaiyuan