skeeto / impatient-mode

Impatient html mode. See your changes in the browser as you type
215 stars 19 forks source link

Filter function outputs filtered string to default-output #26

Closed conao3 closed 4 years ago

conao3 commented 4 years ago

README says filter function should use princ.

Except for html-mode buffers, buffer contents will be run through a user-defined filter. The default user filter is htmlize, but you can set your own with imp-set-user-filter. The user filter is nothing but a regular elisp function. Here's how you would define a basic filter:

(defun my-filter (_)
  (princ "<html><body>test</body></html>" (current-buffer)))

The original editing buffer is passed along the user filter as a parameter, which we didn't use in the previous example, but which is demonstrated in the following example:

(defun my-filter (buffer)
  (let ((count 
     (with-current-buffer buffer
           (count-words-region (point-min) (point-max)))))
    (princ (format  "<html><body>%d</body></html>" count) (current-buffer))))

But imp-htmlize-filter do insert filtered contents.

Since the user is unlikely to notice that the current buffer has changed due to a side effect, I am concerned that INSERT will rewrite the current buffer.

Like the function in README, the filter function outputs a string by princ and I think it would be better to capture it by changing the standard-output.

skeeto commented 4 years ago

Good points! Cherry-picked as fc84f4a.

conao3 commented 4 years ago

Thanks!