The real is the rational, and the rational is the realGeorg Wilhelm Friedrich Hegel
Relates to PHP and Apache, IDEs, X11
Ok, I have gone all XEmacs, and am really impressed. For the best part of two years now I have been using UltraEdit for must web scripting with a little bit of Eclipse on the side for command line testing with PHP5 development. With a large amount of the development work now migrated to my IBook, it was time to seek out a new editor. Currently I am undecided between Eclipse, BBEdit, Vim, Quanta, Kate and XEmacs, although I am very drawn to the latter.
Despite the learning curve, with a bit of Lisp knowledge in hand, the power of XEmacs quickly becomes apparent. Of course an essential feature for any scripting language is syntax highlighting and efficient function lookup. The first is easy enough - add the prog-modes package (which includes an Emacs lisp file for PHP major mode) and all other dependant packages from the package manager. I also enabled syntax highlighting by default in ~/.xemcas/init.el with:
(require 'font-lock)
While perusing the settings for PHP mode from the Options menu (and directly from the package file prog-modes/php-mode.el) I discovered that the key command sequence Ctrl C Ctrl F performs a search for the function currently selected at php.net. This was a problem since the machine is not going to be on a permanant connection. So, I decided to store the PHP Documentation on my local server. Nothing out of the ordinary, except it give me the opportunity to use the RewriteMap directive in the Apache configuration.
Add a virtual server entry to the httpd configuration file. I currently have the system configured to reboot Apache with a different principle conf file for each PHP version - as with my Window 98 box - so I put virtual server directives in one of the user conf files (from /etc/httpd/users) instead.
<VirtualHost 127.0.0.1>
ServerName phpdocumentation
# Rewrite Directives will go here…
DocumentRoot "/path/to/php/documentation/dir"
<Directory "/path/to/php/documentation/dir">
AllowOverride All
Options +FollowSymLinks
</Directory>
</VirtualHost>
Now, instead of hacking the Lisp code in php-mode.el, which could readily be destroyed by a future update of prog-modes, I decided to throw in a rewrite rule to fix the request URI. From XEmacs the request would be for http://phpdocumentation/function_name, so the following might work:
RewriteEngine On
RewriteRule ^([-_a-z0-9])$ /function.$1.html
Sadly not! All function help files take the form function.[the-function-name].html. And that is where I hit the stumbling block! Underscores are replaced by hyphens in the HTML file names for functions.
I was reluctant to resort to Lisp hacking, so decided to try one of the rewrite directives I have had little use for previously - RewriteMap.
Create an executable script that can be called in the rewriting process to replace the underscores. I choose Perl and, due the simplicity of the rewrite, only needed one more line of code than the actual Apache manual:
#!/usr/bin/perl
# php-func-map.pl
# avoid buffered I/O
$| = 1;
while (<STDIN>) {
# globally change the underscore to a hyphen
s/_/-/g;
print $_;
}
Then set up the rewriting directives - for RewriteMap these have to go under the VirtualHost directive in the conf rather than in .htaccess file.
RewriteEngine On
RewriteMap php-func-map prg:/path/to/php-func-map.pl
RewriteRule /([-_a-z0-9]+)$ /function.${php-func-map:$1}.html
And that is that. The magic is in ${php-func-map:$1} which will pass the pattern match $1 to the file defined by php-func-map and get back a PHP manual friendly file name. Of course this could be extended further to perform searches beyond just the manual's function set but servers my purpose well for the time being. So, now when I forget if the needle or the haystack goes first, a quick key combination and the manual entry is available.
Posted on Wednesday, Jun 15, 2005 at 17:58:33.
Comments on PHP Function Lookup from XEmacs (0)