如何配置Firefox在某些链接上运行emacsclientw? [英] How to configure firefox to run emacsclientw on certain links?

查看:314
本文介绍了如何配置Firefox在某些链接上运行emacsclientw?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Perl脚本,其中包含了一些寻找有趣行的日志文件,对于一些有趣的定义。它生成一个HTML文件,该文件由一列表为时间戳,一个文件名/亚麻参考和有趣位组成。我想要做的是将文件名/ linenum作为一个实际的链接,它将带有光标位于该行号上的emacs文件。



emacsclientw将允许这样的事情(例如emacsclientw +60 foo.log),但是我不知道什么样的URL / URI构造将使FireFox调用emacsclientw。原来的HTML文件将是本地的,所以没有问题。



我应该以这种方式定义自己的MIME类型和钩子吗?



Firefox版本是3.5,我正在运行Windows,以防任何重要事项。谢谢!

解决方案

感谢指针p4bl0。不幸的是,这仅适用于真实的操作系统; Windows使用完全不同的方法。有关详细信息,请参阅 http://kb.mozillazine.org/Register_protocol



但是,您一定提供了我需要的开始,非常非常感谢!



这是Windows的解决方案: / p>

首先,您需要正确设置注册表来处理此新的URL类型。为此,将以下内容保存到文件中,编辑它以适应您的环境,保存并双击:

  Windows注册表编辑器版本5.00 

[HKEY_CLASSES_ROOT\emacs]
@ =URL:Emacs协议
URL协议=

[ HKEY_CLASSES_ROOT\emacs\shell]

[HKEY_CLASSES_ROOT\emacs\shell\open]

[HKEY_CLASSES_ROOT\emacs\shell\open\command ]
@ =\c:\\product\\emacs\\\\\emacsclientw.exe\--no-wait -e \(emacs -uri-handler \\\%1 \\\\\

这不如p4bl0的shell脚本那么强大,因为它不能确保Emacs正在运行。然后将以下内容添加到.emacs文件中:

 (defun emacs-uri-handler(uri)
句柄emacs的形式为:emacs:/// path / to / file / LINENUM
(save-match-data
(if(string-matchemacs:// \\ * \\)/ \\([0-9] + \\)$uri)
(let((filename(match-string 1 uri))
(linenum (match-string 2 uri)))
(with-current-buffer(find-file filename)
(goto-line(string-to-number linenum))))
(beep )
(消息无法解析URI<%s>uri))))

上述代码不会检查,以确保文件存在,错误处理是最基本的。但是它有效!



然后创建一个具有以下行的HTML文件:

 < a href =emacs:// c:/temp/my.log/60> file:c:/temp/my.log,line:60< / a> 

然后点击链接。



发布脚本



我最近切换到Linux(Ubuntu 9.10),这是我为该操作系统所做的:

  $ gconftool -s / desktop / gnome / url-handlers / emacs / command'/ usr / bin / emacsclient --no-wait -e emacs-uri-handler \%s\)' -  type String 
$ gconftool -s / desktop / gnome / url-handlers / emacs / enabled --type Boolean true

从上面使用相同的 emacs-uri-handler p>

I've got a Perl script that groks a bunch of log files looking for "interesting" lines, for some definition of interesting. It generates an HTML file which consists of a table whose columns are a timestamp, a filename/linenum reference and the "interesting" bit. What I'd love to do is have the filename/linenum be an actual link that will bring up that file with the cursor positioned on that line number, in emacs.

emacsclientw will allow such a thing (e.g. emacsclientw +60 foo.log) but I don't know what kind of URL/URI to construct that will let FireFox call out to emacsclientw. The original HTML file will be local, so there's no problem there.

Should I define my own MIME type and hook in that way?

Firefox version is 3.5 and I'm running Windows, in case any of that matters. Thanks!

解决方案

Thanks for the pointer, p4bl0. Unfortunately, that only works on a real OS; Windows uses a completely different method. See http://kb.mozillazine.org/Register_protocol for more info.

But, you certainly provided me the start I needed, so thank you very, very much!

Here's the solution for Windows:

First you need to set up the registry correctly to handle this new URL type. For that, save the following to a file, edit it to suit your environment, save it and double click on it:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\emacs]
@="URL:Emacs Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\emacs\shell]

[HKEY_CLASSES_ROOT\emacs\shell\open]

[HKEY_CLASSES_ROOT\emacs\shell\open\command]
@="\"c:\\product\\emacs\\bin\\emacsclientw.exe\" --no-wait -e \"(emacs-uri-handler \\\"%1\\\")\""

This is not as robust as p4bl0's shell script, because it does not make sure that Emacs is running first. Then add the following to your .emacs file:

(defun emacs-uri-handler (uri)
  "Handles emacs URIs in the form: emacs:///path/to/file/LINENUM"
  (save-match-data
    (if (string-match "emacs://\\(.*\\)/\\([0-9]+\\)$" uri)
        (let ((filename (match-string 1 uri))
              (linenum (match-string 2 uri)))
          (with-current-buffer (find-file filename)
            (goto-line (string-to-number linenum))))
      (beep)
      (message "Unable to parse the URI <%s>"  uri))))

The above code will not check to make sure the file exists, and the error handling is rudimentary at best. But it works!

Then create an HTML file that has lines like the following:

<a href="emacs://c:/temp/my.log/60">file: c:/temp/my.log, line: 60</a>

and then click on the link.

Post Script:

I recently switched to Linux (Ubuntu 9.10) and here's what I did for that OS:

$ gconftool -s /desktop/gnome/url-handlers/emacs/command '/usr/bin/emacsclient --no-wait -e "(emacs-uri-handler \"%s\")"' --type String
$ gconftool -s /desktop/gnome/url-handlers/emacs/enabled --type Boolean true

Using the same emacs-uri-handler from above.

这篇关于如何配置Firefox在某些链接上运行emacsclientw?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆