]> git.eshelyaron.com Git - emacs.git/commitdiff
Clean up flymake-log calls
authorEshel Yaron <me@eshelyaron.com>
Thu, 3 Apr 2025 12:01:25 +0000 (14:01 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 3 Apr 2025 12:01:25 +0000 (14:01 +0200)
lisp/progmodes/elisp-mode.el
lisp/progmodes/lua-ts-mode.el
lisp/progmodes/perl-mode.el
lisp/progmodes/php-ts-mode.el
lisp/progmodes/ruby-mode.el
lisp/progmodes/rust-ts-mode.el
lisp/progmodes/sh-script.el
lisp/textmodes/mhtml-ts-mode.el
lisp/textmodes/texinfo.el

index 8e7a0293296fb82d94b20647e63b21b47b82174d..f3d8fc656b2df1cb23f184945cdf682e2678ce7a 100644 (file)
@@ -2371,9 +2371,7 @@ current buffer state and calls REPORT-FN when done."
                 (cond
                  ((not (and (buffer-live-p source-buffer)
                             (eq proc (with-current-buffer source-buffer
-                                       elisp-flymake--byte-compile-process))))
-                  (flymake-log :warning
-                               "byte-compile process %s obsolete" proc))
+                                       elisp-flymake--byte-compile-process)))))
                  ((zerop (process-exit-status proc))
                   (elisp-flymake--byte-compile-done report-fn
                                                     source-buffer
@@ -2683,5 +2681,85 @@ of TARGET."
         (end-of-file (nreverse all))
         (error (message "Encountered error while scanning %s: %S" buffer-file-name e) nil)))))
 
+(defun elisp-eval-1 (vars form)
+  (cond
+   ((consp form)
+    (let ((fun (car form)) (args (cdr form)) (evaluator nil))
+      (cond
+       ((not (listp args)) '(error . wrong-type-argument))
+       ((not (symbolp fun)) '(error . invalid-function))
+       ((setq evaluator (elisp-get-evaluator fun)) (apply evaluator vars args))
+       (t '(error . void-function)))))
+   ((and (symbolp form) (not (or (keywordp form) (booleanp form))))
+    (if-let ((val (alist-get form vars))) `(ok . ,val) '(error . void-variable)))
+   (t `(ok . ,form))))
+
+(defun elisp-eval-n (vars forms)
+  (catch 'ball
+    (while (cdr forms)
+      (let ((val (elisp-eval-1 vars (car forms))))
+        (if (eq (car val) 'ok) (setq forms (cdr forms))
+          (throw 'ball val))))
+    (elisp-eval-1 vars (car forms))))
+
+(defvar elisp-symbol-functions-alist nil)
+
+(defun elisp-get-evaluator (sym)
+  (or (get sym 'elisp-evaluator) (alist-get sym elisp-symbol-functions-alist)))
+
+(defmacro elisp-define-evaluator (fsym args &rest body)
+  (declare (indent defun))
+  (let ((analyzer (intern (concat "elisp--evaluate-" (symbol-name fsym)))))
+    `(progn
+       (defun ,analyzer ,args ,@body)
+       (put ',fsym 'elisp-evaluator #',analyzer))))
+
+(defmacro elisp-mark-function-as-safe (fsym)
+  (let ((analyzer (intern (concat "elisp--evaluate-" (symbol-name fsym)))))
+    `(progn
+       (defun ,analyzer (vars &rest args)
+         (elisp-eval-apply vars #',fsym args))
+       (put ',fsym 'elisp-evaluator #',analyzer))))
+
+(elisp-mark-function-as-safe cons)
+(elisp-mark-function-as-safe car)
+(elisp-mark-function-as-safe list)
+
+;; TODO: Look into unsafep.el.
+;; TODO: Trust `side-effect-free' property.
+
+(defmacro elisp-mark-macro-as-safe (msym)
+  (let ((analyzer (intern (concat "elisp--evaluate-" (symbol-name msym)))))
+    `(progn
+       (defun ,analyzer (vars &rest args)
+         (elisp-eval-expand vars ',msym args))
+       (put ',msym 'elisp-evaluator #',analyzer))))
+
+(elisp-mark-macro-as-safe ignore-errors)
+
+(defun elisp-eval-apply (vars fun args)
+  (catch 'ball
+    (let (vals)
+      (dolist (arg args)
+        (let ((val (elisp-eval-1 vars arg)))
+          (if (eq (car val) 'ok) (push (cdr val) vals)
+            (throw 'ball val))))
+      (condition-case e
+          `(ok . ,(apply fun vals))
+        (error `(error . ,(car-safe e)))))))
+
+(defun elisp-eval-expand (vars mac args)
+  (elisp-eval-1 vars (macroexpand-1 (cons mac args))))
+
+(elisp-define-evaluator progn (vars &rest body)
+  (elisp-eval-n vars body))
+
+(elisp-define-evaluator if (vars cond then &rest else)
+  (let ((cond-val (elisp-eval-1 vars cond)))
+    (if (not (eq (car cond-val) 'ok)) cond-val
+      (if (cdr cond-val)
+          (elisp-eval-1 vars then)
+        (elisp-eval-n vars else)))))
+
 (provide 'elisp-mode)
 ;;; elisp-mode.el ends here
index cec7eae879f812585f6685dfbe0f391f68e2a357..cac56ace749ed304afb520ae250585ea8f6f1e62 100644 (file)
@@ -532,8 +532,7 @@ Calls REPORT-FN directly."
                                  (push (flymake-make-diagnostic
                                         source beg end type msg)
                                        diags)))
-                             (funcall report-fn diags)))
-                       (flymake-log :warning "Canceling obsolete check %s" proc))
+                             (funcall report-fn diags))))
                    (kill-buffer (process-buffer proc)))))))
       (process-send-region lua-ts--flymake-process (point-min) (point-max))
       (process-send-eof lua-ts--flymake-process))))
index 79ca4f9d755f069e65abd4d8935c4a3ed60f4924..0c75ea8f4d7d275de69a277fe5e19669a1ac846f 100644 (file)
@@ -710,9 +710,7 @@ this command is analyzed for error and warning messages."
                                                         type
                                                         msg)
                        into diags
-                       finally (funcall report-fn diags)))
-                  (flymake-log :debug "Canceling obsolete check %s"
-                               proc))
+                       finally (funcall report-fn diags))))
               (kill-buffer (process-buffer proc)))))))
       (process-send-region perl--flymake-proc (point-min) (point-max))
       (process-send-eof perl--flymake-proc))))
index fb5cf46f9e5721d117d43d98cea0cbf3d44979df..a81db80f2a0df49a6dd06d3f6e15900a40aadf79 100644 (file)
@@ -298,8 +298,7 @@ Calls REPORT-FN directly."
                                  (push (flymake-make-diagnostic
                                         source beg end type msg)
                                        diags)))
-                             (funcall report-fn diags)))
-                       (flymake-log :warning "Canceling obsolete check %s" proc))
+                             (funcall report-fn diags))))
                    (kill-buffer (process-buffer proc)))))))
       (process-send-region php-ts-mode--flymake-process (point-min) (point-max))
       (process-send-eof php-ts-mode--flymake-process))))
index 3e56479ed51a88de5f9480fdc399c56f835da257..e9e1af0f2455eaf00f1c703e364d2d12bedc2a2a 100644 (file)
@@ -2552,9 +2552,7 @@ A slash character after any of these should begin a regexp."))
             (unwind-protect
                 (if (with-current-buffer source (eq proc ruby--flymake-proc))
                     (with-current-buffer (process-buffer proc)
-                      (funcall parser-fn proc source))
-                  (flymake-log :debug "Canceling obsolete check %s"
-                               proc))
+                      (funcall parser-fn proc source)))
               (kill-buffer (process-buffer proc)))))))
       (process-send-region ruby--flymake-proc (point-min) (point-max))
       (process-send-eof ruby--flymake-proc))))
@@ -2620,8 +2618,7 @@ the gem \"rubocop\".  When t, it is used unconditionally."
          (when (eq (process-exit-status proc) 127)
            ;; Not sure what to do in this case.  Maybe ideally we'd
            ;; switch back to ruby-flymake-simple.
-           (flymake-log :warning "RuboCop returned status 127: %s"
-                        (buffer-string)))
+           )
          (goto-char (point-min))
          (cl-loop
           while (search-forward-regexp
index ae2bc8ee78c8543893c42c080c11697a6d92f48d..f756ba0c2a19cdd4f64ddb35173eb5e8b7226c13 100644 (file)
@@ -499,9 +499,7 @@ See `prettify-symbols-compose-predicate'."
             (unwind-protect
                 (if (with-current-buffer source (eq proc rust-ts--flymake-proc))
                     (with-current-buffer (process-buffer proc)
-                      (funcall parser-fn proc source))
-                  (flymake-log :debug "Canceling obsolete check %s"
-                               proc))
+                      (funcall parser-fn proc source)))
               (kill-buffer (process-buffer proc)))))))
       (process-send-region rust-ts--flymake-proc (point-min) (point-max))
       (process-send-eof rust-ts--flymake-proc))))
index ab2e30dcee2209a7c59ce40a40d204372a610081..38306ed26e634053fa44caef81418e79b21471aa 100644 (file)
@@ -3274,9 +3274,8 @@ member of `flymake-diagnostic-functions'."
           (lambda (proc _event)
             (when (memq (process-status proc) '(exit signal))
               (unwind-protect
-                  (if (with-current-buffer source
-                        (not (eq proc sh--shellcheck-process)))
-                      (flymake-log :warning "Canceling obsolete check %s" proc)
+                  (when (with-current-buffer source
+                          (eq proc sh--shellcheck-process))
                     (with-current-buffer (process-buffer proc)
                       (goto-char (point-min))
                       (thread-last
index 22c0455a4ee82d449f7c42179c56bbbcb76bb901..0dc39069e1b0de76436f053e80c2eef1bb90e1ea 100644 (file)
@@ -442,8 +442,7 @@ Calls REPORT-FN directly.  Requires tidy."
                                         (msg (match-string 4))) ;; message
                                    (push (flymake-make-diagnostic source (car pos) (cdr pos) type msg)
                                          diags)))
-                               (funcall report-fn diags)))
-                         (flymake-log :warning "Canceling obsolete check %s" proc))
+                               (funcall report-fn diags))))
                      (kill-buffer (process-buffer proc)))))))
         (process-send-region mhtml-ts-mode--flymake-process (point-min) (point-max))
         (process-send-eof mhtml-ts-mode--flymake-process)))))
index 6f29397a5dcbf10393a76cf2bd7c6553acfa25cb..c15b06009a5007fdc2e8e3d53fe6569f00a4e3dc 100644 (file)
@@ -380,9 +380,7 @@ REPORT-FN is the callback function."
                             collect (flymake-make-diagnostic
                                      source beg end type msg)
                             into diags
-                            finally (funcall report-fn diags)))
-                       (flymake-log :warning "Canceling obsolete check %s"
-                                    proc))
+                            finally (funcall report-fn diags))))
                    (kill-buffer (process-buffer proc)))))))
       (process-send-region texinfo--flymake-proc (point-min) (point-max))
       (process-send-eof texinfo--flymake-proc))))