Skip to content

Commit 3ba8f5d

Browse files
authored
Merge pull request #152 from tpapp/tp/fix-error-regexps
Fix up error regexps.
2 parents 4a0a926 + b243555 commit 3ba8f5d

File tree

4 files changed

+84
-38
lines changed

4 files changed

+84
-38
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
emacs_version:
20-
- 25.1
21-
- 25.2
22-
- 25.3
23-
- 26.1
24-
- 26.2
25-
- 26.3
2620
- 27.1
2721
- 27.2
2822
- 28.1

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It is recommended that you use this minor mode with [julia-mode](https://github.
1111

1212
## Installation and loading
1313

14-
**Please make sure you have at least Emacs 25**. The `term` code changed a bit since Emacs 24, and the package does not support that and earlier versions. For example, Ubuntu has had Emacs 25 since 18.04LTS.
14+
**Please make sure you have at least Emacs 27.1**, as the package does not support earlier versions.
1515

1616
Place this in your **Emacs initialization files** (eg `.emacs`):
1717
```emacs-lisp
@@ -181,6 +181,16 @@ Cygwin may require some rewriting of paths for `include` to work. After loading
181181
```
182182
as a reasonable default, or write custom rules for `julia-repl-path-rewrites`.
183183

184+
## Clickable error locations
185+
186+
Error locations in the inferior buffer should be clickable, implemented with `compilation-shell-minor-mode`.
187+
188+
The error printing syntax changed over time, and legacy forms are not included, they are not needed if you are using Julia 1.6 or later. To get them back, use
189+
```emacs-lisp
190+
(setq julia-repl-compilation-location-legacy t)
191+
```
192+
If you find that a Julia error (warning, info, etc) message location is not clickable in Emacs, please open an issue.
193+
184194
## Limitations
185195

186196
See the [issues](https://github.com/tpapp/julia-repl/issues).

julia-repl-tests.el

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,29 @@
4040

4141
(ert-deftest julia-repl-location-rx ()
4242
(let ((str "@ Foo ~/code/Foo/src/Foo.jl:100"))
43-
(string-match julia-repl--rx-at str)
44-
(equal (match-string 1 str) "Foo")
45-
(equal (match-string 2 str) "~/code/Foo/src/Foo.jl")
46-
(equal (match-string 3 str) "100")))
43+
(should (string-match julia-repl--CR-at str))
44+
(should (equal (match-string 1 str) "Foo"))
45+
(should (equal (match-string 2 str) "~/code/Foo/src/Foo.jl"))
46+
(should (equal (match-string 3 str) "100"))))
47+
48+
(ert-deftest julia-repl-error-locations ()
49+
;; module name, absolute path
50+
(should
51+
(equal
52+
(cdr (s-match julia-repl--CR-at " @ Main.MyModule /tmp/tmp.jl:3"))
53+
'("Main.MyModule" "/tmp/tmp.jl" "3")))
54+
;; tilde in path
55+
(should
56+
(equal
57+
(cdr (s-match julia-repl--CR-at " @ Foo ~/tmp.jl:99"))
58+
'("Foo" "~/tmp.jl" "99")))
59+
;; underscore
60+
(should
61+
(equal
62+
(cdr (s-match julia-repl--CR-at " @ Main.test_loops ~/tmp.jl:7"))
63+
'("Main.test_loops" "~/tmp.jl" "7")))
64+
;; no module
65+
(should
66+
(equal
67+
(cdr (s-match julia-repl--CR-at " @ ~/tmp.jl:7"))
68+
'(nil "~/tmp.jl" "7"))))

julia-repl.el

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
;; Copyright (C) 2016–2024 Tamas K. Papp
44
;; Author: Tamas Papp <[email protected]>
55
;; Keywords: languages
6-
;; Version: 1.4.0
7-
;; Package-Requires: ((emacs "25.1")(s "1.12"))
6+
;; Version: 1.5.0
7+
;; Package-Requires: ((emacs "27.1")(s "1.12"))
88
;; URL: https://github.com/tpapp/julia-repl
99

1010
;;; Usage:
@@ -47,7 +47,6 @@
4747
(require 'seq)
4848
(require 'subr-x)
4949

50-
5150
;;
5251
;; customizations
5352
;;
@@ -266,30 +265,40 @@ When PASTE-P, “bracketed paste” mode will be used. When RET-P, terminate wit
266265
(when ret-p
267266
(eat-term-send-string eat-terminal "\^M")))))
268267

268+
(defconst julia-repl--CR-at
269+
(rx "@" space
270+
(? (group (one-or-more (or (any "._") alnum))) space) ; group 1: module name
271+
(group (+ (not (any space ">" "<" "(" ")" "\t" "\n" "," "'" "\"" ";" ":")))) ; group 2: path
272+
":"
273+
(group (+ num)) ; group 3: line number
274+
)
275+
"Matches “@ Foo ~/code/Foo/src/Foo.jl:100”. This is what is used in Julia >= 1.6")
276+
277+
(defconst julia-repl--CR-filename
278+
(rx (one-or-more (not (any " ><()\t\n,'\";:"))))
279+
"An attempt to match filenames in error, info, and warning messages printed by Julia.")
280+
281+
(defconst julia-repl--CR-load-error
282+
(rx
283+
"while loading "
284+
(group (regexp julia-repl--CR-filename))
285+
", in expression starting on line "
286+
(group (one-or-more digit)))
287+
"Compilation regexp matching “while loading /tmp/Foo.jl, in expression starting on line 2”.")
288+
289+
(defconst julia-repl--CR-around
290+
(rx
291+
(or "around" "at" "Revise")
292+
" "
293+
(group (regexp julia-repl--CR-filename))
294+
":"
295+
(group (one-or-more digit)))
296+
"Compilation regexp matching “around /tmp/Foo.jl:2”, also starting with “at or “Revise”")
297+
269298
;;
270299
;; global variables
271300
;;
272301

273-
(defconst julia-repl--rx-at
274-
(rx (seq "@" (syntax whitespace)
275-
(? (group (+ alnum)) space) ; package name
276-
(group (+ (not (any space ">" "<" "(" ")" "\t" "\n" "," "'" "\"" ";" ":")))) ; path
277-
":" (group (+ num)))) ; line
278-
"Matches “@ Foo ~/code/Foo/src/Foo.jl:100”")
279-
280-
(defvar julia-repl--compilation-regexp-alist
281-
`(;; matches "while loading /tmp/Foo.jl, in expression starting on line 2"
282-
(julia-load-error . ("while loading \\([^ ><()\t\n,'\";:]+\\), in expression starting on line \\([0-9]+\\)" 1 2))
283-
;; matches "around /tmp/Foo.jl:2", also starting with "at" or "Revise"
284-
(julia-loc . ("\\(around\\|at\\|Revise\\) \\([^ ><()\t\n,'\";:]+\\):\\([0-9]+\\)" 2 3))
285-
;; matches "omitting file /tmp/Foo.jl due to parsing error near line 2", from Revise.parse_source!
286-
(julia-warn-revise . ("omitting file \\([^ ><()\t\n,'\";:]+\\) due to parsing error near line \\([0-9]+\\)" 1 2))
287-
(julia-error-at . (,julia-repl--rx-at 2 3))
288-
)
289-
"Specifications for highlighting error locations.
290-
291-
Uses function ‘compilation-shell-minor-mode’.")
292-
293302
(defvar julia-repl--terminal-backend
294303
(make-julia-repl--buffer-ansi-term)
295304
"Terminal backend, for internal use. Set using `julia-repl-set-terminal-backend'.")
@@ -374,6 +383,20 @@ generate a buffer name.")
374383
Valid values are NIL or a string. These take effect the next time
375384
a new Julia process is started.")
376385

386+
(defvar julia-repl-compilation-location-legacy nil
387+
"Whether to include recognize various legacy error messages in compilation output.
388+
Mainly useful if you are using Julia <1.6.")
389+
390+
(defun julia-repl--compilation-regexp-alist ()
391+
"Return an alist suitable for use in `compilation-error-regexp-alist' for recognizing Julia error locations.
392+
393+
Cf `julia-repl-compilation-location-legacy'."
394+
(let ((regexp-alist `((,julia-repl--CR-at 2 3))))
395+
(if julia-repl-compilation-location-legacy
396+
(cons regexp-alist
397+
`((,julia-repl--CR-load-error 1 2) (,julia-repl--CR-around 1 2)))
398+
regexp-alist)))
399+
377400
;;
378401
;; REPL buffer creation and setup
379402
;;
@@ -446,10 +469,7 @@ prevent further attempts."
446469
447470
BASEDIR is used for resolving relative paths."
448471
(with-current-buffer inferior-buffer
449-
(setq-local compilation-error-regexp-alist-alist
450-
julia-repl--compilation-regexp-alist)
451-
(setq-local compilation-error-regexp-alist
452-
(mapcar #'car compilation-error-regexp-alist-alist))
472+
(setq-local compilation-error-regexp-alist (julia-repl--compilation-regexp-alist))
453473
(when basedir
454474
(setq-local compilation-search-path (list basedir)))
455475
(compilation-shell-minor-mode 1)))

0 commit comments

Comments
 (0)