[@Shynur has already pointed out, both in a comment and in an answer, the syntax for a hexadecimal number which you can use directly in the goto-char
interactive prompt. The following answer is concerned solely with the second part of the question: being able to use a Lisp expression in the interactive prompt.]
How a command gets its input is specified by using an interactive specification. E.g. goto-char
has an "N" interactive spec[1]:
n -- Number read using minibuffer.
N -- Numeric prefix arg, or if none, do like code ‘n’.
That's probably general enough for 99.99% of the interactive uses of goto-char
(e.g. and FWIW, I have never needed a calculator in order to get the position).
For use in Lisp programs, you can certainly pass whatever complicated expression you want as the argument to goto-char
, as long as it returns some position. Here's an example from a recent question:
...
(goto-char (progn
(skip-syntax-forward "^ " (line-end-position))
(point)))
...
Finally, if you want to be able to have a calculator available, you can follow @Shynur's answer, or you can do something like this:
(defun my/goto-char-with-calculator (res)
(interactive "XType a Lisp expression that evaluates to a number: ")
(goto-char res))
The doc string of interactive
says:
X -- Lisp expression read and evaluated.
So you can say e.g M-x my/goto-char-with-calculator
and type an arbitrary Lisp expression that evaluates to a positive integer, e.g (+ 1000 -992)
a.k.a 8
or more usefully (+ (point) 10)
to advance 10 character positions past the current point
in the buffer.
[1] goto-char
is actually written in C and implemented in editfns.c
, so I should have said: goto-char
has the equivalent of an "N" interactive spec. It is actually implemented by specifying the function call that will do the argument handling: (goto-char--read-natnum-interactive \"Go to char: \")
. But that's a detail...
goto-char #x1000
is working properly! Thanks!C-h i g (elisp)Integer Basics