(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
(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
(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))))
(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