添加协议处理程序
创建文件~/.local/share/applications/org-protocol.desktop,其中包含:
[Desktop Entry]
Name=org-protocol
Exec=emacsclient %u
Type=Application
Terminal=false
Categories=System;
MimeType=x-scheme-handler/org-protocol;
注意:每一行的键必须完全按照显示的大小大写,否则将是无效的.desktop 文件。
然后通过运行更新~/.local/share/applications/mimeinfo.cache:
配置 Emacs
初始化文件
添加到您的 Emacs 初始化文件:
(server-start)
(require 'org-protocol)
捕获模板
您可能希望添加类似这样的捕获模板:
("w" "Web site"
entry
(file+olp "/path/to/inbox.org" "Web")
"* %c :website:\n%U %?%:initial")
注意:使用%:initial 而不是%i 似乎可以更好地处理多行内容。
这将导致这样的捕获:
\* [[http://orgmode.org/worg/org-contrib/org-protocol.html][org-protocol.el – Intercept calls from emacsclient to trigger custom actions]] :website:
[2015-09-29 Tue 11:09] About org-protocol.el
org-protocol.el is based on code and ideas from org-annotation-helper.el and org-browser-url.el.
配置火狐
公开协议处理程序
在某些版本的 Firefox 上,可能需要添加此设置。如果您收到错误提示 Firefox 不知道如何处理 org-protocol 链接,您可以跳过此步骤并返回。
打开about:config 并创建一个名为network.protocol-handler.expose.org-protocol 的新boolean 值并将其设置为true。
注意:如果您确实跳过了这一步,并且确实遇到了错误,Firefox 可能会将窗口中所有打开的选项卡替换为错误消息,从而难以或无法恢复这些选项卡。最好使用带有一次性标签的新窗口来测试此设置,直到您知道它可以正常工作为止。
制作书签
制作一个带有位置的书签:
javascript:location.href='org-protocol://capture://w/'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(window.getSelection())
注意: URL中的w选择对应的抓包模板。如果要提示您输入模板,您可以将其省略。
当你第一次点击这个书签时,Firefox 会询问使用什么程序来处理org-protocol 协议。如果您使用Ubuntu 12.04(精确穿山甲),则必须添加/usr/bin/emacsclient程序,并选择它。使用Ubuntu 12.10 (Quantal Quetzal) 或更高版本,您只需选择出现的默认程序 (org-protocol)。
您可以在捕获时选择页面中的文本并将其复制到模板中,或者您可以只捕获页面标题和URL。
三指
如果您使用Tridactyl,您可以像这样映射键序列:
bind cc js location.href='org-protocol://capture://w/'+encodeURIComponent(content.location.href)+'/'+encodeURIComponent(content.document.title)+'/'+encodeURIComponent(content.document.getSelection())
您可能还想为 `store-link` 子协议添加一个,例如:
bind cl js location.href='org-protocol://store-link://'+encodeURIComponent(content.location.href)+'/'+encodeURIComponent(content.document.title)
捕获脚本
您可能希望使用此脚本从终端捕获输入,无论是作为参数还是通过管道输入:
#!/bin/bash
if [[ $@ ]]
then
data="$@"
else
data=$(cat)
fi
if [[ -z $data ]]
then
exit 1
fi
encoded=$(python -c "import sys, urllib; print urllib.quote(' '.join(sys.argv[1:]), safe='')" "${data[@]}")
# "link" and "title" are not used, but seem to be necessary to get
# $encoded to be captured
emacsclient "org-protocol://capture://link/title/$encoded"
然后你可以像这样从 shell 捕获输入:
tail /var/log/syslog | org-capture
org-capture "I can capture from a terminal!"
这些说明比Mark's answer 中的说明更新。