help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Embedded list selection with ido-completing-read.


From: Hongyi Zhao
Subject: Re: Embedded list selection with ido-completing-read.
Date: Sun, 24 Oct 2021 10:28:46 +0800

On Sun, Oct 24, 2021 at 9:17 AM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > I still can't figure out how to use your suggestions above
> > to further simplify my implementation below:
> >
> > (defun my-pw-ATOMIC_POSITIONS2 ()
> >   (interactive
> >    (list
> >     (insert "ATOMIC_POSITIONS "
> >             (completing-read
> >              "flag: "
> >              '(("alat")
> >                ("bohr")
> >                ("angstrom")
> >                ("crystal")
> >                ("crystal_sg")
> >                )
> >              )))))
>
> Same as I said before ...
>
> 1) Use a formal parameter.

This seems to make the function usable in more situations.

> 2) Don't do anything in the `interactive' form except
>    get/assign the argument(s).

Got it. These jobs are really belongs to things done in `interactive'
manner. So, your idea is: when coding, do the right thing in the right
place.

> 3) Test interactively and non-interactively (i.e., from Lisp).

For portability and usability again.

> (defun atomic-position (flag)
>   (interactive
>    (list (completing-read
>           "flag: "
>           '("alat" "angstrom" "bohr" "crystal" "crystal_sg") )))
>   (insert (format "Atomic Kitten: %s" flag) ))

Got it. Thank you.

> ;; test:
> ;;   (call-interactively #'atomic-position)

Interactively test, equivalent to `M-x atomic-position RET'

> ;;   (atomic-position "bohr")

Test it non-interactively to make sure it works in other Lisp code
blocks to further take advantage of it.


BTW, my ultimate purpose it to implement the in-buffer company-mode
[1] completion support for QE-modes [2], which is the main reason why
I ask this question. And I’ve got some useful advice here [3-5].

[1] https://github.com/company-mode/company-mode
[2] http://pwtk.ijs.si/qe-modes.html
[3] 
https://github.com/company-mode/company-mode/discussions/1247#discussioncomment-1525332
[4] 
https://github.com/company-mode/company-mode/blob/master/CONTRIBUTING.md#guidelines-for-third-party-packages
[5] 
https://github.com/company-mode/company-mode/blob/master/CONTRIBUTING.md#backend-integration

It seems that I still have a long way to go to achieve this goal.

HZ



reply via email to

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