perm url with updates http://xahlee.org/js/zen-coding.html
“Zen-Coding” and “Emacs-Buddha-Coding”
Xah Lee, 2010-01-22
Discovered what's called “zen-coding”. Basically, it is a scheme for inserting html templates in text editors. For example, type “div.beauty”, press a hotkey, then it expands to:
“ul#ref>li*3” expands to:
<ul id="ref"> <li></li> <li></li> <li></li> </ul>
This template system improves html coding efficiency. It is a abbrev expansion or template system. (the latest tech geeking fashion term for this is “snippet”.) The abbreviation used to expand is based on CSS selectors. (CSS “selectors” is basically a syntax for css to match html/xml tags. For a intro, see: What's New in CSS2)
The home page for this project that provides add-ons for several editors is at: http://code.google.com/p/zen-coding/. In particular, there's a emacs one at: http://www.emacswiki.org/emacs/ZenCoding, written by Chris Done.
The gist of the usefulness of “zen-coding” is that: (1) instead of pulling a menu or command to insert a tag, and prompting you for input of tag name and attributes, you simply type them out first in your editor's main window. (2) A consistent, systematic syntax, for the abbreviation.
I've been using a similar method for inserting html tags and templates in Emacs since about 2006. I have a set of home-cooked commands in elisp that does it. For examples, when i type: “div nav”, then press a hotkey, it becomes:
If i type “abc efg”, then it becomes:
If i type a single word instead of 2 words, then “div” tag is automatically assumed. For example, “xyz”, becomes:
If i press the hotkey with the cursor on the empty line, it inserts “<p></p>”.
If i paste a file path and press a different hotkey, it becomes a image tag, with width and height attributes, and alt attribute filled. For example, if the text i pasted is “i/pre_ex_firefox.png”, the result is:
<img src="i/pre_ex_firefox.png" alt="pre ex firefox" width="565" height="109">
If i paste a youtube url, for example: “http://www.youtube.com/watch?v=qaMcImrNnOQ”, then press a hotkey, it becomes a
<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/qaMcImrNnOQ" width="480" height="385"> <param name="movie" value="http://www.youtube.com/v/qaMcImrNnOQ"> </object>
If i type some phrase, for example: “Bertrand Russell”, press another hotkey, it becomes a link to the Wikipedia article:
<a href="http://en.wikipedia.org/wiki/Bertrand_Russell">Bertrand Russell</a>
If i press another hotkey, lines turn into list. Another hotkey turns lines into html table. another hotkey turns a url into particularly formatted reference link for languages perl, php, elisp, python...
If i paste in some source code of perl, python, java... etc any language, and press a hotkey, they become syntax colored (wrapped with different span tags for different keywords.) For example, the page you are reading, with all html source code syntax colored, is done in emacs with my custom commands.
There are quite a lot others, all basically takes the current word, current line, current paragraph, or current text selection as input, and transform them into a link, tag, or other template. The 4 thousand html pages on my website are hand coded, in emacs, with many custom elisp functions gradually developed over the years. With my system, i can write structured document in html faster than any wiki sysetm or light weight markup, yet with more control and flexibility in the actual html, and the generated code are all Valid HTML with controlled formatting so it can be batch-text-processed later if needed. (the down side is, of course, the time spend to know elisp. Basically, it's a trade off with acquiring knowledge vs off-the-shelf generic system.)
I probably won't be using zen-code soon, because my custom system already does all sort of html templates that are particularly crafted for my needs. Though, the “zen-code” system has the advantage of a more coherent syntax, and one single hotkey for all expansion. Though, it can't turn paths to links or inline images, can't turn words into Wikipedia links, or words into google search links, or youtube url into embedded video links. It is a smarter system than most editor's tool that insert single dummy tags, but the system is not flexable enough for outputting dynamic results, such as inserting date time stamp, or turn a image file path into a inline img tag with width and height values, etc.
For my emacs system to be useful to others, i'll need to put them together into a coherent package, with consistent hotkeys, a public website representation, full documentation, and probably a marketing jargon, such as “emacs-buddha-coding”. LOL. The abbrev expansion systax will need to be someting systematic and well known, so CSS Selectors in zen-coding is a good start, but am not sure how can it incorporate the feature where the output needs to contain dynamic info such as timestamp. Thinking about this... it's pretty clear that zen-coding is of limited use, because first of all, vast majority of web pages are not developed by manually coded html. Things have moved to wiki systems, website generating systems, document generating systems, blog sites, using light weight markup. These are useful for vast majority of people, say 99%, of those scientists, writers, engineers, and joe bloggers, who need to publish material thru the web, and doesn't require them to understand any html/css stuff. For programers and tech-savvy who needs to code html, there are no shortage of template systems (aka snippets) that they can define and customize, in all sort of tools and editors, with result that is usually more powerful then zen-coding.
With the above in mind, i think that there's relatively little market or wide utility for my emacs-buddha-coding.
The Name “Zen-Coding”
What's with the name? Zen? another new-agish open source coding geeker's fashionable locution. Such silliness we had in the past... “defensive programing”, “eXtreme programing”, “design patterns”, “agile programing”, “unit testing”, etc. Silly jargons are particularly popular in the unix and perl community. Often these fashionable jargons are shams that do harm on the real educational needs of programers, that is mathematics (so-called “computer science”).
Though, most of these jargons also fulfill a communication need, a unique term to identify a particular practice. It is the choice of the term that is a problem. In severe cases, it is the catchiness, used for marketing purposes of sham that hides truth or reality. Once you choose a term that clearly convey what it means, many shams will no longer have much to sell.