Hi,
It's very interesting. I have made a patch for it.

The -N (--nearest) option is available with the -S or -l option.

$ cd libutil
$ global -xl main               # local search -> not found
$ global -xl main -N            # nearest search
main              363 ../global/global.c main(int argc, char **argv)
main              198 ../gozilla/gozilla.c main(int argc, char **argv)
...

Would you please try it?

Regards,
Shigio


2015-05-25 0:35 GMT+09:00 Gautam Thaker <[email protected]>:

>  I use global (mostly w/ ggtags in emacs.) Work quite well, thanks.
>
> I have one feature request/idea.  In a large software system there are
> often 10s of function definitions w/ the same name. Global finds them all,
> but does not offer to order them in any sense of "nearness" to the place
> where global is being called from.  It would be nice if global had an
> option where it would find matches as it does w/ the "-l" option (in
> present directory or below), but if no entries are found it would then go
> up one directory and repeat this process till at least 1 definition is
> found.
>
> This feature would greatly help manage navigation in large source trees.
> I asked author of "ggtags" itself if this feature can be implemented in
> ggtags, and his reply was:
>
> "Ordering is harder. We have to wait until getting all matches before
> re-ordering it. At the moment, ggtags is async by means of compile.el. I
> think this feature might be best implemented in global itself."
>
> Again, thanks for "global".
>
> Gautam
>
>
> _______________________________________________
> Bug-global mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/bug-global
>
>


-- 
Shigio YAMAGUCHI <[email protected]>
PGP fingerprint: D1CB 0B89 B346 4AB6 5663  C4B6 3CA5 BBB3 57BE DDA3
*** global/global.c     9 Apr 2015 23:03:42 -0000       1.295
--- global/global.c     24 May 2015 23:21:07 -0000
***************
*** 86,91 ****
--- 86,92 ----
  int Lflag;                            /* [option]             */
  int Mflag;                            /* [option]             */
  int nflag;                            /* [option]             */
+ int Nflag;                            /* [option]             */
  int oflag;                            /* [option]             */
  int Oflag;                            /* [option]             */
  int pflag;                            /* command              */
***************
*** 175,180 ****
--- 176,182 ----
        {"file-list", required_argument, NULL, 'L'},
        {"match-case", no_argument, NULL, 'M'},
        {"nofilter", optional_argument, NULL, 'n'},
+       {"nearest", optional_argument, NULL, 'N'},
        {"grep", no_argument, NULL, 'g'},
        {"basic-regexp", no_argument, NULL, 'G'},
        {"ignore-case", no_argument, NULL, 'i'},
***************
*** 391,397 ****
        openconf(root);
        setenv_from_config();
        logging_arguments(argc, argv);
!       while ((optchar = getopt_long(argc, argv, 
"acde:EifFgGIlL:MnoOpPqrsS:tTuvVx", long_options, &option_index)) != EOF) {
                switch (optchar) {
                case 0:
                        break;
--- 393,399 ----
        openconf(root);
        setenv_from_config();
        logging_arguments(argc, argv);
!       while ((optchar = getopt_long(argc, argv, 
"acde:EifFgGIlL:MnNoOpPqrsS:tTuvVx", long_options, &option_index)) != EOF) {
                switch (optchar) {
                case 0:
                        break;
***************
*** 455,460 ****
--- 457,465 ----
                                nofilter = BOTH_FILTER;
                        }
                        break;
+               case 'N':
+                       Nflag++;
+                       break;
                case 'o':
                        oflag++;
                        break;
***************
*** 1760,1768 ****
--- 1765,1793 ----
        /*
         * search in current source tree.
         */
+ heuristic_retry:
        count = search(pattern, root, cwd, dbpath, db);
        total += count;
        /*
+        * Heuristic nearest tag search (-N option)
+        *
+        * At the first time, global(1) executes a local search normally,
+        * but if no entries are found, it goes up one directory and repeat
+        * this process till at least 1 definition is found.
+        */
+       if (count == 0 && Sflag && Nflag && strlen(localprefix) > strlen("./")) 
{
+               /*
+                * localprefix must start with './' and end with '/'.
+                */
+               char *p = localprefix + strlen(localprefix) - 1;
+               while (*--p != '/' && p > localprefix)
+                       ;
+               if (*p != '/')
+                       die("tagsearch: Impossible");
+               *(p + 1)= '\0';
+               goto heuristic_retry;
+       }
+       /*
         * search in library path.
         */
        if (abslib)
_______________________________________________
Bug-global mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-global

Reply via email to