     (with-temp-buffer
       (setq default-directory (completing-read "Project: " projects-list))
       (let ((project (apm--find-project default-directory)))
-        (if project
-            (progn
-              (apm--apply-global-vars)
-              (let ((open-action (apm-project-open-action project)))
-                (if open-action
-                    (if (listp open-action)
-                        (eval open-action)
-                      (call-interactively open-action))
-                  (if ido-mode
-                      (ido-find-file)
-                    (call-interactively 'find-file))))))))))
+        (when project
+          (apm--apply-global-vars)
+          (let ((open-action (apm-project-open-action project)))
+            (if open-action
+                (if (listp open-action)
+                    (eval open-action)
+                  (call-interactively open-action))
+              (call-interactively 'find-file))))))))
 
 (defun apm--change-safe-local-variable-values (local-vars action)
   (let ((vars local-vars))


(defun apm-compile-close ()
  (interactive)
  (if (get-buffer "*compilation*")
      (progn
        (delete-windows-on (get-buffer "*compilation*"))
        (kill-buffer "*compilation*"))))

(defun apm--get-projects-path ()
  (let ((path '())

                      (dir-locals-set-class-variables (intern dir-var-name) local-vars)
                      (dir-locals-set-directory-class project-path (intern dir-var-name))
                      (apm--change-safe-local-variable-values local-vars 'cons))
                  (dir-locals-set-class-variables (intern dir-var-name) '())
                  (dir-locals-set-directory-class project-path (intern dir-var-name))
                  (apm--change-safe-local-variable-values local-vars 'delete)))))
          (setq projects (cdr projects)))
        (setq apm-project-local-vars-is-set isset))))

(defun apm--format-find-flags (name-or-path logic flag-list &optional set-not)
  (concat (if set-not "-not") " -" name-or-path " '" (car flag-list) "' "
          (let (flags)
            (setq flag-list (cdr flag-list))
            (dolist (element flag-list flags)
              (setq flags (concat flags (concat "-" logic " " (if set-not "-not") " -" name-or-path " '" element "' ")))))))

(defun apm--ignore-flags (&optional project)
  (let ((files apm-default-ignore-files)
        (dirs apm-default-ignore-dirs))
    (if (or files
            dirs
            (and project (apm-project-ignore-files project))
            (and project (apm-project-ignore-dirs project)))
        (concat
         " \\( "
         (apm--format-find-flags "name" "and" files t)
         (apm--format-find-flags "path" "and" dirs t)
         (when project
           (apm--format-find-flags "name" "and" (apm-project-ignore-files project) t)
           (apm--format-find-flags "path" "and" (apm-project-ignore-dirs project) t))
         "\\) ")
      " ")))

(defun apm--show-flags (&optional project)
  (if (or (and project (apm-project-project-files project))
          (and project (apm-project-project-dirs project)))
      (concat
       " \\( "
       (apm--format-find-flags "name" "or" (apm-project-project-files project))
       (apm--format-find-flags "path" "or" (apm-project-project-dirs project))
       "\\) ")
    " "))

(defun apm--get-project-files ()
  (let ((project (apm--find-project default-directory)))
    (when project
      (with-temp-buffer
        (setq default-directory (concat (apm-project-path project) "/"))
        (split-string (shell-command-to-string (concat "find . "
                                                       (apm--ignore-flags project)
                                                       (apm--show-flags project)
                                                       apm-find-args " "))
                        "\n" t)))))

(defun apm-find-file-in-project (&optional arg)
  (interactive "P")
  (if (not apm-replace-find-file)
      (call-interactively 'find-file)
    (let ((project (apm--find-project default-directory)))
      (if (and project (not arg))
          (with-temp-buffer
            (setq default-directory (concat (apm-project-path project) "/"))
            (find-file (completing-read "Find file: " (apm--get-project-files))))
        (call-interactively 'find-file)))))

(defun apm--apply-global-vars ()
  (let ((project (apm--find-project default-directory)))
    (when project
      (with-temp-buffer
        (setq default-directory (concat (apm-project-path project) "/"))
        (let ((global-vars (apm-project-global-vars project)))
          (while global-vars
            (eval (car global-vars))
            (setq global-vars (cdr global-vars))))))))

(defun apm-minor-mode-not-for-minibuffer ()
  (when (not (minibufferp (current-buffer)))
    (apm-minor-mode t)))

;;;###autoload
(define-minor-mode apm-minor-mode
