emacs_org_protocol_server 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6cd216cbf9fc6631801e4c4d644c6dadf8cecb5f
4
+ data.tar.gz: 4c7a17b84adba7fa55daf9a9d041dd7cde73006c
5
+ SHA512:
6
+ metadata.gz: 279bdd2eb65b784fbf312c19fb4ac87d42812cbc10dbbb44b47ba68455d902347ae57cc0c73eb38dba2c1190c926803f1763ac73043b672137c3aa23b5ae0c59
7
+ data.tar.gz: 210ca79de52caa60a636ad96482f0763636dd6be8c1e2fef3efbd80ebe4e8638e887bb2e40a2cba01a6e13d166587af7bef72c2d484f59c62b136a4b735a919f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,32 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect
4
+ all people who contribute through reporting issues, posting feature
5
+ requests, updating documentation, submitting pull requests or patches,
6
+ and other activities.
7
+
8
+ We are committed to making participation in this project a
9
+ harassment-free experience for everyone, regardless of level of
10
+ experience, gender, gender identity and expression, sexual
11
+ orientation, disability, personal appearance, body size, race,
12
+ ethnicity, age, or religion.
13
+
14
+ Examples of unacceptable behavior by participants include the use of
15
+ sexual language or imagery, derogatory comments or personal attacks,
16
+ trolling, public or private harassment, insults, or other
17
+ unprofessional conduct.
18
+
19
+ Project maintainers have the right and responsibility to remove, edit,
20
+ or reject comments, commits, code, wiki edits, issues, and other
21
+ contributions that are not aligned to this Code of Conduct. Project
22
+ maintainers who do not follow the Code of Conduct may be removed from
23
+ the project team.
24
+
25
+ Instances of abusive, harassing, or otherwise unacceptable behavior
26
+ may be reported by opening an issue or contacting one or more of the
27
+ project maintainers.
28
+
29
+ This Code of Conduct is adapted from the
30
+ [Contributor Covenant](http://contributor-covenant.org), version
31
+ 1.0.0, available at
32
+ [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in emacs_org_protocol_server.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tamara Temple
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # Emacs Org-Protocol Server
2
+
3
+ Emacs's `org-protocol` module in `org-mode` can be used to accept an
4
+ `org-protocol://` scheme. However, configuring this on Mac OSX using
5
+ Chrome seems problematic. There is a utility called
6
+ [EmacsClient](https://github.com/neil-smithline-elisp/EmacsClient.app)
7
+ that is listed in the
8
+ [`org-protocol`](http://orgmode.org/worg/org-contrib/org-protocol.html#orgheadline6)
9
+ documentation, however, it does not work on 10.11.2 (El Capitan) as of
10
+ this writing (Sat Dec 26 04:42:59 2015). So I cam up with this
11
+ alternative, which uses a [Sinatra](http://www.sinatrarb.com)
12
+ mini-server running locally.
13
+
14
+ ## Installation
15
+
16
+ Install the gem locally:
17
+
18
+ gem install emacs-org-protocol-server
19
+
20
+ Start it up:
21
+
22
+ emacs-org-protocol-server
23
+
24
+ This will run the server on port 4567, and call
25
+ `/usr/local/bin/emacsclient` to operate.
26
+
27
+ ## Command line options
28
+
29
+ The command line options are the same as for any standard Sinatra
30
+ application:
31
+
32
+ emacs-org-protocol-server [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-o HOST] [-s HANDLER]
33
+
34
+ Options are:
35
+
36
+ -h # help
37
+ -p # set the port (default is 4567)
38
+ -o # set the host (default is 0.0.0.0)
39
+ -e # set the environment (default is development)
40
+ -s # specify rack server/handler (default is thin)
41
+ -x # turn on the mutex lock (default is off)
42
+
43
+ In addition, you may set what the path to the `emacsclient`
44
+ application is by setting the environment variable `EMACSCLIENT`. For
45
+ example:
46
+
47
+
48
+ EMACSCLIENT=/usr/bin/emacsclient emacs-org-protocol-server -p 9294 -e production
49
+
50
+ uses the `emacsclient` at `/usr/bin/emacsclient` running on port 9294
51
+ in production.
52
+
53
+ ## Browser Configuration
54
+
55
+ The entire point here is to get something from your browser over into
56
+ emacs. Our good emacs teacher,
57
+ [Sacha Chua](http://sachachua.com/)
58
+ has an article on
59
+ [Capturing links quickly with emacsclient, org-protocol, and Chrome Shortcut Manager on Microsoft Windows 8 - sacha chua living an awesome life](http://sachachua.com/blog/2015/11/capturing-links-quickly-with-emacsclient-org-protocol-and-chrome-shortcut-manager-on-microsoft-windows-8/)
60
+ that helped me a lot in setting up my Chrome browser on OSX 10.11. I
61
+ still had to work out how it all worked, and build my own JavaScript
62
+ scriptlets and bookmarklets.
63
+
64
+ Essentially, you want to end up with a URL that calls the
65
+ `emacs-org-protocol-server` that looks like so:
66
+
67
+ http://localhost:4567/?p=capture&l=http%3A%2F%2Fexample.com%2F&t=Example%20Domain&s=This%20domain%20is%20established%20to%20be%20used%20for%20illustrative%20examples%20in%20documents.%20You%20may%20use%20this%20domain%20in%20examples%20without%20prior%20coordination%20or%20asking%20for%20permission.
68
+
69
+ assuming your browser is sitting at `http://example.com`.
70
+
71
+ ### ShortKeys
72
+
73
+ I wrote the following to put into a
74
+ [ShortKeys](https://chrome.google.com/webstore/detail/shortkeys-custom-keyboard/logpjaacgmcbpdkdchjiaagddngobkck?hl=en)
75
+ definition:
76
+
77
+ ``` javascript
78
+ function fixedEncodeURIComponent (str) {
79
+ return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
80
+ return '%' + c.charCodeAt(0).toString(16);
81
+ });
82
+ };
83
+
84
+ var captureLink = function(){
85
+ var s = fixedEncodeURIComponent(window.getSelection().toString());
86
+ var l = fixedEncodeURIComponent(window.location.href);
87
+ var t = fixedEncodeURIComponent(document.title);
88
+ var p = fixedEncodeURIComponent('capture')
89
+ var uri = 'http://localhost:4567/?' +
90
+ 'p=' + p +
91
+ '&l=' + l +
92
+ '&t=' + t +
93
+ '&s=' + s
94
+ window.location = uri;
95
+ return uri;
96
+ };
97
+ captureLink();
98
+ ```
99
+
100
+ Which is different from the code @sachac shows in her post.
101
+
102
+ In this case, URI encoding needs to go deeper than just the unsafe
103
+ characters, because you could easily have safe characters in any of
104
+ the components but you want
105
+ them encoded anyway, such as `'`, `&`, etc.
106
+
107
+ Also, they are getting put together as a query string to the
108
+ `emacs-org-protocol-server` instead of the URI itself.
109
+
110
+ Copy and paste the into the Shortkeys javascript area when you're
111
+ creating your short key. You can assign
112
+ your own shortkey to it.
113
+
114
+ ### Bookmarklet
115
+
116
+ Another way to do this, which is more what I'm used to, is to create a
117
+ JavaScript Bookmarklet. To do this in Chrome, you create a new
118
+ bookmark in your Bookmark Manager window, give it a name such as
119
+ `capture`, and then paste in some JS code prefixed by the pseudo-scheme
120
+ `javascript:`, for example:
121
+
122
+
123
+ ``` javascript
124
+ javascript:function fx(str){return encodeURIComponent(str).replace(/[!'()*]/g, function(c){return '%' + c.charCodeAt(0).toString(16);});};var captureLink=function(){var s=fx(window.getSelection().toString()),l=fx(window.location.href),t=fx(document.title),p='capture',uri='http://localhost:4567/?'+'p='+p+'&l='+l+'&t='+t+'&s='+s;window.location=uri;return uri;};captureLink();
125
+ ```
126
+
127
+ If you are running your `emacs-org-protocol-server` at a different
128
+ port than 4567, put that in the bookmarklet instead.
129
+
130
+ ## Capture Template
131
+
132
+ The org-protocol capture sub-protocol theoretically lets you give a an
133
+ org-capture template code, but I'm still trying to get this to work
134
+ consistently and well. I've short-circuited the code in the server to
135
+ always use the "w" capture template (which is old behaviour) which
136
+ dumps the captured page information into my links journal file. You
137
+ can set up your own capture template, just name it "w".
138
+
139
+ Here's my "w" capture template:
140
+
141
+ ``` elisp
142
+ ("w"
143
+ "Default Org-protocol Capture Template"
144
+ entry
145
+ (file+datetree (concat org-directory "link_journal.org"))
146
+ "* %:link\n\n Title: %:description\n\n %?%:initial\n\n captured at: %U\n"
147
+ :empty-lines 1)
148
+
149
+ ```
150
+
151
+ ## Development
152
+
153
+ After checking out the repo, run `bin/setup` to install
154
+ dependencies. Then, run `rake` to run the tests. You can also run
155
+ `bin/console` for an interactive prompt that will allow you to
156
+ experiment. Run `bundle exec emacs_org_protocol_server` to use the gem
157
+ in this directory, ignoring other installed copies of this gem.
158
+
159
+ To install this gem onto your local machine, run `bundle exec rake
160
+ install`. To release a new version, update the version number in
161
+ `version.rb`, and then run `bundle exec rake release`, which will
162
+ create a git tag for the version, push git commits and tags, and push
163
+ the `.gem` file to [rubygems.org](https://rubygems.org).
164
+
165
+ ## Contributing
166
+
167
+ Bug reports and pull requests are welcome on GitHub at
168
+ https://github.com/tamouse/emacs_org_protocol_server. This project
169
+ is intended to be a safe, welcoming space for collaboration, and
170
+ contributors are expected to adhere to the
171
+ [Contributor Covenant](contributor-covenant.org) code of conduct.
172
+
173
+ ## License
174
+
175
+ The gem is available as open source under the terms of the
176
+ [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "emacs_org_protocol_server"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/bookmarklet.js ADDED
@@ -0,0 +1 @@
1
+ javascript:function fx(str){return encodeURIComponent(str).replace(/[!'()*]/g, function(c){return '%' + c.charCodeAt(0).toString(16);});};var captureLink=function(){var s=fx(window.getSelection().toString()),l=fx(window.location.href),t=fx(document.title),p='capture',uri='http://localhost:4567/?'+'p='+p+'&l='+l+'&t='+t+'&s='+s;window.location=uri;return uri;};captureLink();
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'emacs_org_protocol_server/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "emacs_org_protocol_server"
8
+ spec.version = EmacsOrgProtocolServer::VERSION
9
+ spec.authors = ["Tamara Temple"]
10
+ spec.email = ["tamouse@gmail.com"]
11
+
12
+ spec.summary = %q{Simple Sinatra server to call org-protocol with emacsclient}
13
+ spec.description = %q{Simple Sinatra server to call org-protocol with emacsclient}
14
+ spec.homepage = "https://github.com/tamouse/emacs_org_protocol_server"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_dependency "thin"
25
+ spec.add_dependency "sinatra"
26
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "emacs_org_protocol_server"
4
+ EmacsOrgProtocolServer::OPServ.run!
@@ -0,0 +1,3 @@
1
+ module EmacsOrgProtocolServer
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,40 @@
1
+ require "emacs_org_protocol_server/version"
2
+ require 'sinatra/base'
3
+ require 'uri'
4
+
5
+ module EmacsOrgProtocolServer
6
+ EMACSCLIENT=ENV['EMACSCLIENT'] || "/usr/local/bin/emacsclient"
7
+
8
+ class OPServ < Sinatra::Application
9
+
10
+ helpers do
11
+ def esc(s)
12
+ URI.escape(s, %r{[^[:alnum:]]})
13
+ end
14
+ end
15
+
16
+ get '/' do
17
+ if params.empty?
18
+ return [422, 'no params passed']
19
+ end
20
+
21
+ p=params['p'].to_s.downcase
22
+ if p.match(%r{capture})
23
+ template='//w'
24
+ else
25
+ template=''
26
+ end
27
+ l=params['l'].to_s
28
+ t=params['t'].to_s
29
+ s=params['s'].to_s
30
+
31
+ emacsclient_target = "org-protocol://#{p}:#{template}//#{esc(l)}/#{esc(t)}/#{esc(s)}"
32
+ cmd = "#{EMACSCLIENT} -n '#{emacsclient_target}'"
33
+ system(cmd)
34
+ puts "ran #{cmd}"
35
+ redirect to(params['l'])
36
+ end
37
+
38
+ end
39
+
40
+ end
data/shortkey.js ADDED
@@ -0,0 +1,20 @@
1
+ function fixedEncodeURIComponent (str) {
2
+ return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
3
+ return '%' + c.charCodeAt(0).toString(16);
4
+ });
5
+ };
6
+
7
+ var captureLink = function(){
8
+ var s = fixedEncodeURIComponent(window.getSelection().toString());
9
+ var l = fixedEncodeURIComponent(window.location.href);
10
+ var t = fixedEncodeURIComponent(document.title);
11
+ var p = fixedEncodeURIComponent('capture')
12
+ var uri = 'http://localhost:4567/?' +
13
+ 'p=' + p +
14
+ '&l=' + l +
15
+ '&t=' + t +
16
+ '&s=' + s
17
+ window.location = uri;
18
+ return uri;
19
+ };
20
+ captureLink();
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emacs_org_protocol_server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tamara Temple
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thin
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Simple Sinatra server to call org-protocol with emacsclient
70
+ email:
71
+ - tamouse@gmail.com
72
+ executables:
73
+ - emacs_org_protocol_server
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - bookmarklet.js
87
+ - emacs_org_protocol_server.gemspec
88
+ - exe/emacs_org_protocol_server
89
+ - lib/emacs_org_protocol_server.rb
90
+ - lib/emacs_org_protocol_server/version.rb
91
+ - shortkey.js
92
+ homepage: https://github.com/tamouse/emacs_org_protocol_server
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.5
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Simple Sinatra server to call org-protocol with emacsclient
116
+ test_files: []
117
+ has_rdoc: