| 您的位置:
Linux时代 > 技术文档 > 内核研究 >
Emacs能很好地在Linux内核上工作
日期:2006-11-21 作者:赵珂 来自:zhaoke.com

本次实验的目的是了解Emacs如何能在linux内核上很好的工作.
仅需要的外部命令是: mount .
文章中的”root_fs_emacs”可以做为一个标准分区或在live CD上使用. 这次实验, 我们用于User Mode Linux上.
1. 初始化root_fs(至少150MB)
cd ~/uml dd if=/dev/zero of=root_fs_emacs bs=1k count=200k yes y|mke2fs root_fs_emacs mkdir /emacs mount -o loop root_fs_emacs /emacs cd /emacs ln -s . emacs # 简单配置 emacs 的 –prefix 参数 cp -a /dev dev # 我们大胆拷贝整个/dev mkdir etc sbin tmp # 创建emacs没有创建的其它目录 cat >etc/fstab < /dev/ubd0 / ext2 defaults 0 1 EOF
2. 在字符环境下静态编译emacs
cd ~/src tar jxvf emacs-21.3.tar.bz2 cd emacs-21.3 CFLAGS=-static LDFLAGS=-static ./configure –without-x –prefix=/emacs make && make install
3. 以/sbin/init方式安装emacs
cd /emacs ln bin/emacs sbin/init cat >.emacs < (message “init starting”) (setq auto-save-interval 0) (defun shutdown () (interactive) (when (yes-or-no-p “Really shut down the system? “) ;; actually, kill-emacs signals emacs ie. init, which makes linux panic. (kill-emacs))) (global-set-key “\C-x\C-c” ’shutdown) (global-set-key “^\” ‘keyboard-quit) ;; strangely, C-g does not work. (call-process “/bin/mount” nil “*log*” t “-n” “-o” “rw,remount” “/”) (if (file-exists-p “/etc/mtab”) (delete-file “/etc/mtab”)) (call-process “/bin/mount” nil “*log*” t “-f” “/dev/ubd0″ “/”) (message “init done”) EOF
4. 静态编译mount
cd ~/src tar jxvf util-linux-2.12a.tar.bz2 cd util-linux-2.12a CFLAGS=-static LDFLAGS=-static ./configure make && install -m 755 mount/umount mount/mount /emacs/bin/
5. 引导linux
cd ~/uml umount /emacs linux ubd0=root_fs_emacs
现在, 你可以通过下面命令运行一个emacs脚本:
M-x eshell RET ls -l RET
运行结果是:
File Edit Options Buffers Tools Help Welcome to the Emacs shell
/ # ls -l total 21 drwxr-xr-x 2 0 0 1024 Jul 26 08:42 bin drwxr-xr-x 1 0 0 0 Jan 1 1970 dev lrwxrwxrwx 1 0 0 1 Jul 26 08:11 emacs -> . drwxr-xr-x 2 0 0 1024 Jul 26 09:20 etc drwxr-xr-x 2 0 0 2048 Jul 26 08:11 info drwxr-xr-x 3 0 0 1024 Jul 26 08:11 libexec drwx—— 2 0 0 12288 Jul 26 08:10 lost+found drwxr-xr-x 3 0 0 1024 Jul 26 08:10 man drwxr-xr-x 2 0 0 1024 Jul 26 08:11 sbin drwxr-xr-x 3 0 0 1024 Jul 26 08:10 share drwxr-xr-x 2 0 0 1024 Jul 26 09:15 tmp / #
–1-:—F1 *eshell* (EShell)–L20–All———————
当然, emacs缺少很多系统调用(同样elisp原语中也没有), 所以, 我们很难用emacs去做任何事情. 不过这只是一个开始.
另外, 你也可以使用具有FFI和可移植Hemlock功能的Common-Lisp方法来实现.
Emacs做为shell程序
Emacs可以很容易做为shell程序使用:
echo /usr/bin/emacs >> /etc/shells chsh -s /usr/bin/emacs GOODUSER
echo ‘(setenv “SHELL” “/bin/bash”)’ >> ~GOODUSER/.emacs # 这种情况用户想使用 M-x shell # [ 我更想使用: (setenv “SHELL” “/usr/bin/clisp”) ]
echo ‘(eshell)’ >> ~GOODUSER/.emacs # 自动启动eshell. # 也可使用: (dired default-directory) 替代…
su - GOODUSER # 很好!
原文链接:http://blog.zhaoke.com/10.html#more-10
本文被浏览次
|