1 ; file: load-gschemrc.scm
 2 ; type: lepton-schematic Guile script
 3 ; copyright (c) 2021 dmn <graahnul.grom@gmail.com>
 4 ; license: GPLv2+
 5 ;
 6 ; When opening a page, load gschemrc file from the page's directory
 7 ; (unlike gafrc, gschemrc file doesn't automatically loaded unless
 8 ; you start lepton-schematic in the directory where gschemrc resides).
 9 ;
10 ; Usage:
11 ; Add the following to the ~/.config/lepton-eda/gschemrc file:
12 ;   ( primitive-load "/path/to/load-gschemrc.scm" )
13 ;
14 
15 
16 
17 ( use-modules ( lepton rc      ) )
18 ( use-modules ( lepton page    ) )
19 ( use-modules ( lepton log     ) )
20 ( use-modules ( schematic hook ) )
21 
22 
23 ( define ( load-gschemrc-file page )
24 ( let*
25     (
26     ( dir ( dirname (page-filename page) ) )
27     ( gschemrc (format #f "~a/gschemrc" dir) )
28     )
29 
30     ( when ( access? gschemrc R_OK )
31         ( chdir dir )
32         ( parse-rc "lepton-schematic" "gschemrc" )
33         ( log!   'warning "load-gschemrc.scm: Loaded [~a/gschemrc]"   gschemrc )
34         ( format #t       "load-gschemrc.scm: Loaded [~a/gschemrc]~%" gschemrc )
35     )
36 
37 ) ; let
38 )
39 
40 
41 ( define ( install_hooks )
42     ( add-hook! open-page-hook load-gschemrc-file #f ) ; #f => prepend
43 )
44 
45 
46 ( install_hooks )
47