djcb / mu

maildir indexer/searcher + emacs mail client + guile bindings
http://www.djcbsoftware.nl/code/mu
GNU General Public License v3.0
1.62k stars 391 forks source link

Wrapping indented lines #1596

Closed codesections closed 4 years ago

codesections commented 4 years ago

A newsletter I subscribe to sends paragraphs consisting of unwrapped lines with each paragraph indicated by indentation (rather than a newline between paragraphs).

For instance, text might look like

            So the claim here is that Misra hired a guy named Alessandro Benedetti to take care of his rivals at work, and Benedetti hired a private intelligence firm to investigate them, and the private intelligence firm hired a public relations firm to get its investigations into the press, and the PR firm hired a freelance reporter to write them up in the press.[1] “At SoftBank, the article and others that resulted were mostly seen as noise.”
            So Benedetti apparently tried something else, asking “law firm Susman Godfrey LLP to represent him as an investor making claims about SoftBank” and Misra’s rivals. Susman Godfrey said no, and if you need a law firm to do dark weird stuff there is only one name to call

I use (mu4e-view-fill-long-lines) to wrap these paragraphs. However, this results in the text being collapsed into a single paragraph for the length of the article. To get around that, I have modified mu4e-view-fill-long-lines as shown below. I'm not sure if anyone else would be interested in the fix, but thought I would include it here in case it seems worth upstreaming. (This may not be the best way to solve the issue – this works, but I suspect a more robust solution might involve paragraph-indent-minor-mode or something similar).

  (defun mu4e-view-fill-long-lines ()
    "Fill lines that are wider than the window width or `fill-column'."
    (interactive)
    (with-current-buffer (mu4e-get-view-buffer)
      (save-excursion
        (let ((inhibit-read-only t)
              (width (window-width (get-buffer-window (current-buffer)))))
          (save-restriction
            (message-goto-body)
            (while (not (eobp))
              (end-of-line)
              (when (> (current-column) (min fill-column width))
                (narrow-to-region (min (1+ (point)) (point-max))
                                  (point-at-bol))
                (let ((goback (point-marker)))
                  (fill-paragraph nil)
                  (goto-char (marker-position goback)))
                (widen)
                (forward-line 1)
                (unless (thing-at-point 'word t)
                  (newline))
                (forward-line -1))
              (forward-line 1)))))))

Note: the only change from the current version is the addition of

                (forward-line 1)
                (unless (thing-at-point 'word t)
                  (newline))
                (forward-line -1)
codesections commented 4 years ago

Er, actually, after a bit more testing, that modified function does not work. Here's a version that does:

(defun mu4e-view-fill-long-lines ()
  "Fill lines that are wider than the window width or `fill-column'."
  (interactive)
  (with-current-buffer (mu4e-get-view-buffer)
    (save-excursion
      (let ((inhibit-read-only t)
            (width (window-width (get-buffer-window (current-buffer)))))
        (save-restriction
          (message-goto-body)
          (while (not (eobp))
            (end-of-line)
            (when (> (current-column) fill-column) ; (min fill-column width)
              (narrow-to-region (min (1+ (point)) (point-max))
                                (point-at-bol))
              (let ((goback (point-marker)))
                (fill-paragraph nil)
                (goto-char (marker-position goback)))
              (widen)
              (forward-line 1)
              (if (and
                   (string-match "^\s" (thing-at-point 'line t)) ; initial whitespace
                   (string-match "\[^\s]" (thing-at-point 'line t))) ; line has text
                  (newline))
              (forward-line -1))
            (forward-line 1)))))))
djcb commented 4 years ago

We're slowly moving to the gnus-based view, so want to avoid making changes to the mu4e-view code.

codesections commented 4 years ago

Makes sense. Given that, I'll close this issue.