git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gitweb: move highlight config out of guess_file_syntax()
@ 2010-07-24 19:46 Alejandro R. Sedeño
       [not found] ` <201007260135.35059.jnareb@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Alejandro R. Sedeño @ 2010-07-24 19:46 UTC (permalink / raw)
  To: git, Jakub Narebski

Move highlight config out of guess_file_syntax() so that it can be
extended/overridden by system/user configuration.

Signed-off-by: Alejandro R. Sedeño <asedeno@mit.edu>
---
 gitweb/gitweb.perl |   47 +++++++++++++++++++++++------------------------
 1 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index cedc357..e0e9532 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -232,6 +232,29 @@ our %avatar_size = (
 # Leave it undefined (or set to 'undef') to turn off load checking.
 our $maxload = 300;
 
+# configuration for 'highlight' (http://www.andre-simon.de/)
+# match by basename
+our %highlight_basename = (
+	#'Program' => 'py',
+	#'Library' => 'py',
+	'SConstruct' => 'py', # SCons equivalent of Makefile
+	'Makefile' => 'make',
+);
+# match by extension
+our %highlight_ext = (
+	# main extensions, defining name of syntax;
+	# see files in /usr/share/highlight/langDefs/ directory
+	map { $_ => $_ }
+		qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
+	# alternate extensions, see /etc/highlight/filetypes.conf
+	'h' => 'c',
+	map { $_ => 'cpp' } qw(cxx c++ cc),
+	map { $_ => 'php' } qw(php3 php4),
+	map { $_ => 'pl'  } qw(perl pm), # perhaps also 'cgi'
+	'mak' => 'make',
+	map { $_ => 'xml' } qw(xhtml html htm),
+);
+
 # You define site-wide feature defaults here; override them with
 # $GITWEB_CONFIG as necessary.
 our %feature = (
@@ -3316,30 +3339,6 @@ sub blob_contenttype {
 sub guess_file_syntax {
 	my ($highlight, $mimetype, $file_name) = @_;
 	return undef unless ($highlight && defined $file_name);
-
-	# configuration for 'highlight' (http://www.andre-simon.de/)
-	# match by basename
-	my %highlight_basename = (
-		#'Program' => 'py',
-		#'Library' => 'py',
-		'SConstruct' => 'py', # SCons equivalent of Makefile
-		'Makefile' => 'make',
-	);
-	# match by extension
-	my %highlight_ext = (
-		# main extensions, defining name of syntax;
-		# see files in /usr/share/highlight/langDefs/ directory
-		map { $_ => $_ }
-			qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
-		# alternate extensions, see /etc/highlight/filetypes.conf
-		'h' => 'c',
-		map { $_ => 'cpp' } qw(cxx c++ cc),
-		map { $_ => 'php' } qw(php3 php4),
-		map { $_ => 'pl'  } qw(perl pm), # perhaps also 'cgi'
-		'mak' => 'make',
-		map { $_ => 'xml' } qw(xhtml html htm),
-	);
-
 	my $basename = basename($file_name, '.in');
 	return $highlight_basename{$basename}
 		if exists $highlight_basename{$basename};
-- 
1.7.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] gitweb: move highlight config out of guess_file_syntax()
       [not found] ` <201007260135.35059.jnareb@gmail.com>
@ 2010-07-25 23:53   ` "Alejandro R. Sedeño"
  2010-07-26 20:48     ` Jakub Narebski
  2010-07-26 20:45   ` Jakub Narebski
  1 sibling, 1 reply; 6+ messages in thread
From: "Alejandro R. Sedeño" @ 2010-07-25 23:53 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git

On 7/25/2010 7:35 PM, Jakub Narebski wrote:
> BTW. is this something _you_ needed (and what did you need to configure
> / to put in $GITWEB_CONFIG file), or just a generalization?


This is something I was using in previous versions of gitweb, though
with the older (pre-592ea41) syntax. (I had applied the older
highlighting patches, and was quite happy to see them merged.)

Before, $GITWEB_CONFIG contained lines like:

  $highlight_type{'\.lisp$'} = 'lisp';

As of 1.7.2, with syntax highlighting merged and refactored (592ea41),
access to the hashes that define syntax highlighting mappings was lost.
Moving the hashes out into the config area lets $GITWEB_CONFIG contain
lines like:

  $highlight_ext{'lisp'} = 'lisp';
  $highlight_basename{'GNUmakefile'} = 'mak'

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] gitweb: move highlight config out of guess_file_syntax()
       [not found] ` <201007260135.35059.jnareb@gmail.com>
  2010-07-25 23:53   ` "Alejandro R. Sedeño"
@ 2010-07-26 20:45   ` Jakub Narebski
  2010-07-28 18:40     ` Alejandro R. Sedeño
  1 sibling, 1 reply; 6+ messages in thread
From: Jakub Narebski @ 2010-07-26 20:45 UTC (permalink / raw)
  To: Alejandro R. Sedeño; +Cc: git

On Mon, 26 Jul 2010, Jakub Narębski wrote:
> On Sat, 24 Jul 2010, Alejandro R. Sedeño wrote:
> 
> > Move highlight config out of guess_file_syntax() so that it can be
> > extended/overridden by system/user configuration.
> > 
> > Signed-off-by: Alejandro R. Sedeño <asedeno@mit.edu>
> 
> Good idea.
> 
> The only _possible_ problem is that this configuration is fairly specific
> with respect to currently the only one sipported hightlighter, i.e. the
> external binary 'highlight' (http://www.andre-simon.de).  If we are to
> add support for other programs (e.g. GNU Source Highlight) or Perl modules
> for syntax highlighting (e.g. Syntax::Highlight::Engine::Kate or 
> Beautifier) in the future, this could mean backward incompatibile change.
> 
> The culprit is using extensions (in 'highlight' main syntax files are 
> named by extensions) rather than format names in %highlight_basename
> and %highlight_ext, e.g. 'py' rather than 'python'.  I don't know if
> it would be much of the problem.
> 
> So perhaps I am worrying about nothing...

I am worrying about nothing.  The default syntax highlighter would be
'highlight' program; if one wants to change highlighter, one can also
modify required configuration (names of 'syntax' to choose from might
be different for different highlighting engines).

Therefore:

Acked-by: Jakub Narebski <jnareb@gmail.com>

-- 
Jakub Narebski
Poland

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] gitweb: move highlight config out of guess_file_syntax()
  2010-07-25 23:53   ` "Alejandro R. Sedeño"
@ 2010-07-26 20:48     ` Jakub Narebski
  2010-07-26 20:56       ` "Alejandro R. Sedeño"
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Narebski @ 2010-07-26 20:48 UTC (permalink / raw)
  To: Alejandro R. Sedeño; +Cc: git

On Mon, 26 Jul 2010, Alejandro R. Sedeño wrote:
> On 7/25/2010 7:35 PM, Jakub Narębski wrote:

> > BTW. is this something _you_ needed (and what did you need to configure
> > / to put in $GITWEB_CONFIG file), or just a generalization?
> 
> 
> This is something I was using in previous versions of gitweb, though
> with the older (pre-592ea41) syntax. (I had applied the older
> highlighting patches, and was quite happy to see them merged.)
> 
> Before, $GITWEB_CONFIG contained lines like:
> 
>   $highlight_type{'\.lisp$'} = 'lisp';
> 
> As of 1.7.2, with syntax highlighting merged and refactored (592ea41),
> access to the hashes that define syntax highlighting mappings was lost.
> Moving the hashes out into the config area lets $GITWEB_CONFIG contain
> lines like:
> 
>   $highlight_ext{'lisp'} = 'lisp';
>   $highlight_basename{'GNUmakefile'} = 'mak';

O.K., I don't think we want to put all possible languages that 'highlight'
supports in %highlight_ext, so you might want to add support for less
common languages, or languages introduced in newer versions of tool.


Note that you can write here

    $highlight_basename{'GNUmakefile'} = 'make';

which might be slightly more readable.

-- 
Jakub Narebski
Poland

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] gitweb: move highlight config out of guess_file_syntax()
  2010-07-26 20:48     ` Jakub Narebski
@ 2010-07-26 20:56       ` "Alejandro R. Sedeño"
  0 siblings, 0 replies; 6+ messages in thread
From: "Alejandro R. Sedeño" @ 2010-07-26 20:56 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git

On 7/26/2010 4:48 PM, Jakub Narebski wrote:
>> As of 1.7.2, with syntax highlighting merged and refactored (592ea41),
>> > access to the hashes that define syntax highlighting mappings was lost.
>> > Moving the hashes out into the config area lets $GITWEB_CONFIG contain
>> > lines like:
>> > 
>> >   $highlight_ext{'lisp'} = 'lisp';
>> >   $highlight_basename{'GNUmakefile'} = 'mak';
> O.K., I don't think we want to put all possible languages that 'highlight'
> supports in %highlight_ext, so you might want to add support for less
> common languages, or languages introduced in newer versions of tool.
> 
> 
> Note that you can write here
> 
>     $highlight_basename{'GNUmakefile'} = 'make';
> 
> which might be slightly more readable.

Yeah, that was a typo on my part; I was recalling samples from memory.
The actual entry reads 'make' not 'mak', just as you suggest. :)

-Alejandro

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] gitweb: move highlight config out of guess_file_syntax()
  2010-07-26 20:45   ` Jakub Narebski
@ 2010-07-28 18:40     ` Alejandro R. Sedeño
  0 siblings, 0 replies; 6+ messages in thread
From: Alejandro R. Sedeño @ 2010-07-28 18:40 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Jakub Narebski

Move highlight config out of guess_file_syntax() so that it can be
extended/overridden by system/user configuration.

Signed-off-by: Alejandro R. Sedeño <asedeno@mit.edu>
Acked-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |   47 +++++++++++++++++++++++------------------------
 1 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index cedc357..e0e9532 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -232,6 +232,29 @@ our %avatar_size = (
 # Leave it undefined (or set to 'undef') to turn off load checking.
 our $maxload = 300;
 
+# configuration for 'highlight' (http://www.andre-simon.de/)
+# match by basename
+our %highlight_basename = (
+	#'Program' => 'py',
+	#'Library' => 'py',
+	'SConstruct' => 'py', # SCons equivalent of Makefile
+	'Makefile' => 'make',
+);
+# match by extension
+our %highlight_ext = (
+	# main extensions, defining name of syntax;
+	# see files in /usr/share/highlight/langDefs/ directory
+	map { $_ => $_ }
+		qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
+	# alternate extensions, see /etc/highlight/filetypes.conf
+	'h' => 'c',
+	map { $_ => 'cpp' } qw(cxx c++ cc),
+	map { $_ => 'php' } qw(php3 php4),
+	map { $_ => 'pl'  } qw(perl pm), # perhaps also 'cgi'
+	'mak' => 'make',
+	map { $_ => 'xml' } qw(xhtml html htm),
+);
+
 # You define site-wide feature defaults here; override them with
 # $GITWEB_CONFIG as necessary.
 our %feature = (
@@ -3316,30 +3339,6 @@ sub blob_contenttype {
 sub guess_file_syntax {
 	my ($highlight, $mimetype, $file_name) = @_;
 	return undef unless ($highlight && defined $file_name);
-
-	# configuration for 'highlight' (http://www.andre-simon.de/)
-	# match by basename
-	my %highlight_basename = (
-		#'Program' => 'py',
-		#'Library' => 'py',
-		'SConstruct' => 'py', # SCons equivalent of Makefile
-		'Makefile' => 'make',
-	);
-	# match by extension
-	my %highlight_ext = (
-		# main extensions, defining name of syntax;
-		# see files in /usr/share/highlight/langDefs/ directory
-		map { $_ => $_ }
-			qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
-		# alternate extensions, see /etc/highlight/filetypes.conf
-		'h' => 'c',
-		map { $_ => 'cpp' } qw(cxx c++ cc),
-		map { $_ => 'php' } qw(php3 php4),
-		map { $_ => 'pl'  } qw(perl pm), # perhaps also 'cgi'
-		'mak' => 'make',
-		map { $_ => 'xml' } qw(xhtml html htm),
-	);
-
 	my $basename = basename($file_name, '.in');
 	return $highlight_basename{$basename}
 		if exists $highlight_basename{$basename};
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-07-28 18:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-24 19:46 [PATCH] gitweb: move highlight config out of guess_file_syntax() Alejandro R. Sedeño
     [not found] ` <201007260135.35059.jnareb@gmail.com>
2010-07-25 23:53   ` "Alejandro R. Sedeño"
2010-07-26 20:48     ` Jakub Narebski
2010-07-26 20:56       ` "Alejandro R. Sedeño"
2010-07-26 20:45   ` Jakub Narebski
2010-07-28 18:40     ` Alejandro R. Sedeño

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).