source: git/emacs/cmpl.pl @ ab733d

spielwiese
Last change on this file since ab733d was 0969f2c, checked in by Tim Wichmann <wichmann@…>, 25 years ago
* wichmann: + Library entries are sorted in reverse order + help completion no scans node and rawnode and inserts ("node" . "rawnode") in list git-svn-id: file:///usr/local/Singular/svn/trunk@3611 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100755
File size: 2.5 KB
Line 
1#!/usr/local/bin/perl
2# $Id: cmpl.pl,v 1.6 1999-09-15 19:03:00 wichmann Exp $
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%symbol = (cmd=>"singular-commands-alist",
21           hlp=>"singular-help-topics-alist",
22           lib=>"singular-standard-libraries-alist");
23
24#
25# parse command line options
26#
27while (@ARGV && $ARGV[0] =~ /^-/)
28{
29  $_ = shift(@ARGV);
30  if (/^-S(ingular)?$/)  { $Singular = shift(@ARGV); next;}
31  if (/^-hlp$/)          { $hlp = shift(@ARGV); next;}
32  if (/^-c(mpl)?$/)      { $cmpl = shift(@ARGV); next;}
33  if (/^-h(elp)?$/)      { print $Usage; exit;}
34  die "Unrecognized option: $_\n$Usage";
35}
36
37#
38# get array of strings
39#
40if ($cmpl eq 'cmd')
41{
42  $strings = `$Singular -tq --exec='reservedName();\$'`;
43  die "Error in execution of: $Singular -tq --exec='reservedName();\$': $!\n"
44    if ($?);
45  @strings = map "(\"$_\")", split(/\s+/, $strings);
46}
47elsif ($cmpl eq 'lib')
48{
49  # Sort libraries in REVERSE order! (Menu is created from bottom to
50  # top in singular.el)
51  @strings = map "(\"$_\")", sort {$b cmp $a} split(/\s+/, <>);
52}
53elsif ($cmpl eq 'hlp')
54{
55  open(FH, "<$hlp") || die "Can not open file $hlp: $!\n";
56  while (<FH>)
57  {
58    if (/Node: Index/)
59    {
60      while (<FH>)
61      {
62        last if /\* Menu:/;
63      }
64      <FH>;
65      while (<FH>)
66      {
67        last if /^\s*$/;
68        if ( /^\* (.*):\s*(.*).\s*/ ) {
69          $node = $1; $rawNode = $2;
70          # remove duplicate counter from node
71          $node =~ s/(.*) <\d+>$/$1/;
72          # quote characters special to Emacs
73          $node =~ s/([\"#\\])/\\\1/g;    #'
74          $rawNode =~ s/([\"#\\])/\\\1/g; #'
75          # only the first occurence of $node is inserted to @string!
76          # all subsequent entries are discarded.
77          push @strings, "(\"$node\" . \"$rawNode\")" if $node ne $prev;
78          $prev = $node;
79        }
80      }
81      last;
82    }
83  }
84  close(FH);
85}
86else
87{
88  die "Error: Can not make completion list for $cmpl\n $Usage";
89}
90print STDOUT <<EOT;
91; Do not edit this file: It was automatically generated by $0
92(setq $symbol{$cmpl}
93  '(
94EOT
95#' prevents breaking of fontification
96 
97foreach $string (@strings)
98{
99  print STDOUT "    $string\n";
100}
101
102print STDOUT "))\n";
103
Note: See TracBrowser for help on using the repository browser.