unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Qiang via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: Qiang Fang <qiang.fang@zoho.com.cn>, 64131@debbugs.gnu.org
Subject: bug#64131: make resolving symlinks in compilation-find-file optional
Date: Tue, 12 Sep 2023 07:56:40 +0800	[thread overview]
Message-ID: <87h6o0b6x3.wl-qiang.fang@zoho.com.cn> (raw)
In-Reply-To: <CADwFkmnAVQ-weZmjtWdesbPrTKuJoKQLkb1ipE6AUTFB8e8ReQ@mail.gmail.com>


No, I couldn't provide a recipe. But it is obvious even to a beginner like me. The solution is just removed the file-truename function from compile-find-file, or make it customisable:

    (defun compilation-find-file (marker filename directory &rest formats)
      "Find a buffer for file FILENAME.
       If FILENAME is not found at all, ask the user where to find it.
       Pop up the buffer containing MARKER and scroll to MARKER if we ask
       the user where to find the file.
       Search the directories in `compilation-search-path'.
       A nil in `compilation-search-path' means to try the
       \"current\" directory, which is passed in DIRECTORY.
       If DIRECTORY is relative, it is combined with `default-directory'.
       If DIRECTORY is nil, that means use `default-directory'.
       FORMATS, if given, is a list of formats to reformat FILENAME when
       looking for it: for each element FMT in FORMATS, this function
       attempts to find a file whose name is produced by (format FMT FILENAME)."
      (or formats (setq formats '("%s")))
      (let ((dirs compilation-search-path)
            (spec-dir (if directory
                          (expand-file-name directory)
                        default-directory))
            buffer thisdir fmts name)
        (if (and filename
                 (file-name-absolute-p filename))
            ;; The file name is absolute.  Use its explicit directory as
            ;; the first in the search path, and strip it from FILENAME.
            (setq filename (abbreviate-file-name (expand-file-name filename))
                  dirs (cons (file-name-directory filename) dirs)
                  filename (file-name-nondirectory filename)))
        ;; Now search the path.
        (while (and dirs (null buffer))
          (setq thisdir (or (car dirs) spec-dir)
                fmts formats)
          ;; For each directory, try each format string.
          (while (and fmts (null buffer))
            (setq name (file-name-concat thisdir (format (car fmts) filename))
                  buffer (and (file-exists-p name)
                              (find-file-noselect name))
                  fmts (cdr fmts)))
          (setq dirs (cdr dirs)))
        ;; If we haven't found it, this might be a parallel build.
        ;; Search the directories further up the buffer.
        (when (and (null buffer)
                   compilation-search-all-directories)
          (with-current-buffer (marker-buffer marker)
            (save-excursion
              (goto-char (marker-position marker))
              (when-let ((prev (compilation--previous-directory (point))))
                (goto-char prev))
              (setq dirs (cdr (or (get-text-property
                                   (1- (point)) 'compilation-directory)
                                  (get-text-property
                                   (point) 'compilation-directory))))))
          (while (and dirs (null buffer))
            (setq thisdir (car dirs)
                  fmts formats)
            (while (and fmts (null buffer))
              (setq name (file-name-concat thisdir (format (car fmts) filename))
                    buffer (and (file-exists-p name)
                                (find-file-noselect name))
                    fmts (cdr fmts)))
            (setq dirs (cdr dirs))))
        (while (null buffer)              ;Repeat until the user selects an existing file.
          ;; The file doesn't exist.  Ask the user where to find it.
          (save-excursion                 ;This save-excursion is probably not right.
            (let ((w (let ((pop-up-windows t))
                       (display-buffer (marker-buffer marker)
                                       '(nil (allow-no-window . t))))))
              (with-current-buffer (marker-buffer marker)
                (goto-char marker)
                (and w (progn (compilation-set-window w marker)
                              (compilation-set-overlay-arrow w))))
              (let* ((name (read-file-name
                            (format-prompt "Find this %s in"
                                           filename compilation-error)
                            spec-dir filename t nil
                            ;; The predicate below is fine when called from
                            ;; minibuffer-complete-and-exit, but it's too
                            ;; restrictive otherwise, since it also prevents the
                            ;; user from completing "fo" to "foo/" when she
                            ;; wants to enter "foo/bar".
                            ;;
                            ;; Try to make sure the user can only select
                            ;; a valid answer.  This predicate may be ignored,
                            ;; tho, so we still have to double-check afterwards.
                            ;; TODO: We should probably fix read-file-name so
                            ;; that it never ignores this predicate, even when
                            ;; using popup dialog boxes.
                            ;; (lambda (name)
                            ;;   (if (file-directory-p name)
                            ;;       (setq name (expand-file-name filename name)))
                            ;;   (file-exists-p name))
                            ))
                     (origname name))
                (cond
                  ((not (file-exists-p name))
                   (message "Cannot find file `%s'" name)
                   (ding) (sit-for 2))
                  ((and (file-directory-p name)
                        (not (file-exists-p
                              (setq name (file-name-concat name filename)))))
                   (message "No `%s' in directory %s" filename origname)
                   (ding) (sit-for 2))
                  (t
                   (setq buffer (find-file-noselect name))))))))
        ;; Make intangible overlays tangible.
        ;; This is weird: it's not even clear which is the current buffer,
        ;; so the code below can't be expected to DTRT here.  -- Stef
        (dolist (ov (overlays-in (point-min) (point-max)))
          (when (overlay-get ov 'intangible)
            (overlay-put ov 'intangible nil)))
        buffer)))
    





  reply	other threads:[~2023-09-11 23:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-17 13:18 bug#64131: make resolving symlinks in compilation-find-file optional Qiang Fang via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-11 18:06 ` Stefan Kangas
2023-09-11 23:56   ` Qiang via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-09-12  0:33     ` Stefan Kangas
2023-09-12  0:59       ` Qiang via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-12  1:01       ` Qiang via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-10 10:39         ` Stefan Kangas
2024-01-10 13:29           ` Eli Zaretskii

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=87h6o0b6x3.wl-qiang.fang@zoho.com.cn \
    --to=bug-gnu-emacs@gnu.org \
    --cc=64131@debbugs.gnu.org \
    --cc=qiang.fang@zoho.com.cn \
    --cc=stefankangas@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).