This plugin is a simple Emacs plugin that allows to interact with the system clipboard when running Emacs without Window System support (e. g when running Emacs from the terminal).
This little plugin is an alternative to
xclip,
but using an Emacs dynamic module, that relies on the
clip library for performing all the
copy/paste logics, instead of executing programs like xcopy
or
pbcopy
for doing so. By doing this, we avoid the necessity of
spawning a new process and waiting for its completion each time the
user wants to copy or paste something from or to the clipboard.
Additionally, this plugin is not intended to define new logics for kill and yank commands, nor new keybindings for interacting with the clipboard in a special way. Instead, the idea behind it is just to port the clipboard functionality that Emacs does by default when running on a windowed environment to a terminal environment.
Steps:
Clone this repo into your .emacs.d folder:
git clone --recursive https://github.com/devcexx/terminal-clip.el
Compile the dynamic module:
cd terminal-clip.el
cmake .
cmake --build .
Edit your init.el
and add the following code for loading the plugin:
(add-to-list 'load-path (concat user-emacs-directory "terminal-clip.el")) ;; Important, add the repository folder into the load-path!
(require 'terminal-clip)
(when terminal-clip-available ;; Enable only when available (no running with a window system, Emacs compiled with module support...)
(terminal-clip-mode t))
Additionally, you may use more complex ways for automatically building the native libraries when starting Emacs. See this code as an example.
The building process requires the Emacs headers. If your Emacs distribution doesn't come with them, you may download them and tell CMake where they are manually:
- Clean the CMake workspace by removing the CMakeCache.txt and CMakeFiles entries.
- Clone the Emacs repo from https://github.com/emacs-mirror/emacs somewhere in your computer and checkout your current version.
- Run CMake like this:
cd <path-to-the-clone-of-this-repo>
CXXFLAGS=-I<path-to-emacs-sources>/src cmake .
cmake --build .
That might be actually normal. In my personal Emacs installation, for some reason, it expects the module to have the extension '.so'. So yeah, can be normal.
This is most likely produced because CMake is trying to ask Emacs what
should be the name of the final modules, but the Emacs executable is
not in the PATH. For fixing that, just clean the CMake cache, and then
retrying execting instead the command: cmake -DEMACS_EXEC_PATH=<path-to-emacs-executable> .