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: Insert one of the flags automatically with tab completion. Date: Sat, 23 Oct 2021 14:10:10 +0800 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11290"; 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 08:11:48 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 1meAFv-0002kg-Rq for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 23 Oct 2021 08:11:47 +0200 Original-Received: from localhost ([::1]:36996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meAFt-0000NY-VW for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 23 Oct 2021 02:11:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meAEd-00006g-Dz for help-gnu-emacs@gnu.org; Sat, 23 Oct 2021 02:10:27 -0400 Original-Received: from mail-ua1-x935.google.com ([2607:f8b0:4864:20::935]:37828) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1meAEZ-0001sS-TZ for help-gnu-emacs@gnu.org; Sat, 23 Oct 2021 02:10:27 -0400 Original-Received: by mail-ua1-x935.google.com with SMTP id f4so11783867uad.4 for ; Fri, 22 Oct 2021 23:10: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; bh=CaraZRzNC4ALRRqsWlIY/eT1majHxbkEy6beQm3QXIM=; b=GR+PwFchHvc8WgbnacPEdk2Urb7SPpfqoBOlcijL4lzgKypE4RjUlHc/hpMwqzVWaP wHl7GjWZVgVSaIhd0ur2Cn7ZhIU9KqkBzNee9DFx6K69vq9+13XCNKUURiWXWFjIIRSS cT0Arb50u8H1siLGjz4XHsXtSU7w4l3JRDb3Ghy6UNnznymkXm3QN2ufdYLOo6t4UGYT p+d5mgkLMTWdZp8H6SUprbbltd5ki4xR2mnzbo91Isim6WQIqexE+QuaMSxN4tc2PkY5 K5++eGk7Frxp5TcvvxcHoD101waNyyLqn5upyKa7dx5wybPvX58Ihv7X+JCuWVWTmN7H /wEg== 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; bh=CaraZRzNC4ALRRqsWlIY/eT1majHxbkEy6beQm3QXIM=; b=EiY4ORl8B3p3bZCvXe007HibcswnDw6UF8NmWw/OFxmMro3ESSOSn/9MqZ5aeakUQF WrJP1Xv/Q3+Tb70T4IIi379f8raVsUVA7t2Dbzxs+Hrjys974FOjsFyrt/7gf5I1ioCi zZkHFWAbDiLKo27DaXcqBMFir0hap0/MM8z+9M5HtcmkauYOGlDClYf7NTKsvfNl0oca pC7Fi4r8l+tJcwoXsRxcRS7iyM/+6IjLFJBGtcHYBhPDIg78QGpyUlyLKG51R4+12cvn Ny7cDvodkUkSfthJ+sUE4GoiQr0ooHce56ykl3HxHvUV99YrzdeQrD0NhZNl4guVmuXV RTyw== X-Gm-Message-State: AOAM532rQb56e/Yg+r0yPf58NN/H3yxV9m+S1YcaUifUUgbtTrbgtS/0 WFfH7oPJTYy5CtNF+1jOverdkTZPUKwz9NkYNasfHwQEGvFSPBR6 X-Google-Smtp-Source: ABdhPJyLkQuhvIicWt1gZLDU+E/k8MchC3XmxVTHlqJL8lC6XA7She8DTjWM8DQZk9N7zMe1vmJ5wePP1HmC6Z4FK30= X-Received: by 2002:a67:a60c:: with SMTP id p12mr5185597vse.25.1634969421912; Fri, 22 Oct 2021 23:10:21 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::935; envelope-from=hongyi.zhao@gmail.com; helo=mail-ua1-x935.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:134034 Archived-At: On Sat, Oct 23, 2021 at 1:07 PM Hongyi Zhao wrote: > > I noticed the following function defined here[1]: > > (defun pw-ATOMIC_POSITIONS () > (interactive) > (let ((flag (read-string "Flags: { alat | bohr | angstrom | crystal > | crystal_sg } "))) > (insert "ATOMIC_POSITIONS " flag)) > (newline 1) > ) > > The above function can only prompt the user to insert one of the flags > manually. But I want to insert one of the flags automatically with tab > completion. Any hints for achieving this enhancement? > > [1] https://github.com/QEF/q-e/blob/03a7fa640903173662b24e4c30e520c9beaba16d/GUI/QE-modes/qe-modes/qe-funcs.el#L1966 I came up with two solutions: 1. by ido-completing-read ;; http://ergoemacs.org/emacs/elisp_idioms_prompting_input.html (require 'ido) (defun my-pw-ATOMIC_POSITIONS1 () (interactive) (let ((flag '("alat" "bohr" "angstrom" "crystal" "crystal_sg"))) (insert "ATOMIC_POSITIONS " (ido-completing-read "Select the flag: " flag))) (newline 1)) 2. by completing-read ;; https://stackoverflow.com/questions/19772394/elisp-function-select-argument-from-list (defun my-pw-ATOMIC_POSITIONS2 () (interactive (list (insert "ATOMIC_POSITIONS " (completing-read "Select the flag: " '(("alat" 1) ("bohr" 2) ("angstrom" 3) ("crystal" 4) ("crystal_sg" 5) ) nil t "")))) (newline 1)) HZ