3

On a Mac, I would like to use "text to speech" to read web content.

I am using the eww browser.

"Text to speech" treats line breaks as the end of the sentence so I would like eww to display long lines, wrapped if needed, but not truncated.

I have tried (among many other things) this in .emacs:

(add-hook 'eww-mode-hook
          (lambda ()
            (set-fill-column 99999)
            (auto-fill-mode 1)))

but eww still breaks the lines at the width of the buffer. Can you please advise me how to avoid these breaks?

  • Can "text to speech" not be configured to recognise multi-line paragraphs? I'm not familiar with it, but it just seems weird to me if that's not a supported format. – phils Apr 2 '17 at 23:36
1

A little investigation indicates that you'll need to modify the various shr-fill-* functions to achieve this. The shr-width variable may or may not still be relevant at that point, but it seems reasonable to set that as well.

It you just want to hard-code this, you can redefine the functions like so:

(eval-after-load 'shr
  '(progn (setq shr-width -1)
          (defun shr-fill-text (text) text)
          (defun shr-fill-lines (start end) nil)
          (defun shr-fill-line () nil)))

If you want behaviour you can toggle, I would probably advise the functions to conditionally do nothing, based upon some variable. e.g.:

(defadvice shr-fill-text (around shr-no-fill-text activate)
  "Do not fill text when `shr-no-fill-mode' is enabled."
  (if (bound-and-true-p shr-no-fill-mode)
      (ad-get-arg 0)
    ad-do-it))

(defadvice shr-fill-lines (around shr-no-fill-lines activate)
  "Do not fill text when `shr-no-fill-mode' is enabled."
  (unless (bound-and-true-p shr-no-fill-mode)
    ad-do-it))

(defadvice shr-fill-line (around shr-no-fill-line activate)
  "Do not fill text when `shr-no-fill-mode' is enabled."
  (unless (bound-and-true-p shr-no-fill-mode)
    ad-do-it))

(define-minor-mode shr-no-fill-mode
  "Global minor mode which prevents `shr' and `eww' from filling text output."
  ;; :lighter (:eval (if (derived-mode-p 'eww-mode) " ShrNoFill"))
  :global t)

(shr-no-fill-mode 1) ;; To enable by default.
                     ;; M-x shr-no-fill-mode to toggle.
  • Answer updated with something you can toggle. I would have made it a buffer-local minor mode to be enabled with eww-mode, but shr renders to a temporary buffer in fundamental-mode, which makes things a little more awkward, so I've simply used a global mode. – phils Apr 3 '17 at 2:48
2

I'm using eww, and needed line wrapping. First I tried line truncation, but that cut through the middle of words.

visual-line-mode seems to provide intelligent line-wrapping on whitespace in the most straightforward way, and I'd be interested to know if that doesn't work for your reader.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.