Issue #33 new

visual-line-mode

Frank Fischer
repo owner created an issue

When using visual-line-mode in Emacs 23, screen lines do not longer correspond to buffer lines. This leads to the situation, that many commands that operate on lines, i.e., on buffer-lines, do not reflect screen lines.

It should be possible to modify all commands that operator on lines including visual line mode and visual block mode (although the latter does not really make sense for screen lines) so that they work on screen-lines instead of buffer lines. This may work well with commands like dd or yy. But it is not clear how removed //visual// lines should be handled for yank/paste. The easiest way would be to convert them into real lines in the kill-ring. Therefore how pasting visual lines should be handled is completely unclear.

I'm not really sure if this makes sense anyhow. Perhaps the most useful features in this are would be visual-line mode and commands like dd and yy, the rest should be ignored.

Comments (1)

  1. Titus von der Malsburg

    Edit: I though this was an issue for Evil not VimMode. Sorry.

    The fact that line-operations do not work with visual lines is the only major gripe that I have with Evil. Commands that I would like to see working with visual lines are of course dd and yy, but also I and A, etc. As you say, it is possible to change all kinds of commands to deal with visual lines, but this probably leads to a lot of changes. Yesterday, I came up with a hack to address this problem and I'm wondering how viable it is. The idea is to wrap line-operations in a function that first fills the buffer line, then executes the line operation on the new buffer lines (dd, yy, I, A, ...), and then "unfills" the line. If the fill-column is set to match the width of the window, filling doesn't change anything in the visual layout, the only thing this does is to temporarily replace display line breaks with real line breaks. Here's some code to illustrate what I mean:

    (defmacro fill-unfill (&rest body)
     `(lambda (&rest args)
        (interactive "p")
        (let ((fill-column-orig fill-column)
              (fill-column (- (window-width) 2))
              (start (save-excursion (beginning-of-line) (point)))
              (end (save-excursion (end-of-line) (point)))
              (end-of-buffer (point-max)))
          (save-excursion (fill-region start end nil 1))
          (apply ,@body args) 
          (let ((fill-column (point-max))
                ; Account for additional newline chars in the region:
                (new-end (+ end (- (point-max) end-of-buffer))))
            (save-excursion (fill-region start end nil 1))))))
    
    (define-key evil-normal-state-map "I" (fill-unfill 'evil-insert-line))
    (define-key evil-normal-state-map "A" (fill-unfill 'evil-append-line))
    

    This may break some other things like macros but maybe this can be fixed somehow. In case this approach can be generalized to handle other operations such as yy and dd as well, this may be a nice approach because it doesn't require changes in too many places. This approach also does what I think is the right thing for yyP.

  2. Log in to comment