all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: "Michaël Cadilhac" <michael@cadilhac.name>
Cc: 65877@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	[thread overview]
Message-ID: <83o7i7pr44.fsf@gnu.org> (raw)
In-Reply-To: <CADt3fpPDMuWXp9S2-FyKaryWVRBpKsNibFC1gqJgQ39FQcT4ZQ@mail.gmail.com> (message from Michaël Cadilhac on Mon, 11 Sep 2023 16:07:42 -0500)

tags 65877 notabug
thanks

> From: Michaël Cadilhac <michael@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*"





  reply	other threads:[~2023-09-12 11:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11 21:07 bug#65877: 29.1; line-number-at-pos crashes with args-out-of-range when ran using emacsclient Michaël Cadilhac
2023-09-12 11:28 ` Eli Zaretskii [this message]
2023-09-12 15:59   ` Michaël Cadilhac
2023-09-12 16:43     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83o7i7pr44.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=65877@debbugs.gnu.org \
    --cc=michael@cadilhac.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.