Search code examples
elispemacs24

M-g g (a.k.a M-x goto-line) acting weird


Emacs noob (sort of) here. I'm getting unexpected behavior from the goto-line command. The wording of the manual seems imprecise. I'm assuming the phrase "move to line LINE..." means "set point to line LINE". So my interpretation of the manual's entry on goto-line is that it is supposed to set mark at the current location of point and then move point to the line specified by the argument you enter. Is this correct? Because what is happening instead is that, yes, it does set mark at the current location successfully (which I don't care about since I can set mark myself very easily if I want to) but then it sets point at the beginning of the buffer instead of where I specified. Is this what goto-line is supposed to do? Am I misunderstanding either the manual or the purpose of this command?

The activity I'm engaged in is reading the Emacs Lisp manual and evaluating expressions in it. I have line numbers turned on in the left margin, and I would like to be able to simply do M-g g LINE-NUMBER, C-e, C-x C-e and see how the form evaluates. But instead, I have to do this klutzy routine of subtracting current point line number from target line number and then doing M-DIFFERENCE C-n. Or I just C-nnnnnnn...or C-pppppp... or even use the mouse, which is the type of slow and clumsy navigation I'm trying to get away from by using Emacs.


Solution

  • Unfortunately, goto-line in an Info buffer is working on the source rather than the rendered outcome.

    (If you visit the elisp.info file, you'll see where the real line numbers are coming from.)

    Unfortunately that doesn't help you (or anyone, I suspect), but it does explain why the feature doesn't work as expected.

    You could M-x report-emacs-bug and propose that this be changed to work the way people would expect it to work.

    If you're using Emacs 26 and its native display-line-numbers-mode then you can customize the display-line-numbers-widen option to prevent line numbers changing when buffers are narrowed, in which case you'll be able to use the number you can see with goto-line.