【问题标题】:Run elisp program without Emacs?在没有 Emacs 的情况下运行 elisp 程序?
【发布时间】:2012-04-29 22:39:52
【问题描述】:

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

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

【问题讨论】:

    标签: emacs elisp


    【解决方案1】:

    您绝对可以在 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 中的一般编码,那应该值得一看(尤其是在考虑性能的情况下)。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    • 2016-01-29
    • 1970-01-01
    • 2014-10-26
    相关资源
    最近更新 更多