all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alex <agrambot@gmail.com>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 24697@debbugs.gnu.org
Subject: bug#24697: 25.1; find-lisp-object-file-name may return wrong locations
Date: Sun, 18 Jun 2017 20:59:25 -0600	[thread overview]
Message-ID: <87y3soel82.fsf@lylat> (raw)
In-Reply-To: <5f2268ec-ae50-a75a-cc28-5e407b524974@yandex.ru> (Dmitry Gutov's message of "Sun, 18 Jun 2017 22:51:43 +0300")

[-- Attachment #1: Type: text/plain, Size: 1905 bytes --]

Dmitry Gutov <dgutov@yandex.ru> 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?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Only-search-for-a-variable-when-instructed.patch --]
[-- Type: text/x-diff, Size: 1872 bytes --]

From 2ff6a3417278a5fae3328b1bdae5afcc7094d646 Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Sun, 18 Jun 2017 18:59:11 -0600
Subject: [PATCH] Only search for a variable when instructed

* lisp/help-fns.el (find-lisp-object-file-name): Check for 'defvar
argument before searching for an internal variable (Bug#24697).
* test/lisp/help-fns-tests.el: New tests.
---
 lisp/help-fns.el            |  1 +
 test/lisp/help-fns-tests.el | 12 ++++++++++++
 2 files changed, 13 insertions(+)

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*")
diff --git a/test/lisp/help-fns-tests.el b/test/lisp/help-fns-tests.el
index 0ab6c3cae7..98898624db 100644
--- a/test/lisp/help-fns-tests.el
+++ b/test/lisp/help-fns-tests.el
@@ -118,4 +118,16 @@ defgh\\\[universal-argument\]b\`c\'d\\e\"f
     (goto-char (point-min))
     (should (looking-at "^font-lock-comment-face is "))))
 
+\f
+;;; Tests for find-lisp-object-file-name
+(ert-deftest help-fns-test-bug24697-function-search ()
+  (should-not (find-lisp-object-file-name 'tab-width 1)))
+
+(ert-deftest help-fns-test-bug24697-non-internal-variable ()
+  (let ((help-fns--test-var (make-symbol "help-fns--test-var")))
+    ;; simulate an internal variable
+    (put help-fns--test-var 'variable-documentation 1)
+    (should-not (find-lisp-object-file-name help-fns--test-var 'defface))
+    (should-not (find-lisp-object-file-name help-fns--test-var 1))))
+
 ;;; help-fns.el ends here
-- 
2.11.0


  reply	other threads:[~2017-06-19  2:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-14 22:19 bug#24697: 25.1; find-lisp-object-file-name may return wrong locations Alex
2017-06-17 22:26 ` Alex
2017-06-18 19:51   ` Dmitry Gutov
2017-06-19  2:59     ` Alex [this message]
2017-09-28 21:26       ` Dmitry Gutov
2020-08-11 13:26       ` Lars Ingebrigtsen

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

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

  git send-email \
    --in-reply-to=87y3soel82.fsf@lylat \
    --to=agrambot@gmail.com \
    --cc=24697@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.