aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2017-10-06 17:51:40 +0100
committerJoão Távora2017-10-06 18:12:58 +0100
commitfa92f0c44715fc49e19de001ee8b217ce847d954 (patch)
treed2d97fb13119402c3a566643733c3f0f8f0e1e1e
parent0d0265bf50e190c77e6a06fd677c0114cb8356a6 (diff)
downloademacs-fa92f0c44715fc49e19de001ee8b217ce847d954.tar.gz
emacs-fa92f0c44715fc49e19de001ee8b217ce847d954.zip
Cleanup emacs-lisp-mode's use of Flymake
* lisp/progmodes/elisp-mode.el (elisp-flymake--checkdoc-1): Delete. (elisp-flymake-checkdoc): Incorporate old elisp-flymake--checkdoc-1. (elisp-flymake--byte-compile-done): Simplify. Don't cleanup here. (elisp-flymake-byte-compile): Remove spurious interactive spec. Simplify. Cleanup on every possible exit.
-rw-r--r--lisp/progmodes/elisp-mode.el120
1 files changed, 54 insertions, 66 deletions
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 3690f673832..99a4841e318 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -1599,8 +1599,11 @@ ARGLIST is either a string, or a list of strings or symbols."
1599(defvar checkdoc-autofix-flag) 1599(defvar checkdoc-autofix-flag)
1600(defvar checkdoc-generate-compile-warnings-flag) 1600(defvar checkdoc-generate-compile-warnings-flag)
1601(defvar checkdoc-diagnostic-buffer) 1601(defvar checkdoc-diagnostic-buffer)
1602(defun elisp-flymake--checkdoc-1 () 1602
1603 "Do actual work for `elisp-flymake-checkdoc'." 1603;;;###autoload
1604(defun elisp-flymake-checkdoc (report-fn &rest _args)
1605 "A Flymake backend for `checkdoc'.
1606Calls REPORT-FN directly."
1604 (let (collected) 1607 (let (collected)
1605 (let* ((checkdoc-create-error-function 1608 (let* ((checkdoc-create-error-function
1606 (lambda (text start end &optional unfixable) 1609 (lambda (text start end &optional unfixable)
@@ -1608,63 +1611,52 @@ ARGLIST is either a string, or a list of strings or symbols."
1608 nil)) 1611 nil))
1609 (checkdoc-autofix-flag nil) 1612 (checkdoc-autofix-flag nil)
1610 (checkdoc-generate-compile-warnings-flag nil) 1613 (checkdoc-generate-compile-warnings-flag nil)
1611 (buf (generate-new-buffer " *checkdoc-temp*")) 1614 (checkdoc-diagnostic-buffer
1612 (checkdoc-diagnostic-buffer buf)) 1615 (generate-new-buffer " *checkdoc-temp*")))
1613 (unwind-protect 1616 (unwind-protect
1614 (save-excursion 1617 (save-excursion
1615 (checkdoc-current-buffer t)) 1618 (checkdoc-current-buffer t))
1616 (kill-buffer buf))) 1619 (kill-buffer checkdoc-diagnostic-buffer)))
1620 (funcall report-fn
1621 (cl-loop for (text start end _unfixable) in
1622 collected
1623 collect
1624 (flymake-make-diagnostic
1625 (current-buffer)
1626 start end :note text)))
1617 collected)) 1627 collected))
1618 1628
1619;;;###autoload
1620(defun elisp-flymake-checkdoc (report-fn &rest _args)
1621 "A Flymake backend for `checkdoc'.
1622Calls REPORT-FN directly."
1623 (unless (derived-mode-p 'emacs-lisp-mode)
1624 (error "Can only work on `emacs-lisp-mode' buffers"))
1625 (funcall report-fn
1626 (cl-loop for (text start end _unfixable) in
1627 (elisp-flymake--checkdoc-1)
1628 collect
1629 (flymake-make-diagnostic
1630 (current-buffer)
1631 start end :note text))))
1632
1633(defun elisp-flymake--byte-compile-done (report-fn 1629(defun elisp-flymake--byte-compile-done (report-fn
1634 origin-buffer 1630 source-buffer
1635 output-buffer 1631 output-buffer)
1636 temp-file) 1632 (with-current-buffer
1637 (unwind-protect 1633 source-buffer
1638 (with-current-buffer 1634 (save-excursion
1639 origin-buffer 1635 (save-restriction
1640 (save-excursion 1636 (widen)
1641 (save-restriction 1637 (funcall
1642 (widen) 1638 report-fn
1643 (funcall 1639 (cl-loop with data =
1644 report-fn 1640 (with-current-buffer output-buffer
1645 (cl-loop with data = 1641 (goto-char (point-min))
1646 (with-current-buffer output-buffer 1642 (search-forward ":elisp-flymake-output-start")
1647 (goto-char (point-min)) 1643 (read (point-marker)))
1648 (search-forward ":elisp-flymake-output-start") 1644 for (string pos _fill level) in data
1649 (read (point-marker))) 1645 do (goto-char pos)
1650 for (string pos _fill level) in data 1646 for beg = (if (< (point) (point-max))
1651 do (goto-char pos) 1647 (point)
1652 for beg = (if (< (point) (point-max)) 1648 (line-beginning-position))
1653 (point) 1649 for end = (min
1654 (line-beginning-position)) 1650 (line-end-position)
1655 for end = (min 1651 (or (cdr
1656 (line-end-position) 1652 (bounds-of-thing-at-point 'sexp))
1657 (or (cdr 1653 (point-max)))
1658 (bounds-of-thing-at-point 'sexp)) 1654 collect (flymake-make-diagnostic
1659 (point-max))) 1655 (current-buffer)
1660 collect (flymake-make-diagnostic 1656 (if (= beg end) (1- beg) beg)
1661 (current-buffer) 1657 end
1662 (if (= beg end) (1- beg) beg) 1658 level
1663 end 1659 string)))))))
1664 level
1665 string))))))
1666 (kill-buffer output-buffer)
1667 (ignore-errors (delete-file temp-file))))
1668 1660
1669(defvar-local elisp-flymake--byte-compile-process nil 1661(defvar-local elisp-flymake--byte-compile-process nil
1670 "Buffer-local process started for byte-compiling the buffer.") 1662 "Buffer-local process started for byte-compiling the buffer.")
@@ -1674,16 +1666,11 @@ Calls REPORT-FN directly."
1674 "A Flymake backend for elisp byte compilation. 1666 "A Flymake backend for elisp byte compilation.
1675Spawn an Emacs process that byte-compiles a file representing the 1667Spawn an Emacs process that byte-compiles a file representing the
1676current buffer state and calls REPORT-FN when done." 1668current buffer state and calls REPORT-FN when done."
1677 (interactive (list (lambda (stuff)
1678 (message "aha %s" stuff))))
1679 (unless (derived-mode-p 'emacs-lisp-mode)
1680 (error "Can only work on `emacs-lisp-mode' buffers"))
1681 (when elisp-flymake--byte-compile-process 1669 (when elisp-flymake--byte-compile-process
1682 (process-put elisp-flymake--byte-compile-process 'elisp-flymake--obsolete t)
1683 (when (process-live-p elisp-flymake--byte-compile-process) 1670 (when (process-live-p elisp-flymake--byte-compile-process)
1684 (kill-process elisp-flymake--byte-compile-process))) 1671 (kill-process elisp-flymake--byte-compile-process)))
1685 (let ((temp-file (make-temp-file "elisp-flymake-byte-compile")) 1672 (let ((temp-file (make-temp-file "elisp-flymake-byte-compile"))
1686 (origin-buffer (current-buffer))) 1673 (source-buffer (current-buffer)))
1687 (save-restriction 1674 (save-restriction
1688 (widen) 1675 (widen)
1689 (write-region (point-min) (point-max) temp-file nil 'nomessage)) 1676 (write-region (point-min) (point-max) temp-file nil 'nomessage))
@@ -1703,21 +1690,22 @@ current buffer state and calls REPORT-FN when done."
1703 :connection-type 'pipe 1690 :connection-type 'pipe
1704 :sentinel 1691 :sentinel
1705 (lambda (proc _event) 1692 (lambda (proc _event)
1706 (unless (process-live-p proc) 1693 (when (eq (process-status proc) 'exit)
1707 (unwind-protect 1694 (unwind-protect
1708 (cond 1695 (cond
1696 ((not (eq proc elisp-flymake--byte-compile-process))
1697 (flymake-log :warning "byte-compile process %s obsolete" proc))
1709 ((zerop (process-exit-status proc)) 1698 ((zerop (process-exit-status proc))
1710 (elisp-flymake--byte-compile-done report-fn 1699 (elisp-flymake--byte-compile-done report-fn
1711 origin-buffer 1700 source-buffer
1712 output-buffer 1701 output-buffer))
1713 temp-file))
1714 ((process-get proc 'elisp-flymake--obsolete)
1715 (flymake-log :warning "byte-compile process %s obsolete" proc))
1716 (t 1702 (t
1717 (funcall report-fn 1703 (funcall report-fn
1718 :panic 1704 :panic
1719 :explanation 1705 :explanation
1720 (format "byte-compile process %s died" proc))))))))) 1706 (format "byte-compile process %s died" proc))))
1707 (ignore-errors (delete-file temp-file))
1708 (kill-buffer output-buffer))))))
1721 :stderr null-device 1709 :stderr null-device
1722 :noquery t))) 1710 :noquery t)))
1723 1711