Emacs 简单脚本
#!/usr/local/bin/emacs --script
;;; emacs-script.el --- a simple emacs lisp script
;;; Commentary:
;; #!(shebang),从 Emacs 22 开始支持。这让 Emacs 也可以用来写类似
;; Bash 的脚本。处理文本文件,用 Emacs Lisp 脚本,应该是很强大的。当
;; 然,据说 perl 才是文本处理之王,但作为一个编辑器,Emacs 在文本处理上
;; 也有其优势的。
;; 一个简单例子,可以处理命令行参数。
;; 打开一个文件,进行一些文本处理,然后保存。
;;; Code:
;; handle command line arguments
(if (/= 1 (length command-line-args-left))
(and (print "just need one argument for filename") (kill-emacs 1)))
(setq filename command-line-args-left)
;; open the file
(find-file (car filename))
;; processing it
;; indenting
(indent-region (point-min) (point-max))
;; filling
;; (fill-region (point-min) (point-max))
;; trailing white space
(delete-trailing-whitespace)
;; save the file
(save-buffer)
;;; emacs-script.el ends here
This entry was posted in Uncategorized. Bookmark the
permalink.