bug#24697: 25.1; find-lisp-object-file-name may return wrong locations

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#24697: 25.1; find-lisp-object-file-name may return wrong locations

Alex-2

#+BEGIN_SRC elisp
(defface tab-width
  '((t :foreground "red"))
  "A face with the same name as a variable.")


(find-lisp-object-file-name 'tab-width 'defface)
#+END_SRC

The above results in the symbol 'C-source'. The result should be nil as
the 'tab-width' face was evaluated in *scratch*.

Putting the above definition into an actual file and using `load-file'
does return the proper source location.

#+BEGIN_SRC elisp
(find-lisp-object-file-name 'mapatoms 1)
#+END_SRC

This should return 'C-source' but instead it returns nil.

#+BEGIN_SRC elisp
(find-lisp-object-file-name 'tab-width 1)
#+END_SRC

This should return nil but instead it returns 'C-source'.



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#24697: 25.1; find-lisp-object-file-name may return wrong locations

Alex-2
Alex <[hidden email]> writes:

> #+BEGIN_SRC elisp
> (defface tab-width
>   '((t :foreground "red"))
>   "A face with the same name as a variable.")
>
>
> (find-lisp-object-file-name 'tab-width 'defface)
> #+END_SRC
>
>
> The above results in the symbol 'C-source'. The result should be nil as
> the 'tab-width' face was evaluated in *scratch*.
>
> Putting the above definition into an actual file and using `load-file'
> does return the proper source location.
>
> #+BEGIN_SRC elisp
> (find-lisp-object-file-name 'mapatoms 1)
> #+END_SRC
>
>
> This should return 'C-source' but instead it returns nil.
>
> #+BEGIN_SRC elisp
> (find-lisp-object-file-name 'tab-width 1)
> #+END_SRC
>
> This should return nil but instead it returns 'C-source'.
The first and last of these are fixed by the following diff.


diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 2c635ffa50..bcf33131fa 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -319,6 +319,7 @@ find-lisp-object-file-name
   (help-C-file-name type 'subr)
  'C-source))
      ((and (not file-name) (symbolp object)
+           (eq type 'defvar)
    (integerp (get object 'variable-documentation)))
       ;; A variable defined in C.  The form is from `describe-variable'.
       (if (get-buffer " *DOC*")


The second is a bit odder. For some reason, find-lisp-object-file-name
searches for an internal function definition using TYPE instead of
OBJECT. I would have expected it to use OBJECT like the rest of the
tests do. I see no reason for the current behaviour.

Either the documentation should be changed to clearly indicate the
current behaviour, or the function should be changed so that OBJECTs for
which (subrp (symbol-function OBJECT)) returns t should return
'C-source'.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#24697: 25.1; find-lisp-object-file-name may return wrong locations

Dmitry Gutov
On 6/18/17 1:26 AM, Alex wrote:

> The first and last of these are fixed by the following diff.
>
> ...
>
>
> The second is a bit odder. For some reason, find-lisp-object-file-name
> searches for an internal function definition using TYPE instead of
> OBJECT. I would have expected it to use OBJECT like the rest of the
> tests do. I see no reason for the current behaviour.

Thanks. Do you think you can write test cases for these problems? There
are some existing ones in test/lisp/help-fns-tests.el.

> Either the documentation should be changed to clearly indicate the
> current behaviour, or the function should be changed so that OBJECTs for
> which (subrp (symbol-function OBJECT)) returns t should return
> 'C-source'.

With a test case, you might also find it easier to make a choice
regarding this problem.



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#24697: 25.1; find-lisp-object-file-name may return wrong locations

Alex-2
Dmitry Gutov <[hidden email]> writes:

> On 6/18/17 1:26 AM, Alex wrote:
>
>> The first and last of these are fixed by the following diff.
>>
>> ...
>>
>>
>> The second is a bit odder. For some reason, find-lisp-object-file-name
>> searches for an internal function definition using TYPE instead of
>> OBJECT. I would have expected it to use OBJECT like the rest of the
>> tests do. I see no reason for the current behaviour.
>
> Thanks. Do you think you can write test cases for these problems? There are some
> existing ones in test/lisp/help-fns-tests.el.
Sure, I've attached a patch below for the simple cases. As I couldn't
find a satisfactory way to make a temporary face, I just made an
uninterned symbol that find-lisp-object-file-name would treat as an
internal variable.

>> Either the documentation should be changed to clearly indicate the
>> current behaviour, or the function should be changed so that OBJECTs for
>> which (subrp (symbol-function OBJECT)) returns t should return
>> 'C-source'.
>
> With a test case, you might also find it easier to make a choice regarding this
> problem.

I'm not sure. I still don't understand why the design decision was made.
I suppose one benefit is that one can search explicitly for internal
functions rather than lisp functions, but the function could have just
accepted 'subr instead of 'defun to do that.

Perhaps the current use of searching with TYPE should be left in for
backwards compatibility (a Github search shows at least 2 instances of
3rd-party code that makes use of that behaviour).

For instance, here's how you find mapatoms' file:

  (find-lisp-object-file-name 'mapatoms (symbol-function 'mapatoms))

You should just be able to do the following:

  (find-lisp-object-file-name 'mapatoms 'defun)

Or without searching for lisp functions named mapatoms first:

  (find-lisp-object-file-name 'mapatoms 'subr)

What do you think?


0001-Only-search-for-a-variable-when-instructed.patch (1K) Download Attachment
Loading...