[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.
C-M-b
andC-M-f
(bound tobackward-sexp
andforward-sexp
resp.) pretty useful: you doC-M-b
to see the context of the opening brace andC-M-f
to go back to after the closing one: no need for line numbers. If you really want them, combine the above withline-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.C-h i g(emacs)
and go to town! Once in the manual, you can search for a term by usingi
, the index command. In this particular case, sayi parentheses TAB TAB
: the TABs provide completion, so this will show you all the index entries with the word 'parentheses' in them. Click on one (themoving across
entry is the one describing the commands above but you'll probably want to look at the other one as well).Info
to do all of that by sayingC-h i g(info)
and reading that manual. The Emacs help system (not just the manuals) is awesome: you can find more about it withC-h ?
.moving across
entry does not talk about the above commands. But when you are in that entry, gou
p and you'll end up in a section called "Commands for editing with parentheses". The above commands are described in the "Expressions" subsection. You should read the whole section - and eventually the whole manual.