Coder Social home page Coder Social logo

unhammer / org-rich-yank Goto Github PK

View Code? Open in Web Editor NEW
86.0 5.0 6.0 404 KB

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

Home Page: https://melpa.org/#/org-rich-yank

Emacs Lisp 100.00%
org-mode emacs rich-text clipboard paste yank

org-rich-yank's Introduction

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.

org-rich-yank.gif

Installation

MELPA

If you use 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:

(require 'org-rich-yank)
(define-key org-mode-map (kbd "C-M-y") #'org-rich-yank)

With use-package, enabled after org:

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

(use-package org-rich-yank
  :ensure t
  :demand t
  :bind (:map org-mode-map
              ("C-M-y" . org-rich-yank)))

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.

(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)

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

#+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]]

org-rich-yank's People

Contributors

heikkil avatar leungbk avatar stephenmsachs avatar sunlin7 avatar unhammer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

org-rich-yank's Issues

copying and pasting from web sources?

Sorry for the late reposne (work life et al :))

as discussed would be cool to also apply similar methodology when copying and pasting sections from the web. so that it would paste the text nicely formatted to org with a nice link to the source/URL

best

Z

Support for styling link format

The code that I yank and paste with org-rich-yank is often destined for others via some export backend (e.g. ox-jira, org-mime, one of the numerous markdown backends for some other random input that accepts markdown). Having the link that jumps back to where the code was pulled from is super convenient, but only for me. The file path is typically a distraction for someone else. If it's left in the export, it's not correct without some editing.

I have developed a pattern of prefixing the link with #+comment: so that it's not exported but it's still available for my own use. I think it would be nice to provide some way to customize the format string. Probably I could figure out some type of advice to munge the string automatically but I haven't set out on that adventure yet.

Detect and use the correct src block type when copying from src blog within org-mode

It would be nice if copies from text within a src block in org mode would paste as the src block type the text came from instead of org.

For example, Say I have this text in my org file:

Say Hello world!

#+caption: Shell command with stderr
#+begin_src sh :results output :exports both
  echo "Hello world!"
#+end_src

#+RESULTS:
: Hello world!

If I select just the line echo "Hello world!" copy it and then paste it with org-rich-yank I get:

#+caption: Code Snippet
#+begin_src org
echo "Hello world!"
#+end_src

But it would be nicer if I got:

#+caption: Code Snippet
#+begin_src sh
echo "Hello world!"
#+end_src

If I select the text before the src block including the src block, then I think it makes sense to pase in org src block:

#+caption: Code Snippet
#+begin_src org
Say Hello world!

,#+caption: Shell command with stderr
,#+begin_src sh :results output :exports both
  echo "Hello world!"
,#+end_src
#+end_src

Thanks again for this lovely package. I use it many times a day.

melpha 404 Not found

When I click the "Download" button in https://melpa.org/#/org-rich-yank, I get a HTTP error

$ wget https://melpa.org/packages/org-rich-yank-20240201.921.tar
--2024-03-02 14:12:00--  https://melpa.org/packages/org-rich-yank-20240201.921.tar
Resolving melpa.org (melpa.org)... 137.184.119.165
Connecting to melpa.org (melpa.org)|137.184.119.165|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2024-03-02 14:12:01 ERROR 404: Not Found.

Preserve indentation

I often want to insert code blocks as an element of a list.
Therefore I would put my cursor into the right column and insert the source block. It would be nice then if the whole insertion would respect the initial indentation.

Say, for example, I have copied // Example from a C++ buffer and i have this org buffer with cursor position marked with |:

- item
  |

then I would like to get the following result after yanking:

- item
  #+BEGIN_SRC 
  // Example
  #+END_SRC
  file:example.cpp

Lines that start with asterisk (*) can break src blocks when pasted

If I yank some text while I am viewing an email in mu4e and any of that text has a line starting with * the src block pasted in org-mode with org-rich-yank does not have those lines prefixed with ,.

image

For example

Say I have an email that has the following line:

* I added the index again.

If I yank it and org-rich-yank to paste it into org-mode I get something like the following:

#+begin_src mu4e-view
* I added the index again.
#+end_src
#+comment: Link to copy source: [[mu4e:msgid:CAGY83Edymb8HdALSHRz58-pfoMn33r5wH7Ehy_iyFrtWFvn4Yg@mail.gmail.com][Re: Accelerating a new edition of the book]]

That breaks the src block since the * is at the start of the line. Either the entire content of the src block needs to be indented one or more spaces or the line should be prefixed with ,.

For example:

#+begin_src mu4e-view
 * I added the index again.
#+end_src
#+comment: Link to copy source: [[mu4e:msgid:CAGY83Edymb8HdALSHRz58-pfoMn33r5wH7Ehy_iyFrtWFvn4Yg@mail.gmail.com][Re: Accelerating a new edition of the book]]

or

#+begin_src mu4e-view
,* I added the index again.
#+end_src
#+comment: Link to copy source: [[mu4e:msgid:CAGY83Edymb8HdALSHRz58-pfoMn33r5wH7Ehy_iyFrtWFvn4Yg@mail.gmail.com][Re: Accelerating a new edition of the book]]

Support for other block types than _SRC

Hi

thx so much for your work this is pretty epic :)

i have some small suggestions if you dont mind

  1. would it be possible to pre define the type of src block before pasting? for example if i want the block to be an EXAMPLE block can i specify that before pasting (via perhaps a different command/bind or helm/ivy?)
  2. can this be extended for also copting and pasting from web sources?

thx so much

Z

[spacemacs] org-rich-yank.elc failed to provide feature ‘org-rich-yank’

When starting Emacs with the spacemacs configuration that enables org functionality, the following error message pops up:

org-rich-yank.elc failed to provide feature ‘org-rich-yank’

OS: Ubuntu 18.04 i386
Emacs version: 27.1
org-rich-yank version: 20201115.823

Let me know what else you'd need to begin pinpointing probable causes.
Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.