[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scad-mode ace55270fd 40/47: Add flymake support
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scad-mode ace55270fd 40/47: Add flymake support |
Date: |
Sat, 12 Nov 2022 13:59:36 -0500 (EST) |
branch: elpa/scad-mode
commit ace55270fdda5b95cced08aea24f36514599b323
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add flymake support
---
scad-mode.el | 116 +++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 82 insertions(+), 34 deletions(-)
diff --git a/scad-mode.el b/scad-mode.el
index 347789d151..115e8e0b71 100644
--- a/scad-mode.el
+++ b/scad-mode.el
@@ -201,6 +201,7 @@ Key bindings:
\\{scad-mode-map}"
:group 'scad
:after-hook (c-update-modeline)
+ (add-hook 'flymake-diagnostic-functions #'scad-flymake nil 'local)
(add-hook 'completion-at-point-functions
#'scad-completion-at-point nil 'local)
(c-initialize-cc-mode t)
@@ -239,8 +240,8 @@ Key bindings:
(concat (file-name-base buffer-file-name)
".stl"))))
" " (shell-quote-argument buffer-file-name))))
-(defvar-local scad--preview-buffer nil)
-(defvar-local scad--preview-process nil)
+(defvar-local scad--preview-buffer nil)
+(defvar-local scad--preview-process nil)
(defvar-local scad--preview-mode-status nil)
(defvar-local scad--preview-mode-camera nil)
(defvar-local scad--preview-timer nil)
@@ -328,39 +329,45 @@ Key bindings:
(write-region (point-min) (point-max) infile nil 'nomsg)))
(setq scad--preview-process
(make-process
- :name scad-command
+ :noquery t
+ :connection-type 'pipe
+ :name "scad-preview"
:buffer "*scad output*"
- :sentinel (lambda (&rest _)
- (when (buffer-live-p buffer)
- (with-current-buffer buffer
- (setq scad--preview-process nil)
- (if (not (ignore-errors
- (and (file-exists-p outfile)
- (> (file-attribute-size
(file-attributes outfile)) 0))))
- (scad--preview-status "Error")
- (with-silent-modifications
- (fundamental-mode)
- (erase-buffer)
- (insert-file-contents outfile)
- (let ((inhibit-message t)
- (message-log-max nil))
- (scad-preview-mode)))
- (scad--preview-status ""))))
- (delete-file outfile)
- (delete-file infile))
- :command (list scad-command
- "-o" outfile
- "--preview"
- (format "--projection=%s" scad-preview-projection)
- (format "--imgsize=%d,%d"
- (car scad-preview-size)
- (cdr scad-preview-size))
- (format "--view=%s"
- (mapconcat #'identity scad-preview-view
","))
- (format "--camera=%s"
- (mapconcat #'number-to-string
scad-preview-camera ","))
- (format "--colorscheme=%s"
scad-preview-colorscheme)
- infile))))))
+ :sentinel
+ (lambda (proc _event)
+ (when (memq (process-status proc) '(exit signal))
+ (unwind-protect
+ (when (buffer-live-p buffer)
+ (with-current-buffer buffer
+ (setq scad--preview-process nil)
+ (if (not (ignore-errors
+ (and (file-exists-p outfile)
+ (> (file-attribute-size
(file-attributes outfile)) 0))))
+ (scad--preview-status "Error")
+ (with-silent-modifications
+ (fundamental-mode)
+ (erase-buffer)
+ (insert-file-contents outfile)
+ (let ((inhibit-message t)
+ (message-log-max nil))
+ (scad-preview-mode)))
+ (scad--preview-status ""))))
+ (delete-file outfile)
+ (delete-file infile))))
+ :command
+ (list scad-command
+ "-o" outfile
+ "--preview"
+ (format "--projection=%s" scad-preview-projection)
+ (format "--imgsize=%d,%d"
+ (car scad-preview-size)
+ (cdr scad-preview-size))
+ (format "--view=%s"
+ (mapconcat #'identity scad-preview-view ","))
+ (format "--camera=%s"
+ (mapconcat #'number-to-string scad-preview-camera
","))
+ (format "--colorscheme=%s" scad-preview-colorscheme)
+ infile))))))
(defun scad--preview-kill ()
"Kill current rendering."
@@ -431,5 +438,46 @@ Key bindings:
(defun scad-preview-size- () (interactive) (scad--preview-size (/ 1.1)))
(defun scad-preview-size+ () (interactive) (scad--preview-size 1.1))
+(defvar-local scad-flymake--process nil)
+
+(defun scad-flymake (report-fn &rest _args)
+ "Flymake backend, diagnostics are passed to REPORT-FN."
+ (unless (executable-find scad-command)
+ (error "Cannot find `%s'" scad-command))
+ (when (process-live-p scad-flymake--process)
+ (delete-process scad-flymake--process))
+ (let* ((buffer (current-buffer))
+ (infile (make-temp-file "scad-flymake-" nil ".scad"))
+ (outfile (concat infile ".ast")))
+ (save-restriction
+ (widen)
+ (write-region (point-min) (point-max) infile nil 'nomsg))
+ (setq
+ scad-flymake--process
+ (make-process
+ :name "scad-flymake"
+ :noquery t
+ :connection-type 'pipe
+ :buffer (generate-new-buffer " *scad-flymake*")
+ :command (list scad-command "-o" outfile infile)
+ :sentinel
+ (lambda (proc _event)
+ (when (memq (process-status proc) '(exit signal))
+ (unwind-protect
+ (when (and (buffer-live-p buffer)
+ (eq proc (buffer-local-value 'scad-flymake--process
buffer)))
+ (with-current-buffer (process-buffer proc)
+ (goto-char (point-min))
+ (let (diags)
+ (while (search-forward-regexp "^\\(ERROR\\|WARNING\\):
\\(.*?\\),? in file [^,]+, line \\([0-9]+\\)" nil t)
+ (let ((msg (match-string 2))
+ (type (if (equal (match-string 1) "ERROR") :error
:warning))
+ (region (flymake-diag-region buffer
(string-to-number (match-string 3)))))
+ (push (flymake-make-diagnostic buffer (car region)
(cdr region) type msg) diags)))
+ (funcall report-fn (nreverse diags)))))
+ (delete-file outfile)
+ (delete-file infile)
+ (kill-buffer (process-buffer proc)))))))))
+
(provide 'scad-mode)
;;; scad-mode.el ends here
- [nongnu] elpa/scad-mode 56a3af8661 37/47: Update keywords, (continued)
- [nongnu] elpa/scad-mode 56a3af8661 37/47: Update keywords, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 710cf2b7ce 45/47: Rename preview output buffer, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 3609ca3ee1 29/47: Use setq-local, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 30e523aa68 05/47: Don't mention Marmalade, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 012e753485 14/47: README: Fix language keyword, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 230302d875 22/47: Update authors, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode ad1254a3de 27/47: Add scad-preview-view, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode ec9bf4c643 30/47: Larger preview image, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 61f306462a 36/47: Version 93.0, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 268a8c46d6 38/47: Remove scad-indent-style, instead configure c-default-style, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode ace55270fd 40/47: Add flymake support,
ELPA Syncer <=
- [nongnu] elpa/scad-mode 900ca6fc25 41/47: Update README, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode efc5f1cf14 46/47: Update status if original buffer is dead, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode aa2e76a29b 23/47: Rename mode back, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 1cdc9f304f 26/47: README: Update badges, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 28879e735c 33/47: Update status if preview is stale, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode b0d138e9ec 43/47: Print warning if the scad-preview package is installed, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode e5ed92217e 10/47: Cleanup mode map, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 311797dc44 15/47: Commentary: Remove old todos, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 2c9124f718 16/47: Remove some publicly exposed variables, ELPA Syncer, 2022/11/12
- [nongnu] elpa/scad-mode 9bfaed13bc 25/47: Add support for Org babel, ELPA Syncer, 2022/11/12