In the description of the function goto-line
in the built-in emacs documentation, I found the following at the end:
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.
Similarly, the switch-to-buffer
function's documentation says:
WARNING: This is NOT the way to work on another buffer temporarily
within a Lisp program! Use `set-buffer' instead. That avoids
messing with the window-buffer correspondences.
Is it possible to know the non-interactive versions of frequent interactive functions like save-buffer
, kill-line
etc. or that these are efficient and do not have a non-interactive equivalent?
I did not find any relevant information about the two specific commands save-buffer
and kill-line
in the built-in documentation, so I would also like to know if that implies that these are okay for non-interactive use.
C-h f
for the command will give you a link to its source code. If there is a more-or-less corresponding non-interactive function then the command will typically invoke that. So the answer is to look at the source code to see what it does and whether there is a non-interactive function that does the bulk of the job. But the larger point is made by @JulesTamagnan in his comment and phils in his answer: assume that you can use a command in your code.C-h f
. But, I don't see a link to the source code there.C-h f kill-line
I get "kill-line is an interactive compiled Lisp function in `simple.el'", and "simple.el" is a link to the actual file on disk. Clicking on it or tabbing to it and hitting enter will activate the link and load the source file.emacs24-el
for example. That covers the elisp sources. For linking to C-code sources (if you want that) you would need to download them and tell Emacs where to find them (unless you compile Emacs yourself, in which case it already knows where to find them).