casouri / expreg

Your friendly neighborhood expand-region clone
65 stars 1 forks source link

Accept numeric prefix arg for commands? #4

Open protesilaos opened 1 year ago

protesilaos commented 1 year ago

Hello @casouri and thank you for this package!

Have you thought about passing a prefix numeric argument to expreg-expand? I think it is useful. For now I use a variant of this:

(defun prot/expreg-expand (n)
  (interactive "p")
  (dotimes (_ n)
    (expreg-expand)))
casouri commented 1 year ago

Oh cool. May I ask how do you use it with prefix args? For me, I never know how many calls I need, so I just press the key until the region is what I want.

protesilaos commented 1 year ago

I use this:

  (defun prot/expreg-expand (n)
    "Expand to N syntactic units, defaulting to 1 in interactive use."
    (interactive "p")
    (dotimes (_ n)
      (expreg-expand)))

  (defun prot/expreg-expand-dwim ()
    "Do-What-I-Mean `expreg-expand' to start with symbol or word.
If over a real symbol, mark that directly, else start with a
word.  Fall back to regular `expreg-expand'."
    (interactive)
    (let ((symbol (bounds-of-thing-at-point 'symbol)))
      (cond
       ((equal (bounds-of-thing-at-point 'word) symbol)
        (prot/expreg-expand 1))
       (symbol (prot/expreg-expand 2))
       (t (expreg-expand)))))

The reason is that I usually need to start marking symbols like bounds-of-thing-at-point and don't want to mark, say, bounds and then the symbol. Having a numeric arg helps in this case. Though it also useful interactively for small units where I can guess the number.