Function: flymake-proc--diagnostics-for-pattern

flymake-proc--diagnostics-for-pattern is a byte-compiled function defined in flymake-proc.el.gz.

Signature

(flymake-proc--diagnostics-for-pattern PROC PATTERN)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/flymake-proc.el.gz
(defun flymake-proc--diagnostics-for-pattern (proc pattern)
  (cl-flet ((guess-type
             (pred message)
             (cond ((null message)
                    :error)
                   ((stringp pred)
                    (if (string-match pred message)
                        :warning
                      :error))
                   ((functionp pred)
                    (let ((probe (funcall pred message)))
                      (cond ((and (symbolp probe)
                                  (get probe 'flymake-category))
                             probe)
                            (probe
                             :warning)
                            (t
                             :error)))))))
    (condition-case-unless-debug err
        (cl-loop
         with (regexp file-idx line-idx col-idx message-idx) = pattern
         while (and
                (search-forward-regexp regexp nil t)
                ;; If the preceding search spanned more than one line,
                ;; move to the start of the line we ended up in. This
                ;; preserves the usefulness of the patterns in
                ;; `flymake-proc-err-line-patterns', which were
                ;; written primarily for flymake's original
                ;; line-by-line parsing and thus never spanned
                ;; multiple lines.
                (if (/= (line-number-at-pos (match-beginning 0))
                        (line-number-at-pos))
                    (goto-char (line-beginning-position))
                  t))
         for fname = (and file-idx (match-string file-idx))
         for message = (and message-idx (match-string message-idx))
         for line-string = (and line-idx (match-string line-idx))
         for line-number = (or (and line-string
                                    (string-to-number line-string))
                               1)
         for col-string = (and col-idx (match-string col-idx))
         for col-number = (and col-string
                               (string-to-number col-string))
         for full-file = (with-current-buffer (process-buffer proc)
                           (and fname
                                (funcall
                                 (flymake-proc--get-real-file-name-function
                                  fname)
                                 fname)))
         for buffer = (and full-file
                           (find-buffer-visiting full-file))
         if (and (eq buffer (process-buffer proc)) message)
         collect (pcase-let ((`(,beg . ,end)
                              (flymake-diag-region buffer line-number col-number)))
                   (flymake-make-diagnostic
                    buffer beg end
                    (with-current-buffer buffer
                      (guess-type flymake-proc-diagnostic-type-pred message))
                    message))
         else
         do (flymake-log 2 "Reference to file %s is out of scope" fname))
      (error
       (flymake-log 1 "Error parsing process output for pattern %s: %s"
                    pattern err)
       nil))))