[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[STUMP] Fwd: [PATCH] Use multiple directories when searching for modules
From: |
Evan |
Subject: |
[STUMP] Fwd: [PATCH] Use multiple directories when searching for modules |
Date: |
Tue, 18 Feb 2014 09:47:49 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 |
Here's the patch for having multiple contrib-dirs. Originally submitted
by Diogo F. S. Ramos.
-E
-------- Original Message --------
Subject: [STUMP] [PATCH] Use multiple directories when searching for modules
Date: Sun, 29 Sep 2013 17:20:02 -0300
From: Diogo F. S. Ramos <address@hidden>
To: address@hidden
Having only one directory as the source of modules limits where the
user can collect these modules, specially if StumpWM is a system-wide
installation.
This patch adds a new variable, `*contrib-dirs*', which holds a list
of directories where StumpWM should search for modules.
To preserve backward compatibility, `*contrib-dir*' still exists and
behaves as expected.
When the user decides to use this new feature, both variables are
taken into account, with `*contrib-dirs*' taking precedence over the
old variable; if no module is found inside `*contrib-dirs*',
`*contrib-dir*' is used. The reasoning for this is that
`*contrib-dir*' has a default value to look for contrib modules
distributed with StumpWM, so an user might want to add new modules,
possibly patched versions of the ones distributed with StumpWM.
Two functions, `set-contrib-dirs' and `add-contrib-dir' are exported
to maintain the same semantics of `set-contrib-dir', but there is no
command for them.
---
module.lisp | 44 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 37 insertions(+), 7 deletions(-)
diff --git a/module.lisp b/module.lisp
index 7f65a05..90262be 100644
--- a/module.lisp
+++ b/module.lisp
@@ -28,7 +28,11 @@
list-modules
*contrib-dir*
set-contrib-dir
- find-module))
+ find-module
+ *contrib-dirs*
+ set-contrib-dirs
+ add-contrib-dir
+ ))
(defun module-string-as-directory (dir)
(unless (string= "/" (subseq dir (1- (length dir))))
@@ -41,10 +45,28 @@
'(:relative "contrib")))
"The location of the contrib modules on your system.")
+(defvar *contrib-dirs*
+ nil
+ "Additional list of directories where to find StumpWM modules.")
+
(defcommand set-contrib-dir (dir) ((:string "Directory: "))
"Sets the location of the contrib modules"
(setf *contrib-dir* (module-string-as-directory dir)))
+(defun set-contrib-dirs (list-of-directories)
+ "Set the multiple locations of StumpWM modules."
+ (setf *contrib-dirs* (mapcar 'module-string-as-directory
list-of-directories)))
+
+(defun add-contrib-dir (directory)
+ "Add a new location where StumpWM can find modules."
+ (push (module-string-as-directory directory) *contrib-dirs*))
+
+(defun merge-contribs ()
+ "Merge *contrib-dir* and *contrib-dirs*.
+
+This function dictates the policy taken for directory precedence."
+ (append *contrib-dirs* (list *contrib-dir*)))
+
(define-stumpwm-type :module (input prompt)
(or (argument-pop-rest input)
(completing-read (current-screen) prompt (list-modules)
:require-match t)))
@@ -52,14 +74,22 @@
(defun list-modules ()
"Return a list of the available modules."
(mapcar 'pathname-name
- (directory (make-pathname :defaults *contrib-dir*
- :name :wild
- :type "lisp"))))
+ (loop
+ for dir in (merge-contribs)
+ append (directory (make-pathname :defaults dir
+ :name :wild
+ :type "lisp")))))
(defun find-module (name)
- (probe-file (make-pathname :defaults *contrib-dir*
- :name name
- :type "lisp")))
+ "Search for a module inside contrib sources.
+
+This will return the first match."
+ (some #'probe-file
+ (mapcar (lambda (dir)
+ (make-pathname :defaults dir
+ :name name
+ :type "lisp"))
+ (merge-contribs))))
(defcommand load-module (name) ((:module "Load Module: "))
"Loads the contributed module with the given NAME."
--
1.8.4.rc3
_______________________________________________
Stumpwm-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
- [STUMP] Fwd: [PATCH] Use multiple directories when searching for modules,
Evan <=