[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What can I do to help?

From: gnucash
Subject: Re: What can I do to help?
Date: Mon, 30 Sep 2002 19:33:38 -0400

Derek Atkins wrote:
> This is indeed the main goal behind using guile as an extension
> language for GnuCash..  The main hurdle right now is the lack of a
> user-created startup file (ala .emacs) that gets loaded at system
> startup.  Similarly lacking is a plug-in directory to all the system
> to autoload new modules (ala a system-wide '.emacs' ;) I think once
> both of those issues are resolved it will be MUCH easier for users to
> write gnucash applets.
> So, if there is some guile guru who can help me implement the "load
> all .scm files in directory <foo>", I'd be happy to listen.

Here's something.

;;; To find all .scm files in a directory:

(define (find-scm-files dir)
   (let ((idir (opendir dir))
         (matcher (make-regexp  ".*\.scm$")))
      (let loop ((files '()))
         (let ((element (readdir idir)))
            (if (eof-object? element)
                   (closedir idir)
                (if (regexp-exec matcher element)
                    (loop (cons element files))
                    (loop files)))))))

;;; To load all the files found using find-scm-files
(define (load-scm-files-from-dir dir)
  (for-each (lambda (file)
               (load dir "/" file))
            (find-scm-files dir)))

Note that this does _not_ load them in any special order, which is
almost certainly the /wrong/ thing to do.

The way that Emacs works, which seems entirely appropriate to follow, is
to (require "filename"), which searches a set of pathnames for
"filename.elc" and/or "filename.el".

I would think it almost certain that something analagous to that, which,
as it happens, is /already supported/, is /MUCH/ more appropriate than
"loading all the files in a directory."

What we /already have/ are three relevant functions, and one variable:
 gnc:depend, gnc:support, gnc:load, gnc:*load-path*

(gnc:depend "foo.scm")
  loads foo.scm, using gnc:load, if it has not yet been loaded.

(gnc:support "foo.scm")
  indicates that the present file implements "foo.scm", so that it'll
  "satisfy" a gnc:depend call. 

(gnc:load "foo.scm")
  tries to load foo.scm, and attempts to locate the file in all the
  directories specified by gnc:*load-path*

If you need to add an extra directory, such as ~/.gnucash, throw it into
gnc:*load-path* and "stuff'll work."

Conclusion:  While it's not hard to make a "load all these files"
function, I'd much rather suggest using the existent methods of 
gnc:depend, gnc:support, gnc:load, and gnc:*load-path*.  

Add the home directory to gnc:*load-path*, try to get GnuCash to
(trapped, in case the file isn't there) load some sort of
"gnucash-init.scm" file from that directory, and you've got /everything/
you need.

If a user wants to load-scm-files-from-dir, they can certainly do so,
but I'd suggest that this is not what is /really/ wanted.

The "hook" that is needed is for some reasonably conspicuous part of the
startup process to perform the following:

;;; Start user defined portion of processing...
(define gnc:*load-path* 
       (string-append (getenv "HOME") "/.gnucash") 

(if (file-exists? (string-append (getenv "HOME")
    (gnc:load "customizations.scm"))
(reverse (concatenate 'string "gro.mca@" "enworbbc"))
Signs of a Klingon  Programmer - 5. "Indentation?! -  I will  show you
how to indent when I indent your skull!"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]