• Stars
    star
    316
  • Rank 129,671 (Top 3 %)
  • Language
    Emacs Lisp
  • Created over 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Insert org-mode links from clipboard

http://melpa.org/packages/org-cliplink-badge.svg https://travis-ci.org/rexim/org-cliplink.svg?branch=master https://coveralls.io/repos/rexim/org-cliplink/badge.svg

org-cliplink

http://i.imgur.com/oA0birm.gif

A simple command that takes a URL from the clipboard and inserts an org-mode link with a title of a page found by the URL into the current buffer.

This code was a part of my Emacs config almost a year. I decided to publish it as a separate package in case someone needs this feature too.

Usage

org-cliplink

Bind org-cliplink function to something. For example, put this line in your init file:

(global-set-key (kbd "C-x p i") 'org-cliplink)

Then copy any http/https URL to the clipboard, switch to the Emacs window and hit C-x p i.

org-cliplink-capture

org-cliplink version for org-capture templates. Makes synchronous request. Returns the link instead of inserting it to the current buffer. Doesn’t support Basic Auth. Doesn’t support cURL transport.

Here is how it’s supposed to be used in org-capture-templates:

(setq org-capture-templates
   '(("K" "Cliplink capture task" entry (file "")
      "* TODO %(org-cliplink-capture) \n  SCHEDULED: %t\n" :empty-lines 1)))

Custom Transformers

You can actually customize how org-cliplink transforms and inserts url and title to the current buffer. To do that use org-cliplink-insert-transformed-title function. It takes the URL and a CALLBACK which is invoked when the title is retrieved.

For example, if you want to strip off Github - <description>: from the GitHub titles you can implement the following custom-org-cliplink function and use it instead of the original org-cliplink:

(defun custom-org-cliplink ()
  (interactive)
  (org-cliplink-insert-transformed-title
   (org-cliplink-clipboard-content)     ;take the URL from the CLIPBOARD
   (lambda (url title)
     (let* ((parsed-url (url-generic-parse-url url)) ;parse the url
            (clean-title
             (cond
              ;; if the host is github.com, cleanup the title
              ((string= (url-host parsed-url) "github.com")
               (replace-regexp-in-string "GitHub - .*: \\(.*\\)" "\\1" title))
              ;; otherwise keep the original title
              (t title))))
       ;; forward the title to the default org-cliplink transformer
       (org-cliplink-org-mode-link-transformer url clean-title)))))

Requirements

  • Linux
  • Emacs version 24.4+
  • cURL 7.35.0+ (optional)

Windows

Windows is not officially supported until #35 is resolved.

  • GnuTLS — if you use Emacs installation from the official GNU FTP server — ftp://ftp.gnu.org/gnu/emacs/windows/ — you may simply download the latest version of GnuTLS from ftp://ftp.gnutls.org/gcrypt/gnutls/w32/ and copy the content of the downloaded archive to the emacs installation folder.

Bugs

bug

Development

  1. open org-cliplink.el in Emacs;
  2. change something;
  3. M-x eval-buffer RET;
  4. manual testing;
  5. go to 3 until it’s done;

Automated testing

For automated testing you need to install Cask first.

To run unit tests:

$ cask # only once to download development dependencies
$ cask exec ert-runner

To run integration and unit tests together:

$ ./run-travis-ci.sh

This exact script is run on every push to org-cliplink GitHub repo on Travis CI (that’s why it’s called run-travis-ci.sh). This script starts up a testing web-server, executes integrations tests defined in *-integration-tests.el files and executes unit tests after that.

You can start the testing web-server standalone:

$ ./run-testing-server.py

It requires Python 2.7.6+. It will serve test-data/site folder on different ports with different features (like HTTPS, Gziped content, Basic Auth, etc.).

To stop the server just ^C it.

The automated testing stuff was tested only under Linux so far.

Contribution

This command doesn’t handle some cases (like different encodings) but I do my best to improve it. If you find this code useful and want to make a contribution I’m waiting for your pull requests. :)

Thanks.

More Repositories

1

dotfiles

Config files for mixer
Emacs Lisp
279
star
2

gruber-darker-theme

Gruber Darker color theme for Emacs 24+
Emacs Lisp
181
star
3

qemu-android-x86-runner

Quick Start on How to Run Android x86 in QEMU
Shell
177
star
4

aids

std replacement for C++
C++
114
star
5

simpc-mode

Simple C mode for Emacs
Emacs Lisp
30
star
6

bnfuzzer

Generate random messages based on their BNF definition
Go
30
star
7

five-programming-problems

Solutions for five programming problems every Software Engineer should be able to solve in less than 1 hour
Java
26
star
8

aoc-2023

My Solutions for Advent of Code 2023
21
star
9

beatwave

A musical puzzle game
C++
19
star
10

ebf

Brainfuck language transpiler to Emacs Lisp
Emacs Lisp
17
star
11

todo

CLI tool for manipulating source code TODOs
OCaml
16
star
12

aoc-2022

Python
14
star
13

sobaki

Doggo Browser
Python
10
star
14

freepascal-opengl-shaders

Small OpenGL Shaders example using FreePascal Compiler
Pascal
9
star
15

resume

Source code of my resume
Python
8
star
16

Loprog

Loprog is a stupid implementation of Prolog programming language.
Scala
8
star
17

io

Presentation about IO monad
Haskell
7
star
18

imtui-rs-prototype

Immediate TUI library prototype
Rust
7
star
19

pascalik

Rogue-like game in Pascal as a Recreational Programming Exercise
Pascal
7
star
20

cpp_concurrent_queue

Simple Concurrent Queue implementation in C++ using pthreads
C++
6
star
21

pongplotter

Calculates and plots delays between pings
Python
6
star
22

fantom2048

2048 game written in Fantom
Fantom
6
star
23

matrix-multiplication

C++
5
star
24

ninety-nine-ocaml-problems

99 Problems in OCaml
OCaml
5
star
25

rexim.me

Source code of my blog
CSS
5
star
26

libla

Just practicing in linear algebra. Nothing special. :)
C
5
star
27

Repackman

Just another clone of Pac-Man game
Java
5
star
28

md5

My implementation of md5 as an exercise for a cryptography university course.
Haskell
5
star
29

Olyvova

Static blog generator
Perl
4
star
30

BouncingBall

Bouncing Ball
QMake
3
star
31

cppig

C Pre-Processor Include Graph
C++
3
star
32

autocommit-el

A mode for autocommitting changes in a particular folder
Emacs Lisp
3
star
33

gcm-vis

Visualization of Greatest Common Measure algorithm for two segments.
C++
3
star
34

nixos-obs-linuxbrowser

Work in progress effort to bring obs-linuxbrowser to NixOS
Nix
3
star
35

nothings-mode

Inspired by VC6 setup of @nothings
Emacs Lisp
3
star
36

rexim.github.io

Hosting rexim.me on GitHub Pages
HTML
3
star
37

working-opengl-example-in-rust-omg-iwanna-die

Rust
3
star
38

transition-color

Implementation of transition color effect.
C++
2
star
39

buckwheatjs

Buckwheat Journaling System
Haskell
2
star
40

expenses-sqlite-migration

Scripts for migrating my expenses from org-mode to sqlite
Python
2
star
41

routes-drawer

Just a simple drawer of a graph of routes stored in a binary file.
C++
2
star
42

freq-parser

Parser of HTML logs produced by freqbot
Scala
2
star
43

comment2card

Add comments as note cards to the project boards
Python
1
star
44

mapie

Haskell
1
star
45

gcj.el

helpers to use elisp on GCJ
Emacs Lisp
1
star
46

scala-parser-combinators

Materials of 4geo's seminar on "Parser Combinators"
Scala
1
star
47

bigger-is-greater

Solution for Bigger is Greater problem on HackerRank.
OCaml
1
star