Merge lp:~patrickniedzielski/zeitgeist-datasources/emacs-zeitgeist into lp:zeitgeist-datasources/0.8

Proposed by PatrickNiedzielski
Status: Merged
Merged at revision: 87
Proposed branch: lp:~patrickniedzielski/zeitgeist-datasources/emacs-zeitgeist
Merge into: lp:zeitgeist-datasources/0.8
Diff against target: 261 lines (+220/-1)
4 files modified
configure.ac (+5/-1)
emacs/Makefile.am (+16/-0)
emacs/README (+10/-0)
emacs/zeitgeist.el (+189/-0)
To merge this branch: bzr merge lp:~patrickniedzielski/zeitgeist-datasources/emacs-zeitgeist
Reviewer Review Type Date Requested Status
Seif Lotfy Pending
Review via email: mp+32038@code.launchpad.net

Description of the change

Adds Zeitgeist support to Emacs 23. Works great on my system (Debian Sid x64) and Ubuntu 10.04 (tested by user mtvoid).

Features:
  * Opening, closing, creating, and saving file detection support.
  * Several file types, and falling back on text/plain.
  * Requires a single addition to the user's .emacs file.

Only thing I am not sure about is how to make the environment variable change from Makefile.am. Currently, I just write out to the user's .profile file.

Cheers!

To post a comment you must log in.
86. By Patrick Michael Niedzielski <email address hidden>

Changed ontologies that were out of date.

Added thanks to mtvoid.

87. By Patrick Michael Niedzielski <email address hidden>

Changed some things with local install.

And URI mistake.

Revision history for this message
Seif Lotfy (seif) wrote :

Seems ok to me
my lisp is rusty but sounds sane :)

Revision history for this message
PatrickNiedzielski (patrickniedzielski) wrote :

On mar, 2010-08-24 at 17:30 +0000, Seif Lotfy wrote:
> Seems ok to me
> my lisp is rusty but sounds sane :)

I've been running it for two weeks now with no problems whatsoever.
Seems to be working just fine.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configure.ac'
--- configure.ac 2010-06-29 20:40:15 +0000
+++ configure.ac 2010-08-08 17:09:42 +0000
@@ -51,7 +51,7 @@
51AC_MSG_RESULT($all_plugins)51AC_MSG_RESULT($all_plugins)
5252
53# The full list of plugins53# The full list of plugins
54allowed_plugins="bzr chrome eog firefox-libzg geany gedit rhythmbox totem-libzg vim"54allowed_plugins="bzr chrome eog firefox-libzg geany gedit rhythmbox totem-libzg vim emacs"
55# currently disabled = "epiphany tomboy"55# currently disabled = "epiphany tomboy"
5656
57# npapi-plugin has a template Makefile.am, but don't use it directly57# npapi-plugin has a template Makefile.am, but don't use it directly
@@ -177,6 +177,9 @@
177 ;;177 ;;
178 vim)178 vim)
179 ;;179 ;;
180 emacs)
181 AM_PATH_LISPDIR
182 ;;
180 *)183 *)
181 plugin_error_or_ignore "${plugin} is not handled"184 plugin_error_or_ignore "${plugin} is not handled"
182 continue185 continue
@@ -213,6 +216,7 @@
213rhythmbox/Makefile216rhythmbox/Makefile
214totem-libzg/Makefile217totem-libzg/Makefile
215vim/Makefile218vim/Makefile
219emacs/Makefile
216])220])
217221
218AC_MSG_NOTICE([Zeitgeist-dataproviders was configured with the following options:])222AC_MSG_NOTICE([Zeitgeist-dataproviders was configured with the following options:])
219223
=== added directory 'emacs'
=== added file 'emacs/Makefile.am'
--- emacs/Makefile.am 1970-01-01 00:00:00 +0000
+++ emacs/Makefile.am 2010-08-08 17:09:42 +0000
@@ -0,0 +1,16 @@
1PLUGIN_FILES = zeitgeist.el
2outfilesemacs = zeitgeist.elc
3
4dist_lisp_LISP = $(PLUGIN_FILES)
5
6# we want to allow also local install
7EMACS_PLUGIN_HOME_DIR = ~/.emacs.d/lisp
8
9local-install:
10 mkdir -p $(EMACS_PLUGIN_HOME_DIR)
11 cp $(PLUGIN_FILES) $(EMACS_PLUGIN_HOME_DIR)
12 cp $(outfilesemacs) $(EMACS_PLUGIN_HOME_DIR)
13
14local-uninstall:
15 rm $(EMACS_PLUGIN_HOME_DIR)/$(PLUGIN_FILES)
16 rm $(EMACS_PLUGIN_HOME_DIR)/$(outfilesemacs)
017
=== added file 'emacs/README'
--- emacs/README 1970-01-01 00:00:00 +0000
+++ emacs/README 2010-08-08 17:09:42 +0000
@@ -0,0 +1,10 @@
1You should be able to add the following line to your ``.emacs''
2file:
3
4 (load-library "zeitgeist.elc")
5
6If you chose a local install, before that line, add:
7
8 (setq load-path (cons "~/.emacs.d/lisp" load-path))
9
10Special thanks to mtvoid <m_tuli@yahoo.com> for several bugfixes.
011
=== added file 'emacs/zeitgeist.el'
--- emacs/zeitgeist.el 1970-01-01 00:00:00 +0000
+++ emacs/zeitgeist.el 2010-08-08 17:09:42 +0000
@@ -0,0 +1,189 @@
1;;; The Zeitgeist Emacs Script -- integrates Emacs with Zeitgeist.
2;;; Copyright (C) 2010, Patrick M. Niedzielski <PatrickNiedzielski@gmail.com>
3;;;
4;;; This program is free software: you can redistribute it and/or modify
5;;; it under the terms of the GNU General Public License as published by
6;;; the Free Software Foundation, either version 3 of the License, or
7;;; (at your option) any later version.
8;;;
9;;; This program is distributed in the hope that it will be useful,
10;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12;;; GNU General Public License for more details.
13;;;
14;;; You should have received a copy of the GNU General Public License
15;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
16;;;
17;;; For more information about the Zeitgeist Project, see
18;;; <http://zeitgeist-project.com/>.
19
20(require 'dbus)
21
22
23(defun zeitgeist-call (method &rest args)
24 "Call the zeitgeist method METHOD with ARGS over dbus"
25 (apply 'dbus-call-method
26 :session ; use the session (not system) bus
27 "org.gnome.zeitgeist.Engine" ; service name
28 "/org/gnome/zeitgeist/log/activity" ; path name
29 "org.gnome.zeitgeist.Log" ; interface name
30 method args))
31
32(defun zeitgeist-event-timestamp ()
33 "Get the timestamp in zeitgeist format."
34 (let* ((now-time (current-time))
35 (hi (car now-time))
36 (lo (car (cdr now-time)))
37 (msecs (car (cdr (cdr now-time))))) ; This is *micro*seconds.
38
39 (substring (number-to-string (+ (/ msecs 1000)
40 (* (+ lo (* hi 65536.0)) 1000))) 0 -2))) ; Convert system time to milliseconds.
41
42(defun zeitgeist-get-mime-type ()
43 "Get the mime type from the extension."
44 (let ((ext (file-name-extension (buffer-file-name))))
45 ; Maybe use file mode later...
46 (cond ((eq "el" ext) "text/x-script.elisp")
47
48 ((eq "cpp" ext) "text/x-c++src")
49 ((eq "C" ext) "text/x-c++src")
50 ((eq "c++" ext) "text/x-c++src")
51 ((eq "cxx" ext) "text/x-c++src")
52 ((eq "cc" ext) "text/x-c++src")
53
54 ((eq "hpp" ext) "text/x-c++hdr")
55 ((eq "h++" ext) "text/x-c++hdr")
56 ((eq "hxx" ext) "text/x-c++hdr")
57 ((eq "hh" ext) "text/x-c++hdr")
58
59 ((eq "csv" ext) "text/comma-separated-values")
60
61 ((eq "h" ext) "text/x-chdr")
62
63 ((eq "c" ext) "text/x-csrc")
64
65 ((eq "java" ext) "text/x-java")
66
67 ((eq "p" ext) "text/x-pascal")
68 ((eq "pas" ext) "text/x-pascal")
69
70 ((eq "tcl" ext) "text/x-tcl")
71 ((eq "tk" ext) "text/x-tcl")
72
73 ((eq "tex" ext) "text/x-tex")
74 ((eq "sty" ext) "text/x-tex")
75 ((eq "cls" ext) "text/x-tex")
76
77 ((eq "html" ext) "text/html")
78 ((eq "htm" ext) "text/html")
79
80 ((eq "latex" ext) "application/x-latex")
81 ((eq "ltx" ext) "application/x-latex")
82
83 ((eq "sh" ext) "application/x-sh")
84
85 ((eq "pl" ext) "application/x-perl")
86 ((eq "pm" ext) "application/x-perl")
87
88 ((eq "texinfo" ext) "application/x-texinfo")
89 ((eq "texi" ext) "application/x-texinfo")
90
91 ((eq "t" ext) "application/x-troff")
92 ((eq "tr" ext) "application/x-troff")
93 ((eq "roff" ext) "application/x-troff")
94
95 ((eq "xml" ext) "text/xml")
96 ((eq "xsd" ext) "text/xml")
97
98 ((eq "xslt" ext) "application/xslt+xml")
99 ((eq "xsl" ext) "application/xslt+xml")
100
101 ((eq "txt" ext) "text/plain")
102 (t "text/plain"))))
103
104(defun zeitgeist-event-interpretation (event)
105 "Get the Event Interpretation of EVENT."
106 (cond
107 ((eq event 'zeitgeist-open-event)
108 "http://www.zeitgeist-project.com/ontologies/2010/01/27/zg#AccessEvent")
109 ((eq event 'zeitgeist-close-event)
110 "http://www.zeitgeist-project.com/ontologies/2010/01/27/zg#LeaveEvent")
111 ((eq event 'zeitgeist-create-event)
112 "http://www.zeitgeist-project.com/ontologies/2010/01/27/zg#CreateEvent")
113 ((eq event 'zeitgeist-modify-event)
114 "http://www.zeitgeist-project.com/ontologies/2010/01/27/zg#ModifyEvent")
115 (t nil)))
116
117(defun zeitgeist-send (event fileurl filemime)
118 "Send zeitgeist an event EVENT using the list FILEINFO."
119 (let ((event-interpretation (zeitgeist-event-interpretation event)))
120 (if (eq nil event-interpretation)
121 (message "YOU FAIL")
122 (zeitgeist-call "InsertEvents"
123 (list (list :struct (list ""
124 (zeitgeist-event-timestamp)
125 event-interpretation
126 "http://www.zeitgeist-project.com/ontologies/2010/01/27/zg#UserActivity"
127 "application://emacs23.desktop")
128 (list (list (concat "file://" fileurl)
129 "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Document"
130 "http://www.semanticdesktop.org/ontologies/nfo#FileDataObject"
131 (concat "file://" (file-name-directory fileurl))
132 filemime
133 (file-name-nondirectory (file-name-sans-versions fileurl))
134 "")) ; Some black magic later?
135 '(:array :byte 0)))))))
136
137(defun zeitgeist-open-file ()
138 "Tell zeitgeist we opened a file!"
139 (if (eq nil (buffer-file-name))
140 (message "You are not on a file.")
141 (zeitgeist-send 'zeitgeist-open-event
142 buffer-file-name
143 (zeitgeist-get-mime-type))))
144(defun zeitgeist-close-file ()
145 "Tell zeitgeist we closed a file!"
146 (if (eq nil (buffer-file-name))
147 (message "You are not on a file.")
148 (zeitgeist-send 'zeitgeist-close-event
149 buffer-file-name
150 (zeitgeist-get-mime-type))))
151(defun zeitgeist-create-file ()
152 "Tell zeitgeist we created a file!"
153 (zeitgeist-send 'zeitgeist-create-event
154 buffer-file-name
155 (zeitgeist-get-mime-type)))
156(defun zeitgeist-modify-file ()
157 "Tell zeitgeist we modified a file!"
158 (zeitgeist-send 'zeitgeist-modify-event
159 buffer-file-name
160 (zeitgeist-get-mime-type)))
161
162(defun zeitgeist-find-file-hook ()
163 "Call zeitgeist-open-file if the file exists."
164 (if (file-exists-p (buffer-file-name))
165 (zeitgeist-open-file)))
166(defun zeitgeist-kill-buffer-hook ()
167 "Call zeitgeist-close-file if the file exists."
168 (if (and (not (eq nil (buffer-file-name)))
169 (file-exists-p (buffer-file-name)))
170 (zeitgeist-close-file)))
171(defun zeitgeist-kill-emacs-hook ()
172 "Call zeitgeist-close-file on all files that exist."
173 (mapc '(lambda (buffer)
174 (set-buffer buffer)
175 (zeitgeist-close-file))
176 (buffer-list)))
177(defun zeitgeist-before-save-hook ()
178 "Call zeitgeist-modify-file or zeitgeist-create-file."
179 (if (and (not (eq nil (buffer-file-name)))
180 (file-exists-p (buffer-file-name)))
181 (zeitgeist-modify-file)
182 (zeitgeist-create-file)))
183
184(add-hook 'find-file-hook 'zeitgeist-find-file-hook)
185(add-hook 'kill-buffer-hook 'zeitgeist-kill-buffer-hook)
186(add-hook 'kill-emacs-hook 'zeitgeist-kill-emacs-hook)
187(add-hook 'before-save-hook 'zeitgeist-before-save-hook)
188
189;;; zeitgeist.el ends here

Subscribers

People subscribed via source and target branches