File: jedpcre.sl

package info (click to toggle)
jed-extra 2.5.7-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 2,972 kB
  • ctags: 2,490
  • sloc: makefile: 75; ruby: 43; sed: 38; sh: 31
file content (45 lines) | stat: -rw-r--r-- 1,068 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
% jedpcre.sl
% 
% $Id: jedpcre.sl,v 1.4 2008/10/21 18:48:25 paul Exp paul $
%
% Copyright (c) 2004-2008 Paul Boekholt.
% Released under the terms of the GNU GPL (version 2 or later).
% 
% This provides a pcre occur function.

provide("jedpcre");
require("pcre");
require("occur");  % this requires the occur from jedmodes.sf.net/mode/occur

%{{{ occur


public define pcre_occur()
{
   variable pat, str, tmp, n;
   if (_NARGS) pat = ();
   else
     pat = read_mini("Find All (Regexp):", LAST_SEARCH, Null_String);
   variable occur_re = pcre_compile(pat);
   tmp = "*occur*";
   occur->obuf = whatbuf();
   occur->nlines=0;
   occur->mbuffers=0;
   push_spot_bob;
   push_mark_eob;
   str = strchop(bufsubstr, '\n', 0);
   pop_spot;
   variable index = where(array_map(Integer_Type, &pcre_exec, occur_re, str));
   ifnot (length(index)) return message("no matches");
   pop2buf(tmp);
   erase_buffer();
   foreach n (index)
     {
	vinsert ("%*d: %s\n", occur->line_number_width, 1+n, str[n]);
     }
   bob(); set_buffer_modified_flag(0);
   occur_mode();
}


%}}}