From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark Oteiza Newsgroups: gmane.emacs.devel Subject: [PATCH] latex-mode flymake backend Date: Wed, 11 Oct 2017 09:39:14 -0400 Message-ID: <20171011133914.c2kvlqip6cyiudfp@logos.localdomain> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1507729170 10498 195.159.176.226 (11 Oct 2017 13:39:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 11 Oct 2017 13:39:30 +0000 (UTC) User-Agent: NeoMutt/20170912-97-b97206-dirty Cc: Stefan Monnier , =?iso-8859-1?Q?Jo=E3o_T=E1vora?= To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 11 15:39:26 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2HEJ-00021t-G6 for ged-emacs-devel@m.gmane.org; Wed, 11 Oct 2017 15:39:23 +0200 Original-Received: from localhost ([::1]:41117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2HEQ-0006GS-Qg for ged-emacs-devel@m.gmane.org; Wed, 11 Oct 2017 09:39:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2HEJ-0006Fw-Pl for emacs-devel@gnu.org; Wed, 11 Oct 2017 09:39:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2HEF-0004DK-QM for emacs-devel@gnu.org; Wed, 11 Oct 2017 09:39:23 -0400 Original-Received: from mail-qt0-x22d.google.com ([2607:f8b0:400d:c0d::22d]:44945) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e2HEF-0004D9-K5 for emacs-devel@gnu.org; Wed, 11 Oct 2017 09:39:19 -0400 Original-Received: by mail-qt0-x22d.google.com with SMTP id 8so5215361qtv.1 for ; Wed, 11 Oct 2017 06:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=udel-edu.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=e5qTitIoJ/Lr3l69aQbseM0CFsgettHhZaqctLwq1H0=; b=mc2U1D17wmSWLvuTTqytxDAifFwZVdwpeHVTfA2XxcjXWy+23cgVt+mRs/U12bX9Oo HERVDsiRjJ8G+jjc68GjH1NeVrLFKVVc8SSm9HYn7gMPKsYW9RDWrvd8tTVBdoaai4FJ YYa/mIi172VETZFx/80MHburkfArSeUJfx3diNZ7149LR5uoKWlWqSQBberO1QcV5wyX 6vyI2jLcYi8sfw6oII+JXatUDkEmZ1uQZru5veiK9RW4fe46VYDvD1Io/o5DhFK2j3n9 7AzRgkwoO3cesSSBJe5VqBOJqVOm1liALJNvOOT6YNfjJUC0wNKHAg801MIItKQkXKBn 9KfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=e5qTitIoJ/Lr3l69aQbseM0CFsgettHhZaqctLwq1H0=; b=nVCNVIYPJOxKNvPNtlxGjVIa7AaR++2/zBa1EiE97DJaO5pX6xvTWKAyyW6X09GZhr JG45khHwE06foBJHUQEdepobDj+AHTfoRYeuBVjT7WjtUiC3LvfKEbyy+1w5mtTfMA87 7L6eCXc2yEGlpriRTSneKYHHic/ruFwRzuBF8zDqZrKt2OnqfAe3k8ahpS/iPw+t7hSm oM14Bv7b1kmhXaFBIcRoPlcoKgmjV2A3sTbGIhf8tQe6agGGXd8P6bDouZIgFb453qJq ChUfvSbOMTiW5ATwdvK0/4/dUABcu7BbakX8pK+nGjo31zyv6pQAIQRlFTD1moadEc/I FErQ== X-Gm-Message-State: AMCzsaXOPlUXjhsBugG5MjOSzTuww5trBFmYcPRZl2adLbJfitX/8uQQ kjhB9vIN4D33ztxV35bwbYdsE5lqqg9rhw== X-Google-Smtp-Source: AOwi7QBk83+5cGs9VO4to700oqeLiSFSJZnun3FOC3glsfeFPbMW0h4XLAzxxVD1AWXnPMD0vjteTw== X-Received: by 10.55.5.144 with SMTP id 138mr18586856qkf.319.1507729155921; Wed, 11 Oct 2017 06:39:15 -0700 (PDT) Original-Received: from logos.localdomain (pool-173-67-36-61.bltmmd.fios.verizon.net. [173.67.36.61]) by smtp.gmail.com with ESMTPSA id x65sm7790803qke.60.2017.10.11.06.39.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Oct 2017 06:39:14 -0700 (PDT) Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::22d X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:219375 Archived-At: Hi, Here is a patch for a flymake backend using chktex. diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index 948743e8e5..5e778ec526 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -55,6 +55,11 @@ tex-view :prefix "tex-" :group 'tex) +(defgroup tex-flymake nil + "Flymake backend for linting TeX files." + :prefix "tex-" + :group 'tex) + ;;;###autoload (defcustom tex-shell-file-name nil "If non-nil, the shell file name to run in the subshell used to run TeX." @@ -259,6 +264,17 @@ tex-font-script-display (float :tag "Superscript")) :version "23.1") +(defcustom tex-chktex-program "chktex" + "ChkTeX executable to use for linting TeX files." + :type 'string + :link '(url-link "man:chktex(1)") + :group 'tex-flymake) + +(defcustom tex-chktex-extra-flags nil + "Extra command line flags for `tex-chktex-program'." + :type '(repeat string) + :group 'tex-flymake) + (defvar tex-last-temp-file nil "Latest temporary file generated by \\[tex-region] and \\[tex-buffer]. Deleted when the \\[tex-region] or \\[tex-buffer] is next run, or when the @@ -1154,6 +1170,7 @@ latex-mode (setq-local fill-indent-according-to-mode t) (add-hook 'completion-at-point-functions #'latex-complete-data nil 'local) + (add-hook 'flymake-diagnostic-functions 'tex-chktex nil t) (setq-local outline-regexp latex-outline-regexp) (setq-local outline-level #'latex-outline-level) (setq-local forward-sexp-function #'latex-forward-sexp) @@ -3465,6 +3482,52 @@ tex--prettify-symbols-compose-p ;; Don't compose inside verbatim blocks. (eq 2 (nth 7 (syntax-ppss)))))))) + +;;; Flymake support + +(defvar-local tex-chktex--process nil) + +(defun tex-chktex-command () + "Return a list of command arguments for invoking ChkTeX." + `(,tex-chktex-program ,@tex-chktex-extra-flags + "--quiet" "--verbosity=0" "--inputfiles")) + +(defun tex-chktex (report-fn &rest _args) + "Flymake backend for linting TeX buffers with ChkTeX." + (unless (executable-find tex-chktex-program) + (error "Cannot find a suitable TeX checker")) + (when (process-live-p tex-chktex--process) + (kill-process tex-chktex--process)) + (let ((source (current-buffer))) + (save-restriction + (widen) + (setq tex-chktex--process + (make-process + :name "tex-chktex" + :buffer (generate-new-buffer "*tex-chktex*") + :command (tex-chktex-command) + :noquery t :connection-type 'pipe + :sentinel + (lambda (process _event) + (unwind-protect + (when (eq process tex-chktex--process) + (with-current-buffer (process-buffer process) + (goto-char (point-min)) + (cl-loop + while (search-forward-regexp + "^stdin:\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\):\\(.*\\)$" + nil t) + for msg = (match-string 4) + for (beg . end) = (flymake-diag-region source + (string-to-number (match-string 1)) + (string-to-number (match-string 2))) + collect (flymake-make-diagnostic source beg end :warning msg) + into diags + finally (funcall report-fn diags)))) + (kill-buffer (process-buffer process)))))) + (process-send-region tex-chktex--process (point-min) (point-max)) + (process-send-eof tex-chktex--process)))) + (run-hooks 'tex-mode-load-hook) (provide 'tex-mode)