GNU ELPA - clipboard-collector


Collect clipboard entries according to regex rules
clipboard-collector-0.3.tar, 2021-Mar-18, 60.0 KiB
Clemens Radermacher <>
Home page
Browse ELPA's repository
CGit or Gitweb

To install this package, run in Emacs:

M-x package-install RET clipboard-collector RET

Full description

<a href=""><img alt="ELPA" src=""/></a>

* Introduction

When collecting information using copy/paste, it would be useful if one could
stay at one place to copy things and later insert them all at once at another
place. Emacs has =append-next-kill= but it only works inside Emacs and it only
applies to the very next command. Further it would be great if Emacs could
detect specific clipboard entries and transform them to a different format
automatically. =clipboard-collector= provides you with those features (tested
only for Linux).

You can use it to simply collect multiple entries by binding
=clipboard-collector-mode= to a key:

#+BEGIN_SRC elisp
(global-set-key (kbd "C-M-w") 'clipboard-collector-mode)

Once called the clipboard is observed and any text that is copied/killed gets
collected. To finish use =C-c C-c= in any buffer to insert the collected items
separated by newlines.

By default a timer is used to poll the clipboard for changes, you can use
[[][gpastel]] to avoid polling the clipboard (using =gpastel-update-hook=). This
will be done automatically if =gpastel-mode= is found to be active.

If you want to have specific rules for which items get collected and maybe
transform them before collecting them you can create you own commands using
=clipboard-collector-create= macro.

Here is an example for collecting contact information from a website for org
capture (contact info gets transformed to be used as org property drawer items).

#+BEGIN_SRC elisp
(clipboard-collector-create cc-capture-rss
 (("^http.*"                           ":TWITTER: %s")
  ("^http.*"                            ":REDDIT: %s")
  ("^http.*"                            ":GITHUB: %s")
  ("^http.*"                           ":YOUTUBE: %s")
  ("^http.*stack.*.com"                           ":STACK: %s")
  ("^https?://.*\\.[a-z]+/?\\'"                   ":DOMAIN: %s")
  ("^.*@.*"                                       ":MAIL: %s")
  ("^http.*\\(dotemacs\\|.?emacs\\|.?emacs.d\\)"  ":DOTEMACS: %s"))
 (lambda (items)
   (clipboard-collector-finish-default items)

This creates a command called =cc-capture-rss=. When called the clipboard is
observed and any changes which match one of the regexes will be collected. The
clipboard contents are transformed via the format string provided above.

When done collecting, you can press =C-c C-c= to call the finalize function (in
the above example it would inserts the collected items separated by newlines and
finish org-capture).

Rules can also contain a function which gets applied to the clipboard entry
before the format string is applied. You can use match-data of your matching
regex in that function, too:

#+BEGIN_SRC elisp
(clipboard-collector-create cc-url
 (("https?://\\([^/]*\\)"  "Url: %s" (lambda (item) (match-string 1 item)))))

If you just want to apply a matched group to the format string you can provide
the match group number instead of using a function, too:

#+BEGIN_SRC elisp

* Related projects

There is [[][clipmon]] but I wanted something more flexible and I wanted it to work for text
copied in and outside of Emacs.

* Contribute

See the

Old versions

clipboard-collector-0.2.el.lz2019-Jan-072.92 KiB