Function: flymake-proc--check-patch-master-file-buffer

flymake-proc--check-patch-master-file-buffer is a byte-compiled function defined in flymake-proc.el.gz.

Signature

(flymake-proc--check-patch-master-file-buffer MASTER-FILE-TEMP-BUFFER MASTER-FILE-NAME PATCHED-MASTER-FILE-NAME SOURCE-FILE-NAME PATCHED-SOURCE-FILE-NAME INCLUDE-DIRS REGEXP)

Documentation

Check if MASTER-FILE-NAME is a master file for SOURCE-FILE-NAME.

If yes, patch a copy of MASTER-FILE-NAME to include PATCHED-SOURCE-FILE-NAME instead of SOURCE-FILE-NAME.

For example, foo.cpp is a master file if it includes foo.h.

When a buffer for MASTER-FILE-NAME exists, use it as a source instead of reading master file from disk.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/flymake-proc.el.gz
(defun flymake-proc--check-patch-master-file-buffer
    (master-file-temp-buffer
     master-file-name patched-master-file-name
     source-file-name patched-source-file-name
     include-dirs regexp)
  "Check if MASTER-FILE-NAME is a master file for SOURCE-FILE-NAME.
If yes, patch a copy of MASTER-FILE-NAME to include PATCHED-SOURCE-FILE-NAME
instead of SOURCE-FILE-NAME.

For example, foo.cpp is a master file if it includes foo.h.

When a buffer for MASTER-FILE-NAME exists, use it as a source
instead of reading master file from disk."
  (let* ((source-file-nondir (file-name-nondirectory source-file-name))
         (source-file-extension (file-name-extension source-file-nondir))
         (source-file-nonext (file-name-sans-extension source-file-nondir))
         (found                     nil)
	 (inc-name                  nil)
	 (search-limit              flymake-proc-check-file-limit))
    (setq regexp
          (format regexp	; "[ \t]*#[ \t]*include[ \t]*\"\\(.*%s\\)\""
                  ;; Hack for tex files, where \include often excludes .tex.
                  ;; Maybe this is safe generally.
                  (if (and (> (length source-file-extension) 1)
                           (string-equal source-file-extension "tex"))
                      (format "%s\\(?:\\.%s\\)?"
                              (regexp-quote source-file-nonext)
                              (regexp-quote source-file-extension))
                    (regexp-quote source-file-nondir))))
    (unwind-protect
        (with-current-buffer master-file-temp-buffer
          (if (or (not search-limit)
                  (> search-limit (point-max)))
              (setq search-limit (point-max)))
          (flymake-log 3 "checking %s against regexp %s"
                       master-file-name regexp)
          (goto-char (point-min))
          (while (and (< (point) search-limit)
                      (re-search-forward regexp search-limit t))
            (let ((match-beg   (match-beginning 1))
                  (match-end   (match-end 1)))

              (flymake-log 3 "found possible match for %s" source-file-nondir)
              (setq inc-name (match-string 1))
              (and (> (length source-file-extension) 1)
                   (string-equal source-file-extension "tex")
                   (not (string-match (format "\\.%s\\'" source-file-extension)
                                      inc-name))
                   (setq inc-name (concat inc-name "." source-file-extension)))
              (when (eq t (compare-strings
                           source-file-nondir nil nil
                           inc-name (- (length inc-name)
                                       (length source-file-nondir)) nil))
                (flymake-log 3 "inc-name=%s" inc-name)
                (when (flymake-proc--check-include source-file-name inc-name
                                                   include-dirs)
                  (setq found t)
                  ;;  replace-match is not used here as it fails in
                  ;; XEmacs with 'last match not a buffer' error as
                  ;; check-includes calls replace-in-string
                  (flymake-proc--replace-region
                   match-beg match-end
                   (file-name-nondirectory patched-source-file-name))))
              (forward-line 1)))
          (when found
            (flymake-proc--save-buffer-in-file patched-master-file-name)))
      ;;+(flymake-log 3 "killing buffer %s"
      ;;                (buffer-name master-file-temp-buffer))
      (kill-buffer master-file-temp-buffer))
    ;;+(flymake-log 3 "check-patch master file %s: %s" master-file-name found)
    (when found
      (flymake-log 2 "found master file %s" master-file-name))
    found))