-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmodule.lisp.in
97 lines (80 loc) · 3.06 KB
/
module.lisp.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
;; Copyright (C) 2008 Julian Stecklina, Shawn Betts, Ivy Foster
;;
;; This file is part of dswm.
;;
;; dswm is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; dswm is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this software; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
;; Boston, MA 02111-1307 USA
;; Commentary:
;;
;; Use `add-modules-dir' to add the location dswm searches for modules.
;; Directories with external modules:
;;
;; * $PREFIX/share/modules
;; * ~/.dswm.d/modules
;; * user-defined-dir
;; Code:
(in-package #:dswm)
(export '(load-module
modules-list
*user-modules-dir*
add-modules-dir
find-module))
(defvar *list-modules-dir* (list (string-as-directory "@prefix@/share/dswm/modules"))
"The location of the contrib modules on your system.")
;; Add users home directory
(add-to-list *list-modules-dir* (merge-pathnames #p"modules/" (data-dir)))
(define-dswm-type :module (input prompt)
(or (argument-pop-rest input)
(completing-read (current-screen) prompt (modules-list) :require-match t)))
(defun modules-list ()
"Return a list of the available modules."
(let ((mod-list '()))
(dolist (i *list-modules-dir*)
(dolist (element
(mapcar 'pathname-name
(directory (make-pathname :defaults i
:name :wild
:type "lisp"))))
(add-to-list mod-list element)))
mod-list))
(defun find-module (name)
"Find module from list avaliable modules FIXME: test"
(labels
((module-p (dir-list name)
(cond
((null dir-list) nil)
((file-exists-p (make-pathname :defaults (car dir-list) :name name :type "lisp"))
(make-pathname :defaults (car dir-list) :name name :type "lisp"))
(t (module-p (cdr dir-list) name)))))
(module-p (reverse *list-modules-dir*) name)))
(defcommand add-modules-dir (dir) ((:string "Input directory name: "))
;; TODO: define dswm type pathname with autocomplete and automatic
;; directories creation
"Add the location of the contrib modules"
(add-to-list *list-modules-dir* (string-as-directory dir)))
(defcommand load-module (name) ((:module "Input module name: "))
"Loads the contributed module with the given NAME."
;; FIXME: This should use ASDF in the future. And maybe there should
;; be an extra dswm-contrib repository.
(when name
(let ((module (find-module name)))
(when module
(load module)))))
(defcommand list-modules () ()
(let ((list nil))
(dolist (w (modules-list))
(setf list (concat w "~%" list)))
(if (not (null list))
(message (format nil "~a" list))
(message "No modules found"))))
;; End of file