Merge pull request #12579 from lujun9972/translate-MjAxNzA3MjEgRmlyZWZveCBhbmQgb3JnLXByb3RvY29sIFVSTCBDYXB0dXJlLm1kCg==

translate done: 20170721 Firefox and org-protocol URL Capture.md
This commit is contained in:
Xingyu.Wang 2019-02-28 18:16:47 +08:00 committed by GitHub
commit 823e750ddc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 122 additions and 122 deletions

View File

@ -1,122 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (lujun9972)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Firefox and org-protocol URL Capture)
[#]: via: (http://www.mediaonfire.com/blog/2017_07_21_org_protocol_firefox.html)
[#]: author: (Andreas Viklund http://andreasviklund.com/)
Firefox and org-protocol URL Capture
======
### Introduction
As an Emacs guy, I attempt to force all my workflow into [org-mode][1] for me life is better in text.
I tend to prefer to store bookmarks in [org-mode][1] todo lists, and [org-protocol][2] allows external processes to interact with some of [org-mode's][1] features. Setup, though, is an hassle. There are plenty of tutorials out there ([search][3]), and there are Firefox [extensions][4], but overall I've not had great luck with them.
I therefore decided to put my current setup in this blog post as another data point for those trying to get it all working.
### Setup your Emacs Org Mode Configuration
Enable org-protocol:
```
(require 'org-protocol)
```
Add a capture template - here's mine:
```
(setq org-capture-templates
(quote (...
("w" "org-protocol" entry (file "~/org/refile.org")
"* TODO Review %a\n%U\n%:initial\n" :immediate-finish)
...)))
```
The [capture templates][5] section in the [org-mode][1] manual will help.
Add the default template to use:
```
(setq org-protocol-default-template-key "w")
```
Eval those additions so they're active in your current Emacs session.
### A Quick Test
Before going further, it's a good idea to test your configuration:
```
emacsclient -n "org-protocol:///capture?url=http%3a%2f%2fduckduckgo%2ecom&title=DuckDuckGo"
```
This should pop open a capture window based on the template you added. Until this works, no point in going forward. If it doesn't work, go back through the configuration above and ensure that you've eval'd the code blocks.
If you have an old version of [org-mode][1] (older than 7, I believe), the format is different: the urlencoded form is replaced by slashes as separators of the url and title. A quick search will show you the difference.
### Firefox Protocol
Now to setup Firefox. Browse to about:config. Right-click on the list of configuration items, choose New -> Boolean, and enter network.protocol-handler.expose.org-protocol for the name and toggle the value to true.
Some tutorials indicate this step is optional YMMV.
### Add Desktop File
Most of the tutorials include this:
Add ~/.local/share/applications/org-protocol.desktop:
```
[Desktop Entry]
Name=org-protocol
Exec=/path/to/emacsclient -n %u
Type=Application
Terminal=false
Categories=System;
MimeType=x-scheme-handler/org-protocol;
```
Then run your updater. For i3 I use (same as for gnome):
```
update-desktop-database ~/.local/share/applications/
```
KDE has a different method… again some of the tutorials for getting org-protocol working can help.
### Setup Capture Button in Firefox
Create a bookmark (I create it in the toolbar) with the following "Location":
```
javascript:location.href="org-protocol:///capture?url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title||"[untitled page]")
```
After you save it, should you edit the bookmark, expect to see any spaces replaced by '%20' the url encoding for a "space".
Now when you click the bookmark, you should get a window opened in an Emacs frame, any random frame, showing your template.
--------------------------------------------------------------------------------
via: http://www.mediaonfire.com/blog/2017_07_21_org_protocol_firefox.html
作者:[Andreas Viklund][a]
选题:[lujun9972][b]
译者:[lujun9972](https://github.com/lujun9972)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: http://andreasviklund.com/
[b]: https://github.com/lujun9972
[1]: http://orgmode.org/
[2]: http://orgmode.org/worg/org-contrib/org-protocol.html
[3]: https://duckduckgo.com/?q=org-protocol+firefox&t=ffab&ia=qa
[4]: https://addons.mozilla.org/en-US/firefox/search/?q=org-protocol&cat=1,0&appver=53.0&platform=linux
[5]: http://orgmode.org/manual/Capture-templates.html

View File

@ -0,0 +1,122 @@
[#]collector(lujun9972)
[#]translator(lujun9972)
[#]reviewer( )
[#]publisher( )
[#]url( )
[#]subject(Firefox and org-protocol URL Capture)
[#]via(http://www.mediaonfire.com/blog/2017_07_21_org_protocol_firefox.html)
[#]author(Andreas Viklund http://andreasviklund.com/)
在 Firefox 上使用 org-protocol 捕获 URL
======
### 介绍
作为一名 Emacs 人,我尽可能让所有的工作流都在 [org-mode][1] 上进行 我比较喜欢文本。
我倾向于将书签记录为 [org-mode][1] 代办列表,而 [org-protocol][2] 则允许外部进程利用 [org-mode][1] 的某些功能。然而,要做到这一点配置起来很麻烦。([搜索引擎上 ][3]) 有很多教程Firefox 也有很多这类 [扩展 ][4],然而我对它们都不太满意。
因此我决定将我现在的配置记录在这篇博客中,方便其他有需要的人使用。
### 配置 Emacs Org Mode
启用 org-protocol
```
(require 'org-protocol)
```
添加一个捕获模板 (capture template) - 我的配置是这样的:
```
(setq org-capture-templates
(quote (...
("w" "org-protocol" entry (file "~/org/refile.org")
"* TODO Review %a\n%U\n%:initial\n" :immediate-finish)
...)))
```
你可以从 [org-mode][1] 手册中 [capture templates][5] 章节中获取帮助。
设置默认使用的模板:
```
(setq org-protocol-default-template-key "w")
```
执行这些新增配置让它们在当前 Emacs 会话中生效。
### 快速测试
在下一步开始前,最好测试一下配置:
```
emacsclient -n "org-protocol:///capture?url=http%3a%2f%2fduckduckgo%2ecom&title=DuckDuckGo"
```
基于的配置的模板,可能会弹出一个捕获窗口。请确保正常工作,否则后面的操作没有任何意义。如果工作不正常,检查刚才的配置并且确保你执行了这些代码块。
如果你的 [org-mode][1] 版本比较老(老于 7 版本),测试的格式会有点不同:这种 URL 编码后的格式需要改成用斜杠来分割 url 和标题。在网上搜一下很容易找出这两者的不同。
### Firefox 协议
现在开始设置 Firefox。浏览 aboutconfig。右击配置项列表选择 New -> Boolean然后输入 network.protocol-handler.expose.org-protocol 作为名字并且将值设置为 true。
有些教程说这一步是可以省略的 配不配因人而异。
### 添加 Desktop 文件
大多数的教程都有这一步:
增加一个文件 ~/.local/share/applications/org-protocol.desktop
```
[Desktop Entry]
Name=org-protocol
Exec=/path/to/emacsclient -n %u
Type=Application
Terminal=false
Categories=System;
MimeType=x-scheme-handler/org-protocol;
```
然后运行更新器。对于 i3 窗口管理器我使用下面命令(跟 gnome 一样)
```
update-desktop-database ~/.local/share/applications/
```
KDE 的方法不太一样… 你可以查询其他相关教程。
### 在 FireFox 中设置捕获按钮
创建一个书签(我是在工具栏上创建这个书签的),地址栏输入下面内容:
```
javascript:location.href="org-protocol:///capture?url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title||"[untitled page]")
```
保存该书签后,再次编辑该书签,你应该会看到其中的所有空格都被替换成了 '%20' 也就是空格的 URL 编码形式。
现在当你点击该书签,你就会在某个 Emacs Frame可能是任何一个 Frame 中,打开一个窗口,显示你预定的模板。
--------------------------------------------------------------------------------
via: http://www.mediaonfire.com/blog/2017_07_21_org_protocol_firefox.html
作者:[Andreas Viklund][a]
选题:[lujun9972][b]
译者:[lujun9972](https://github.com/lujun9972)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: http://andreasviklund.com/
[b]: https://github.com/lujun9972
[1]: http://orgmode.org/
[2]: http://orgmode.org/worg/org-contrib/org-protocol.html
[3]: https://duckduckgo.com/?q=org-protocol+firefox&t=ffab&ia=qa
[4]: https://addons.mozilla.org/en-US/firefox/search/?q=org-protocol&cat=1,0&appver=53.0&platform=linux
[5]: http://orgmode.org/manual/Capture-templates.html