ada-mode-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Ada-mode-users] [patch] ada-goto-declaration when point is on an operat


From: Ludovic Brenta
Subject: [Ada-mode-users] [patch] ada-goto-declaration when point is on an operator
Date: Tue, 08 Nov 2016 18:47:42 +0200
User-agent: Roundcube Webmail/0.5.3

Hello,

Consider the following line:

    Set_Model (Tree.View, +Tree.Store); -- line 3775

ada-goto-declaration has two bugs which this patch corrects.

First, if point is inside the second occurrence of "Tree",
ada-identifier-at-point skips backward until point is on the + and
then it returns the string "+".  With my patch,
ada-identifier-at-point correctly moves point to the T and returns
"Tree" instead.

Second, if ada-gnat-xref-other receives an identifier which is an
operator (e.g. it receives the string "+"), it calls gnat find like
so:

gnat find +:lgtk-tree_store.adb:3775:27

and gnat find returns nothing.  gnat find insists that the + be
surrounded in double-quotes, like this:

gnat find "+":lgtk-tree_store.adb:3775:27

(If you want to try this in a shell, it won't work: you need to
surround the entire argument in single quotes:

gnat find '+:lgtk-tree_store.adb:3775:27'
gnat find '"+":lgtk-tree_store.adb:3775:27'
)

In my patch, when point is on the +, ada-identifier-at-point returns
the string "\"+\"", which is what gnat find wants.  However, gnat find
also wants the column number to be one less than the actual column
where the "+" lies, or it returns nothing.  I only have an ugly
solution for this; if someone has a better idea, that would be
welcome.

--
Ludovic Brenta.


Index: ada-mode/ada-mode.el
==================================================================
--- ada-mode/ada-mode.el
+++ ada-mode/ada-mode.el
@@ -2134,11 +2134,13 @@
 identifier.  May be an Ada identifier or operator."

   (when (ada-in-comment-p)
     (error "Inside comment"))

-  (skip-chars-backward "a-zA-Z0-9_<>=+\\-\\*/&")
+  (if (looking-at "[a-zA-Z0-9_]")
+ (skip-chars-backward "a-zA-Z0-9_") ; move to the beginning of the identifier, which might be preceded by an operator symbol + (skip-chars-backward "+\\-\\*/&<>=")) ; inside a two-character operator like >=, move to its beginning

   ;; Just in front of, or inside, a string => we could have an
   ;; operator function declaration.
   (cond
    ((ada-in-string-p)
@@ -2156,11 +2158,18 @@

    ((and (= (char-after) ?\")
         (looking-at (concat "\"\\(" ada-operator-re "\\)\"")))
     (concat "\"" (match-string-no-properties 1) "\""))

-   ((looking-at "[a-zA-Z0-9_]+\\|[+\\-*/&=<>]")
+   ((looking-at ada-operator-re)
+ ; surround the operator between double quotes, as this is what 'gnat find' expects. This unfortunately implies that we do not + ; return a string that actually exists in the buffer at point, so we must move point back one character for 'gnat find' to work
+    ; :(
+    (if (> (current-column) 0) (forward-char -1))
+    (concat "\"" (match-string-no-properties 0) "\""))
+
+   ((looking-at "[a-zA-Z0-9_]+")
     (match-string-no-properties 0))

    (t
     (error "No identifier around"))
    ))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]