用 Emacs Lisp 开发 CGI 程序
2012-09-02 10:14
393 查看
Emacs Lisp 作为编程语言也是非常强大的。尤其 Emacs 作为一款编辑器,自带了很多处理文本的函数,用起来很方便。
我一直希望用 Emacs Lisp 作为服务端脚本语言来开发 Web 程序。在网上搜索了很久,还真有人做过类似的事情:http://www.emacswiki.org/emacs/cgi.el。但他封装的还不够彻底,用起来还是挺麻烦,于是自己动手写了一个。目前支持:
script-let,即可在 <% %> 或 <%= %> 之中插入 lisp 代码;
原生 s-exp 生成 html 文档;
GET/POST 请求支持;
存取 Cookie。
程序作为 CGI 运行于 Apache 下,这里提供一个简单的求斐波那契数的例程作为演示。
BTW,这也是我第一次使用 Github 托管代码:https://github.com/redraiment/emacs-cgi。
我一直希望用 Emacs Lisp 作为服务端脚本语言来开发 Web 程序。在网上搜索了很久,还真有人做过类似的事情:http://www.emacswiki.org/emacs/cgi.el。但他封装的还不够彻底,用起来还是挺麻烦,于是自己动手写了一个。目前支持:
script-let,即可在 <% %> 或 <%= %> 之中插入 lisp 代码;
原生 s-exp 生成 html 文档;
GET/POST 请求支持;
存取 Cookie。
程序作为 CGI 运行于 Apache 下,这里提供一个简单的求斐波那契数的例程作为演示。
BTW,这也是我第一次使用 Github 托管代码:https://github.com/redraiment/emacs-cgi。
#!/usr/local/bin/emacs --script (require 'cgi) (cgi/cookie "n" (or (cgi/param "n") (cgi/cookie "n") "15")) (html (head (title "Fabonacci 1 -> n") (meta (http-equiv . "Content-Type") (content . "text/html; charset=UTF-8"))) (body (form (method . post) (span "n = ") (input (type . text) (name . n)) (button (type . submit) "Submit")) (table (border . 1) (width . "100%") (thead (caption "Fabonacci") (tr (th "#") (th "Value"))) (tbody <% (let ((a 0) (b 1) x) (dotimes (i (string-to-number (cgi/cookie "n"))) (tr (td <%= (1+ i) %>) (td <%= (setq x a a b b (+ x b)) %>)))) %>))))运行效果:
相关文章推荐
- 用Perl、Shell脚本基于Tomcat6开发cgi程序环境配置
- 开发基于Apache服务器上的CGI程序
- 【Linux】【CGI】用CGIC库来开发CGI程序
- Windows/Linux下使用Emacs+Slime+SBCL/SCHEME搭建LISP开发环境
- CGI程序开发基础
- 在用Emacs Lisp调用外部程序
- emacs lisp 研究 lisp.h 继续 (几何画板开发笔记 七)
- Ubuntu13.10下搭建emacs+sbcl+slime的lisp开发环境
- emacs lisp 研究 lisp.h 继续 (几何画板开发笔记 六)
- C、Shell、Perl基于Tomcat开发CGI程序环境配置
- emacs lisp 研究 lisp.h 继续 (几何画板开发笔记 五)
- emacs lisp 研究 lisp.h (几何画板开发笔记 四)
- emacs lisp(elisp)程序像脚本一样运行
- C、Shell、Perl基于Tomcat开发CGI程序环境配置
- emacs lisp 求值 eval 研究 (几何画板开发笔记 九)
- cgi程序读取post发送的特殊字符,尤其适合于微信公众平台开发中发送被动消息
- Emacs下设置Lisp开发环境路径
- 开发Apache服务器上的CGI程序
- 用CGIC库来开发CGI程序
- 开发基于Apache服务器上的CGI程序