After opening a
.txt file with Emacs, when the point is at the line
How can I fast jump to line 435 of the above mentioned file?
What I tried:
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
If you added a trailing colon to each line like so:
M-x compilation-minor-mode will have the desired outcome, such that you can type
RET or use mouse-1 to visit the specified file at the specified line.
The trailing colon is needed because an error message is expected. In this case the error message (following the new colon) is an empty string; but the separator is still required.
And as commented by @glucas, you can then also use
You can add this functionality to
find-file-at-point with the following elisp snippet in your init file.
Please be aware that this method does not take into account that
inclusive the sub-string
:435 is a valid file name.
(defun find-file-at-point-goto-line (ret) "Ignore RET and jump to line number given in `ffap-string-at-point'." (when (and (stringp ffap-string-at-point) (string-match ":\\([0-9]+\\)\\'" ffap-string-at-point)) (goto-char (point-min)) (forward-line (string-to-number (match-string 1 ffap-string-at-point)))) ret) (advice-add 'find-file-at-point :filter-return #'find-file-at-point-goto-line)
If you turn on org-mode, you can open links of the sort
C-c C-o so with a few changes to the text in your example it's easy to open that link.
Maybe you can't edit the text or don't want to use org-mode so you could implement your own function. I'd still have a look at org mode (specifically
org-open-file) to see how line number jumping is implemented.
I think you can just use the go-to line function in emacs. below is its brief help doc:
goto-line is an interactive compiled Lisp function in ‘simple.el’.
It is bound to s-l, M-g g, M-g M-g, .
(goto-line LINE &optional BUFFER)
helm-find-files does this out-of-the-box, if you are a helm user, you probably already have bound it to C-x C-f.