好的,我沒有找到更好的方法來做到這一點。但我確實決定將Javascript代碼作爲字符串嵌入到elisp模塊中......工作得很好。
爲了實現目標,我編寫了一個簡短的elisp函數,它創建了一個新的elisp模塊。 它根據舊名稱 - xxxx-bundle.el而不是xxxx.el選擇一個新名稱。然後它將原始.el文件中的內容寫入具有新名稱的文件中。然後它將一個簡單的setq
語句寫入同一個文件;整個JavaScript程序是該語句中的字面值。簡化setq
的是elisp中的pp-to-string
函數,它將所有Javascript代碼轉換爲適用於emacs的文字字符串。
的FN鍵生成包看起來像這樣:
(defun jsshell-produce-bundle (&optional jsshell-el bundle-el jsshell-js)
"Produce a new .el file, which contains all the jsshell.el
function and also embeds the jsshell.js source as a string. The
resulting .el file will then be suitable for a one-file
distribution of JSShell.
JSShell depends on two pieces: jsshell.el and jsshell.js. Rather
than distributing and installing two distinct files, the bundle
embeds the .js file into the .el file, for a one-file
distribution option. This function produces that one file.
Most people will never need to use this function. It's useful only
after modifying either the original jsshell.el or the jsshell.js file,
when you want to produce a new distributable bundle. In other words, it's
useful for the developer of jsshell.el.
"
(let ((jsshell-el (or jsshell-el
(concat (file-name-directory jsshell--load-path) "jsshell.el")
"jsshell.el")))
(let ((bundle-el (or bundle-el
(concat (file-name-directory jsshell-el) "jsshell-bundle.el")))
(jsshell-js (or jsshell-js
(and jsshell-js-tmpf
(file-readable-p jsshell-js-tmpf)
jsshell-js-tmpf)
jsshell-location-of-jsshell-js ;; orig dev wkstation
(concat (file-name-directory jsshell-el) "jsshell.js")))
jssrc)
(with-temp-file bundle-el
(insert (concat
";;; "
(file-name-nondirectory bundle-el)
" -- JSShell generated bundle\n"))
(insert (concat ";;\n;; generated " (current-time-string) "\n;;\n\n"))
(insert-file-contents jsshell-el)
(goto-char (point-max))
(insert "\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n")
(insert ";; this is the embedded Javascript code for the JS REPL\n\n")
(setq jssrc (jsshell--minimized-js-contents jsshell-js))
(goto-char (point-max))
(insert (concat "(setq jsshell-js-src "
(pp-to-string jssrc)
")\n"
"\n(provide '"
(file-name-sans-extension (file-name-nondirectory bundle-el))
")\n"
"\n;;; "
(file-name-nondirectory bundle-el)
" ends\n"))))))
助手FN鍵最小化內容只是崩潰的空白,消除了連續的換行符之類的事情。然後
所得.el文件可以引用該變量,jsshell-js-src
,它包含最小化的Javascript源。它看起來像這樣:
,因爲我覺得這種方法很可能是在其他模塊也是有用的,我在這裏張貼這一點 - 任何需要捆綁一個單獨的數據文件。