2

I want to programmatically navigate emacs lisp (and similar "nested paren code").

Specific functions I want:

  • Go to first child (which errors if there are no children (maybe lispy-outline-goto-child but better)
  • Go to sibling
  • Go to parent (already supported by (backward-up-list))
Drew
  • 75,699
  • 9
  • 109
  • 225
Att Righ
  • 725
  • 4
  • 14

1 Answers1

3

Please check out Moving in the Parenthesis Structure, specifically:

  • C-M-f, which runs the command forward-sexp
  • C-M-b, which runs the command backward-sexp
  • C-M-d, which runs the command down-list

To get to the beginning of the 1st child, enter the list, then jump behind the 1st child and back to arrive at its beginning: C-M-d C-M-f C-M-b

sds
  • 5,928
  • 20
  • 39
  • Thanks. I'm completely aware of those functions, as far as I'm aware they don't address motion to the first child. – Att Righ Nov 09 '17 at 21:23
  • `forward-sexp` does not move to the next sibling but to the end of a sibling. It does however look like one can a "move to next sibling command" by calling `(progn (forward-sexp) (backward-sexp))`. So I guess the only think I'm after is *the first child*. – Att Righ Nov 09 '17 at 21:30
  • 1
    @AttRigh: see edit. – sds Nov 09 '17 at 21:32
  • **enter the list by moving past** might be more fiddly that one imagines, but it looks like `move-down` does this. So yep, `(progn (move-down) (forward-sexp) (backward-sexp))` goes to the first child (following your answer). Thanks for the help! The motions "child, parent, beginning-of-sibling, matching-bracket" seem somehow more natural to traverse the tree structure to me than `forward-sexp` `backward-sexp`. – Att Righ Nov 09 '17 at 21:45
  • 1
    +1. These are the commands I use, FWIW. Lately some Emacs users seem to prefer the more "structured-editing" approach of *smartparens*, *lispy*, and the like. Not I. That kind of editing was first introduced (to my knowledge) back in the 80s. I didn't like it then, and I don't like it now. At least when adopted for Emacs things are more flexible: you are not *locked into* having the code always have valid syntax at every moment. Editors that let you *only* perform editing operations that retain well-formedness or validity (e.g. wrt a schema or DTD) are too limiting, IMAO. (Tastes differ.) – Drew Nov 09 '17 at 22:30
  • Oops, I mean `(down-list)` rather than `(move-down)` – Att Righ Nov 09 '17 at 23:27