【发布时间】:2011-03-10 19:21:05
【问题描述】:
我正在编写一个 elisp 文件以通过 dbus 将 GNU Emacs 与 Zeitgeist 集成。由于缺乏关于 emacs 中 dbus 的良好文档以及我缺乏高级 elisp 的经验,我的方法 zeitgeist-send 中出现以下错误:
错误类型参数:D-Bus, (zeitgeist-event-timestamp)
我尝试通过在所有参数之前放置 :string 来纠正问题,但这给了我错误:
错误类型参数:stringp, (zeitgeist-event-timestamp)
这毫无意义,因为我很肯定 (zeitgeist-event-timestamp) 的值是一个字符串。
如果您需要,zeitgeist 的 dbus 文档是 here。它的格式是asaasay。
代码如下:
(require 'dbus)
(defun zeitgeist-call (method &rest args)
"Call the zeitgeist method METHOD with ARGS over dbus"
(apply 'dbus-call-method
:session ; use the session (not system) bus
"org.gnome.zeitgeist.Engine" ; service name
"/org/gnome/zeitgeist/log/activity" ; path name
"org.gnome.zeitgeist.Log" ; interface name
method args))
(defun zeitgeist-event-timestamp ()
"Get the timestamp in zeitgeist format."
(let* ((now-time (current-time))
(hi (car now-time))
(lo (car (cdr now-time)))
(msecs (car (cdr (cdr now-time))))) ; This is *micro*seconds.
(number-to-string (+ (/ msecs 1000)
(* (+ lo (* hi 65536)) 1000))))) ; Convert system time to milliseconds.
(defun zeitgeist-event-interpretation (event)
"Get the Event Interpretation of EVENT."
(case event
('zeitgeist-open-event
"http://zeitgeist-project.com/ontologies/2010/01/27/zg#AccessEvent")
('zeitgeist-close-event
"http://zeitgeist-project.com/schema/1.0/core#CloseEvent")
('zeitgeist-create-event
"http://zeitgeist-project.com/schema/1.0/core#CreateEvent")
('zeitgeist-modify-event
"http://zeitgeist-project.com/schema/1.0/core#ModifyEvent")
(otherwise nil)))
(defun zeitgeist-send (event fileurl filemime)
"Send zeitgeist an event EVENT using the list FILEINFO."
(let ((event-interpretation (zeitgeist-event-interpretation event)))
(if (eq nil event-interpretation)
(message "YOU FAIL")
(zeitgeist-call "InsertEvents"
'(""
(zeitgeist-event-timestamp)
event-interpretation
"http://zeitgeist-project.com/schema/1.0/core#UserActivity"
"app://emacs.desktop")
'((fileurl
"http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/#Document"
"http://www.semanticdesktop.org/ontologies/nfo/#FileDataObject"
fileurl
filemime
(file-name-sans-versions fileurl)
"")) ; Some black magic later
'(:array)))))
(defun zeitgeist-open-file ()
"Tell zeitgeist we openned a file!"
(if (eq nil (buffer-file-name))
(message "You are not on a file.")
(zeitgeist-send 'zeitgeist-open-event buffer-file-name "text/plain")))
(zeitgeist-open-file)
感谢您的帮助! 帕特里克·尼齐尔斯基
【问题讨论】:
-
这很奇怪,因为 (type-of (zeitgeist-event-timestamp)) 绝对是一个字符串。如果我将 (zeitgeist-event-timestamp) 替换为 "",则调用会抱怨下一个参数。
-
我在邮件列表中询问过,我被告知由于我使用的是 (quote ...),因此不会调用函数 (zeitgeist-event-timestamp)。变量也没有被评估。我已经用 (list ...) 对其进行了测试,现在效果很好。让我来回答这个问题。