2012-04-18 4 views
18

elispは良い言語ですが、すべての種類のジョブを処理できますが、シェルスクリプトのように使用できますか?Emacsのないelispプログラムを実行しますか?

つまり、コンソールからEmacsを起動せずにいくつかの* .elファイルを実行します。 Emacsを起動しますが、対話モードには入りません。

答えて

21

エディタインターフェイスを起動しなくても、Emacsでelispスクリプトを実行することは間違いありません。

ここには、私が作った非常に有用ないくつかのQのメモがあります。 (特に以下の2つ)。

;;;; Elisp executable scripts 

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

;; Passing additional command-line arguments to Emacs: 
;; https://stackoverflow.com/questions/6238331/#6259330 
;; 
;; 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 set "argv" to nil at the end of the script 
;; (to prevent Emacs from visiting the non-option arguments as files). 
;; 
;; #!/bin/sh 
;; ":"; exec emacs --no-site-file --script "$0" -- "[email protected]" # -*-emacs-lisp-*- 
;; (print (+ 2 2)) 
;; (setq argv nil) ;; always end with this 

;; Processing with STDIN and STDOUT via --script: 
;; https://stackoverflow.com/questions/2879746/#2906967 
;; 
;; #!/usr/local/bin/emacs --script 
;; ;;-*- mode: emacs-lisp;-*- 
;; 
;; (defun process (string) 
;; "just reverse the string" 
;; (concat (nreverse (string-to-list string)))) 
;; 
;; (condition-case nil 
;;  (let (line) 
;;  ;; commented out b/c not relevant for `cat`, but potentially useful 
;;  ;; (princ "argv is ") 
;;  ;; (princ argv) 
;;  ;; (princ "\n") 
;;  ;; (princ "command-line-args is") 
;;  ;; (princ command-line-args) 
;;  ;; (princ "\n") 
;; 
;;  (while (setq line (read-from-minibuffer "")) 
;;   (princ (process line)) 
;;   (princ "\n"))) 
;; (error nil)) 

Emacsはさておき、私の知る唯一の他のelisp通訳/コンパイラはガイルで

  • Idomatic batch processing of text in Emacs?
  • Emacs shell scripts - how to put initial options into the script?
    • 。 elispの一般的なコーディングに熱心であれば、それは一見価値があるはずです(特にパフォーマンスが問題になる場合)。

    +0

    ご協力ありがとうございます。 –

    関連する問題