aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2017-11-03 16:05:39 +0000
committerJoão Távora2017-11-05 12:53:56 +0000
commit58e742b21dcd15f5a00381de3e7179210978ddc9 (patch)
treea6359d9d9a9eab27bb75f9f0df67671576c22703
parent9dee764165f54bf93039b8301e0ef6dd143d6cf1 (diff)
downloademacs-58e742b21dcd15f5a00381de3e7179210978ddc9.tar.gz
emacs-58e742b21dcd15f5a00381de3e7179210978ddc9.zip
Add a Flymake backend for Perl
Define a simple backend in perl-mode.el, which cperl-mode.el also uses. * lisp/progmodes/cperl-mode.el (cperl-mode): Add to flymake-diagnostic-functions. * lisp/progmodes/flymake-proc.el (flymake-proc-allowed-file-name-masks): Disable legacy backend for perl files. * lisp/progmodes/perl-mode.el (perl-flymake-command): New defcustom. (perl--flymake-proc): New buffer-local variable. (perl-flymake): New function. (perl-mode): Add to flymake-diagnostic-functions.
-rw-r--r--lisp/progmodes/cperl-mode.el4
-rw-r--r--lisp/progmodes/flymake-proc.el2
-rw-r--r--lisp/progmodes/perl-mode.el71
3 files changed, 74 insertions, 3 deletions
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 853604d1d79..4c63ec2fb4e 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -1896,7 +1896,9 @@ or as help on variables `cperl-tips', `cperl-problems',
1896 (if cperl-pod-here-scan 1896 (if cperl-pod-here-scan
1897 (or cperl-syntaxify-by-font-lock 1897 (or cperl-syntaxify-by-font-lock
1898 (progn (or cperl-faces-init (cperl-init-faces-weak)) 1898 (progn (or cperl-faces-init (cperl-init-faces-weak))
1899 (cperl-find-pods-heres))))) 1899 (cperl-find-pods-heres))))
1900 ;; Setup Flymake
1901 (add-hook 'flymake-diagnostic-functions 'perl-flymake nil t))
1900 1902
1901;; Fix for perldb - make default reasonable 1903;; Fix for perldb - make default reasonable
1902(defun cperl-db () 1904(defun cperl-db ()
diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el
index 5c4d451d638..2e98b2afd1e 100644
--- a/lisp/progmodes/flymake-proc.el
+++ b/lisp/progmodes/flymake-proc.el
@@ -73,7 +73,7 @@
73 ("\\.xml\\'" flymake-proc-xml-init) 73 ("\\.xml\\'" flymake-proc-xml-init)
74 ("\\.html?\\'" flymake-proc-xml-init) 74 ("\\.html?\\'" flymake-proc-xml-init)
75 ("\\.cs\\'" flymake-proc-simple-make-init) 75 ("\\.cs\\'" flymake-proc-simple-make-init)
76 ("\\.p[ml]\\'" flymake-proc-perl-init) 76 ;; ("\\.p[ml]\\'" flymake-proc-perl-init)
77 ("\\.php[345]?\\'" flymake-proc-php-init) 77 ("\\.php[345]?\\'" flymake-proc-php-init)
78 ("\\.h\\'" flymake-proc-master-make-header-init flymake-proc-master-cleanup) 78 ("\\.h\\'" flymake-proc-master-make-header-init flymake-proc-master-cleanup)
79 ("\\.java\\'" flymake-proc-simple-make-java-init flymake-proc-simple-java-cleanup) 79 ("\\.java\\'" flymake-proc-simple-make-java-init flymake-proc-simple-java-cleanup)
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index 24b934ce6c2..8e7cd13088f 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -581,6 +581,73 @@ create a new comment."
581 (match-string-no-properties 1)))) 581 (match-string-no-properties 1))))
582 582
583 583
584;;; Flymake support
585(defcustom perl-flymake-command '("perl" "-w" "-c")
586 "External tool used to check Perl source code.
587This is a non empty list of strings, the checker tool possibly
588followed by required arguments. Once launched it will receive
589the Perl source to be checked as its standard input."
590 :group 'perl
591 :type '(repeat string))
592
593(defvar-local perl--flymake-proc nil)
594
595;;;###autoload
596(defun perl-flymake (report-fn &rest _args)
597 "Perl backend for Flymake. Launches
598`perl-flymake-command' (which see) and passes to its standard
599input the contents of the current buffer. The output of this
600command is analysed for error and warning messages."
601 (unless (executable-find (car perl-flymake-command))
602 (error "Cannot find a suitable checker"))
603
604 (when (process-live-p perl--flymake-proc)
605 (kill-process perl--flymake-proc))
606
607 (let ((source (current-buffer)))
608 (save-restriction
609 (widen)
610 (setq
611 perl--flymake-proc
612 (make-process
613 :name "perl-flymake" :noquery t :connection-type 'pipe
614 :buffer (generate-new-buffer " *perl-flymake*")
615 :command perl-flymake-command
616 :sentinel
617 (lambda (proc _event)
618 (when (eq 'exit (process-status proc))
619 (unwind-protect
620 (if (with-current-buffer source (eq proc perl--flymake-proc))
621 (with-current-buffer (process-buffer proc)
622 (goto-char (point-min))
623 (cl-loop
624 while (search-forward-regexp
625 "^\\(.+\\) at - line \\([0-9]+\\)"
626 nil t)
627 for msg = (match-string 1)
628 for (beg . end) = (flymake-diag-region
629 source
630 (string-to-number (match-string 2)))
631 for type =
632 (if (string-match
633 "\\(Scalar value\\|Useless use\\|Unquoted string\\)"
634 msg)
635 :warning
636 :error)
637 collect (flymake-make-diagnostic source
638 beg
639 end
640 type
641 msg)
642 into diags
643 finally (funcall report-fn diags)))
644 (flymake-log :debug "Canceling obsolete check %s"
645 proc))
646 (kill-buffer (process-buffer proc)))))))
647 (process-send-region perl--flymake-proc (point-min) (point-max))
648 (process-send-eof perl--flymake-proc))))
649
650
584(defvar perl-mode-hook nil 651(defvar perl-mode-hook nil
585 "Normal hook to run when entering Perl mode.") 652 "Normal hook to run when entering Perl mode.")
586 653
@@ -665,7 +732,9 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'."
665 ;; Setup outline-minor-mode. 732 ;; Setup outline-minor-mode.
666 (setq-local outline-regexp perl-outline-regexp) 733 (setq-local outline-regexp perl-outline-regexp)
667 (setq-local outline-level 'perl-outline-level) 734 (setq-local outline-level 'perl-outline-level)
668 (setq-local add-log-current-defun-function #'perl-current-defun-name)) 735 (setq-local add-log-current-defun-function #'perl-current-defun-name)
736 ;; Setup Flymake
737 (add-hook 'flymake-diagnostic-functions #'perl-flymake nil t))
669 738
670;; This is used by indent-for-comment 739;; This is used by indent-for-comment
671;; to decide how much to indent a comment in Perl code 740;; to decide how much to indent a comment in Perl code