DBus方法中的错误类型(GNU Emacs)

4
我正在编写一个elisp文件,用于通过dbus将GNU Emacs与Zeitgeist集成。由于emacs中关于dbus的文档不充分,以及我的高级elisp经验不足,所以在我的方法zeitgeist-send中出现了以下错误:

Wrong type argument: D-Bus, (zeitgeist-event-timestamp)

我尝试通过在所有参数前面放置:string来纠正此问题,但是这给了我以下错误:

Wrong type argument: stringp, (zeitgeist-event-timestamp)

这毫无意义,因为我确定(zeitgeist-event-timestamp)的值是一个字符串。如果需要,zeitgeist的dbus文档在这里。它的格式是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)

感谢任何帮助! Patrick Niedzielski


很奇怪,因为 (type-of (zeitgeist-event-timestamp)) 明确是一个字符串。如果我用 "" 替换 (zeitgeist-event-timestamp),调用会抱怨下一个参数。 - stsquad
我在邮件列表上询问,得知由于我使用了(quote ...),函数(zeitgeist-event-timestamp)没有被调用。变量也没有被评估。我已经使用(list ...)进行了测试,现在它运行得很好。让我回答这个问题。 - Patrick Niedzielski
1个回答

4

我在邮件列表上询问后发现,由于我使用的是(quote ...)而不是(list ...),所以变量和函数没有被评估。这是一个愚蠢的LISP错误。

另外,如果有人感兴趣,我将把这个补丁提交到Zeitgeist项目中。

祝好, Patrick


请做吧!我也一直在考虑Emacs-Zeitgeist的集成。 - Thomas Kappler
当我弄清楚确切的步骤时,我会在我的博客(http://freesoftwarehacker.blogspot.com/)上发布。^_^ - Patrick Niedzielski

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接