{"thread":{"id":"6976","subject":"Syntax highlighting for gitweb","startedAt":"2007-02-26T18:18:58Z","lastAt":"2007-02-27T01:45:10Z","messageCount":3,"participants":["Ed Schouten","Johannes Schindelin","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"35520","messageId":"20070226181858.GC11232@hoeg.nl","threadId":"6976","inReplyTo":null,"subject":"Syntax highlighting for gitweb","fromName":"Ed Schouten","fromEmail":"ed@fxq.nl","sentAt":"2007-02-26T18:18:58Z","receivedAt":"2007-02-26T18:18:58Z","isPatch":false,"sender":{"key":"ed@fxq.nl","avatar":null},"body":"Hello everyone,\n\nI just wrote a really awful patch to add syntax highlighting to gitweb:\n\n%%%\n--- gitweb\tMon Feb 26 18:36:42 2007\n+++ gitweb\tMon Feb 26 19:12:20 2007\n@@ -16,6 +16,7 @@\n use Fcntl ':mode';\n use File::Find qw();\n use File::Basename qw(basename);\n+use IPC::Open2;\n binmode STDOUT, ':utf8';\n \n our $cgi = new CGI;\n@@ -3186,15 +3187,25 @@\n \tgit_print_page_path($file_name, \"blob\", $hash_base);\n \tprint \"<div class=\\\"page_body\\\">\\n\";\n \tmy $nr;\n+\n+\tmy $pid;\n+\tlocal (*HLR, *HLW);\n+\t$pid = open2(\\*HLR, \\*HLW, \"highlight -f --syntax c\");\n \twhile (my $line = <$fd>) {\n-\t\tchomp $line;\n-\t\t$nr++;\n-\t\t$line = untabify($line);\n-\t\tprintf \"<div class=\\\"pre\\\"><a id=\\\"l%i\\\" href=\\\"#l%i\\\" class=\\\"linenr\\\">%4i</a> %s</div>\\n\",\n-\t\t       $nr, $nr, $nr, esc_html($line, -nbsp=>1);\n+\t\tprint HLW $line;\n \t}\n+\tclose HLW\n+\t\tor print \"Failed to start highlight.\\n\";\n \tclose $fd\n \t\tor print \"Reading blob failed.\\n\";\n+\n+\twhile (my $line = <HLR>) {\n+\t\t$nr++;\n+\t\tprintf \"<div class=\\\"pre\\\"><a id=\\\"l%i\\\" href=\\\"#l%i\\\" class=\\\"linenr\\\">%4i</a> %s</div>\\n\",\n+\t\t       $nr, $nr, $nr, $line;\n+\t}\n+\tclose HLR\n+\t\tor print \"Failed to highlight blob.\\n\";\n \tprint \"</div>\";\n \tgit_footer_html();\n }\n%%%\n\nI am not a Perl programmer, so I kept it really simple by just\nhardcoding '--syntax c'. Would it be possible for some real Perl\nprogrammer to clean this up? I think a feature like this would be really\ncool to have.\n\nYours,\n-- \n Ed Schouten <ed@fxq.nl>\n WWW: http://g-rave.nl/\n"},{"id":"35522","messageId":"Pine.LNX.4.63.0702261953420.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6976","inReplyTo":"20070226181858.GC11232@hoeg.nl","subject":"Re: Syntax highlighting for gitweb","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-26T18:55:18Z","receivedAt":"2007-02-26T18:55:18Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 26 Feb 2007, Ed Schouten wrote:\n\n> I just wrote a really awful patch to add syntax highlighting to gitweb:\n> \n> [...]\n>\n> +\t$pid = open2(\\*HLR, \\*HLW, \"highlight -f --syntax c\");\n\nSince this fork()s an external program, which is possibly expensive, or \ncan fail because the program is not there, you should at least\n\n- document it, and\n- make it optional.\n\nCiao,\nDscho\n"},{"id":"35569","messageId":"es02au$ocf$1@sea.gmane.org","threadId":"6976","inReplyTo":"Pine.LNX.4.63.0702261953420.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: Syntax highlighting for gitweb","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-02-27T01:45:10Z","receivedAt":"2007-02-27T01:45:10Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Johannes Schindelin wrote:\n\n> On Mon, 26 Feb 2007, Ed Schouten wrote:\n> \n>> I just wrote a really awful patch to add syntax highlighting to gitweb:\n>> \n>> [...]\n>>\n>> +    $pid = open2(\\*HLR, \\*HLW, \"highlight -f --syntax c\");\n> \n> Since this fork()s an external program, which is possibly expensive, or \n> can fail because the program is not there, you should at least\n> \n> - document it, and\n> - make it optional.\n\nIt was planned (search for \"[RFC] gitweb wishlist and TODO list\" in\narchives), and gitweb-xmms2 (http://git.xmms.se/?p=gitweb-xmms2.git)\nhas it: see http://git.or.cz/gitwiki/InterfacesFrontendsAndTools#gitweb\nbut it was postponed together with committags support to have git config\nreader in Perl to use in gitweb.\n\nHmmm... perhaps we should use open2 in few places where we use non-list form\nof magic open \"-|\" (the one which spawns shell)?\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"}]}