Subject: Re: bug#36459: 27.0.50; octave-mode ElDoc support bug

From: Mauro Aranda <[email-masked]>
Date: Tue, 6 Aug 2019 13:07:59 -0300

tags 36459 patch
quit

I attach a patch, which I think tackles the problems presented.  It
stops matching incorrectly when there is no function defined, with the
change suggested by Leo Liu.

Also, the regexp used now matches the newer help output (GNU Octave
4.2.x and newer), while still supporting older GNU Octave versions.

I've tested with GNU Octave 4.0.0 and GNU Octave 5.1.0.

Best regards,
Mauro.
From 6e704f00be224371a2aab9b6bce3a792dfeb934b Mon Sep 17 00:00:00 2001
From: Mauro Aranda <[email-masked]>
Date: Tue, 6 Aug 2019 12:45:28 -0300
Subject: [PATCH] Fix octave-mode ElDoc support

* lisp/progmodes/octave.el (octave-eldoc-function-signatures): Fix the
regexp used, so no match happens when there is no defined function FN.
Also, tweak the regexp to support GNU Octave 4.2.x and newer.  (Bug#36459)
---
 lisp/progmodes/octave.el | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index b770edb..51ba34f 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -1616,8 +1616,23 @@ octave-eldoc-function-signatures
      (list (format "print_usage ('%s');\n" fn)))
     (let (result)
       (dolist (line inferior-octave-output-list)
+        ;; The help output has changed a few times in GNU Octave.
+        ;; Earlier versions output "usage: " before the function signature.
+        ;; After deprecating the usage function, and up until GNU Octave 4.0.3,
+        ;; the output looks like this:
+        ;; -- Mapping Function: abs (Z).
+        ;; After GNU Octave 4.2.0, the output is less verbose and it looks like
+        ;; this:
+        ;; -- abs (Z)
+        ;; The following regexp matches these three formats.
+        ;; The "usage: " alternative matches the symbol, because a call to
+        ;; print_usage with a non-existent function (e.g., print_usage ('A'))
+        ;; would output:
+        ;; error: print_usage: 'A' not found
+        ;; and we wouldn't like to match anything in this case.
+        ;; See bug #36459.
         (when (string-match
-               "\\s-*\\(?:--[^:]+\\|usage\\):\\s-*\\(.*\\)$"
+               "\\s-*\\(?:--[^:]+:\\|\\_<usage:\\|--\\)\\s-*\\(.*\\)$"
                line)
           (push (match-string 1 line) result)))
       (setq octave-eldoc-cache
-- 
2.7.4