1

Why some functions in simple.el are invokable with M-x and some others aren't?
For example I can do M-x what-line but I can't do M-x line-number-at-pos.

Drew
  • 75,699
  • 9
  • 109
  • 225
element
  • 27
  • 5
  • https://emacs.stackexchange.com/tags/elisp/info – Drew May 14 '22 at 21:19
  • There are also other duplicates, e.g. https://emacs.stackexchange.com/q/54602/105. – Drew May 14 '22 at 21:25
  • See [Defining Commands](https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Commands.html) in the [Emacs Lisp Manual](https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html). – NickD May 15 '22 at 02:00

1 Answers1

1

Only functions which are declared to be interactive are callable with M-x. The declaration is done by putting an (interactive) form as the first thing in the body of the function. Like this:

(defun an-example ()
  "this is an example function"
  (interactive)
  (insert "42"))

There is a lot of other information you should know about interactive functions, so you should type C-h f and enter interactive to see more help for it.

db48x
  • 15,741
  • 1
  • 19
  • 23