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

Subscribers

People subscribed via source and target branches