summaryrefslogtreecommitdiff
path: root/regen
diff options
context:
space:
mode:
authorLukas Mai <lukasmai.403@gmail.com>2023-03-23 17:43:28 +0100
committerYves Orton <demerphq@gmail.com>2023-03-24 06:10:05 +0800
commit9a3a94ffdd8cf71ee39fede590ae136ce59f7cf7 (patch)
treea76682477d84dbb79d1266cdee811365aeedb3d1 /regen
parentb7eedb08953678c5b222f3776892756053dc00aa (diff)
downloadperl-9a3a94ffdd8cf71ee39fede590ae136ce59f7cf7.tar.gz
don't set a special filetype for generated .gitignore
Previously it would default to Perl, which happens to produce the right comment character ("#"), but results in nonsensical syntax highlighting. Now we set $lang to the special value 'None', which still produces read-only declarations, but doesn't force a mode/filetype on editors.
Diffstat (limited to 'regen')
-rw-r--r--regen/regen_lib.pl26
1 files changed, 18 insertions, 8 deletions
diff --git a/regen/regen_lib.pl b/regen/regen_lib.pl
index f511857781..1e418402b0 100644
--- a/regen/regen_lib.pl
+++ b/regen/regen_lib.pl
@@ -37,8 +37,11 @@ sub safer_unlink {
sub open_new {
my ($final_name, $mode, $header, $force) = @_;
my $name = $final_name . '-new';
- my $lang = $final_name =~ /\.pod$/ ? 'Pod' :
- $final_name =~ /\.(?:c|h|inc|tab|act)$/ ? 'C' : 'Perl';
+ my $lang =
+ $final_name =~ /\.pod\z/ ? 'Pod' :
+ $final_name =~ /\.(?:c|h|inc|tab|act)\z/ ? 'C' :
+ $final_name =~ /\.gitignore\z/ ? 'None' :
+ 'Perl';
if ($force && -e $final_name) {
chmod 0777, $name if $Needs_Write;
CORE::unlink $final_name
@@ -128,7 +131,12 @@ sub close_and_rename {
rename $name, $final_name or die "renaming $name to $final_name: $!";
}
-my %lang_opener = (Perl => '# ', Pod => '', C => '/* ');
+my %lang_opener = (
+ Perl => '# ',
+ Pod => '',
+ C => '/* ',
+ None => '# ',
+);
sub read_only_top {
my %args = @_;
@@ -139,7 +147,7 @@ sub read_only_top {
my $style = $args{style} ? " $args{style} " : ' ';
# Generate the "modeline" for syntax highlighting based on the language
- my $raw = "-*- mode: $lang; buffer-read-only: t -*-\n";
+ my $raw = "-*- " . ($lang eq 'None' ? "" : "mode: $lang; ") . "buffer-read-only: t -*-\n";
if ($args{file}) {
$raw .= "\n $args{file}\n";
@@ -203,14 +211,16 @@ sub read_only_bottom_close_and_rename {
$comment .= "$digest $file\n";
}
}
- $comment .= "ex: set ro ft=\L$lang\E:";
+ $comment .= "ex: set ro" . ($lang eq 'None' ? "" : " ft=\L$lang\E") . ":";
- if (defined $lang && $lang eq 'Perl') {
- $comment =~ s/^/# /mg;
- } elsif (!defined $lang or $lang ne 'Pod') {
+ if ($lang eq 'Pod') {
+ # nothing
+ } elsif ($lang eq 'C') {
$comment =~ s/^/ * /mg;
$comment =~ s! \* !/* !;
$comment .= " */";
+ } else {
+ $comment =~ s/^/# /mg;
}
print $fh "\n$comment\n";