From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help Subject: Re: Embedded list selection with ido-completing-read. Date: Sat, 23 Oct 2021 16:43:10 +0800 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16235"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 23 10:43:47 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1meCd0-00042J-TD for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 23 Oct 2021 10:43:46 +0200 Original-Received: from localhost ([::1]:42018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCcz-0000w4-Mq for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 23 Oct 2021 04:43:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51244) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCce-0000vw-PP for help-gnu-emacs@gnu.org; Sat, 23 Oct 2021 04:43:24 -0400 Original-Received: from mail-vk1-xa32.google.com ([2607:f8b0:4864:20::a32]:44916) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1meCcc-0004q7-KZ for help-gnu-emacs@gnu.org; Sat, 23 Oct 2021 04:43:24 -0400 Original-Received: by mail-vk1-xa32.google.com with SMTP id ba39so2588586vkb.11 for ; Sat, 23 Oct 2021 01:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=HVuEOoR+wue1PsE6NgQEDXqVtzCNpXUQrR4ExhNN8DI=; b=hSu/pBpUhWv9fK3gN5qZIQEfRrsEdobG+mbJTwqI2iB5CJytTE364VJR3sfH34EYQv 5CKm0+wuRl99z54EHC8qn7MzSfp1oR6OgaynmYmsm1CBT1bD8pY3DUDMK0jiJS0tU9k9 Avko89OdepsXYNH4jbJ/1HWgGUCCOG+2GBNHGLZtGgM9wItgbKXr+pQvmv+ol4akNDpO c+9VWBrguH9LmCL/iWssFiXTFK0kEiGOm/ZzUTjQ2dAvi42235qmqidxRmzaG2L0B2nj IISXeAQ0Jlhcevg1HMDgsP7r15fggzrkDqApur4YUHk4zEOgYvJ3vsS/M9gmFE8LtJNT eKug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=HVuEOoR+wue1PsE6NgQEDXqVtzCNpXUQrR4ExhNN8DI=; b=2Bcq4cIRs10Ceyd3ZJgeiyizbhCwyXXuUyClmYB7gfdfQ2PflAMhf7XluopqzMLmEu b4cIzUMjBGRFsVqEX/jstIHYRWv8Guh3/Q/5ZMRVBWln8tVFyQikIUJym+hZArnIImvH HUKBn2v44MSOtC9qqbYPY2t5gv49Yr7CTbY/QFLxeSvKMslVdPURLk01oO32xVwwclxN raa68kAKBlfUGfV8e8u/vRAD6T7UD3Q7nIbDrm5HNBiTSuH6XBAmX2BpyGxJ79ELiq3r g84etXjav+qvjzWsLiLVCs8ZK15Hk+80W2J6PA+9UC84gJAIH8hSUqgaeJ6N/HmauwjL Uwbw== X-Gm-Message-State: AOAM53359oltqt7hTsxZJaZPC+Ygo5vx8kOvoQZX0ZcGrnw8H3nrFTQE WWbovg2SkMUS5d0VZPJOY7/w0CAOmjNpZzLHLEAeYj6yruyWLZat X-Google-Smtp-Source: ABdhPJzuG/VZlGMQjZPxuJEl4Hd+y5PAOq+xXek/rmqON+rcdL5vqoeYjsQYnt0qCI/TfJ1kOVovL3euz8DBTi1ddn4= X-Received: by 2002:a05:6122:a10:: with SMTP id 16mr5070167vkn.1.1634978601575; Sat, 23 Oct 2021 01:43:21 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::a32; envelope-from=hongyi.zhao@gmail.com; helo=mail-vk1-xa32.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:134040 Archived-At: On Sat, Oct 23, 2021 at 3:33 PM Hongyi Zhao 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=E2=80=99t output results. > > Any hints for this problem? > > Regards > -- > Assoc. Prof. Hongyi Zhao > Theory and Simulation of Materials > Hebei Vocational University of Technology and Engineering > No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province