meow-edit / meow

Yet another modal editing on Emacs / 猫态编辑
GNU General Public License v3.0
1.07k stars 128 forks source link

Expanding versions of the thing selection commands #552

Open chrisbouchard opened 3 months ago

chrisbouchard commented 3 months ago

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.

DogLooksGood commented 3 months ago

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

okamsn commented 3 months ago

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))))))))