[This is a comment-made-into-an-answer: it turns out that the OP does not need line numbers; they were a means that would allow him to get to another place, but as usual, line numbers are indirect means to get there: first you find the line number, then you use it to get where you are supposed to be. Emacs in general discourages the use of line numbers for such purposes, by providing means to get there directly. So the answer does not really answer the question as stated, but it points out the direct methods that emacs provides.]
Do you really need the line number? What do you intend to do with it? If all you want is to find the context, you might find C-M-b
and C-M-f
(bound to backward-sexp
and forward-sexp
resp.) pretty useful: you do C-M-b
to see the context of the opening brace and C-M-f
to go back to after the closing one: no need for line numbers. If you really want them, combine the above with line-number-mode
which shows you the line number the cursor is on in the modeline. But in general line numbers, although sometimes necessary, are a crutch that you might be better off without.
Emacs provides facilities for editing with parentheses (and brackets and braces - matched delimiters in general). The best place to find out about that is the Emacs manual: do C-h i g(emacs) parentheses
to get to that section.