[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode d52e291 270/468: Don't fontify "stdin:N:" stacktr
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode d52e291 270/468: Don't fontify "stdin:N:" stacktrace entries in REPL buffer |
Date: |
Thu, 5 Aug 2021 04:58:51 -0400 (EDT) |
branch: elpa/lua-mode
commit d52e2913287db3683c6c10c39a6f22ece4a5dbe2
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Don't fontify "stdin:N:" stacktrace entries in REPL buffer
Add couple of minor tweaks here and there on the way.
---
lua-mode.el | 22 ++++++++++++------
test/inferior-test.el | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++
test/test-helper.el | 40 ++++++++++++++++++++++++--------
3 files changed, 110 insertions(+), 16 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index e08955c..c4f087d 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -383,7 +383,9 @@ If the latter is nil, the keymap translates into
`lua-mode-map' verbatim.")
:group 'lua)
(defcustom lua-traceback-line-re
- "^\\(?:[\t ]*\\|.*>[\t ]+\\)\\([^\n\t ]+\\):\\([0-9]+\\):"
+ ;; 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]+\\):\\)"
"Regular expression that describes tracebacks and errors."
:type 'regexp
:group 'lua)
@@ -1640,17 +1642,17 @@ When called interactively, switch to the process
buffer."
(accept-process-output (get-buffer-process (current-buffer)))
(goto-char (point-max)))
;; send initialization code
- (comint-simple-send nil lua-process-init-code)
+ (lua-send-string lua-process-init-code)
;; enable error highlighting in stack traces
(require 'compile)
(make-local-variable 'compilation-error-regexp-alist)
(setq compilation-error-regexp-alist
- (cons '("^\t*\\([^:\n]+\\):\\([^:\n]+\\):" 1 2)
+ (cons (list lua-traceback-line-re 1 2)
;; Remove 'gnu entry from error regexp alist, it somehow forces
;; leading TAB to be recognized as part of filename in Emacs23.
(delq 'gnu compilation-error-regexp-alist)))
- (compilation-shell-minor-mode))
+ (compilation-shell-minor-mode 1))
;; when called interactively, switch to process buffer
(if (lua--called-interactively-p 'any)
@@ -1664,7 +1666,7 @@ When called interactively, switch to the process buffer."
lua-process)
(defun lua-kill-process ()
- "Kill lua subprocess and its buffer."
+ "Kill Lua subprocess and its buffer."
(interactive)
(if lua-process-buffer
(kill-buffer lua-process-buffer)))
@@ -1679,8 +1681,14 @@ When called interactively, switch to the process buffer."
(interactive)
(set-marker lua-region-end (or arg (point))))
+(defun lua-send-string (str)
+ "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))
+
(defun lua-send-current-line ()
- "Send current line to lua subprocess, found in `lua-process'.
+ "Send current line to Lua subprocess, found in `lua-process'.
If `lua-process' is nil or dead, start a new process first."
(interactive)
(lua-send-region (line-beginning-position) (line-end-position)))
@@ -1734,7 +1742,7 @@ Otherwise, return START."
(lua-make-lua-string region-str)
(lua-make-lua-string lua-file)
lineno)))
- (comint-simple-send (lua-get-create-process) command)
+ (lua-send-string command)
(when lua-always-show (lua-show-process-buffer))))
(defun lua-prompt-line ()
diff --git a/test/inferior-test.el b/test/inferior-test.el
index 34fbdbf..ba29585 100644
--- a/test/inferior-test.el
+++ b/test/inferior-test.el
@@ -25,3 +25,67 @@
(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()
+ error(123)
+end
+
+function foo()
+ bar()
+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))
+ (lua-send-buffer)
+ (lua-send-string "foo()")
+ ;; Make sure to wait enough to get all the output from the subprocess.
+ (while (accept-process-output lua-process 0 200))
+ (with-current-buffer lua-process-buffer
+ (should
+ (equal
+ ;; (buffer-string)
+ (get-buffer-line-faces)
+ '(nil ;; motd line
+ ("> " comint-highlight-prompt
+ "test-send-runtime-error.lua" compilation-error
+ "2" compilation-line-number) ;; error message
+ 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'
+ 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))
+ (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
+ "test-send-syntax-error.lua" compilation-error
+ "4" compilation-line-number)
+ ;; stacktrace with misc info, no font-lock
+ nil nil nil nil nil nil)))))))
diff --git a/test/test-helper.el b/test/test-helper.el
index 3c407ba..20f1104 100644
--- a/test/test-helper.el
+++ b/test/test-helper.el
@@ -1,6 +1,7 @@
(require 'ert)
(require 'lua-mode)
+
(defun get-str-faces (str)
"Find contiguous spans of non-default faces in STR.
@@ -11,13 +12,25 @@ E.g. for properly fontified Lua string \"local x = 100\" it
should return
"
(let ((pos 0)
nextpos
- result prop)
+ result prop newprop)
(while pos
- (setq nextpos (next-single-property-change pos 'face str)
- prop (get-text-property pos 'face str))
- (when prop
- (push (substring-no-properties str pos nextpos) result)
- (push prop result))
+ (setq nextpos (next-property-change pos str)
+ newprop (or (get-text-property pos 'face str)
+ (get-text-property pos 'font-lock-face str)))
+ (when (not (equal prop newprop))
+ (setq prop newprop)
+
+ (when (listp prop)
+ (when (eq (car-safe (last prop)) 'default)
+ (setq prop (butlast prop)))
+ (when (= 1 (length prop))
+ (setq prop (car prop)))
+ (when (symbolp prop)
+ (when (eq prop 'default)
+ (setq prop nil))))
+ (when prop
+ (push (substring-no-properties str pos nextpos) result)
+ (push prop result)))
(setq pos nextpos))
(nreverse result)))
@@ -29,6 +42,12 @@ E.g. for properly fontified Lua string \"local x = 100\" it
should return
(font-lock-fontify-buffer)
(buffer-string)))
+(defun get-buffer-line-faces ()
+ (font-lock-fontify-buffer)
+ (mapcar 'get-str-faces
+ (split-string (buffer-string) "\n" nil)))
+
+
(defun lua-get-line-faces (str)
"Find contiguous spans of non-default faces in each line of STR.
@@ -59,12 +78,15 @@ This is a mere typing/reading aid for lua-mode's font-lock
tests."
(defmacro with-lua-buffer (&rest body)
`(with-temp-buffer
+ (lua-mode)
(set (make-local-variable 'lua-process) nil)
(set (make-local-variable 'lua-process-buffer) nil)
- (switch-to-buffer (current-buffer))
- (lua-mode)
(font-lock-fontify-buffer)
- ,@body))
+ (pop-to-buffer (current-buffer))
+ (unwind-protect
+ (progn ,@body)
+ (when (buffer-live-p lua-process-buffer)
+ (lua-kill-process)))))
(defun lua-get-indented-strs (strs)
(butlast
- [nongnu] elpa/lua-mode 45a881d 243/468: lua-search-documentation: fix 'foo.bar' lookups broken when making '.' punctuation, (continued)
- [nongnu] elpa/lua-mode 45a881d 243/468: lua-search-documentation: fix 'foo.bar' lookups broken when making '.' punctuation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f8a41b8 246/468: Fix cl-lib dependency for Emacs23 tests, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9e200e8 247/468: Fix font-locking of functions with underscores (issue #63), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bbab5a6 253/468: Don't anchor arglist continuation to block openers, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9d86a22 254/468: Fix indentation error raised if 'else' is on the same line as 'if', Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 2ad2ac8 256/468: lua-imenu-generic-expression add support for local function, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8ff3427 257/468: Merge pull request #65 from guoxx/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 78f0e09 260/468: Make sure nested token searches begin from open-token positions, Philip Kaludercic, 2021/08/05
- [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 <=
- [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, 2021/08/05
- [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