[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: |
Sat, 23 Oct 2021 16:43:10 +0800 |
On Sat, Oct 23, 2021 at 3:33 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> I've written the following code snippet:
>
> (require 'ido)
> (defun ATOMIC_POSITIONS ()
> (interactive)
> (let ((prog '("neb" "pw" "cp")))
> (cond
> ((or (equal (ido-completing-read "prog: " prog) "neb")
> (equal (ido-completing-read "prog: " prog) "pw"))
Got it. The ido-completing-read command should be run only once for
one call. The correct usage should be as follows:
1. By ido-completing-read:
(require 'ido)
(defun ido-ATOMIC_POSITIONS ()
(interactive)
(let* ((prog '("neb" "pw" "cp"))
(prog-read (ido-completing-read "prog: " prog))
)
(cond
((or (equal prog-read "neb")
(equal prog-read "pw"))
(let ((flag '("alat" "bohr" "angstrom" "crystal" "crystal_sg")))
(insert "ATOMIC_POSITIONS " (ido-completing-read "flag: " flag))))
((equal prog-read "cp")
(let ((flag '("alat" "bohr" "angstrom" "crystal")))
(insert "ATOMIC_POSITIONS " (ido-completing-read "flag: " flag))))
))
(newline 1))
2. By completing-read:
(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))
> (let ((flag '("alat" "bohr" "angstrom" "crystal" "crystal_sg")))
> (insert "ATOMIC_POSITIONS " (ido-completing-read "flag: " flag)))
> )
> ((equal (ido-completing-read "prog: " prog) "cp")
> (let ((flag '("alat" "bohr" "angstrom" "crystal")))
> (insert "ATOMIC_POSITIONS " (ido-completing-read "flag: " flag)))
> )
> ))
>
> (newline 1))
>
>
> The purpose is do the following:
>
> If the user selects "neb" or "pw", then insert one entry coming from
> '("alat" "bohr" "angstrom" "crystal" "crystal_sg").
>
> If the user selects "cp", then insert one entry coming from '("alat"
> "bohr" "angstrom" "crystal").
>
>
> But based on tries, the above code snippet only works for selection of
> "neb", while for the other two selections, sometimes it works,
> sometimes it doesn’t output results.
>
> Any hints for this problem?
>
> Regards
> --
> Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
> Theory and Simulation of Materials
> Hebei Vocational University of Technology and Engineering
> No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province
- Embedded list selection with ido-completing-read., Hongyi Zhao, 2021/10/23
- Re: Embedded list selection with ido-completing-read.,
Hongyi Zhao <=
- Re: Embedded list selection with ido-completing-read., Emanuel Berg, 2021/10/23
- Re: Embedded list selection with ido-completing-read., Hongyi Zhao, 2021/10/23
- Re: Embedded list selection with ido-completing-read., Emanuel Berg, 2021/10/23
- Re: Embedded list selection with ido-completing-read., Hongyi Zhao, 2021/10/23
- Re: Embedded list selection with ido-completing-read., Hongyi Zhao, 2021/10/23
- Re: Embedded list selection with ido-completing-read., Hongyi Zhao, 2021/10/23
- Re: Embedded list selection with ido-completing-read., Emanuel Berg, 2021/10/24
- Re: Embedded list selection with ido-completing-read., Hongyi Zhao, 2021/10/24
- Re: Embedded list selection with ido-completing-read., Emanuel Berg, 2021/10/24
- Re: Embedded list selection with ido-completing-read., Hongyi Zhao, 2021/10/24