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 23:21:34 +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.
>
> 2) Don't do anything in the `interactive' form except
>    get/assign the argument(s).
>
> 3) Test interactively and non-interactively (i.e., from Lisp).
>
> (defun atomic-position (flag)
>   (interactive
>    (list (completing-read
>           "flag: "
>           '("alat" "angstrom" "bohr" "crystal" "crystal_sg") )))
>   (insert (format "Atomic Kitten: %s" flag) ))

I've tried to rewrite the following more complex function written by
me by your above rules/guidelines, but still failed to do the trick:

(defun ATOMIC_POSITIONS ()
  (interactive
   (let* ((prog '("neb" "pw" "cp"))
      (prog-read (completing-read "prog: " prog))
      )

     (cond ((or (equal prog-read "neb")
        (equal prog-read "pw"))
        (insert "ATOMIC_POSITIONS "
            (completing-read "flag: "
                     '("alat" "bohr" "angstrom" "crystal" "crystal_sg"))))
       ((equal prog-read "cp")
        (insert "ATOMIC_POSITIONS "
            (completing-read "flag: "
                     '("alat" "bohr" "angstrom" "crystal")))))
     ))
  (newline 1))


> ;; test:
> ;;   (call-interactively #'atomic-position)
> ;;   (atomic-position "bohr")
>
> --
> underground experts united
> https://dataswamp.org/~incal



reply via email to

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