1

I work with latex/other documents with long nested of texts/codes are enclosed by paratheses or braces, like this:

{
   long blocks of latex or other materials
   (
      another long blocks of texts
   )
   some text
}

In emacs, if e.g. I move the cursor to the closing }, delete the } and then type it again, emacs will say

Matching {

Is there a way to get emacs to tell me the line number of this matching { ? The structure/nature of the document is such that I cannot easily add modifier/comments/indentation to help identify this {.

p.s. I am not sure what's the correct tags for this question; feel free to give suggestions!

8
  • 3
    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.
    – NickD
    Dec 10, 2021 at 4:48
  • C-M-b and C-M-f are exactly what I am looking for. THANKS! Related newbie question: How might I have discovered this myself? What tags/keywords should I have searched for in the emacs wiki/documentation?
    – underflow
    Dec 10, 2021 at 14:24
  • 1
    You should at least scan the Emacs manual: it is available within Emacs itself and uses Info which provides pretty powerful searching and navigation facilities: do C-h i g(emacs) and go to town! Once in the manual, you can search for a term by using i, the index command. In this particular case, say i 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 (the moving across entry is the one describing the commands above but you'll probably want to look at the other one as well).
    – NickD
    Dec 10, 2021 at 14:35
  • ... And you can learn enough about Info to do all of that by saying C-h i g(info) and reading that manual. The Emacs help system (not just the manuals) is awesome: you can find more about it with C-h ?.
    – NickD
    Dec 10, 2021 at 14:41
  • Actually, the moving across entry does not talk about the above commands. But when you are in that entry, go up 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.
    – NickD
    Dec 10, 2021 at 14:45

1 Answer 1

1

[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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.