#emacs doesn't ship a goto-line function. M-x apropos goto-line shows several implementations. But I was surprised to see avy's implementation https://github.com/abo-abo/avy/blob/933d1f36cca0f71e4acb5fac707e9ae26c536264/avy.el#L1750-L1784
Conversation
Notices
-
Embed this notice
PuercoPop (puercopop@mastodon.social)'s status on Thursday, 03-Apr-2025 20:57:21 JST PuercoPop
-
Embed this notice
PuercoPop (puercopop@mastodon.social)'s status on Thursday, 03-Apr-2025 20:57:19 JST PuercoPop
@HaraldKi It is not riddles, it is a mistake as acknowledged in https://mastodon.social/@PuercoPop/114269945473188483
That said, that point about people re-implementing still stands. ej.
avy-goto-line, org-goto-line[0], sly-goto-line[1], go--goto-line[2], etc.[0]: https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/org-macs.el#n867
[1]: https://github.com/joaotavora/sly/blob/c48defcf58596e035d473f3a125fdd1485593146/sly.el#L4141
[2]: https://github.com/dominikh/go-mode.el/blob/0ed3c5227e7f622589f1411b4939c3ee34711ebd/go-mode.el#L2400C8-L2400C21In conversation permalink Attachments
-
Embed this notice
Alfred M. Szmidt (amszmidt@mastodon.social)'s status on Thursday, 03-Apr-2025 20:57:19 JST Alfred M. Szmidt
@PuercoPop Correct, because using goto-line in a Lisp program is not the right thing. goto-char/forward-line is the preferred method there.
All the implementations you cited are exactly that .. for use in Lisp code (and not interactive usage).
In conversation permalink -
Embed this notice
Harald (haraldki@nrw.social)'s status on Thursday, 03-Apr-2025 20:57:21 JST Harald
@PuercoPop You are speaking in riddles. It is even called goto-line.
https://www.gnu.org/software/emacs/manual/html_node/emacs/Moving-Point.html#index-M_002dg-M_002dg
In conversation permalink -
Embed this notice
PuercoPop (puercopop@mastodon.social)'s status on Thursday, 03-Apr-2025 20:58:03 JST PuercoPop
Takes dedication to implement something more complex that
(defun goto-line (lnum)
(save-restriction
(widen)
(goto-char (point-min))
(forward-line (1- lnum))))In conversation permalink -
Embed this notice
PuercoPop (puercopop@mastodon.social)'s status on Thursday, 03-Apr-2025 20:58:03 JST PuercoPop
scratch that. simple.el does implement goto-line. Why do people re-implement it? compatibility with old emacs versions?
In conversation permalink -
Embed this notice
Alfred M. Szmidt (amszmidt@mastodon.social)'s status on Thursday, 03-Apr-2025 20:58:03 JST Alfred M. Szmidt
@PuercoPop From the doc-string:
This function is usually the wrong thing to use in a Lisp program.
What you probably want instead is something like:
(goto-char (point-min))
(forward-line (1- N))
If at all possible, an even better solution is to use char counts
rather than line counts.In conversation permalink
-
Embed this notice