Issue #263 open

opening new lines in longlines-mode

George V. Reilly
created an issue

A couple of days ago, I was editing a document in Markdown mode. Many of the lines were very long, so I turned on longlines-mode to get decent line wrapping. Evil seemed to work fairly well.

I had one large block of preformatted text where the lines where short and separated by newlines even before longlines-mode was turned on. I had a lot of difficulty creating new lines of text in that region. The 'o' command didn't work. Typing some text and pressing Enter didn't work as expected. Lines started getting joined together. If I switched into Emacs state or if I turned off longlines-mode and used Normal state and Insert state, I was able to edit the preformatted block as expected.

I can't repro it now, so I can't give very specific repro steps.

Comments (13)

  1. Frank Fischer repo owner
    • changed status to open

    Hm, I've never used longlines mode and I do not know how it works. It will take some time.

    But shouldn't visual-line-mode be the better alternative and superseeding long-lines?

  2. George V. Reilly reporter

    I played with visual-line-mode but I didn't like that k and j moved up and down by logical lines rather than screen lines. I know that I could have used gk and gj, but they're not in my muscle memory, and I was too lazy to figure out how to do the appropriate keybindings.

  3. Frank Fischer repo owner
    (define-key evil-motion-state-map "j" "gj")
    (define-key evil-motion-state-map "k" "gk")
    

    or

    (define-key evil-motion-state-map "j" 'evil-next-visual-line)
    (define-key evil-motion-state-map "k" 'evil-previous-visual-line)
    

    The file evil-maps.el contains the definitions of almost all keybindings.

  4. rfflrccrd

    With Visual Line Mode turned on, Evil behaves like Vim, which as George said can be counterintuitive. Thank you, Frank, for providing a fix. There is also the option of displaying the visual line breaks on the fringe by customizing the mode.

    Visual Line Mode does not supersede Longlines Mode, because the latter allows to specify any width, whilst the former only works with the width of the window. I think that Longlines Mode is useful to writers, because narrow columns are easier to read. Thank you, Frank, for considering support for it in a future release.

  5. Frank Fischer repo owner

    I use visual-line-mode in conjunction with the following code (which is certainly not perfect but works for me) to restrict the window with to a certain size by adjusting the right window margin.

    (defvar fifr/visual-line-wrap-column 81)
    (defun fifr/set-window-margin (&optional frame)
      (dolist (win (window-list frame))
        (with-selected-window win
          (with-current-buffer (window-buffer win)
            (when fifr/visual-line-wrap-column-mode
              (let ((margins (window-margins))
                    (edges (window-edges)))
                (set-window-margins nil (car margins)
                                    (max 0
                                         (- (- (nth 2 edges) (nth 0 edges))
                                            fifr/visual-line-wrap-column)))))))))
    
    (define-minor-mode fifr/visual-line-wrap-column-mode
      "Wrap visual line at some column"
      :lighter ""
      (when fifr/visual-line-wrap-column-mode
        (add-hook 'window-configuration-change-hook #'fifr/set-window-margin)
        (add-hook 'window-size-change-functions #'fifr/set-window-margin)))
    

    I use hooks to activate them, e.g.

    (add-hook 'latex-mode-hook 'visual-line-mode)
    (add-hook 'latex-mode-hook 'fifr/visual-line-wrap-column-mode)
    

    Visual line mode has a few advantages: it does not add additional newlines (which might confuse some operations), works well if the window is smaller than the desired column width and also works if fonts of different sizes are used (see the following two images for the difference between longlines and visual line mode).

    longlines

    visual lines

  6. rfflrccrd

    Wow! What can I say? Visual Line Mode with your snippet is the superior choice. It also adds a helpful right margin indicator. I'm sold.

    Thank you for your quick reply and kind support. Have a sweet day.

  7. rfflrccrd

    Frank, have you tried to disable fifr/visual-line-wrap-column-mode? Here, disabling doesn't do anything: the right margin stays there. Thanks.

  8. Frank Fischer repo owner

    Well, I know that disabling does not work, but I never do it ;)

    When disabling this mode one has to go through all windows of the corresponding buffer and call (set-window-margin win nil nil) or so. But I never needed this functionality.

  9. rfflrccrd

    Hello Frank, I have tried (set-window-margins nil nil nil) and nothing happened. Any idea about other expressions which I could try?

    Also, I have noticed that the available columns are less than what fifr/visual-line-wrap-column specifies. I guess that you have specified 81: to have an actual width of 80, didn't you?

    Thank you for your support and happy new year.

  10. Frank Fischer repo owner

    Of course, you have to reset the margins in every window associated with the buffer in which you disable that mode, i.e.

    (define-minor-mode fifr/visual-line-wrap-column-mode
      "Wrap visual line at some column"
      :lighter ""
      (if fifr/visual-line-wrap-column-mode
          (progn
            (add-hook 'window-configuration-change-hook #'fifr/set-window-margin)
            (add-hook 'window-size-change-functions #'fifr/set-window-margin))
        (dolist (win (get-buffer-window-list))
          (set-window-margins win nil nil))))
    

    I do not remember the actual reason for having a width of 81. But in order to get 80 columns before wrapping happens you probably need 83 or so, but this depends on whether you use X or terminal. That's because the left and right fringe each counts as 1 column and the very last column in the text part cannot be filled with a character (so you need 3 additional columns in X). Note that in terminal there is no fringe so 81 should be sufficient there. Furthermore, variable-width fonts naturally have an unpredictable column width (I usually use such fonts when writing text, that's why the exact window width is not important for me).

  11. Log in to comment