all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Eshel Yaron <me@eshelyaron.com>
Cc: Eli Zaretskii <eliz@gnu.org>,  emacs-devel@gnu.org
Subject: Re: [ELPA] New package: dict
Date: Sat, 20 May 2023 19:11:12 +0000	[thread overview]
Message-ID: <875y8m95tb.fsf@posteo.net> (raw)
In-Reply-To: <m1bkiezwmt.fsf@esmac.lan> (Eshel Yaron's message of "Sat, 20 May 2023 21:27:22 +0300")

Eshel Yaron <me@eshelyaron.com> writes:

>>> +(defcustom dictionary-display-definition-function nil
>>> +  "Function to use for displaying dictionary definitions.
>>> +It is called with three string arguments: the word being defined,
>>> +the dictionary name, and the full definition."
>>> +  :type '(choice (const :tag "Dictionary buffer" nil)
>>> +                 (const :tag "Help buffer"
>>> +                        dictionary-display-definition-in-help-buffer)
>>> +                 (function :tag "Custom function"))
>>> +  :version "30.1")
>>
>> What is the reason for having this option fallback to nil?  I couldn't
>> make that out from the patch.  If all the other options offer a
>> concrete-default function (that you could also call in your own
>> function), then it seems inconsistent to not provide this here as well.
>
> The reason is that, unlike the other options, the default path that
> `dictionary-search` takes to displaying a definition is highly coupled
> with how it obtains the definition, making it difficult to extract into
> a standalone function.  That's a refactor I prefer to avoid at this
> point.  So, if you set `dictionary-display-definition-function` to a
> custom function, we use the new function `dictionary-define-word` to
> cleanly obtain the definition and let your custom function display it.
> If you use the default (nil) value, we let `dictionary-search` call the
> "old" function `dictionary-new-search` that both obtains and displays
> the definition.

OK, I am not familiar with the code and I get that it could take too
much effort to refactor this properly right now.

>>> +(defun dictionary-define-word (word dictionary)
>>> +  "Return the definition of WORD in DICTIONARY, or nil if not found."
>>> +  (dictionary-send-command
>>> +   (format "define %s \"%s\"" dictionary word))
>>> +  (when (and (= (read (dictionary-read-reply)) 150)
>>> +             (= (read (dictionary-read-reply)) 151))
>>
>> I think a memq would be nice here.
>>
>
> No, `memq` would be appropriate if we wanted to check that the
> expression `(read (dictionary-read-reply))` evaluates to either 150 or
> to 151, but here we want to check that it evaluates 150 and then
> afterwards that it evaluates to 151.

Whoops, misread that as and `or' and forgot about side-effects.

>>> +(defun dictionary-display-definition-in-help-buffer (word dictionary definition)
>>> +  "Display DEFINITION, the definition of WORD in DICTIONARY."
>>> +  (let ((help-buffer-under-preparation t))
>>> +    (help-setup-xref (list #'dictionary-search word dictionary)
>>> +                     (called-interactively-p 'interactive))
>>> +    (with-help-window (help-buffer)
>>> +      (with-current-buffer (help-buffer)
>>> +        (insert definition)
>>> +        (goto-char (point-min))
>>> +        (while (re-search-forward (rx "{"
>>> +                                      (group-n 1 (* (not (any ?}))))
>>> +                                      "}")
>>> +                                  nil t)
>>
>> Perhaps you could explain what is going on here.  Why is this pattern
>> significant?
>
> We want to buttonize references to other definitions in the *Help*
> buffer, which appear enclosed in curly braces.  I've added a comment
> explaining this.

So the protocol always wraps other definitions in curly braces?



  reply	other threads:[~2023-05-20 19:11 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-11 13:22 [ELPA] New package: dict Eshel Yaron
2023-05-11 13:59 ` Eli Zaretskii
2023-05-11 14:14   ` Philip Kaludercic
2023-05-11 17:56     ` Eshel Yaron
2023-05-11 18:16       ` Eli Zaretskii
2023-05-11 18:29       ` Philip Kaludercic
2023-05-12 13:17         ` Eshel Yaron
2023-05-12 13:44           ` Eli Zaretskii
2023-05-14  6:41             ` Eshel Yaron
2023-05-14  9:14               ` Eli Zaretskii
2023-05-15 18:50                 ` Eshel Yaron
2023-05-18  7:57                   ` Eshel Yaron
2023-05-18  8:32                     ` Eli Zaretskii
2023-05-18 10:59                   ` Eli Zaretskii
2023-05-18 12:21                     ` Eshel Yaron
2023-05-18 14:09                       ` Eli Zaretskii
2023-05-18 15:51                         ` Eshel Yaron
2023-05-18 15:58                           ` Eli Zaretskii
2023-05-19  8:34                             ` Eshel Yaron
2023-05-20 14:19                               ` Eli Zaretskii
2023-05-20 16:49                               ` Philip Kaludercic
2023-05-20 18:27                                 ` Eshel Yaron
2023-05-20 19:11                                   ` Philip Kaludercic [this message]
2023-05-21  6:52                                     ` Eshel Yaron
2023-05-25  9:52                                       ` Eshel Yaron
2023-05-25 19:10                                         ` Philip Kaludercic
2023-05-26  9:16                                         ` Eli Zaretskii
2023-05-26 11:36                                         ` Rudolf Adamkovič
2023-05-26 12:26                                           ` Eshel Yaron
2023-05-18 12:59                   ` Philip Kaludercic
2023-05-18 15:37                     ` Eshel Yaron
2023-05-18 15:58                       ` Philip Kaludercic
2023-05-14 16:06               ` Stephen Leake
2023-05-15 18:58                 ` Eshel Yaron
2023-05-11 14:18 ` Philip Kaludercic
2023-05-11 18:00   ` Eshel Yaron
2023-05-11 18:31     ` Philip Kaludercic
2023-05-12 13:32       ` Eshel Yaron
2023-05-16 19:38         ` Philip Kaludercic
2023-05-17  2:25           ` Eli Zaretskii
2023-05-13 22:30     ` Richard Stallman
2023-05-14  6:48       ` Eshel Yaron

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=875y8m95tb.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=me@eshelyaron.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 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.