[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Insert one of the flags automatically with tab completion.
From: |
Hongyi Zhao |
Subject: |
Re: Insert one of the flags automatically with tab completion. |
Date: |
Sat, 23 Oct 2021 14:10:10 +0800 |
On Sat, Oct 23, 2021 at 1:07 PM Hongyi Zhao <hongyi.zhao@gmail.com> 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
- Insert one of the flags automatically with tab completion., Hongyi Zhao, 2021/10/23
- Re: Insert one of the flags automatically with tab completion.,
Hongyi Zhao <=
- Re: Insert one of the flags automatically with tab completion., Emanuel Berg, 2021/10/23
- Re: Insert one of the flags automatically with tab completion., Hongyi Zhao, 2021/10/24
- Re: Insert one of the flags automatically with tab completion., Emanuel Berg, 2021/10/24
- Re: Insert one of the flags automatically with tab completion., Hongyi Zhao, 2021/10/25
- Re: Insert one of the flags automatically with tab completion., Emanuel Berg, 2021/10/26
- Re: Insert one of the flags automatically with tab completion., Hongyi Zhao, 2021/10/26
- Re: Insert one of the flags automatically with tab completion., Hongyi Zhao, 2021/10/24