source: git/emacs/cmpl.pl @ d92d71

spielwiese
Last change on this file since d92d71 was 341696, checked in by Hans Schönemann <hannes@…>, 14 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100755
File size: 2.6 KB
Line 
1#!/usr/local/bin/perl
2# $Id$
3###################################################################
4#
5# FILE:    cmpl.pl
6# PURPOSE: generate completion strings for singular emacs mode
7# AUTHOR: obachman
8####
9$Usage = <<EOT;
10$0 [-Singular binary] [-hlp file] [cmpl 'hlp|cmd|lib'] [-help]
11Generates completion strings for singular emacs mode and prints it to STDOUT
12EOT
13 
14#
15# default settings of command-line arguments
16#
17$Singular = "../Singular/Singular";
18$hlp = "../doc/singular.hlp";
19$cmpl = "cmd";
20$ex_dir= "../examples";
21%symbol = (cmd=>"singular-commands-alist",
22           hlp=>"singular-help-topics-alist",
23           lib=>"singular-standard-libraries-alist",
24            ex=>"singular-examples-alist");
25
26#
27# parse command line options
28#
29while (@ARGV && $ARGV[0] =~ /^-/)
30{
31  $_ = shift(@ARGV);
32  if (/^-S(ingular)?$/)  { $Singular = shift(@ARGV); next;}
33  if (/^-hlp$/)          { $hlp = shift(@ARGV); next;}
34  if (/^-c(mpl)?$/)      { $cmpl = shift(@ARGV); next;}
35  if (/^-e(x_dir)?$/)    { $ex_dir = shift(@ARGV); next;}
36  if (/^-h(elp)?$/)      { print $Usage; exit;}
37  die "Unrecognized option: $_\n$Usage";
38}
39
40#
41# get array of strings
42#
43if ($cmpl eq 'cmd')
44{
45  $strings = `$Singular -tq --exec='reservedName();\$'`;
46  die "Error in execution of: $Singular -tq --exec='reservedName();\$': $!\n"
47    if ($?);
48  @strings = map "(\"$_\")", split(/\s+/, $strings);
49}
50elsif ($cmpl eq 'lib')
51{
52  # Sort libraries in REVERSE order! (Menu is created from bottom to
53  # top in singular.el)
54  @strings = map "(\"$_\")", sort {$b cmp $a} split(/\s+/, <>);
55}
56elsif ($cmpl eq 'hlp')
57{
58  open(FH, "<$hlp") || die "Can not open file $hlp: $!\n";
59  while (<FH>)
60  {
61    if (/Node: Index/)
62    {
63      while (<FH>)
64      {
65        last if /\* Menu:/;
66      }
67      <FH>;
68      while (<FH>)
69      {
70        last if /^\s*$/;
71        if ( /^\* (.*):\s*(.*).\s*/ ) {
72          $node = $1; $rawNode = $2;
73          # remove duplicate counter from node
74          $node =~ s/(.*) <\d+>$/$1/;
75          # quote characters special to Emacs
76          $node =~ s/([\"#\\])/\\\1/g;    #'
77          $rawNode =~ s/([\"#\\])/\\\1/g; #'
78          # only the first occurence of $node is inserted to @string!
79          # all subsequent entries are discarded.
80          push @strings, "(\"$node\" . \"$rawNode\")" if $node ne $prev;
81          $prev = $node;
82        }
83      }
84      last;
85    }
86  }
87  close(FH);
88}
89elsif ($cmpl eq 'ex')
90{
91  @strings = <$ex_dir/*.sing>;
92  map {$_ =~ s|.*/(.*?)\.sing$|(\"$1\")|;} @strings;
93}
94else
95{
96  die "Error: Can not make completion list for $cmpl\n $Usage";
97}
98print STDOUT <<EOT;
99; Do not edit this file: It was automatically generated by $0
100(setq $symbol{$cmpl}
101  '(
102EOT
103#' prevents breaking of fontification
104 
105foreach $string (@strings)
106{
107  print STDOUT "    $string\n";
108}
109
110print STDOUT "))\n";
111
Note: See TracBrowser for help on using the repository browser.