line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2012 Kevin Ryde |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This file is part of Regexp-Common-Other. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Regexp-Common-Other is free software; you can redistribute it and/or |
6
|
|
|
|
|
|
|
# modify it under the terms of the GNU General Public License as published |
7
|
|
|
|
|
|
|
# by the Free Software Foundation; either version 3, or (at your option) any |
8
|
|
|
|
|
|
|
# later version. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Regexp-Common-Other is distributed in the hope that it will be useful, |
11
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
13
|
|
|
|
|
|
|
# Public License for more details. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along |
16
|
|
|
|
|
|
|
# with Regexp-Common-Other. If not, see . |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package Regexp::Common::Emacs; |
20
|
1
|
|
|
1
|
|
13112
|
use 5.005; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
21
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
22
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
70
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# no import(), don't want %RE or builtins, and will call pattern() by full name |
25
|
1
|
|
|
1
|
|
5
|
use Regexp::Common (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
5
|
use vars '$VERSION'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
104
|
|
28
|
|
|
|
|
|
|
$VERSION = 11; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
## no critic (RequireInterpolationOfMetachars) |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
33
|
|
|
|
|
|
|
# use Smart::Comments; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# "[:digit:]" in perl 5.6 where available |
37
|
|
|
|
|
|
|
# "0-9" in perl 5.005 and earlier |
38
|
1
|
|
|
|
|
2
|
use constant DIGIT => do { |
39
|
1
|
|
|
|
|
5
|
local $^W = 0; |
40
|
1
|
50
|
|
|
|
86
|
eval q{'0' =~ /[[:digit:]]/ ? '[:digit:]' : '0-9'} |
41
|
|
|
|
|
|
|
|| die "Oops, eval for [:digit:] error: ",$@; |
42
|
1
|
|
|
1
|
|
7
|
}; |
|
1
|
|
|
|
|
2
|
|
43
|
|
|
|
|
|
|
### DIGIT: DIGIT() |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Ending with "~", per Emacs manual info "(emacs)Backup Names" and function |
47
|
|
|
|
|
|
|
# backup-file-name-p |
48
|
|
|
|
|
|
|
# Eg. "foo.c~" or "foo.c.~123~" |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
Regexp::Common::pattern |
51
|
|
|
|
|
|
|
(name => ['Emacs','backup'], |
52
|
|
|
|
|
|
|
create => sub { |
53
|
|
|
|
|
|
|
my ($self, $flags) = @_; |
54
|
|
|
|
|
|
|
### $flags |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
if (exists $flags->{'-single'}) { |
57
|
|
|
|
|
|
|
# presumed from single only |
58
|
|
|
|
|
|
|
# $1=whole |
59
|
|
|
|
|
|
|
# $2=basename |
60
|
|
|
|
|
|
|
if (exists $flags->{'-keep'}) { |
61
|
|
|
|
|
|
|
return '(?k:(?k:.+)~$)'; |
62
|
|
|
|
|
|
|
} else { |
63
|
|
|
|
|
|
|
return '.~$'; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
if (exists $flags->{'-numbered'}) { |
68
|
|
|
|
|
|
|
if (! exists $flags->{'-notnumbered'}) { |
69
|
|
|
|
|
|
|
# numbered only |
70
|
|
|
|
|
|
|
# $1=whole |
71
|
|
|
|
|
|
|
# $2=basename |
72
|
|
|
|
|
|
|
# $3=number |
73
|
|
|
|
|
|
|
if (exists $flags->{'-keep'}) { |
74
|
|
|
|
|
|
|
return '(?k:(?k:.+)\.~(?k:\d+)~$)'; |
75
|
|
|
|
|
|
|
} else { |
76
|
|
|
|
|
|
|
return '.\.~\d+~$'; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} else { |
80
|
|
|
|
|
|
|
if (exists $flags->{'-notnumbered'}) { |
81
|
|
|
|
|
|
|
# not numbered only |
82
|
|
|
|
|
|
|
# $1=whole |
83
|
|
|
|
|
|
|
# $2=basename |
84
|
|
|
|
|
|
|
# |
85
|
|
|
|
|
|
|
# .* \D~ z~ non-digit |
86
|
|
|
|
|
|
|
# .* [^~]\d+~ z123~ non-~ |
87
|
|
|
|
|
|
|
# .* [^.]~\d+~ z~123~ non-. |
88
|
|
|
|
|
|
|
# ^ \.~\d+~ .~123~ basename empty |
89
|
|
|
|
|
|
|
# |
90
|
|
|
|
|
|
|
return '(?k:(?k:.*(?:\D|(?:[^~'.DIGIT().']|(?:[^.]|^\.)~)\d+))~$)'; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# numbered or not numbered |
95
|
|
|
|
|
|
|
if (exists $flags->{'-keep'}) { |
96
|
|
|
|
|
|
|
# $1=whole |
97
|
|
|
|
|
|
|
# $2=basename |
98
|
|
|
|
|
|
|
# $3=number or undef |
99
|
|
|
|
|
|
|
return '(?k:(?k:.+?)(?:\.~(?k:\d+))?~$)'; |
100
|
|
|
|
|
|
|
} else { |
101
|
|
|
|
|
|
|
return '.~$'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
}); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# begin and end with "#", per Emacs function auto-save-file-name-p |
107
|
|
|
|
|
|
|
Regexp::Common::pattern |
108
|
|
|
|
|
|
|
(name => ['Emacs','autosave'], |
109
|
|
|
|
|
|
|
create => '^(?k:#(?k:.+)#$)'); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# file-locked-p and C source MAKE_LOCK_NAME() |
112
|
|
|
|
|
|
|
Regexp::Common::pattern |
113
|
|
|
|
|
|
|
(name => ['Emacs','lockfile'], |
114
|
|
|
|
|
|
|
create => sub { |
115
|
|
|
|
|
|
|
my ($self, $flags) = @_; |
116
|
|
|
|
|
|
|
if (exists $flags->{'-keep'}) { |
117
|
|
|
|
|
|
|
return '^(?k:\.\#(?k:.+))$'; |
118
|
|
|
|
|
|
|
} else { |
119
|
|
|
|
|
|
|
return '^\.\#.'; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
}); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# any of backup,autosave,lockfile |
124
|
|
|
|
|
|
|
# (.+) ~$ backup |
125
|
|
|
|
|
|
|
# ^# (.+) #$ autosave |
126
|
|
|
|
|
|
|
# ^\.# (.+) lockfile |
127
|
|
|
|
|
|
|
Regexp::Common::pattern |
128
|
|
|
|
|
|
|
(name => ['Emacs','skipfile'], |
129
|
|
|
|
|
|
|
create => sub { |
130
|
|
|
|
|
|
|
my ($self, $flags) = @_; |
131
|
|
|
|
|
|
|
if (exists $flags->{'-keep'}) { |
132
|
|
|
|
|
|
|
return '^(?k:\.\#.+|\#.+\#|.+~)$'; |
133
|
|
|
|
|
|
|
} else { |
134
|
|
|
|
|
|
|
return '^(?:\.\#.|\#.+\#$)|.~$'; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
}); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
__END__ |