在没有 Emacs 的情况下运行 elisp 程序? [英] Run elisp program without Emacs?

查看:26
本文介绍了在没有 Emacs 的情况下运行 elisp 程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

elisp is a good language, I find it can handle all kind of jobs, but can I use it like a shell script?

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

i.e. execute some *.el files from the console, without launching Emacs. Or launch Emacs, but don't enter interactive mode.

推荐答案

您绝对可以在 Emacs 中运行 elisp 脚本,而无需启动编辑器界面.

You can most definitely run elisp scripts in Emacs without starting the editor interface.

以下是我在 S.O. 的一些非常有用的问答中制作/复制的笔记.(尤其是以下两个).

Here are the notes I've made/copied from a few extremely useful Q&As on the subject here at S.O. (and the following two in particular).

这些信息的大部分以及更多信息都包含在以下出色的概述中,推荐阅读:

Much of this information, and more besides, is also covered in the following excellent overview, which is recommended reading:

;;;; 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
" (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 中进行通用编码,那应该值得一看(尤其是在考虑性能的情况下).

Emacs aside, the only other elisp interpreter/compiler I'm aware of is Guile. If you're keen on general coding in elisp, that should be worth a look (especially if performance is a concern).

这篇关于在没有 Emacs 的情况下运行 elisp 程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆