Re: [STUMP] Fwd: [PATCH] Use multiple directories when searching for modules

David Bjergaard <[email protected]>
Newsgroups gmane.comp.window-managers.stumpwm.devel
Message-ID <[email protected]>
Thanks, I'll take it from here.

    Dave

Evan <[email protected]> writes:

> 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 <[email protected]>
> To: [email protected]
>
> 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."
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.