[software and hardware technology originating from or otherwise pertinent to planet earth]
Caveat: For these ideas to work, you might [depending on your system] need to download and install either or both of these Elisp modules:
php-mode css-mode
Presumption [for the purposes of this tip]: IF you are using Emacs to edit PHP and/or CSS, THEN you know about and are using one or the other or both of these modules. If not, then you should probably give up now or seek professional help immediately.
Task: Editing a PHP source file using Emacs can involve working in several source code language formatting modes, since it is common to mix PHP, CSS, (X)HTML, Javascript, and even MySQL query syntax in one PHP source file.
Rationale: Although mixing languages in a single source file may on the face of it seem to violate the kind of *nixish organizational precepts that give us e.g. header (.h) and source (.c) files in C, sometimes painful experience has shown that the object oriented (OOD) precepts of "Encapsulation", "Isolation of Commonality", "Maintainability", and even (in some cases) "Human Readability" are all served by facilitating the mixing of languages within a single source file.
All that to say this: When editing a block of CSS code within a PHP file (using Emacs, of course), I have found it helpful to use the Emacs 'css-mode' Meta-Q key binding to format CSS rule blocks. However, when entering a multi-line CSS comment in the traditional 'C' style, it is useful to ask Emacs to use 'php-mode' Meta-Q to format the comments.
<?php
$str = "example";
>
<style<
body {
/*
* To format this comment block:
* 1. Move the cursor to this line
* 2. Meta-X php-mode
* 3. Meta-Q
*
*/
margin:0;
padding:0;
}
Summary:
Meta-Q keystroke in Emacs formats the text under the cursor in the current buffer into a 'paragraph' [block] conforming to some arbitrary standard established for whatever mode Emacs is running in (assuming, of course, that Meta-Q is mapped for that mode).php-mode formatting works most readably that way.…In constructing a web application with more than 2 PHP source modules, I found that it is useful to have a quick and easy way of finding a syntax error that may exist in one (or more) of a list of included modules.
Getting a List of PHP Includes
There is a function in PHP for this, which we will get back to in a moment. For right now I wanted to address some things we can do at a Bash prompt to troubleshoot why a script may not be sending any output to the browser on STDOUT.
That's a very common situation when you're working on a large application with many modules. It becomes important in those situations to be meticulous about syntax checking each change in any code before making additional changes.
I've been using the 'Lint' mechanism provided by PHP to syntax check PHP source code. It works like this:
$php -l <fileName>
Now, some of you might already be seeing the implications of this. Hows about:
$for fn in \
`grep require frmPlayerInformation_body.09.inc\
| perl -ne '/\"([a-zA-Z0-9.]+)\"\;/ && print "$1\n";'` ;;
do
echo $fn ;;
php -l $fn ;;
echo "########" ;;
done
The implications for scripting this operation from the command line are clear.
PHP provides a function to get a list of module dependencies for a running script. It's called
get_included_files()
… and here's the URL for the docs: http://us2.php.net/manual/en/function.get-included-files.php
Problems with this Approach
There is at least one serious deficiency inherent in using the require, require_once, include, and include_once directives as the sole indicators of module dependency; that is that, simply, the modules which are required or "included" due to HTML element attribute values.
Examples include the ACTION attrubute value(s) of HTML FORM element(s), the SRC attribute values for SCRIPT elements. and so on. IFRAME and LINK elements are also among those that can cause a module dependency within the HTML, CSS, or Javascript layer(s) generated by PHP code of a site.
Labels: 0x0000, bash, code, css, html, javascript, linux, perl, php, script, source, webappdev
#!/usr/bin/perl -w # # ls2csv.pl - show a listing of the PHP file # (*.inc and *.php) # as a CSV table; no table headings included in # output; no params defined # sub create_listing($) { my $xtn = shift; my @files = `ls -ghoG *.$xtn`; foreach my $f (@files) { chomp($f); $f =~ s/^\s*[-rw]+\s+\d\s+(.+)/$1/; $f =~ s/ /\",\"/g; $f =~ s/^(.)/\"$1/; $f =~ s/(.)$/$1\"/; print "$f\n"; } } map { create_listing($_) } ("inc","php");
Labels: 0x0000, bash, code, gnu, linux, perl, script, shebang, source
http://code.google.com/apis/gdata/client-js.html#Obtain_Key
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>My Google Data API Application</title>
<script src="http://www.google.com/jsapi?key=ABQIAAAAEF0hbwoIdolnKjr5eMdCPRR65_V0rae5Sii3SwQWquZGohjOQRRV-du2YimkeA46q7aGVN6U-luT3w" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
google.load("gdata", "1");
function OnLoad() {
// Fill out
}
//]]>
</script>
</head>
<body onload="OnLoad()">
<div id="panel"/>
</body>
</html>
Labels: code, gdata, gooogle, javascript, web
Checking out the JavaScript drawing program example called Doodle at the webreference.com section on JavaScript Programming, I found this bit of CSS that does syntax highlighting: SyntaxHighlighter.css [http://www.webreference.com/css/SyntaxHighlighter.css]
See also the Doodle Javascript programming example provided by WebReference for use of these style classes. Nice bit of work.
Here is a trivial example of the HTML to use of some of SyntaxHighlighter.css classes [from the example article, page 3]:
<div style="width: 700px;">
<textarea name="code" class="javascript" cols="60" rows="10">
<P class=code><script src="core.js"
type=text/javascript></script><BR><script src="graphics.js"
type=text/javascript></script><BR><script src="canvas.js"
type=text/javascript></script><BR><script
type=text/javascript><BR>var canvas = null;<BR>function initCanvas()
{<BR> canvas = new
Canvas($('theCanvas'));<BR>}<BR>window.setTimeout(initCanvas,
10);<BR></script><BR> <div id="theFrame"
class="CanvasFrame"></div><BR> <div id="theCanvas"
class="Canvas"></div><BR></div></P>
</textarea>
</div>
Other examples occur in the article.
This CSS seems to make a nice complement to the PHP syntax highlighter blogged about elsewhere.
Labels: blog, blogger, code, css, html, javascript, php, source, syntax highlighter, web
2006/12 2007/01 2007/05 2007/06 2007/07 2007/08 2007/10 2008/01 2008/02 2008/03 2008/05 2008/11 2008/12 2009/01 2009/02 2009/03 2009/04 2009/05 2009/07 2009/09 2009/10 2009/11 2009/12 2010/01
Subscribe to Posts [Atom]