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

https://github.com/jmromer/yankee.el

Yank your code in VCS-annotated GFM or Org-mode source blocks
https://github.com/jmromer/yankee.el

emacs emacs-lisp github-flavored-markdown markdown org-mode

Last synced: 7 months ago
JSON representation

Yank your code in VCS-annotated GFM or Org-mode source blocks

Awesome Lists containing this project

README

          

* yankee.el

Yankee extends ~copy-as-format~ to provide a function for yanking source blocks
in Emacs with helpful annotations to help readers gain more context:

- ~yankee-yank~

These are especially useful when composing issues and pull/merge requests on
GitHub / GitLab / Bitbucket, but have broader utility as well. See the full list
of supported formats (and how to add your own) at [[https://github.com/sshaw/copy-as-format][~copy-as-format~]].

If the yanked region is in a project, its path relative to the project root will
be used to annotate the code block with a comment that including the selected
line numbers.

If not in a project, an abbreviated absolute path will be included instead.

Additionally, if the buffer being yanked from is backed by a file under version
control, a commit ref will be included.

# And lastly, if the yanked region is committed to version control, a hyperlink to
# the selection, at the correct commit ref, will be included as well. (Currently,
# only Git is supported.)

** GitHub-flavored Markdown

#+BEGIN_SRC markdown
```emacs-lisp
;; yankee.el L158-L163 (ea278931)

(defun yankee/current-commit-ref ()
"The current commit's SHA, if under version control.
Currently only supports Git."
(if (equal 'Git (vc-backend (buffer-file-name)))
(substring (shell-command-to-string "git rev-parse HEAD") 0 8)
nil))
```


yankee.el#L158-L163 (ea278931)


#+END_SRC

which produces this [[https://github.com/jmromer/yankee.el/pull/1#user-content-gfm][output]]:

#+CAPTION: yank-as-gfm-code-block
#+NAME: fig: gfm
[[https://cloud.githubusercontent.com/assets/4433943/26434857/271536bc-40d9-11e7-93f9-fe0988975259.png]]

** GitHub-flavored Markdown (foldable)

(The summary line is customizable at runtime)

#+BEGIN_SRC markdown

yankee/current-commit-ref

```emacs-lisp
;; yankee.el L158-L163 (ea278931)

(defun yankee/current-commit-ref ()
"The current commit's SHA, if under version control.
Currently only supports Git."
(if (equal 'Git (vc-backend (buffer-file-name)))
(substring (shell-command-to-string "git rev-parse HEAD") 0 8)
nil))
```


yankee.el#L158-L163 (ea278931)

#+END_SRC

which produces this [[https://github.com/jmromer/yankee.el/pull/1#user-content-gfm-foldable][output]]:

#+CAPTION: yank-as-gfm-code-block-foldable
#+NAME: fig: gfm-foldable
[[https://cloud.githubusercontent.com/assets/4433943/26434858/271fbf6a-40d9-11e7-91fb-66511c42cdc2.gif]]

** Org mode

NB: The `BEGIN_SRC` tag is intentionally broken here for display purposes.

#+BEGIN_SRC org
#+BEGIN SRC emacs-lisp
;; yankee.el L158-L163 (517300b3)

(defun yankee/current-commit-ref ()
"The current commit's SHA, if under version control.
Currently only supports Git."
(if (equal 'Git (vc-backend (buffer-file-name)))
(substring (shell-command-to-string "git rev-parse HEAD") 0 8)
nil))
#+END SRC
[[https://github.com/jmromer/yankee.el/blob/517300b3/yankee.el#L158-L163][yankee.el#L158-L163 (517300b3)]]
#+END_SRC

which produces this output:

#+BEGIN_SRC emacs-lisp
;; yankee.el L158-L163 (517300b3)

(defun yankee/current-commit-ref ()
"The current commit's SHA, if under version control.
Currently only supports Git."
(if (equal 'Git (vc-backend (buffer-file-name)))
(substring (shell-command-to-string "git rev-parse HEAD") 0 8)
nil))
#+END_SRC
[[https://github.com/jmromer/yankee.el/blob/517300b3/yankee.el#L158-L163][yankee.el#L158-L163 (517300b3)]]

** Jira

#+BEGIN_SRC
{code:python}
# testproj/articles/models.py L4-L9 (ee46f59fb1)

class Article(models.Model):
title = models.CharField(help_text="title model help_text", max_length=255, blank=False, unique=True)
body = models.TextField(help_text="article model help_text", max_length=5000, blank=False)
slug = models.SlugField(help_text="slug model help_text", unique=True, blank=True)
date_created = models.DateTimeField(auto_now_add=True)
date_modified = models.DateTimeField(auto_now=True)
{code}

[testproj/articles/models.py#L4-L9 (ee46f59fb1)|https://github.com/axnsan12/drf-yasg/blob/ee46f59fb1/testproj/articles/models.py#L4-L9]
#+END_SRC

which renders as follows:

#+CAPTION: yank-as-jira-code-block
#+NAME: fig: jira
[[https://user-images.githubusercontent.com/4433943/39444725-b02dadb2-4c86-11e8-9a04-b03e6fd4503e.png][https://user-images.githubusercontent.com/4433943/39444725-b02dadb2-4c86-11e8-9a04-b03e6fd4503e.png]]

** Demo

(Click to view animated)

#+CAPTION: yankee.el demo
#+NAME: fig: yankee-demo
[[https://cloud.githubusercontent.com/assets/4433943/26436253/2afd53f4-40e3-11e7-9791-b671042755d4.gif]]

** Installation

To install, load yankee.el and require ~yankee~ (the following assumes the
project's parent directory has been added to the ~load-path~):

#+BEGIN_SRC emacs-lisp
;; ~/spacemacs.d/init.el
(require 'yankee)
#+END_SRC

*** Suggested keybindings for evil-mode

Spacemacs and Evil-mode users may find the following key bindings intuitive:

#+BEGIN_SRC emacs-lisp
;; ~/spacemacs.d/init.el
(define-key evil-visual-state-map (kbd "g y") #'yankee/yank)
#+END_SRC