expreg icon indicating copy to clipboard operation
expreg copied to clipboard

Accept numeric prefix arg for commands?

Open protesilaos opened this issue 2 years ago • 3 comments

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

protesilaos avatar Sep 28 '23 14:09 protesilaos

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.

casouri avatar Sep 29 '23 01:09 casouri

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.

protesilaos avatar Sep 29 '23 16:09 protesilaos

So what Combobulate does here is uses overlays to indicate how many levels up you can navigate up the tree

image

I can do C-1 to C-5 here to jump to a specific one, I think that could work well here.

elken avatar Jan 06 '25 15:01 elken