GNU bug report logs - #65877
29.1; line-number-at-pos crashes with args-out-of-range when ran using emacsclient

Previous Next

Package: emacs;

Reported by: Michaël Cadilhac <michael <at> cadilhac.name>

Date: Mon, 11 Sep 2023 21:09:01 UTC

Severity: normal

Tags: notabug

Found in version 29.1

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michaël Cadilhac <michael <at> cadilhac.name>
Cc: 65877 <at> debbugs.gnu.org
Subject: bug#65877: 29.1; line-number-at-pos crashes with args-out-of-range when ran using emacsclient
Date: Tue, 12 Sep 2023 14:28:59 +0300
tags 65877 notabug
thanks

> From: Michaël Cadilhac <michael <at> cadilhac.name>
> Date: Mon, 11 Sep 2023 16:07:42 -0500
> 
> How to reproduce: start with
> 
> $ emacs -Q
> 
> M-x server-start
> 
> Open a file with say 200 lines, scroll at the bottom, so that the
> first line of the file is not at the top of the window.
> 
> Then in a shell, run:
> 
> $ emacsclient -e '(line-number-at-pos (window-start))'
> *ERROR*: Args out of range: 146, 1, 1

This is a cockpit error, not a bug.  The doc string of
line-number-at-pos says:

  line-number-at-pos is a built-in function in ‘src/fns.c’.

  (line-number-at-pos &optional POSITION ABSOLUTE)

  Return the line number at POSITION in the current buffer.
                                     ^^^^^^^^^^^^^^^^^^^^^

So the correct form to evaluate is this:

  $ emacsclient -e "(with-current-buffer (window-buffer) (line-number-at-pos (window-start)))"

IOW, you must make sure the buffer of the selected window is current
when the server evaluates the expression.  It is not guaranteed by
default:

  $ emacsclient -e "(message \"%s\" (current-buffer))"
  " *server*"




This bug report was last modified 1 year and 255 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.