Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/unhammer/org-rich-yank

📋 Rich text clipboard for org-mode: Paste as a #+BEGIN_SRC block of correct mode, with link to where it came from
https://github.com/unhammer/org-rich-yank

clipboard emacs org-mode paste rich-text yank

Last synced: about 2 months ago
JSON representation

📋 Rich text clipboard for org-mode: Paste as a #+BEGIN_SRC block of correct mode, with link to where it came from

Awesome Lists containing this project

README

        

#+TITLE: org-rich-yank

[[https://melpa.org/#/org-rich-yank][https://melpa.org/packages/org-rich-yank-badge.svg]]

Do you often yank source code into your org files, manually
surrounding it in =#+BEGIN_SRC= blocks? This package will give you a
new way of pasting that automatically surrounds the snippet in blocks,
marked with the major mode of where the code came from, and adds a
link to the source file after the block.

#+ATTR_HTML: :alt org-rich-yank demo
[[file:org-rich-yank.gif][file:org-rich-yank.gif]]

* Installation

** MELPA
If you use [[https://melpa.org/][MELPA]], you can just do =M-x list-packages=, find
=org-rich-yank= in the list and hit =i x=.

** Manual
Just put =org-rich-yank.el= somewhere in =load-path=.

* Usage

** Manual, loading on startup:

To use, require and bind whatever keys you prefer to the
interactive function:

#+BEGIN_SRC emacs-lisp
(require 'org-rich-yank)
(define-key org-mode-map (kbd "C-M-y") #'org-rich-yank)
#+END_SRC

** With use-package, enabled after org:

If you prefer =use-package=, the above settings would be:

#+BEGIN_SRC emacs-lisp
(use-package org-rich-yank
:ensure t
:demand t
:bind (:map org-mode-map
("C-M-y" . org-rich-yank)))
#+END_SRC

The =:demand t= in there is because we never know when the user will
hit =C-M-y=, so we always have to store the current buffer on
kills. You can remove the =:demand t= and have lazy/deferred loading,
but then the first time you hit =C-M-y= after startup, you'll get a
message that you have to kill the selection again.

* Configuration

** Image support

If you have =org-download= installed and you copy image contents,
=org-rich-yank= will defer to =org-download-clipboard=. You can turn
this feature off by setting =org-rich-yank-download-image= to =nil=.

** Changing the link/block format

If you want to change how the source block or link is formatted, you
can do so by setting =org-rich-yank-format-paste= to a function. For
example, links to local files might be useful in your org document but
not so useful in exported content, so you may want to make such a link
a /comment/ line.

#+begin_src emacs-lisp :tangle no
(defun my-org-rich-yank-format-paste (language contents link)
"Based on `org-rich-yank--format-paste-default'."
(format "#+BEGIN_SRC %s\n%s\n#+END_SRC\n#+comment: %s"
language
(org-rich-yank--trim-nl contents)
link))
(customize-set-variable 'org-rich-yank-format-paste #'my-org-rich-yank-format-paste)
#+end_src

Configuring the variable as above results in the following content being pasted:

#+begin_example
,#+BEGIN_SRC emacs-lisp
;; URL: https://github.com/unhammer/org-rich-yank
;; Package-Requires: ((emacs "24.4"))
;; Keywords: convenience, hypermedia, org
,#+END_SRC
,#+comment: [[file:~/src/org-rich-yank/org-rich-yank.el]]
#+end_example