genorg.pl
changeset 6 c576e88fef13
parent 5 24fc5a406138
child 7 f00ed34eca17
equal deleted inserted replaced
5:24fc5a406138 6:c576e88fef13
    61 #+creator: <a href="https://www.gnu.org/software/emacs/">Emacs</a> 31.0.50 (<a href="https://orgmode.org">Org</a> mode 9.7.11)
    61 #+creator: <a href="https://www.gnu.org/software/emacs/">Emacs</a> 31.0.50 (<a href="https://orgmode.org">Org</a> mode 9.7.11)
    62 #+latex_header:
    62 #+latex_header:
    63 END
    63 END
    64 
    64 
    65 my $req_config = <<"END";
    65 my $req_config = <<"END";
    66 (with-eval-after-load 'org
    66 (require 'org)
    67     (org-link-set-parameters "genorg"
    67 (require 'ob)
       
    68 (org-link-set-parameters "genorg"
    68 			 :follow nil
    69 			 :follow nil
    69 			 :export
    70 			 :export
    70 			 #'(lambda (link desc _ _)
    71 			 #'(lambda (link desc _ _)
    71 			     (format "<genorg desc=\"%s\" link=\"%s\"/>" desc link))
    72 			     (format "<a class=\"rakim\" href=\"%s\">%s</a>" desc link))
    72 			 :store nil))
    73 			 :store nil)
    73 END
    74 END
    74 
    75 
    75 my $custom_code = "(require 'ob-dot) (setq org-confirm-babel-evaluate nil)";
    76 my $custom_code = "(list 1)";
    76 
    77 
    77 my $elisp_code = <<"END" =~ s/\n\s+//gr;
    78 my $elisp_code = <<"END" =~ s/\n\s+//gr;
    78 (let ((ls '(LIST)))
    79 (let ((ls '(LIST)))
    79   (require 'org)
    80   (require 'org)
    80   $custom_code
       
    81   (mapc
    81   (mapc
    82    (lambda (b)
    82    (lambda (b)
    83      (with-current-buffer b
    83      (with-current-buffer b
    84        (when (and (not (string-match "^ " (buffer-name b)))
    84        (when (and (not (string-match "^ " (buffer-name b)))
    85 		  (eq major-mode 'org-mode))
    85 		  (eq major-mode 'org-mode))
    86 	 (org-export-to-file 'html (pop ls)))))
    86 	 (org-export-to-file 'html (pop ls)))))
    87    (buffer-list))
    87    (buffer-list))
    88   (kill-emacs))
    88    (kill-emacs)
       
    89 )
    89 END
    90 END
    90 
    91 
    91 
    92 
    92 my ($h_intro, $h_c_intro, $h_cat_li, $h_chap, $h_en_cat, $h_en, $h_end)
    93 my ($h_intro, $h_c_intro, $h_cat_li, $h_chap, $h_en_cat, $h_en, $h_end)
    93   = split /SPLIT/ ,<<"END" =~ s/\n\s+//gr;
    94   = split /SPLIT/ ,<<"END" =~ s/\n\s+//gr;
   166    indir => \$dir,
   167    indir => \$dir,
   167    outdir => \$outdir,
   168    outdir => \$outdir,
   168    no_name_dir => \$no_name_dir
   169    no_name_dir => \$no_name_dir
   169   );
   170   );
   170 
   171 
       
   172 
   171 sub read_config ($path) {
   173 sub read_config ($path) {
   172   open my $fh, '<', $path or die "Couldn't open config file\n";
   174   open my $fh, '<', $path or die "Couldn't open config file\n";
   173   while (<$fh>) {
   175   while (<$fh>) {
   174     next if /^\s+$/;
   176     next if /^\s+$/;
       
   177     if (/^>>---+/) {
       
   178       local $/;
       
   179       $custom_code = <$fh>;
       
   180       return;
       
   181     }
   175     chomp;
   182     chomp;
   176     my ($directive, $rest) = split /\s+/, $_, 2;
   183     my ($directive, $rest) = split /\s+/, $_, 2;
   177     if (exists($config_vars{$directive})) {
   184     if (exists($config_vars{$directive})) {
   178       ${$config_vars{$directive}} = $rest;
   185       ${$config_vars{$directive}} = $rest;
   179     } else {
   186     } else {
   243       push @modified_files, $rel_file;
   250       push @modified_files, $rel_file;
   244     }
   251     }
   245   }
   252   }
   246   %changed_files // exit;
   253   %changed_files // exit;
   247   $elisp_code =~ s/LIST/join '', map "\"$_\" ", values %changed_files /e;
   254   $elisp_code =~ s/LIST/join '', map "\"$_\" ", values %changed_files /e;
   248   open my $fh, '-|', ($emacs, '--batch', '~/.emacs.d/init.el', keys %changed_files, "--eval" , "$elisp_code");
   255   open my $fh, '-|', ($emacs, '-Q','--eval', "(progn $custom_code)", keys %changed_files, "--eval" , "$elisp_code");
   249   close $fh;
   256   close $fh;
   250   \%changed_files
   257   \%changed_files
   251 }
   258 }
   252 
   259 
   253 my $cdir;
   260 my $cdir;
   254 
   261 
   255 $ARGV[0] // die "No arguments provided\n";
   262 $ARGV[0] // die "No arguments provided\n";
   256 while ($_ = shift @ARGV) {
   263 while ($_ = shift @ARGV) {
       
   264   /^-c$/ && do { print "$req_config\n"; exit };
   257   /^(-h|--?help)$/ && help_and_bye;
   265   /^(-h|--?help)$/ && help_and_bye;
   258   /^-t$/ && do { template shift @ARGV ; exit };
   266   /^-t$/ && do { template shift @ARGV ; exit };
   259   /^-c$/ && do { $config_file = shift @ARGV; next };
   267   /^-c$/ && do { $config_file = shift @ARGV; next };
   260   /^-d$/ && do { $cache = 0; next };
   268   /^-d$/ && do { $cache = 0; next };
   261   $cdir = $_;
   269   $cdir = $_;
   586     my $self = shift;
   594     my $self = shift;
   587     join "-", ($self->{year}, $self->{month}, $self->{day});
   595     join "-", ($self->{year}, $self->{month}, $self->{day});
   588   }
   596   }
   589 }
   597 }
   590 
   598 
       
   599