Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meow-line should grow partially-completed lines #547

Open
aecepoglu opened this issue Jan 30, 2024 · 7 comments
Open

meow-line should grow partially-completed lines #547

aecepoglu opened this issue Jan 30, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@aecepoglu
Copy link

aecepoglu commented Jan 30, 2024

if the selection is like the following (M: mark, P: point)

........M.........
....................
....P.........

then meow-line should turn it into the following and change the selection-type to (expand . line)

M.................
....................
.............P

but it selects only the line point is on:

.................
....................
M.............P

This can be accomplished with a function like so, and I can open a PR for this you agree with the change:

(defun my:meow-line (n &optional expand)
  "Select the current line, eol is not included.

Create selection with type (expand . line).
For the selection with type (expand . line), expand it by line.
For the other types, change selection type to (expand . line)
 and grow selection to cover the entire lines

Prefix:
numeric, repeat times.
"
  (interactive "p")
  (let* ((orig (mark t))
         (n (if (meow--direction-backward-p)
                (- n)
              n))
         (forward (> n 0)))
    (cond
     ((not (region-active-p))
      (let ((m (if forward
                   (line-beginning-position)
                 (line-end-position)))
            (p (save-mark-and-excursion
                 (if forward
                     (progn
                       (forward-line (1- n))
                       (line-end-position))
                   (progn
                     (forward-line (1+ n))
                     (when (meow--empty-line-p)
                       (backward-char 1))
                     (line-beginning-position))))))
        (thread-first
          (meow--make-selection '(expand . line) m p expand)
          (meow--select))
        (meow--maybe-highlight-num-positions '(meow--backward-line-1 . meow--forward-line-1))))
     ((equal '(expand . line) (meow--selection-type))
      (let (p)
        (save-mark-and-excursion
          (forward-line n)
          (goto-char
           (if forward
               (setq p (line-end-position))
             (setq p (line-beginning-position)))))
        (thread-first
          (meow--make-selection '(expand . line) orig p expand)
          (meow--select))
        (meow--maybe-highlight-num-positions '(meow--backward-line-1 . meow--forward-line-1))))
     (t
      (let ((m (save-mark-and-excursion
		 (goto-char orig)
		 (if forward (line-beginning-position) (line-end-position))))
	    (p (if forward (line-end-position) (line-beginning-position))))
	(thread-first
          (meow--make-selection '(expand . line) m p expand)
          (meow--select))
	(meow--maybe-highlight-num-positions '(meow--backward-line-1 . meow--forward-line-1)))))))
@DogLooksGood
Copy link
Collaborator

Meow introduces a concept selection. Here is the explanation.

https://github.com/meow-edit/meow/blob/master/EXPLANATION.org#selection

@DogLooksGood DogLooksGood added question Further information is requested and removed question Further information is requested labels Jan 30, 2024
@aecepoglu
Copy link
Author

Yes, I am aware meow has selections. I am a previous kakoune user so I am comfortable using selections.

It's just that meow-line should not cancel the selection. It should instead change the type of the selection and grow it

@DogLooksGood
Copy link
Collaborator

The selection will be expanded when current selection is expandable, and has the same type with command. In your case, I guess the selection is created with char movements, it will be canceled when met a line command. This selection is not the one in kakoune.

@aecepoglu
Copy link
Author

I understand. my use case is:

when I press the keys o e (meaning (meow-block) (meow-line)) I don't want (meow-line) to cancel my existing selection. Similarly when I do o . l (meaning (meow-block) (meow-bounds-of-thing 'line)) I want to grow my region to contain full lines.

If I wanted to cancel my selection, I'd invoke (meow-cancel) myself.

@DogLooksGood
Copy link
Collaborator

DogLooksGood commented Jan 30, 2024

To force expand, there's a command meow-line-expand, however it doesn't expand the beginning and the end at the same time. Probably we should make it work on all lines, since the line selection should always keep the same shape.

@DogLooksGood DogLooksGood added the enhancement New feature or request label Jan 30, 2024
@aecepoglu
Copy link
Author

Would you be OK with me opening a PR for that?

I thin kthe answer is the final cond statement from my code sample above.

@DogLooksGood
Copy link
Collaborator

meow-line should stay the same. It should cancel the selection with other types and expand itself.

And we can update meow-line-expand according to your code, also add it to the documentation. As it's still a preserved, undocumented command at the moment.

Yes, I'm OK with a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants