Подтвердить что ты не робот

Запустить программу elisp без Emacs?

elisp - хороший язык, я считаю, что он может обрабатывать все виды заданий, но могу ли я использовать его как оболочку script?

то есть. выполните некоторые *.el файлы с консоли, не запуская Emacs. Или запустите Emacs, но не входите в интерактивный режим.

4b9b3361

Ответ 1

Скорее всего, вы можете запускать сценарии elisp в Emacs без запуска интерфейса редактора.

Вот заметки, которые я сделал/скопировал из нескольких чрезвычайно полезных вопросов и ответов по этому вопросу здесь, в SO (и в двух следующих, в частности).

Большая часть этой информации, а также многое другое, также рассматривается в следующем превосходном обзоре, который рекомендуется прочитать:

;;;; 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/info/6238331/#6259330 (and others)
;;
;; For robustness, it 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" -- "[email protected]" # -*-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/info/2879746/#2906967
;;
;; #!/bin/sh
;; ":"; exec emacs -Q --script "$0" -- "[email protected]" # -*-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, на это стоит обратить внимание (особенно если речь идет о производительности).