File: module.lisp

package info (click to toggle)
stumpwm 1:20110819.gitca08e08-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,948 kB
  • sloc: lisp: 14,330; sh: 179; makefile: 112
file content (75 lines) | stat: -rw-r--r-- 2,506 bytes parent folder | download
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
;; Copyright (C) 2008 Julian Stecklina, Shawn Betts, Ivy Foster
;;
;;  This file is part of stumpwm.
;;
;; stumpwm 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.

;; stumpwm 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 `set-contrib-dir' to set the location stumpwm searches for modules.

;; Code:

(in-package #:stumpwm)

(export '(load-module
          list-modules
	  *contrib-dir*
	  set-contrib-dir
          find-module))

(defun module-string-as-directory (dir)
  (unless (string= "/" (subseq dir (1- (length dir))))
    (setf dir (concat dir "/")))
  (pathname dir))

(defvar *contrib-dir*
  #.(asdf:system-relative-pathname (asdf:find-system :stumpwm)
                                   (make-pathname :directory
                                                  '(:relative "contrib")))
  "The location of the contrib modules on your system.")

(defcommand set-contrib-dir (dir) ((:string "Directory: "))
    "Sets the location of the contrib modules"
  (setf *contrib-dir* (module-string-as-directory dir)))

(define-stumpwm-type :module (input prompt)
  (or (argument-pop-rest input)
      (completing-read (current-screen) prompt (list-modules) :require-match t)))

(defun list-modules ()
  "Return a list of the available modules."
  (mapcar 'pathname-name
          (directory (make-pathname :defaults *contrib-dir*
				    :name :wild
				    :type "lisp"))))

(defun find-module (name)
  (probe-file (make-pathname :defaults *contrib-dir*
                             :name name
                             :type "lisp")))

(defcommand load-module (name) ((:module "Load Module: "))
  "Loads the contributed module with the given NAME."
  ;; FIXME: This should use ASDF in the future. And maybe there should
  ;; be an extra stumpwm-contrib repository.
  (when name
    (let ((module (find-module name)))
      (when module
          (load module)))))


;; End of file