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!

Drew
  • 75,699
  • 9
  • 109
  • 225
underflow
  • 111
  • 3
  • 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 '21 at 04: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 '21 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 '21 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 '21 at 14:41
  • Actually, the `moving across` entry does *not* talk about the above commands. But when you are in that entry, go `u`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. – NickD Dec 10 '21 at 14:45
  • This is a [XY-question](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) and should be closed. Problem X is solved in the comments and Y will never be answered here. @underflow: No offence meant! [Closing](https://stats.stackexchange.com/help/closed-questions) does not mean deleting. The question does just no longer appear in the list of unanswered questions. – Tobias Dec 15 '21 at 21:02
  • If the question posed is X, and the answer is in the comments, someone please post an answer based on that answer in the comments. – Drew Dec 16 '21 at 03:52
  • I made my comment into an answer. – NickD Dec 18 '21 at 23:10

1 Answers1

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.

NickD
  • 27,023
  • 3
  • 23
  • 42