Subject: bug#19468: 25.0.50; UI inconveniences with M-.

From: Eli Zaretskii <[email-masked]>
Date: Sat, 02 May 2015 14:16:22 +0300

> Cc: [email-masked]
> From: Dmitry Gutov <[email-masked]>
> Date: Sat, 2 May 2015 13:11:58 +0300
> 
> On 05/02/2015 10:10 AM, Eli Zaretskii wrote:
> 
> > I get "Symbol's function definition is void: mapcan".
> 
> Sorry, fixed now.

Thanks.

> > I then manually load cl, and re-invoke the command.  The result now is
> > "No known references for: set_cursor_from_row".
> 
> It expected you to load the tags tables first

It did, so that's not the problem.

> Now it'll prompt for one otherwise.

I don't understand this new prompt, it says:

  In directory: /patch/to/emacs/trunk/src/

What does it ask about?  (I just pressed RET, since the directory
sounds correct.)

> > In case it matters, the ID file was produced manually with this
> > command in the top-level Emacs directory:
> >
> >    mkid -o ID .
> 
> If you want to see it used, then like I said, it needs to be in the same 
> directory as TAGS (not one level above).

I tried both, and got the same results.  So this is not the reason;
there's something else at work here.

> But without it, we default to using Grep.

So why didn't it do that?  Why did I get "no known references"?

[Time passes] Ah, I see the reason: Some code that uses ID Utils
expects the file names in the ID database to be absolute.  So if I
create the ID database like this:

   mkid -o ID /path/to/emacs/src

then the feature starts working.

I think it should support relative names as well, by expanding them
relative to the directory in which the ID database was found.  And in
any case, claiming it found no references instead of saying something
about finding no files whose names were returned by ID Utils is a less
than useful error message, IMO.

Now to the Grep alternative: if I rename the ID database, I get an
error message:

  Searching for program: No such file or directory, sh

(This is on MS-Windows.)  The patch for that is below.

But that doesn't end the saga, because after fixing this, I get "No
known references for: set_cursor_from_row" again, when there's no ID
database.  The reason is that the find/grep command uses the wrong
quoting style; the patch below fixes that as well.

And the saga is not yet over, but now I need help.  The method
semantic-symref-parse-tool-output-one-line returns nil, but I cannot
seem to figure out why.  The buffer which contains Grep hits look fine
to me (except that it includes SGR escape sequences, due to
"--color=always" switch to Grep -- why is that a good idea?), but
where's the code of this method?  I couldn't step into it with Edebug,
for some reason.

Help?....

Here's that patch I promised.  I will push it if no one objects.

diff --git a/lisp/cedet/semantic/symref/grep.el b/lisp/cedet/semantic/symref/grep.el
index 981dab8..ecb3279 100644
--- a/lisp/cedet/semantic/symref/grep.el
+++ b/lisp/cedet/semantic/symref/grep.el
@@ -115,7 +115,7 @@ (defun semantic-symref-grep-use-template (rootdir filepattern grepflags greppatt
     ;;(message "New command: %s" cmd)
     cmd))
 
-(defcustom semantic-symref-grep-shell "sh"
+(defcustom semantic-symref-grep-shell shell-file-name
   "The shell command to use for executing find/grep.
 This shell should support pipe redirect syntax."
   :group 'semantic
@@ -140,7 +140,8 @@ (cl-defmethod semantic-symref-perform-search ((tool semantic-symref-tool-grep))
 	 (greppat (cond ((eq (oref tool :searchtype) 'regexp)
 			 (oref tool searchfor))
 			(t
-			 (concat "'\\<" (oref tool searchfor) "\\>'"))))
+			 (shell-quote-argument
+                          (concat "\\<" (oref tool searchfor) "\\>")))))
 	 ;; Misc
 	 (b (get-buffer-create "*Semantic SymRef*"))
 	 (ans nil)
@@ -158,10 +159,12 @@ (cl-defmethod semantic-symref-perform-search ((tool semantic-symref-tool-grep))
 	  (let ((cmd (concat "find " default-directory " -type f " filepattern " -print0 "
 			     "| xargs -0 grep -H " grepflags "-e " greppat)))
 	    ;;(message "Old command: %s" cmd)
-	    (call-process semantic-symref-grep-shell nil b nil "-c" cmd)
+	    (call-process semantic-symref-grep-shell nil b nil
+                          shell-command-switch cmd)
 	    )
 	(let ((cmd (semantic-symref-grep-use-template rootdir filepattern grepflags greppat)))
-	  (call-process semantic-symref-grep-shell nil b nil "-c" cmd))
+	  (call-process semantic-symref-grep-shell nil b nil
+                        shell-command-switch cmd))
 	))
     (setq ans (semantic-symref-parse-tool-output tool b))
     ;; Return the answer