2012-04-18 40 views
18

elisp là một ngôn ngữ tốt, tôi tìm thấy nó có thể xử lý tất cả các loại công việc, nhưng tôi có thể sử dụng nó như một kịch bản shell?Chạy chương trình elisp không có Emacs?

tức là thực hiện một số tệp * .el từ bảng điều khiển mà không cần khởi chạy Emacs. Hoặc khởi chạy Emacs, nhưng không vào chế độ tương tác.

Trả lời

21

Bạn chắc chắn có thể chạy tập lệnh elisp trong Emacs mà không cần bắt đầu giao diện trình chỉnh sửa.

Dưới đây là các ghi chú tôi đã tạo/sao chép từ một số rất hữu ích Q & Về chủ đề tại đây tại S.O. (và hai đặc biệt sau đây).

;;;; 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 sang một bên, chỉ elisp phiên dịch/biên dịch khác tôi biết là Guile. Nếu bạn đang quan tâm đến mã hóa chung trong elisp, đó sẽ là giá trị một cái nhìn (đặc biệt là nếu hiệu suất là một mối quan tâm).

+0

Cảm ơn sự giúp đỡ của bạn. –

Các vấn đề liên quan