Code Monkey home page Code Monkey logo

copy-as-format's Introduction

copy-as-format

MELPA

Emacs function to copy buffer locations as GitHub/Slack/JIRA etc... formatted code

copy-as-format demo

Supported Formats/Services

  • AsciiDoc
  • Bitbucket
  • Disqus
  • GitHub
  • GitLab
  • โšฐ HipChat
  • HTML
  • JIRA
  • Markdown
  • MediaWiki
  • Org-mode
  • POD
  • reStructuredText
  • Slack
  • Telegram
  • WhatsApp

Usage

M-x copy-as-format or C-u M-x copy-as-format

Copy the current line or active region and add it to the kill ring as GitHub/Slack/JIRA... formatted code. Format defaults to copy-as-format-default. The buffer will not be modified.

With a prefix argument prompt for the format.

M-x copy-as-format-SERVICE

Where SERVICE is one of the supported services.

It's a good idea to bind these functions to a key sequence:

(global-set-key (kbd "C-c w s") 'copy-as-format-slack)
(global-set-key (kbd "C-c w g") 'copy-as-format-github)

For AsciiDoc customization see copy-as-format-asciidoc-include-file-name and copy-as-format-asciidoc-language-alist.

Adding Formats

Create a format function with a signature of TEXT MULTILINE:

  • TEXT - the text to be formatted
  • MULTILINE - t if TEXT spans multiple lines, otherwise nil

For example:

(defun some-great-format (text multiline)
  (if multiline
      (multiline-format text)
    (single-line-format text)))

Then, add an entry to copy-as-format-format-alist. The key is the format's name and the value is the format function:

(add-to-list 'copy-as-format-format-alist '("great-format" some-great-format))

See Also

copy-as-format's People

Contributors

mavit avatar sshaw avatar syohex 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

copy-as-format's Issues

Add a Reddit option

Reddit confuses people a lot, because its current default front-end supports code formatting options which are not supported by the old front-end (and reddit has shown no interest in fixing this long-standing problem). Consequently people using the default front-end have no idea that the code they paste is liable to look incredibly broken for many of their readers, unless someone points it out to them.

The single formatting technique which is compatible between the old and the new is to indent everything by 4 spaces. If copy-as-format had a reddit option which did that, that would help to reduce the number of broken posts seen at https://old.reddit.com/r/emacs

better api for programmatic use

right now the only api is the copy-as-format function which inspects the prefix argument and relies on the region being active.

it would be nice to have a public function that would take two positions (begin and end) and a format argument (string, t to prompt for format, nil for default format) that would copy the text in between those two positions using the specified format.

something like this:

(defun copy-as-format-positions (beg end &optional format)
  ...)

this would allow for better use in custom commands, and also for better integration with evil-mode, which has its own concepts to define various regions (e.g. with text objects).

even better, there should be an option to not copy but only return the formatted text, which would mean it can be used in other functions.

what do you think about this? i could come up with a pr if you agree this makes sense to have.

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.