[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 6d66aee 284/468: Redo handling of "stdin:N" in tr
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 6d66aee 284/468: Redo handling of "stdin:N" in tracebacks |
Date: |
Thu, 5 Aug 2021 04:58:54 -0400 (EDT) |
branch: elpa/lua-mode
commit 6d66aee136e65a2b9df7e252dd41da3c4965b12f
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Redo handling of "stdin:N" in tracebacks
The regexp that disabled highlighting of "stdin:N" turned out to be
overly magical (unstable, any change in it caused breakage).
This change enables highlighting back and adds advices around
compilation-mode functions to ensure minimum inconvenience: now any
"stdin:N:" message at line L points to line L of REPL buffer.
---
lua-mode.el | 43 ++++++++++++++++++++++--
test/inferior-test.el | 93 ++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 114 insertions(+), 22 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 843a727..66f07d2 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -302,11 +302,47 @@ If the latter is nil, the keymap translates into
`lua-mode-map' verbatim.")
(defcustom lua-traceback-line-re
;; This regexp skips prompt and meaningless "stdin:N:" prefix when looking
;; for actual file-line locations.
- "^\\(?:[\t ]*\\|.*>[\t ]+\\)\\(?:stdin:[0-9]+:[\t
]*\\)?\\(?:stdin:[0-9]+:\\|\\([^\n\t ]*\\):\\([0-9]+\\):\\)"
+ "^\\(?:[\t ]*\\|.*>[\t ]+\\)\\(?:[^\n\t ]+:[0-9]+:[\t ]*\\)*\\(?:\\([^\n\t
]+\\):\\([0-9]+\\):\\)"
"Regular expression that describes tracebacks and errors."
:type 'regexp
:group 'lua)
+(defvar lua--repl-buffer-p nil
+ "Buffer-local flag saying if this is a Lua REPL buffer.")
+(make-variable-buffer-local 'lua--repl-buffer-p)
+
+
+(defadvice compilation-find-file (around lua--repl-find-file
+ (marker filename directory &rest
formats)
+ activate)
+ "Return Lua REPL buffer when looking for \"stdin\" file in it."
+ (if (and
+ lua--repl-buffer-p
+ (string-equal filename "stdin")
+ ;; NOTE: this doesn't traverse `compilation-search-path' when
+ ;; looking for filename.
+ (not (file-exists-p (expand-file-name
+ filename
+ (when directory (expand-file-name directory))))))
+ (setq ad-return-value (current-buffer))
+ ad-do-it))
+
+
+(defadvice compilation-goto-locus (around lua--repl-goto-locus
+ (msg mk end-mk)
+ activate)
+ "When message points to Lua REPL buffer, go to the message itself.
+Usually, stdin:XX line number points to nowhere."
+ (let ((errmsg-buf (marker-buffer msg))
+ (error-buf (marker-buffer mk)))
+ (if (and (with-current-buffer errmsg-buf lua--repl-buffer-p)
+ (eq error-buf errmsg-buf))
+ (progn
+ (compilation-set-window (display-buffer (marker-buffer msg)) msg)
+ (goto-char msg))
+ ad-do-it)))
+
+
(defcustom lua-indent-string-contents nil
"If non-nil, contents of multiline string will be indented.
Otherwise leading amount of whitespace on each line is preserved."
@@ -1600,6 +1636,7 @@ When called interactively, switch to the process buffer."
;; enable error highlighting in stack traces
(require 'compile)
+ (setq lua--repl-buffer-p t)
(make-local-variable 'compilation-error-regexp-alist)
(setq compilation-error-regexp-alist
(cons (list lua-traceback-line-re 1 2)
@@ -1639,7 +1676,9 @@ When called interactively, switch to the process buffer."
"Send STR plus a newline to Lua subprocess.
If `lua-process' is nil or dead, start a new process first."
- (comint-simple-send (lua-get-create-process) str))
+ (unless (string-equal (substring str -1) "\n")
+ (setq str (concat str "\n")))
+ (process-send-string (lua-get-create-process) str))
(defun lua-send-current-line ()
"Send current line to Lua subprocess, found in `lua-process'.
diff --git a/test/inferior-test.el b/test/inferior-test.el
index 8d3bd80..bf8468a 100644
--- a/test/inferior-test.el
+++ b/test/inferior-test.el
@@ -1,5 +1,7 @@
;; lua-mode tests for inferior process handling
+(require 'cl-lib)
+
(load (concat (file-name-directory (or load-file-name (buffer-file-name)
default-directory))
"test-helper.el") nil 'nomessage 'nosuffix)
@@ -27,9 +29,8 @@
;; lua-process-buffer should be nil
(lua-hide-process-buffer)
(should (get-buffer-window cur-buf)))))
-
+
(ert-deftest lua-runtime-error-msg-is-fontified ()
- :expected-result (if (eq 23 emacs-major-version) :failed :passed)
(with-lua-buffer
(insert "\
function bar()
@@ -41,9 +42,9 @@ function foo()
end
")
(rename-buffer "test-send-runtime-error.lua" 'unique)
- ;; By default, basic face for all error messages is 'underline, this is pain
- ;; to filter out, let's change that to 'default.
- (let ((compilation-message-face 'default))
+ ;; By default non-nil compilation-message-face is appended to
+ ;; compilation-error faces, let's simplify the checks.
+ (let ((compilation-message-face nil))
(lua-send-buffer)
(lua-send-string "foo()")
;; Make sure to wait enough to get all the output from the subprocess.
@@ -53,41 +54,93 @@ end
(equal
;; (buffer-string)
(get-buffer-line-faces)
- '(nil ;; motd line
- ("> " comint-highlight-prompt
- "test-send-runtime-error.lua" compilation-error
+ '(nil ;; motd line (not highlighted)
+ nil ;; first prompt (also not highlighted)
+ ("test-send-runtime-error.lua" compilation-error
"2" compilation-line-number) ;; error message
- nil ;; stack traceback
- nil ;; in function error
+ nil ;; stack traceback
+ nil ;; in function error
("test-send-runtime-error.lua" compilation-error
"2" compilation-line-number) ;; in 'bar'
("test-send-runtime-error.lua" compilation-error
"6" compilation-line-number) ;; in 'foo'
+ ("stdin" compilation-error "1" compilation-line-number)
nil ;; in main chunk
- nil
nil)))))))
(ert-deftest lua-syntax-error-msg-is-fontified ()
- :expected-result (if (eq 23 emacs-major-version) :failed :passed)
(with-lua-buffer
(rename-buffer "test-send-syntax-error.lua")
(insert "\
-foo = 1
-bar = 2
-
function () end
")
- (let ((compilation-message-face 'default))
+ ;; By default non-nil compilation-message-face is appended to
+ ;; compilation-error faces, let's simplify the checks.
+ (let ((compilation-message-face nil))
(lua-send-buffer)
(while (accept-process-output lua-process 0 200))
(with-current-buffer lua-process-buffer
(should
(equal
(get-buffer-line-faces)
- '(nil
- ("> " comint-highlight-prompt
+ '(nil ;; motd line, no highlight
+ nil ;; first prompt, also no highlight
+ (;; "stdin" is being highlighted here because compilation mode
+ ;; thinks it is some sort of "make: ..." message. This doesn't
+ ;; happen in wildlife, because there's a default message face
+ ;; (underline) that prevents this. In tests this is turned off,
+ ;; see `(compilation-message-face nil)' above, to simplify
+ ;; font-lock face checks.
+ "stdin" font-lock-function-name-face
"test-send-syntax-error.lua" compilation-error
- "4" compilation-line-number)
+ "1" compilation-line-number)
;; stacktrace with misc info, no font-lock
- nil nil nil nil nil nil)))))))
+ nil nil
+ ("stdin" compilation-error "1" compilation-line-number)
+ ("stdin" compilation-error "1" compilation-line-number)
+ nil nil)))))))
+
+
+(require 'compile)
+(if (fboundp 'compilation--loc->file-struct)
+ (defun get-error-file (err-info)
+ (caar (compilation--loc->file-struct
+ (compilation--message->loc (compilation-next-error 0)))))
+ (defun get-error-file (err-info)
+ (caar (nth 2 (car err-info)))))
+
+(ert-deftest lua-repl-doesnt-ask-for-stdin-file ()
+ "Ensure REPL doesn't annoyingly ask to open file named \"stdin\"."
+ (let ((fname (make-temp-file "lua_mode_test" nil ".lua"))
+ buf)
+ (unwind-protect
+ (progn
+ (save-current-buffer
+ (setq buf (find-file fname))
+ (insert "function () end")
+ ;; Make sure the buffer can be killed cleanly
+ (set-buffer-modified-p nil)
+ (lua-send-buffer)
+ (while (accept-process-output lua-process 0 200))
+ (with-current-buffer lua-process-buffer
+ (font-lock-fontify-buffer))
+ (cl-letf
+ (((symbol-function 'read-file-name)
+ (lambda (&rest args)
+ (error "read-file-name must not be called"))))
+ (should (equal (next-error) nil))
+ (with-current-buffer lua-process-buffer
+ (should (equal
+ fname
+ (get-error-file (compilation-next-error 0)))))
+
+ (should (equal (next-error) nil))
+ (with-current-buffer lua-process-buffer
+ (should (equal
+ "stdin"
+ (get-error-file (compilation-next-error 0))))))))
+ (when buf
+ (kill-buffer buf))
+ (delete-file fname)
+ (kill-buffer "*lua*"))))
- [nongnu] elpa/lua-mode 2cdfda7 264/468: Add inferior-test.el with some basic (failing) tests, (continued)
- [nongnu] elpa/lua-mode 2cdfda7 264/468: Add inferior-test.el with some basic (failing) tests, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d166d5e 267/468: Merge remote-tracking branch 'upstream/master', Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d52e291 270/468: Don't fontify "stdin:N:" stacktrace entries in REPL buffer, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ec1b634 271/468: Bump NEWS, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d4ee03e 278/468: Use syntax-propertize-function if it is available, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode fd0f6ba 280/468: Merge pull request #69 from atomontage/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 694421c 274/468: Add lua-remove-syntax-table-property to syntactic keywords, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b73794f 276/468: Merge pull request #79 from j-fu/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 13f6ffa 277/468: Provide lua--setq-local fallback macro for pre-24.3, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ce0a813 282/468: Mention xristos in AUTHORS, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6d66aee 284/468: Redo handling of "stdin:N" in tracebacks,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode d7855bc 285/468: remove function lua-comment-p, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5995697 286/468: Merge pull request #81 from v2e4lisp/remove-lua-comment-p, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8a37fce 288/468: Merge pull request #82 from holomorph/browse-url, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c3b103d 290/468: lua-beginning-of-proc: improve defun header regex, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 522edaf 289/468: with-lua-buffer: mark as debuggable, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a57e25e 293/468: Update documentation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ceb74ae 296/468: Add file test/.nosearch, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a7780dc 304/468: silence 25.1 byte-compiler, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 37f3c42 306/468: Silence compilation warning about referencing a variable from compile.el, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 148858c 309/468: Migrate tests to buttercup, Philip Kaludercic, 2021/08/05