Closed danielsz closed 10 years ago
That sounds like a great idea and I'd be happy to let you own it.
I think a buffer would be preferable to a string as the API but buffers aren't garbage collected so ownership becomes a point of confusion if we simply return newly created buffers.
So, how about this:
imp creates a temporary buffer and sets standard-output before it calls the filter function. The filter function does whatever it wants (and can even just use all the standard print functions to do its business) and then imp continues processing with whatever ends up in the temp buffer.
For reference: c334d0b
Please feel free to comment.
Usage:
The user may define a basic function like this:
(defun user-function (&rest buffer)
(princ "<html><body>test</body></html" (current-buffer)))
The original editing buffer is passed along the user function as a parameter, which allows for preprocessing, like so:
(defun user-function (buffer)
(let ((count
(with-current-buffer buffer
(count-words-region (point-min) (point-max)))))
(princ (format "<html><body>%d</body></html" count) (current-buffer))))
The motivation for this PR is live coding goodness. The possibilities are endless. For example, one edits a Clojure buffer where hiccup is used to produce HTML and garden processes the CSS. By setting the user function appropriately (via cider-eval), one is effectively able to live previewing the code in the browser as one edits it.
Hi,
For non html files, buffers go through the htmlize-buffer function. Following that line of thought, I would like to be able to register my own function on a per buffer basis. (This will give me the flexibility I need for tooling purposes).
I am willing to write a PR, but I would like to coordinate the effort with you. Is the idea acceptable to you? If so, we need to decide what that function will return: a string of the html document, a buffer with a html document, etc.
Thanks!