Function: prolog-consult-compile-filter

prolog-consult-compile-filter is a byte-compiled function defined in prolog.el.gz.

Signature

(prolog-consult-compile-filter PROCESS OUTPUT)

Documentation

Filter function for Prolog compilation PROCESS.

Argument OUTPUT is a name of the output file.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/prolog.el.gz
;; FIXME: This has been obsolete since Emacs-20!
;; (defun prolog-parse-sicstus-compilation-errors (limit)
;;   "Parse the prolog compilation buffer for errors.
;; Argument LIMIT is a buffer position limiting searching.
;; For use with the `compilation-parse-errors-function' variable."
;;   (setq compilation-error-list nil)
;;   (message "Parsing SICStus error messages...")
;;   (let (filepath dir file errorline)
;;     (while
;;         (re-search-backward
;;          "{\\([a-zA-Z ]* ERROR\\|Warning\\):.* in line[s ]*\\([0-9]+\\)"
;;          limit t)
;;       (setq errorline (string-to-number (match-string 2)))
;;       (save-excursion
;;         (re-search-backward
;;          "{\\(consulting\\|compiling\\|processing\\) \\(.*\\)\\.\\.\\.}"
;;          limit t)
;;         (setq filepath (match-string 2)))

;;       ;; ###### Does this work with SICStus under Windows
;;       ;; (i.e. backslashes and stuff?)
;;       (if (string-match "\\(.*/\\)\\([^/]*\\)$" filepath)
;;           (progn
;;             (setq dir (match-string 1 filepath))
;;             (setq file (match-string 2 filepath))))

;;       (setq compilation-error-list
;;             (cons
;;              (cons (save-excursion
;;                      (beginning-of-line)
;;                      (point-marker))
;;                    (list (list file dir) errorline))
;;              compilation-error-list)
;;             ))
;;     ))

(defun prolog-consult-compile-filter (process output)
  "Filter function for Prolog compilation PROCESS.
Argument OUTPUT is a name of the output file."
  ;;(message "start")
  (setq prolog-consult-compile-output
        (concat prolog-consult-compile-output output))
  ;;(message "pccf1: %s" prolog-consult-compile-output)
  ;; Iterate through the lines of prolog-consult-compile-output
  (let (outputtype)
    (while (and prolog-process-flag
                (or
                 ;; Trace question
                 (progn
                   (setq outputtype 'trace)
                   (and (eq prolog-system 'sicstus)
                        (string-match
                         "^[ \t]*[0-9]+[ \t]*[0-9]+[ \t]*Call:.*? "
                         prolog-consult-compile-output)))

                 ;; Match anything
                 (progn
                   (setq outputtype 'normal)
                   (string-match "^.*\n" prolog-consult-compile-output))
                   ))
      ;;(message "outputtype: %s" outputtype)

      (setq output (match-string 0 prolog-consult-compile-output))
      ;; remove the text in output from prolog-consult-compile-output
      (setq prolog-consult-compile-output
            (substring prolog-consult-compile-output (length output)))
      ;;(message "pccf2: %s" prolog-consult-compile-output)

      ;; If temporary files were used, then we change the error
      ;; messages to point to the original source file.
      ;; FIXME: Use compilation-fake-loc instead.
      (cond

       ;; If the prolog process was in trace mode then it requires
       ;; user input
       ((and (eq prolog-system 'sicstus)
             (eq outputtype 'trace))
        (let ((input (concat (read-string output) "\n")))
          (process-send-string process input)
          (setq output (concat output input))))

       ((eq prolog-system 'sicstus)
        (if (and prolog-consult-compile-real-file
                 (string-match
                  "\\({.*:.* in line[s ]*\\)\\([0-9]+\\)-\\([0-9]+\\)" output))
            (setq output (replace-match
                          ;; Adds a {processing ...} line so that
                          ;; `prolog-parse-sicstus-compilation-errors'
                          ;; finds the real file instead of the temporary one.
                          ;; Also fixes the line numbers.
                          (format "Added by Emacs: {processing %s...}\n%s%d-%d"
                                  prolog-consult-compile-real-file
                                  (match-string 1 output)
                                  (+ prolog-consult-compile-first-line
                                     (string-to-number
                                      (match-string 2 output)))
                                  (+ prolog-consult-compile-first-line
                                     (string-to-number
                                      (match-string 3 output))))
                          t t output)))
        )

       ((eq prolog-system 'swi)
        (if (and prolog-consult-compile-real-file
                 (string-match (format
                                "%s\\([ \t]*:[ \t]*\\)\\([0-9]+\\)"
                                prolog-consult-compile-file)
                               output))
            (setq output (replace-match
                          ;; Real filename + text + fixed linenum
                          (format "%s%s%d"
                                  prolog-consult-compile-real-file
                                  (match-string 1 output)
                                  (+ prolog-consult-compile-first-line
                                     (string-to-number
                                      (match-string 2 output))))
                          t t output)))
        )

       (t ())
       )
      ;; Write the output in the *prolog-compilation* buffer
      (insert output)))

  ;; If the prompt is visible, then the task is finished
  (if (string-match (prolog-prompt-regexp) prolog-consult-compile-output)
      (setq prolog-process-flag nil)))