emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The source linke in the help buffer


From: Lennart Borgman (gmail)
Subject: Re: The source linke in the help buffer
Date: Wed, 24 Sep 2008 23:48:41 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666

Lennart Borgman (gmail) wrote:
> martin rudalics wrote:
>>> It doesn't of course, sorry for the bad mixing of things here.
>>> (However before your changes the link in the help buffer could lead
>>> either to the installed tree or the checked out tree.)
>> But your function doesn't check these links.  So what can I do to help
>> you?  The function you're using seems to accomplish all you need.
> 
> Sorry for beeing unclear. I was (a bit too implicity) saying that
> instead of the variables you suggested to make the help buffer link go
> to either the install or the source tree it would suffice with a
> function like the one I provided.
> 
> I think it would be good if this function shared room with find-function
> and its relatives inside Emacs.

But I think this version would live a more pleasant and longer life there:

(defun find-emacs-other-file (display-file)
  "Find corresponding file to source or installed elisp file.
If you have checked out and compiled Emacs yourself you may have
Emacs lisp files in two places, the checked out source tree and
the installed Emacs tree.  If buffer contains an Emacs elisp file
in one of these places then find the corresponding elisp file in
the other place. Return the file name of this file.

When DISPLAY-FILE is non-nil display this file in other window
and go to the same line number as in the current buffer."
  (interactive (list t))
  (unless (buffer-file-name)
    (error "This buffer is not visiting a file"))
  (unless source-directory
    (error "Can't find the checked out Emacs sources"))
  (let* ((installed-directory (file-name-as-directory
                               (expand-file-name ".." exec-directory)))
         (relative-installed (file-relative-name
                              (buffer-file-name) installed-directory))
         (relative-source (file-relative-name
                           (buffer-file-name) source-directory))
         (name-nondir (file-name-nondirectory (buffer-file-name)))
         source-file
         installed-file
         other-file
         (line-num (line-number-at-pos)))
    (cond
     ((and relative-installed
           (not (string= name-nondir relative-installed))
           (not (file-name-absolute-p relative-installed))
           (not (string= ".." (substring relative-installed 0 2))))
      (setq source-file (expand-file-name relative-installed
source-directory)))
     ((and relative-source
           (not (string= name-nondir relative-source))
           (not (file-name-absolute-p relative-source))
           (not (string= ".." (substring relative-source 0 2))))
      (setq installed-file (expand-file-name relative-source
installed-directory))))
    (setq other-file (or source-file installed-file))
    (unless other-file
      (error "This file is not in Emacs source or installed lisp tree"))
    (unless (file-exists-p other-file)
      (error "Can't find the corresponding file %s" other-file))
    (when display-file
      (find-file-other-window other-file)
      (goto-line line-num))
    other-file))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]