]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/ada-mode/gpr-query.el
release ada-mode 5.1.7, wisi 1.1.0; minor format changes in ada-ref-man (take 2)
[gnu-emacs-elpa] / packages / ada-mode / gpr-query.el
old mode 100755 (executable)
new mode 100644 (file)
index 71761c3..be03ca8
@@ -1,6 +1,5 @@
 ;;; gpr-query.el --- minor-mode for navigating sources using the
-;;; custom gpr_query tool, based on AdaCore cross reference tool
-;;; gnatinspect.
+;;; custom gpr_query tool.
 ;;;
 ;;; gpr-query supports Ada and any gcc language that supports the
 ;;; AdaCore -fdump-xref switch (which includes C, C++).
@@ -47,9 +46,7 @@
 
 (cl-defstruct (gpr-query--session)
   (process nil) ;; running gpr_query
-  (buffer nil)  ;; receives output of gpr_query
-  (sent-kill-p nil)
-  (closed-p nil))
+  (buffer nil)) ;; receives output of gpr_query
 
 (defconst gpr-query-buffer-name-prefix " *gpr_query-")
 
@@ -162,6 +159,14 @@ Return buffer that holds output."
       (current-buffer)
       )))
 
+(defun gpr-query-kill-session (session)
+  (let ((process (gpr-query--session-process session)))
+    (when (process-live-p process)
+      (process-send-string (gpr-query--session-process session) "exit\n")
+      (while (process-live-p process)
+       (accept-process-output process 1.0)))
+    ))
+
 (defun gpr-query-kill-all-sessions ()
   (interactive)
   (let ((count 0))
@@ -190,9 +195,9 @@ Uses 'gpr_query'. Returns new list."
     (gpr-query-session-send "source_dirs" t)
     (goto-char (point-min))
     (while (not (looking-at gpr-query-prompt))
-      (add-to-list 'src-dirs
-                  (directory-file-name
-                   (buffer-substring-no-properties (point) (point-at-eol))))
+      (cl-pushnew (directory-file-name
+                   (buffer-substring-no-properties (point) (point-at-eol)))
+                  src-dirs :test #'equal)
       (forward-line 1))
     )
   src-dirs)
@@ -205,9 +210,9 @@ Uses 'gpr_query'. Returns new list."
     (gpr-query-session-send "project_path" t)
     (goto-char (point-min))
     (while (not (looking-at gpr-query-prompt))
-      (add-to-list 'prj-dirs
-                  (directory-file-name
-                   (buffer-substring-no-properties (point) (point-at-eol))))
+      (cl-pushnew (directory-file-name
+                   (buffer-substring-no-properties (point) (point-at-eol)))
+                  prj-dirs :test #'equal)
       (forward-line 1))
     )
   prj-dirs)
@@ -247,8 +252,13 @@ set compilation-mode with compilation-error-regexp-alist set to COMP-ERR."
       (gpr-query-session-send cmd-1 t)
       ;; point is at EOB. gpr_query returns one line per result plus prompt
       (setq result-count (- (line-number-at-pos) 1))
-      (font-lock-fontify-buffer)
+      ;; Won't be needed in 24.5 any more.
+      (if (fboundp 'font-lock-ensure)
+          (font-lock-ensure)
+        (font-lock-fontify-buffer))
       ;; font-lock-fontify-buffer applies compilation-message text properties
+      ;; FIXME: Won't be needed in 24.5 any more, since compilation-next-error
+      ;; will apply compilation-message text properties on the fly.
       ;; IMPROVEME: for some reason, next-error works, but the font
       ;; colors are not right (no koolaid!)
       (goto-char (point-min))
@@ -263,6 +273,7 @@ set compilation-mode with compilation-error-regexp-alist set to COMP-ERR."
         ;; just go there, don't display session-buffer. We have to
         ;; fetch the compilation-message while in the session-buffer.
         (let* ((msg (compilation-next-error 0 nil (point-min)))
+                ;; FIXME: '--' indicates internal-only; use compile-goto-error
                (loc (compilation--message->loc msg)))
           (setq file (caar (compilation--loc->file-struct loc))
                 line (caar (cddr (compilation--loc->file-struct loc)))
@@ -364,7 +375,7 @@ buffer in another window."
     ;; FIXME: (define-key map "\C-c\M-d" 'gpr-query-parents)
     ;; FIXME: overriding
     map
-  )  "Local keymap used for GNAT inspect minor mode.")
+  )  "Local keymap used for gpr query minor mode.")
 
 (defvar gpr-query-menu (make-sparse-keymap "gpr-query"))
 (easy-menu-define gpr-query-menu gpr-query-map "Menu keymap for gpr-query minor mode"
@@ -397,7 +408,10 @@ Enable mode if ARG is positive"
 (defun gpr-query-refresh ()
   "For `ada-xref-refresh-function', using gpr_query."
   (interactive)
-  (with-current-buffer (gpr-query-session-send "refresh" t)))
+  ;; need to kill session to get changed env vars etc
+  (let ((session (gpr-query-cached-session)))
+    (gpr-query-kill-session session)
+    (gpr-query--start-process session)))
 
 (defun gpr-query-other (identifier file line col)
   "For `ada-xref-other-function', using gpr_query."
@@ -407,6 +421,11 @@ Enable mode if ARG is positive"
     (setq identifier (substring identifier 1 (1- (length identifier))))
     )
 
+  (when (eq system-type 'windows-nt)
+    ;; Since Windows file system is case insensitive, GNAT and Emacs
+    ;; can disagree on the case, so convert all to lowercase.
+    (setq file (downcase file)))
+
   (let ((cmd (format "refs %s:%s:%d:%d" identifier (file-name-nondirectory file) line col))
        (decl-loc nil)
        (body-loc nil)
@@ -445,14 +464,20 @@ Enable mode if ARG is positive"
        (cond
         ((looking-at gpr-query-ident-file-type-regexp)
          ;; process line
-         ;; 'expand-file-name' converts Windows directory separators to normal Emacs
-         (let* ((found-file (expand-file-name (match-string 1)))
+         (let* ((found-file (match-string 1))
                 (found-line (string-to-number (match-string 2)))
                 (found-col  (string-to-number (match-string 3)))
                 (found-type (match-string 4))
                 (dist       (gpr-query-dist found-line line found-col col))
                 )
 
+           (when (eq system-type 'windows-nt)
+             ;; 'expand-file-name' converts Windows directory
+             ;; separators to normal Emacs.  Since Windows file
+             ;; system is case insensitive, GNAT and Emacs can
+             ;; disagree on the case, so convert all to lowercase.
+             (setq found-file (downcase (expand-file-name found-file))))
+
            (when (string-equal found-type "declaration")
              (setq decl-loc (list found-file found-line (1- found-col))))
 
@@ -550,7 +575,6 @@ Enable mode if ARG is positive"
   (setq ada-make-package-body       'ada-gnat-make-package-body)
 
   (add-hook 'ada-syntax-propertize-hook 'gnatprep-syntax-propertize)
-  (add-hook 'ada-syntax-propertize-hook 'ada-gnat-syntax-propertize)
 
   ;; must be after indentation engine setup, because that resets the
   ;; indent function list.
@@ -574,7 +598,6 @@ Enable mode if ARG is positive"
   (setq ada-make-package-body       nil)
 
   (setq ada-syntax-propertize-hook (delq 'gnatprep-syntax-propertize ada-syntax-propertize-hook))
-  (setq ada-syntax-propertize-hook (delq 'ada-gnat-syntax-propertize ada-syntax-propertize-hook))
   (setq ada-mode-hook (delq 'ada-gpr-query-setup ada-mode-hook))
 
   (setq ada-xref-other-function      nil)
@@ -602,7 +625,7 @@ Enable mode if ARG is positive"
 
   (font-lock-add-keywords 'ada-mode
    ;; gnatprep preprocessor line
-   (list (list "^[ \t]*\\(#.*\n\\)"  '(1 font-lock-type-face t))))
+   (list (list "^[ \t]*\\(#.*\n\\)"  '(1 font-lock-preprocessor-face t))))
   )
 
 (provide 'gpr-query)