meow icon indicating copy to clipboard operation
meow copied to clipboard

Expanding versions of the thing selection commands

Open chrisbouchard opened this issue 1 year ago • 2 comments

I'd really like to see expanding versions of the current transient thing-based selection commands. For example, I'd like to be able to say . p ; ] p (or something) to select two paragraphs. Even nicer would be if I could type . p 5 (or something) to select the current paragraph and the next five.

Deleting large blocks of text is very painful without this feature.

chrisbouchard avatar Feb 06 '24 04:02 chrisbouchard

You can just expand the selection with builtin forward-paragraph and backward-paragraph, . p M-} M-}. The same to the sentence.

DogLooksGood avatar Feb 06 '24 07:02 DogLooksGood

Here is what I have been using, based on meow-beginning-of-thing and meow-end-of-thing:

  (defun my-meow-extend-to-end-of-thing (thing)
    "Extend selection to the end of THING."
    (interactive (list (meow-thing-prompt "Extend to end of: ")))
    (if (not (use-region-p))
        (meow-end-of-thing thing)
      (save-window-excursion
        (let ((back (equal 'backward (meow--thing-get-direction 'end)))
              (bounds (meow--parse-inner-of-thing-char thing)))
          (let ((beg (min (point) (mark))))
            (when bounds
              (thread-first
                (meow--make-selection '(select . transient)
                                      (if back (cdr bounds) beg)
                                      (if back beg (cdr bounds)))
                (meow--select))))))))

  (defun my-meow-extend-to-beginning-of-thing (thing)
    "Extend selection to the beginning of THING."
    (interactive (list (meow-thing-prompt "Extend to beginning of: ")))
    (if (not (use-region-p))
        (meow-beginning-of-thing thing)
      (save-window-excursion
        (let ((back (equal 'backward (meow--thing-get-direction 'beginning)))
              (bounds (meow--parse-inner-of-thing-char thing)))
          (let ((end (max (point) (mark))))
            (when bounds
              (thread-first
                (meow--make-selection '(select . transient)
                                      (if back end (car bounds))
                                      (if back (car bounds) end))
                (meow--select))))))))

okamsn avatar Feb 13 '24 02:02 okamsn