unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Navigating an enormous code base
Date: Tue, 13 Dec 2022 22:47:49 -0500	[thread overview]
Message-ID: <jwvedt28xf7.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: jwv4k2gkocd.fsf-monnier+emacs@gnu.org

> There could be several notions of "sibling":
> - jump from /foo/bar/main/src/hello.c to /foo/bar/stable/src/hello.c.
> - jump from /foo/bar/main/src/hello.c to /foo/bar/main/test/src/hello-tests.el.
> - jump from /foo/bar/main/src/hello.c to /foo/bar/main/src/hello.h.

The function below can do all three given the appropriate hint:
- "stable" for the first.
- "-tests" for the second.
- ".h" for the third.

It can also find "/foo/bar/stable/src/hello.h" when given the hint
"stable/.h".


        Stefan


(defun my-other-files (hint file)
  (cl-assert (file-name-absolute-p file))
  (named-let loop ((fullname file)
                   (hint hint)
                   (rest nil))
    (if (file-name-directory hint)
        (let* ((hintbase (directory-file-name (file-name-directory hint)))
               (hintend (file-name-nondirectory hint)))
          (apply #'append
                 (mapcar (lambda (x)
                           (let ((default-directory
                                  (file-name-as-directory (car x)))
                                 (tail (cdr x)))
                             (mapcar
                              (lambda (x)
                                (cons (file-name-concat default-directory
                                                        (car x))
                                      (cdr x)))
                              (loop tail hintend rest))))
                         (loop fullname hintbase rest))))
      (let ((dir (file-name-directory fullname))
            (file (file-name-nondirectory fullname))
            (names '())
            (re (regexp-quote hint)))
        (when dir
          (dolist (candidate (directory-files dir nil re))
            (when (string-match re candidate)
              (let ((prefix (substring candidate 0 (match-beginning 0)))
                    (suffix (substring candidate (match-end 0))))
                (when (and (>= (length file)
                               (+ (length prefix) (length suffix)))
                           (string-prefix-p prefix file)
                           (string-suffix-p suffix file))
                  (push candidate names)))))
          (nconc
           (mapcar (lambda (name) (cons (file-name-concat dir name) rest)) names)
           (when (> (length dir)
                    (length (setq dir (directory-file-name dir))))
             (loop dir hint (if rest (file-name-concat file rest) file)))))))))




  reply	other threads:[~2022-12-14  3:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-26  2:31 Navigating an enormous code base John Yates
2022-04-26  6:06 ` Daniel Fleischer
2022-04-26 11:03 ` Eli Zaretskii
2022-04-26 12:53   ` John Yates
2022-04-26 14:06     ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-04-26 12:49 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-12-14  3:47   ` Stefan Monnier via Users list for the GNU Emacs text editor [this message]
2022-12-14 17:55     ` Emanuel Berg
2022-04-27  7:59 ` Marcus Harnisch
2022-04-27  8:36   ` mrf
2022-04-27 16:35     ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-04-27 22:59       ` John Yates
2022-04-28  0:46         ` Emanuel Berg
2022-04-28  6:42         ` Marcus Harnisch
2022-04-28  7:39           ` Leo Liu
2022-04-28  8:38             ` Marcus Harnisch
2022-04-28 10:45               ` Leo Liu
2022-04-28 14:34               ` John Yates
2022-04-28 14:45                 ` Marcus Harnisch
2022-04-28 14:30           ` John Yates
2022-04-28 14:40             ` Marcus Harnisch
2022-04-28 14:50           ` John Yates
2022-04-28 16:10             ` Óscar Fuentes
2022-04-28 16:15             ` Marcus Harnisch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvedt28xf7.fsf-monnier+emacs@gnu.org \
    --to=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).