emacs-devel
[Top][All Lists]
Advanced

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

Re: [ELPA] New package: dict


From: Eshel Yaron
Subject: Re: [ELPA] New package: dict
Date: Fri, 12 May 2023 16:17:53 +0300
User-agent: Gnus/5.13 (Gnus v5.13)

Philip Kaludercic <philipk@posteo.net> writes:

> Eshel Yaron <me@eshelyaron.com> writes:
>
>> Alright, I can give augmenting dictionary.el a shot.
>>
>> [...]
>>
>> does it imply that you think it'll be hard to keep Dict's simplicity
>> intact upon incorporating it with dictionary.el?
>
> Right, you'll either have to remove stuff from dictionary.el that people
> have started to depend on, or ignore that fact.

After studying dictionary.el more carefully, I don't currently see a
good way of augmenting it to facilitate the same behavior that Dict
provides.

Basically, Dict has just one command, `dict-describe-word`, and the
question is how this command can be implemented or imitated in terms of
dictionary.el.

`dict-describe-word` is not complex, its behavior is described in
https://eshelyaron.com/dict.html#word-definitions, but let's just take a
look at its definition:

--8<---------------cut here---------------start------------->8---
(defun dict-describe-word (word)
  "Display the definition of WORD.
..."
  (interactive (list (dict-read-word)))
  (let ((definition (dict-define-word word)))
    (if definition
        (funcall dict-display-definition-function word definition)
      (user-error "No definition found for \"%s\"" word))))
--8<---------------cut here---------------end--------------->8---

It only uses two Dict-specific functions: `dict-read-word` and
`dict-define-word`.  `dict-define-word` takes a word and returns its
definition, as a string.  `dict-read-word` reads a word using
`completing-read`, with completion based on dictionary matches.  It
relies on another function, `dict-match-word`, to retrieve the list of
completion candidates from the dictionary server.

In order to implement `dict-describe-word` as part of dictionary.el, I'd
need to replace `dict-match-word` and `dict-describe-word` with
corresponding functions from dictionary.el.  Unfortunately, the parts of
dictionary.el that deal with obtaining information and the parts that
deal with displaying it are not easily separable.  Indeed, their is no
API for obtaining word definitions or matches, and the functions that
perform these actions also do unrelated UI stuff.

For that reason I don't see a good way to reuse code from dictionary.el
to port `dict-describe-word`.

Another option would be to refactor dictionary.el to make it more
modular and to provide a cleaner API.  That's possible, but refactoring
would most likely mean risking breaking stuff, and I couldn't find any
tests that'd help circumvent that risk.

All in all, I currently think it's best to keep these two separate after all.
The only concrete downside that I see is that Dict define a couple of user
options that are very similar to those defined in dictionary.el, and users of
both packages may find it annoying to customize both.  Perhaps I can have Dict
pick up these user options from their corresponding dictionary.el variables if
they're already set.

Any thoughts/ideas?



reply via email to

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