i have the following command in my .vimrc:
nmap gtb texecute "!perl /home/hermann/hi.pl ".shellescape(getline('.'), 1)
it executes a perl script and sends whichever line the cursor is over, to it.
how do i send to the script whatever is in the copy-paste buffer instead?
There is no single 'copy-paste' buffer in Vim, there is a set of named registers instead. You can get the contents of a register using getreg function - it has a single argument, register name. For example, use this to get the contents of a default yank/paste buffer:
getreg('0')
you can use the 'normal' function to paste the clipboard contents.
function MyPastingFunc()
"paste from clipboard
normal! "+p
"do more stuff
endfunction
Related
I'm looking for a solution to copy the command prompt's current content to the clipboard. I know something similar is possible by redirecting the output or using clip but I'm looking for something else. I'm looking for a command which copies the entire content of the command prompt window to the clipboard/a file anytime when it's called(not just the output of one command). It's quite easy to do manually by selecting everything and press ctrl-c but I need a command for this.
Basically it should achieve the same as doskey /history > somefile.txt but saving the output of the commands too.
Is something like this possible?
you can use simple java program , to get the entire content of the command prompt and out it into a String variable or write it to txt file
If I'm in a term-mode buffer and there is a file path displayed, how would I go about making the path "clickable", opening the file in a new buffer? It doesn't have to be mouse-clickable, in fact I'd prefer a key binding that works when the point is on the file path. Other than the common case of using ls, this function could be used when viewing a log file. Some debug info contains the file path and line number. Something like lib/library.rb:34 for example. Ideally, Emacs could open a new buffer and move the cursor to line 34.
The short answer is: don't work against Emacs. Let Emacs work for you.
While you can use find-file-at-point or put together something yourself, you will be much better off running make, grep and other stuff which prints "dir/file:pos" using M-x compile or M-x grep.
If you need to interact with your program which prints "dir/file:pos", you can pass a prefix argument to compile and the compilation buffer will be interactive.
If you have an arbitrary program whose output starts with "dir/file:pos", e.g., rails server, all you need to do is run it as (grep "rails server").
When using magic %paste in ipython, it executes pasted code, rather than just pasting. How can i get it to just paste the copied code so that it can be edited?
You have two options:
To edit it by hand, run %cpaste. Then you can paste it in with standard terminal options (try Ctrl-Shift-V), and edit it. Enter -- on a line to finish.
To change it as text in your code, run %paste foo. It will store the clipboard contents in foo.
Adding to Thomas K's answer (quoted below), if you have stored statements to a string variable foo by using %paste foo, you can later run that string (or any python statements in string form) using the exec(foo [, globals, locals]).
You have two options:
To edit it by hand, run %cpaste. Then you can paste it in with standard terminal options (try Ctrl-Shift-V), and edit it. Enter --
on a line to finish.
To change it as text in your code, run %paste foo. It will store the clipboard contents in foo.
There is a solution for this issue in ipython, if you are not concerned with indentation,
Just run %autoindent to Automatic indentation OFF.
How to make Emacs run a program and don't wait for output/respond? I tried to open a pdf in an external program:
(shell-command (concat "start sumatrapdf " (shell-quote-argument path) " -page " search))))
But it won't open another files until the existing sumatrapdf process is closed. I tried async-shell-command, but it opens a new buffer with Async output which I don't need.
What is the right way to open files in external programs?
start-process function can handle that:
(start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)
Start a program in a subprocess. Return the process object for it.
NAME is name for process. It is modified if necessary to make it unique.
BUFFER is the buffer (or buffer name) to associate with the process.
Process output (both standard output and standard error streams) goes
at end of BUFFER, unless you specify an output stream or filter
function to handle the output. BUFFER may also be nil, meaning that
this process is not associated with any buffer.
PROGRAM is the program file name. It is searched for in `exec-path'
(which see). If nil, just associate a pty with the buffer. Remaining
arguments are strings to give program as arguments.
If you want to separate standard output from standard error, invoke
the command through a shell and redirect one of them using the shell
syntax.
If you don't want to associate bufer with open process — pass nil as BUFFER argument
See C-h k M-!
...
If COMMAND ends in ampersand, execute it asynchronously. The output
appears in the buffer `Async Shell Command'. That buffer is in shell
mode.
...
IOW, M-! my_command --opt=foo arg1 arg2 & will start my_command and create a *Async Shell Command* buffer with my_command running in it but emacs will give control back to you right away.
I would like to write a small script in ELisp that would:
send a command to a given buffer
get its output
parse it
send it to another buffer
I am struggling with point 2: I cant get the output of a command. For example, if I have a shell buffer on, I can use
(process-send-string "shell" "help\n")
to send "help" to my shell buffer. It will then show the list of the commands available. But how can I get this list to use it somewhere else?
Thanks,
S4m
(buffer-string) returns the contents of the current buffer, so (with-current-buffer <buf> (buffer-string)) will return the contents of <buf>.
I don't know the exact emacs commands for this off the top of my head, but one option would be to do the following:
Set the mark in the shell buffer right below the command line
Execute the command.
Move the point to the end of the file and kill the text between there and the mark.
Move to the destination buffer and yank the text into there.
Have you considered using the shell-command or shell-command-to-string functions?
The don't "send a command to a buffer" like you asked, but they do both allow running a command through a process that will be started just for that purpose and either dumping the output into a target buffer or collecting it into a string.