ambrevar/emacs: Overhaul Emacs string and stream functions.
parent
416ec2eea8
commit
39af2ace95
|
@ -68,18 +68,31 @@ See `princ-emacs-buffer'."
|
||||||
`(with-current-buffer (get-buffer-create ,buffer-or-name)
|
`(with-current-buffer (get-buffer-create ,buffer-or-name)
|
||||||
(insert ,(princ-to-string thing)))))
|
(insert ,(princ-to-string thing)))))
|
||||||
|
|
||||||
(export-always 'emacs-buffer-stream)
|
(defun emacs-unescape (string)
|
||||||
(defun emacs-buffer-stream (buffer-or-name)
|
"Since Emacsclient returns escaped strings, return the string in a form
|
||||||
"Return Emacs' BUFFER-OR-NAME content as a stream."
|
understood by Common Lisp."
|
||||||
(emacs-eval>
|
(if (<= 2 (length string))
|
||||||
`(with-current-buffer (get-buffer-create ,buffer-or-name)
|
(str:replace-all "\\n" (string #\newline)
|
||||||
(buffer-string))))
|
(subseq string 1 (1- (length string))))
|
||||||
|
string))
|
||||||
|
|
||||||
(export-always 'emacs-buffer-string)
|
(export-always 'emacs-buffer-string)
|
||||||
(defun emacs-buffer-string (buffer-or-name)
|
(defun emacs-buffer-string (buffer-or-name)
|
||||||
"Return Emacs' BUFFER-OR-NAME content as a string."
|
"Return Emacs' BUFFER-OR-NAME content as a string."
|
||||||
(emacs-$eval
|
(emacs-unescape
|
||||||
|
(emacs-$eval
|
||||||
`(with-current-buffer (get-buffer-create ,buffer-or-name)
|
`(with-current-buffer (get-buffer-create ,buffer-or-name)
|
||||||
(buffer-string))))
|
(buffer-substring-no-properties (point-min) (point-max) )))))
|
||||||
|
|
||||||
|
;; (export-always 'emacs-buffer-stream)
|
||||||
|
(defun emacs-buffer-stream (buffer-or-name)
|
||||||
|
"Return Emacs' BUFFER-OR-NAME content as a stream."
|
||||||
|
(make-string-input-stream (emacs-buffer-string buffer-or-name)))
|
||||||
|
|
||||||
|
(export-always 'with-emacs-buffer-stream)
|
||||||
|
(defmacro with-emacs-buffer-stream ((in buffer-or-name) &body body)
|
||||||
|
"Evaluate BODY with IN bound to an input stream of the Emacs' BUFFER-OR-NAME."
|
||||||
|
`(with-input-from-string (,in (emacs-buffer-string ,buffer-or-name))
|
||||||
|
,@body))
|
||||||
|
|
||||||
;; TODO: Make Emacs buffer output stream.
|
;; TODO: Make Emacs buffer output stream.
|
||||||
|
|
Loading…
Reference in New Issue