首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >运行不带Emacs的elisp程序?

运行不带Emacs的elisp程序?
EN

Stack Overflow用户
提问于 2012-04-18 21:46:25
回答 1查看 2.9K关注 0票数 22

elisp是一种很好的语言,我发现它可以处理所有类型的工作,但是我可以像shell脚本一样使用它吗?

例如,从控制台执行一些*.el文件,而不启动Emacs。或者启动Emacs,但不要进入交互模式。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-18 22:05:18

您完全可以在Emacs中运行elisp脚本,而无需启动编辑器界面。

这里是我从一些非常有用的问答中摘录的笔记,就像在S.O.这里的主题一样(特别是下面两个)。

这些信息的大部分,以及更多信息,也包含在下面的优秀概述中,这是推荐阅读:

;;;; Elisp executable scripts

;; --batch vs --script
;; M-: (info "(emacs) Initial Options") RET
;; M-: (info "(elisp) Batch Mode") RET

;; Processing command-line arguments (boiler-plate)
;; http://stackoverflow.com/questions/6238331/#6259330 (and others)
;;
;; For robustness, it's important to both pass '--' as an argument
;; (to prevent Emacs from trying to process option arguments intended
;; for the script), and also to exit explicitly with `kill-emacs' at
;; the end of the script (to prevent Emacs from carrying on with other
;; processing, and/or visiting non-option arguments as files).
;;
;; #!/bin/sh
;; ":"; exec emacs -Q --script "$0" -- "$@" # -*-emacs-lisp-*-
;; (pop argv) ; Remove the "--" argument
;; ;; (setq debug-on-error t) ; if a backtrace is wanted
;; (defun stdout (msg &optional args) (princ (format msg args)))
;; (defun stderr (msg &optional args) (princ (format msg args)
;;                                           #'external-debugging-output))
;; ;; [script body here]
;; Always exit explicitly. This returns the desired exit
;; status, and also avoids the need to (setq argv nil).
;; (kill-emacs 0)

;; Processing with STDIN and STDOUT via --script:
;; https://stackoverflow.com/questions/2879746/#2906967
;;
;; #!/bin/sh
;; ":"; exec emacs -Q --script "$0" -- "$@" # -*-emacs-lisp-*-
;; (pop argv) ; Remove the "--" argument
;; (setq debug-on-error t) ; if a backtrace is wanted
;; (defun stdout (msg &optional args) (princ (format msg args)))
;; (defun stderr (msg &optional args) (princ (format msg args)
;;                                           #'external-debugging-output))
;; (defun process (string)
;;   "Reverse STRING."
;;   (concat (nreverse (string-to-list string))))
;;
;; (condition-case nil
;;     (let (line)
;;       (while (setq line (read-from-minibuffer ""))
;;         (stdout "%s\n" (process line))))
;;   (error nil))
;;
;; ;; Always exit explicitly. This returns the desired exit
;; ;; status, and also avoids the need to (setq argv nil).
;; (kill-emacs 0)

抛开Emacs不谈,我所知道的唯一其他的elisp解释器/编译器是Guile。如果你热衷于在elisp中编写通用代码,那应该值得一看(特别是如果性能是个问题)。

票数 24
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10210742

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档