Function: prolog-consult-compile

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

Signature

(prolog-consult-compile COMPILEP FILE &optional FIRST-LINE)

Documentation

Consult/compile FILE.

If COMPILEP is non-nil, perform compilation, otherwise perform CONSULTING. COMMAND is a string described by the variables prolog-consult-string(var)/prolog-consult-string(fun) and prolog-compile-string(var)/prolog-compile-string(fun). Optional argument FIRST-LINE is the number of the first line in the compiled region.

This function must be called from the source code buffer.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/prolog.el.gz
(defun prolog-consult-compile (compilep file &optional first-line)
  "Consult/compile FILE.
If COMPILEP is non-nil, perform compilation, otherwise perform CONSULTING.
COMMAND is a string described by the variables `prolog-consult-string'
and `prolog-compile-string'.
Optional argument FIRST-LINE is the number of the first line in the compiled
region.

This function must be called from the source code buffer."
  (if prolog-process-flag
      (error "Another Prolog task is running"))
  (prolog-ensure-process t)
  (let* ((buffer (get-buffer-create prolog-compilation-buffer))
         (real-file buffer-file-name)
         (command-string (prolog-build-prolog-command compilep file
                                                      real-file first-line))
         (process (get-process "prolog")))
    (with-current-buffer buffer
      (delete-region (point-min) (point-max))
      ;; FIXME: Wasn't this supposed to use prolog-inferior-mode?
      (compilation-mode)
      ;; FIXME: This doesn't seem to cooperate well with new(ish) compile.el.
      ;; Setting up font-locking for this buffer
      (setq-local font-lock-defaults
                  '(prolog-font-lock-keywords nil nil ((?_ . "w"))))
      ;; (if (eq prolog-system 'sicstus)
      ;;     ;; FIXME: This looks really problematic: not only is this using
      ;;     ;; the old compilation-parse-errors-function, but
      ;;     ;; prolog-parse-sicstus-compilation-errors only accepts one
      ;;     ;; argument whereas compile.el calls it with 2 (and did so at
      ;;     ;; least since Emacs-20).
      ;;     (setq-local compilation-parse-errors-function
      ;;                 #'prolog-parse-sicstus-compilation-errors))
      (setq buffer-read-only nil)
      (insert command-string "\n"))
    (display-buffer buffer)
    (setq prolog-process-flag t
          prolog-consult-compile-output ""
          prolog-consult-compile-first-line (if first-line (1- first-line) 0)
          prolog-consult-compile-file file
          prolog-consult-compile-real-file (if (string=
                                                file buffer-file-name)
                                               nil
                                             real-file))
    (with-current-buffer buffer
      (goto-char (point-max))
      (add-function :override (process-filter process)
                    #'prolog-consult-compile-filter)
      (process-send-string "prolog" command-string)
      ;; (prolog-build-prolog-command compilep file real-file first-line))
      (while (and prolog-process-flag
                  (accept-process-output process 10)) ; 10 secs is ok?
        (sit-for 0.1)
        (unless (get-process "prolog")
          (setq prolog-process-flag nil)))
      (insert (if compilep
                  "\nCompilation finished.\n"
                "\nConsulted.\n"))
      (remove-function (process-filter process)
                       #'prolog-consult-compile-filter))))