4
;;; plugin.scm: Plugin for uim.
6
;;; Copyright (c) 2005 uim Project http://uim.freedesktop.org/
8
;;; All rights reserved.
10
;;; Redistribution and use in source and binary forms, with or without
11
;;; modification, are permitted provided that the following conditions
13
;;; 1. Redistributions of source code must retain the above copyright
14
;;; notice, this list of conditions and the following disclaimer.
15
;;; 2. Redistributions in binary form must reproduce the above copyright
16
;;; notice, this list of conditions and the following disclaimer in the
17
;;; documentation and/or other materials provided with the distribution.
18
;;; 3. Neither the name of authors nor the names of its contributors
19
;;; may be used to endorse or promote products derived from this software
20
;;; without specific prior written permission.
22
;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
23
;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
26
;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28
;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31
;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37
(define uim-plugin-lib-load-path
39
(list (string-append (sys-pkglibdir) "/plugin"))
41
(append (list (getenv "LIBUIM_PLUGIN_LIB_DIR")
42
(string-append (getenv "HOME") "/.uim.d/plugin")
43
(string-append (sys-pkglibdir) "/plugin"))
45
(if (getenv "LD_LIBRARY_PATH")
46
(string-split (getenv "LD_LIBRARY_PATH") ":")
49
(define uim-plugin-scm-load-path
51
(list (sys-pkgdatadir))
53
(list (getenv "LIBUIM_SCM_FILES")
54
(string-append (getenv "HOME") "/.uim.d/plugin")
57
(define plugin-alist ())
58
(define plugin-func-alist ())
60
(define-record 'plugin-entry
69
(define plugin-list-append
70
(lambda (plugin-name library init quit)
71
(let ((entry (plugin-entry-new plugin-name library init quit)))
73
(append plugin-alist (list entry))))))
75
(define plugin-list-delete
78
(alist-delete plugin-name plugin-alist string=?))))
80
(define plugin-list-query
82
(assoc plugin-name plugin-alist)))
84
(define plugin-list-query-library
86
(let ((entry (plugin-list-query plugin-name)))
88
(plugin-entry-library entry)))))
90
(define plugin-list-query-instance-init
92
(let ((entry (plugin-list-query plugin-name)))
94
(plugin-entry-init-proc entry)))))
96
(define plugin-list-query-instance-quit
98
(let ((entry (plugin-list-query plugin-name)))
100
(plugin-entry-quit-proc entry)))))
103
;; The name 'module' is adopted from a post from Hiroyuki. If you
104
;; feel bad about the meaning of 'module', post your opinion to
107
(define installed-im-module-list ())
108
(define currently-loading-module-name #f)
111
;; TODO: write test for load-plugin
112
;; returns whether initialization is succeeded
113
(define require-module
114
(lambda (module-name)
115
(set! currently-loading-module-name module-name)
116
(let ((succeeded (or (load-plugin module-name)
117
(try-require (string-append module-name ".scm")))))
118
(set! currently-loading-module-name #f)
122
(define load-module-conf
124
(let* ((user-module-dir (string-append (getenv "HOME") "/.uim.d/plugin/"))
125
(conf-file "installed-modules.scm")
126
(user-conf-file (string-append user-module-dir conf-file)))
130
(if (not (getenv "LIBUIM_VANILLA"))
131
(let ((orig-module-list installed-im-module-list)
132
(orig-enabled-list enabled-im-list))
133
(and (try-load user-conf-file)
134
(set! installed-im-module-list
135
(append orig-module-list installed-im-module-list))
136
(set! enabled-im-list
137
(append orig-enabled-list enabled-im-list)))))))))
141
(define load-enabled-modules
143
(let* ((user-module-dir (string-append (getenv "HOME") "/.uim.d/plugin/"))
145
(user-file (string-append user-module-dir file)))
147
(or (and (not (is-set-ugid?))
148
(try-load user-file))