copy/paste from emacs in command line - emacs

I run emacs from command line using the command emacs -nw
However when I do this, and I try to copy paste something from, say, my browser to my emacs session, it returns me the error "kill ring is empty".
Can someone please let me know how I can copy/paste this way? Thanks.

Programs run in terminal sessions don't have access to the windowing system clipboard. Use the cut and paste functionality provided by your terminal emulator. For example, in Gnome's terminal program press C-S-v (shift-control-V) to paste.
Alternatively, if you're using X11 you can use the xsel program to access the X selection. For example, this function will paste the current X selection into the current buffer:
(defun paste-from-x ()
(interactive)
(call-process "xsel" nil t))

Does marking the text you want to copy with the mouse and then pressing Shift-Insert in Emacs work for you?

I think this previous answer of mine might help you:
First you need to install xclip
sudo apt-get install xclip
For Emacs 24
M-x package-list-packages
Select
xclip //mine was version 1.3
Detailed info and other operating systems
https://stackoverflow.com/a/14659015/54848

Related

How to configure simpleclip in emacs terminal mode to copy-paste interchangeably with OS?

I'm using emacs -nw (Emacs 24.5, Ubuntu 16.04). And I found that the default emacs M-w C-y keys don't work interchangeably with the operating system.
After some research, it seems that the most comprehensive solution is to use simpleclip. EmacsWiki says that
simpleclip
You can use https://github.com/rolandwalker/simpleclip which ALWAYS
works.
But looking into its usage guide above, simpleclip makes use of a set of keys that are completely different from the default M-w C-y or the OS Ctrl-Shift-c, Ctrl-Shift-v for copy-paste
;; Press super-c to copy without affecting the kill ring.
;; Press super-x or super-v to cut or paste.
I don't really want to use super key a lot with my PC keyboards, and don't want to remember (or persuade others to remember) yet another set of copy-paste keys.
For the GUI emacs, I can copy something in emacs and paste it into another terminal without any configuration. Mostly, I don't feel that Emacs is any different from gedit except that the emacs copy-paste keys M-w C-y can be used in addition.
In the terminal mode, most of it breaks down. If I use OS copy (Ctrl-Shift-c), one line in emacs can be copied into two or more lines in a target terminal because the line is too long. contents copied using M-w simply do not paste into other programs, even though I tried to set certain variables following other SO questions, e.g.:
(setq x-select-enable-clipboard t)
I'm not very familiar with elisp. My question:
How can I customize or configure simpleclip so that copy-paste in emacs -nw is exactly the same as copy-paste in the OS?
Other related SO questions:
How to copy text from Emacs to another application on Linux
emacs terminal mode: how to copy and paste efficiently
I recommend you use the xclip package, which you can install from GNU ELPA (i.e. via M-x package-list-packages). It requires installation of the xclip utility under X11 (e.g. via aptitude install xclip) and uses the pbcopy/pbpaste under macOS.

Run emacs command in terminal

I'm using Emacs Muse for work reasons and I don't really enjoy editing my .muse files in emacs.
I haven't found alternatives to publishing .muse files in another editor.
Is it possible to run Emacs commands from outside Emacs almost as if using it as a sort of interpreter?
I want to be able to go to the terminal and run something like:
> emacs -ne file_with_command file_to_publish.muse
The command in question is M-x muse-project-publish-this-file
edit: In Emacs, this command also has inputs that it prompts me to give one at a time. It's the style of publishing (html in my case) and the directory where the publication will go to.
muse-project-publish-this-file is not design to use in batch mode.Use muse-publish-file instead.
First,
git clone https://github.com/jwiegley/muse /path/to/muse
Then create script.el with content
(add-to-list 'load-path "/path/to/muse/lisp")
(require 'muse-publish)
(muse-publish-file "file_to_publish.muse" (muse-define-style "newstyle" nil) "/path/to/publish/directory")
notice is /muse/lisp not muse.
Last, emacs --batch -l script.el

Run latex within Emacs

I used to launch latex within Emacs on a .tex file by C-c C-c.
I just changed my machine, and need to reconfigure all. I have already installed texlive-full, and copied .emacs from the previous machine to the new machine.
When I open a .tex file under Emacs, launch C-c C-c, and then type LaTeX, it opens another buffer, named *tex-shell*, and looks like as so:
Could anyone tell me what happened?
I don't really now what happen, but it seem you want to use auctex:
sudo apt-get install auctex
and relaunch Emacs should solve your problem.

How can i paste the selected region outside of emacs?

I am using Mac OS and emacs -nw (the terminal mode).
I don't know how can I paste things (having been implemented by M-w in emacs -nw) outside the emacs.
I know that the emacs -ns can do it.
Searching the internet and the command C-h b, i find out that method, but it didn't work out.
(setq x-select-enable-clipboard t)
(setq interprogram-cut-function 'x-select-text)
I don't know much about the argument of interprogram-cut-function.
Where does the x-select-text come from and what does it mean?
If you are using Ubuntu 12.04 or Fedora 21, there are a couple of options to make this work.
First you need to install xclip
sudo apt-get install xclip
First Option: For Emacs 24
If you are using emacs24 you can install from the list of packages
M-x package-list-packages
Select
xclip //mine was version 1.3
In your .emacs add:
(xclip-mode 1)
Second Option. For emacs before version 24
Install xclip.el:
Integrating Emacs with the X11 Clipboard in Linux
Third Option. Using #Nicholas Riley code shown in the answer
To use the code in the answer you need
pbcopy / pbpaste in Ubuntu (command line clipboard)
x-select-text is only used if you're running Emacs in a GUI. (Emacs maps the Mac/Windows pasteboard/clipboard APIs to the X11 model, hence the name). You can always use C-h f to find out more about a function like this one and view its definition if it's written in elisp.
On the Mac, there is no concept of CLIPBOARD versus PRIMARY selections, so there is no point in setting x-select-enable-clipboard.
The whole point of running emacs -nw is that it doesn't interact with the windowing system. Why use Emacs in a terminal when there are plenty of graphical Emacsen that work very nicely on the Mac?
That said, if you really wanted to hook up terminal Emacs to the Mac pasteboard, you could do something like this:
(setq interprogram-cut-function
(lambda (text &optional push)
(let* ((process-connection-type nil)
(pbproxy (start-process "pbcopy" "pbcopy" "/usr/bin/pbcopy")))
(process-send-string pbproxy text)
(process-send-eof pbproxy))))
If you want a way to place the contents of the emacs region onto the clipboard only sometimes, as opposed to every time you do an emacs yank (which causes the clipboard contents the be overwitten all the time), you should check this answer to a related question:
https://stackoverflow.com/a/19625063/3363328
I found that it solved my problem much better than setting xclip mode.

.emacs Edit to Always Start Emacs in Terminal Mode?

I use emacs as my editor-of-choice, and since I'm doing a lot of work in a terminal I always run emacs as
emacs -nw
so that it runs in the terminal instead of in a window.
I'd like to just run emacs and have it know that it should run in a terminal. My question is - how do I edit my .emacs file so that this is the default behavior?
You can't do this in the .emacs file. By the time that file is being parsed, the "chosen" emacs binary is already running.
You can install the emacs-nox package as one commenter suggests, or create an alias in your shell so that "emacs" is always treated as "emacs -nw".
Randy
I'm using a bash alias instead of .emacs to do that.
Add this line to your ~/.bashrc.
alias emacs='emacs -nw'
There is any easy way to solve the problem in general that has nothing to do with emacs at all and will work for any program that can choose between running in the console vs X:
unset DISPLAY
Of course you may not want to put that in your configuration file to be applied globally to all your shell sessions, so if you want it to apply to only emacs, then either call it from the command line like this:
DISPLAY= emacs
note the space!!! if you leave the space out it means you're setting the DISPLAY to emacs instead of setting DISPLAY to nothing... this command is a shorthand for:
DISPLAY=; emacs
So either use the above from the command line(s) or put that in a wrapper script that would look something like this:
#!/bin/bash
unset DISPLAY
exec emacs
I recommend the exec there because it will replace your wrapper script with emacs; to see the difference between the two you can run:
pstree -p
When I was first setting up a "emacs -nw" alias for emacs in windows I got stuck in a situation where I thought tototoshi's explanation hadn't worked. Yet all that was required was a restart of my terminal. Therefore, i think its worth mentioning that in windows (at least) if you are using emacs within the git bash terminal to create the .bashrc file and add "alias emacs='emacs -nw" to it (as tototoshi mentions) you have to close and reopen your terminal for it to work.