首页 > 其他 > 详细

emacs lisp(elisp)程序像脚本一样运行

时间:2014-01-23 04:31:51      阅读:429      评论:0      收藏:0      [点我收藏+]

elisp程序的运行被称为取值,一般的过程是打开一个emacs编辑器,然后用快捷键C-x C-e 调用函数eval-current-buffer运行当前buffer里的elisp程序。

emacs 22以后支持#!/usr/bin/emacs --script像脚本一样执行elisp程序,这样就没必要打开一个emacs编辑器后再执行了。

下面是一个程序实例,见我的GitHub链接

#!/usr/bin/emacs --script 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NAME 
;;    kit.el   ---- an example elisp script, which is 
;;             used to calculate intern salary.
;; 
;; USAGE
;;   emacs -Q --script kit.el iday
;;   ./kit.el iday
;;
;; NOTE
;; #!/  shebang works for emacs22 and later.
;; 
;; AUTHOR
;;   Aborn Jiang (aborn.jiang@gmail.com)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;(print argv)
(message "input argument are %s" argv)
(message "system-type:%s system-name:%s" system-type system-name)

(defun cal-salary (iday)
  "Calculate the salary for intern in shanghai"
  (interactive "p")
  (setq total (* iday 180))
  (if (> total 800)
      (setq value (+ 800 (* 0.8 (- total 800))) 
            tvalue  (- total value))      ;; if true
    (setq value total                     ;; else part
          tvalue 0))
  (message "You have worked %d day(s), and salary is %d, tax is %d."  iday value tvalue)
  )

(cal-salary (string-to-number (elt argv 0)))


在终端里运行:

 emacs -Q --script kit.el 10

或者直接运行

./kit.el 10

结果如下:

bubuko.com,布布扣

emacs lisp(elisp)程序像脚本一样运行

原文:http://blog.csdn.net/loveaborn/article/details/18669351

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!