Skip to content

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

License

Notifications You must be signed in to change notification settings

jmromer/yankee.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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 ~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.

GitHub-flavored 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))
```
<sup>
  <a href="https://github.com/jmromer/yankee.el/blob/ea278931/yankee.el#L158-L163">
    yankee.el#L158-L163 (ea278931)
  </a>
</sup>

which produces this output:

https://cloud.githubusercontent.com/assets/4433943/26434857/271536bc-40d9-11e7-93f9-fe0988975259.png

GitHub-flavored Markdown (foldable)

(The summary line is customizable at runtime)

<details>
<summary>yankee/current-commit-ref</summary>

```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))
```
<sup>
  <a href=https://github.com/jmromer/yankee.el/blob/ea278931/yankee.el#L158-L163">
    yankee.el#L158-L163 (ea278931)
  </a>
</sup>
</details>

which produces this output:

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

which produces this output:

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

yankee.el#L158-L163 (517300b3)

Jira

{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]

which renders as follows:

https://user-images.githubusercontent.com/4433943/39444725-b02dadb2-4c86-11e8-9a04-b03e6fd4503e.png

Demo

(Click to view animated)

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

;; ~/spacemacs.d/init.el
(require 'yankee)

Suggested keybindings for evil-mode

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

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published