C 博客-XGuru's Blog (九点)
来源:百度文库 编辑:神马文学网 时间:2024/04/29 10:42:53
[趣闻]Emacs是否真的能煮咖啡?
2010-07-27 13:15:00查看原文Emacs是否真的能煮咖啡? by XGuru
坊间有传言曰:“emacs无所不能,甚至能够用来煮咖啡!”
煮咖啡何解?勾起了我的考究欲望。
上网搜索之,得出几种初步结论如下:
1.这只是一种好玩的说法,只是用来形容emacs功能无所不包而已。
2.Java的标志就一杯咖啡,用来形象的表示写代码
3.emacs的确具有煮咖啡的功 能,有脚本能够控制自动咖啡机运行。
觉得第一种说法比较符合逻辑;第二种说法感觉有点唐突,毕竟Emacs是Richard Stallman(GNU创始人)所写,而Java是Bill Joy(vi作者)等人完成的,这两派都差点上升到宗教冲突了,这种解释有点差强人意;第三种的如果是真的话就会变得很有趣。
于是就开始了探究,首先追本溯源,找到这段脚本代码的源头。发现已经地址已经失效,终于在在debian的一个软件包里找到了副本。这是emacs常用脚本的一个打包。
代码如下
1 ;;; coffee.el --- Submit a BREW request to an RFC2324-compliant coffee device
2 ;;;
3 ;;; Author: Eric Marsden
4 ;;; Version: 0.2
5 ;;; Copyright: (C) 1999 Eric Marsden
6 ;;; Keywords: coffee, brew, kitchen-sink, can't
7 ;;
8 ;; This program is free software; you can redistribute it and/or
9 ;; modify it under the terms of the GNU General Public License as
10 ;; published by the Free Software Foundation; either version 2 of
11 ;; the License, or (at your option) any later version.
12 ;;
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17 ;;
18 ;; You should have received a copy of the GNU General Public
19 ;; License along with this program; if not, write to the Free
20 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 ;; MA 02111-1307, USA.
22 ;;
23 ;; Please send suggestions and bug reports to
24 ;; The latest version of this package should be available at
25 ;;
26 ;;
27
28 ;;; Commentary:
29 ;;
30 ;; This module provides an Emacs interface to RFC2324-compliant coffee
31 ;; devices (Hyper Text Coffee Pot Control Protocol, or HTCPCP). It
32 ;; prompts the user for the different additives, then issues a BREW
33 ;; request to the coffee device.
34 ;;
35 ;; coffee.el requires a special BREW-capable version of Emacs/W3 to be
36 ;; installed.
37 ;;
38 ;; Reference:
39 ;;
40 ;;
41 ;; Thanks to Giacomo Boffi
42 ;; and the addition of the "Brown-Coffee" sweetener type.
43
44 ;;; Code:
45
46 (require 'cl)
47
48 (defvar coffee-host "coffee"
49 "*The host which provides the coffee service.")
50
51 (defvar coffee-pot-designator 1
52 "*On machines with multiple pots, the number of the pot to brew in")
53
54 (defvar coffee-brew-hook nil
55 "*Hook executed before issuing a BREW request")
56
57 (defconst coffee-milk-types
58 '("Cream" "Half-and-Half" "Whole-Milk" "Part-Skim" "Skim" "Non-Dairy"))
59
60 (defconst coffee-syrup-types '("Vanilla" "Almond" "Raspberry" "Chocolate"))
61
62 (defconst coffee-sweetener-types '("White-Sugar" "Brown-Sugar" "Artificial-Sweetener"))
63
64 (defconst coffee-alcohol-types '("Whiskey" "Rum" "Kahula" "Aquavit"))
65
66 (defconst coffee-addition-types
67 `(("Milk" . ,coffee-milk-types)
68 ("Syrup" . ,coffee-syrup-types)
69 ("Sweetener" . ,coffee-sweetener-types)
70 ("Alcohol" . ,coffee-alcohol-types)))
71
72 ;;;###autoload
73 (defun coffee ()
74 "Submit a BREW request to an RFC2324-compliant coffee device"
75 (interactive)
76 (require 'url)
77 (let* ((additions-list
78 (append coffee-milk-types
79 coffee-syrup-types
80 coffee-sweetener-types
81 coffee-alcohol-types))
82 (additions-string
83 (mapconcat #'identity additions-list ","))
84 (url (coffee-url))
85 (url-request-method "BREW")
86 (url-request-extra-headers
87 `(("Content-type" . "message-coffeepot")
88 ("Accept-Additions" . ,additions-string)))
89 (url-request-data "START"))
90 (run-hooks 'coffee-brew-hook)
91 (url-retrieve url)))
92
93 (defun coffee-additions ()
94 (let* ((type-name
95 (completing-read "Coffee addition: " coffee-addition-types nil t))
96 (type (cdr (assoc type-name coffee-addition-types)))
97 (ingredients (mapcar #'(lambda (a) (cons a a)) type))
98 (ingredient
99 (completing-read "Addition type: " ingredients nil t)))
100 ingredient))
101
102 (defun coffee-url ()
103 (require 'w3-forms)
104 (concat "coffee://" coffee-host "/"
105 (int-to-string coffee-pot-designator)
106 "?" (w3-form-encode-xwfu (coffee-additions))))
107
108
109 (provide 'coffee)
110
111 ;; coffee.el ends here
这个脚本看起来还是煞有其事的,文中提到"Submit a BREW request to an RFC2324-compliant coffee device"
能够向与RFC2324协议兼容的咖啡设备提交BREW请求 ,即兼容Hyper Text Coffee Pot ControlProtocol(HTCPCP/1.0)协议。超文本咖啡壶协议,光看这名字就够喜庆了,但这份协议写得很规范,看不出一丝破绽。有细心的朋友shrek.wang提醒了我,注意看日期:
Network Working Group L. Masinter
Request for Comments: 2324 1 April 1998
1998年4月1号,愚人节!这个就让人产生了疑问。
通过查wiki发现,原来互联网国际标准机构也是很有才的恶搞高手。
这里列举其中几个好玩的
-
- 2001年,RFC 1149由一班挪威Linux使用者协会的成员实现了。他们传送 了9个封包到约5公里外的地方,每个封包由不同的鸽子携带,并有一个ICMP应答要求封包(ping)。他们收到4个回 应,封包流失率是55%,回应时间是3000至6000秒。[1]
- RFC 1607 — 来自21世纪的观点 Vint Cerf 1994.
- RFC 3091 — 圆周率数字产生协定 . H. Kennedy 2001年
这里可以大胆地作出推断,这个协议只是 IETF开的一个善意的joke,而coffee.el的作者Eric Marsden也是一个幽默的程序员,于是就做了一个兼容RFC2324的脚本,他也没想过要真正的控制咖啡机,所以这整个事情都源于程序员的冷幽默。
然而远程控制咖啡机还是有可能的,这里有一个开源咖啡机;这里还有一个允许网络控制的咖啡机(据说还是兼容RFC2324的)。
估计IETF应该做梦也没想到自己开的一个玩笑竟然还真的有人做出了实物。 国外的牛人们还真是闲得蛋疼阿。可见geek们还是极富幽默感的。
朋友们,你的心中已经有答案了么?你们想要一台这样的咖啡机不?
PS.在这里BS下CPPBLOG的编辑器,真的很烂啊,文章写到一半时点保存,竟然给发布了!
C 博客-XGuru's Blog (九点)
如何通过FILE*操作内存文件? - Mythma‘s C blog - C 博客
[导入]跟我一起写 Makefile - Robin Chow's C Blog - C 博客
[翻译]关于数据对齐(About Data Alignment) - saga's blog - C 博客
Vincent's blog: Visual C 編譯器選項設置
Ren-Huang‘s Blog | [C ]Visual C 的.NET Socket
C语言之内存使用 - 欢迎阁下光临我的网络日志-safeking‘s blog - 博客园
C 博客 - Programmer‘s Cookbook - #pragma使用
S-C-P- TMT分析师 - 新浪BLOG
Joshua Zhu’s Blog ? A Word on TIME_WAIT and C...
C 运算符优先级列表 - brent‘s hut - C 博客
C#入门代码 - C Programmer's Cookbook - C 博客
博客园 - Rickie Lee‘s blog
迎迎的博客(迎迎'S Blog)
4rthur's Blog - 博客园
luox8093's blog - 细胞周期 | 丁香博客
卡巴斯基的博客 KEugene Kaspersky's Blog
c/s
c/s
it博客网-newekin‘s blog-newekin‘s blog - 2005年7月18日 entries
博客园 - Rickie Lee‘s blog - Duwamish架构分析篇
SVG Authoring Guidelines[转] - Avlee‘s Blog - 博客园
Bo’s Blog 邵博客 为什么我喜欢车库
Bo’s Blog 邵博客 招怎么样的人