[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Add/remove an element into/from a cons.
From: |
Hongyi Zhao |
Subject: |
Re: Add/remove an element into/from a cons. |
Date: |
Tue, 26 Oct 2021 14:22:33 +0800 |
On Tue, Oct 26, 2021 at 2:17 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Tue, Oct 26, 2021 at 2:09 PM Tassilo Horn <tsdh@gnu.org> wrote:
> >
> > Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> >
> > >> > > How can I add/remove an element into/from a cons, taking the
> > >> > > following one as an example:
> > >> > >
> > >> > > ```emacs-lisp
> > >> > > (setq company-backends '((company-tabnine :separate company-capf
> > >> > > company-dabbrev company-keywords company-files company-ispell)))
> > >> > > ```
> > >> > >
> > >> > > How can I remove `company-ispell` from and re-add it into the
> > >> > > company-backends defined above?
> > >> >
> > >> > You can use `setf' with the place being the alist entry like this
> > >> > (company-backends replaced with th/test in my example):
> > >> >
> > >> > --8<---------------cut here---------------start------------->8---
> > >> > (setq th/test '(( company-tabnine :separate company-capf
> > >> > company-dabbrev
> > >> > company-keywords company-files company-ispell)))
> > >> >
> > >> > (let ((place (assoc 'company-tabnine th/test)))
> > >> > (setf place (remove 'company-ispell place)))
> > >> > --8<---------------cut here---------------end--------------->8---
> > >>
> > >> Yes. It does the trick:
> > >>
> > >> `C-j' (setq th/test '((company-tabnine :separate company-capf
> > >> company-dabbrev
> > >> company-keywords company-ispell company-files)))
> > >>
> > >> ;; ((company-tabnine :separate company-capf company-dabbrev
> > >> company-keywords company-ispell company-files))
> > >>
> > >>
> > >> `C-j' (setq th/test (let ((place (assoc 'company-tabnine th/test)))
> > >> (setf place (remove 'company-ispell place))))
> > >>
> > >> ;; (company-tabnine :separate company-capf company-dabbrev
> > >> company-keywords company-files)
> > >>
> > >> But how to add it back to the alist?
> > >
> > > I mean: But how to add it back to its original position in the list?
> >
> > This would add it again as the last element:
> >
> > --8<---------------cut here---------------start------------->8---
> > (let ((place (assoc 'company-tabnine th/test)))
> > (setf place (append place '(company-ispell))))
> > --8<---------------cut here---------------end--------------->8---
>
> Thanks. But the push doesn't work:
>
> (let ((place (assoc 'company-tabnine th/test)))
> (setf place (push place '(company-ispell))))
I also tried out the following method:
`C-j'
(let ((place (assoc 'company-tabnine th/test)))
(setf place (push 'company-ispell place)))
=>
;; (company-ispell company-tabnine :separate company-capf
company-dabbrev company-keywords company-files company-ispell)
> Debugger entered--Lisp error: (wrong-number-of-arguments (lambda
> (command &optional arg &rest ignored) "`company-mode' completion
> backend using Ispell." (interactive (list 'interactive)) (cond ((eql
> command 'interactive) (company-begin-backend 'company-ispell)) ((eql
> command 'prefix) (if (company-ispell-available) (progn
> (company-grab-word)))) ((eql command 'candidates) (let ((words
> (company-ispell--lookup-words arg ...)) (completion-ignore-case t))
> (if (string= arg "") words (all-completions arg words)))) ((eql
> command 'kind) 'text) ((eql command 'sorted) t) ((eql command
> 'ignore-case) 'keep-prefix))) 0)
> company-ispell()
> (let* ((v (company-ispell))) (\(setf\ quote\) (cons place 'v) v))
> (setq place (let* ((v (company-ispell))) (\(setf\ quote\) (cons place 'v)
> v)))
> (let ((place (assoc 'company-tabnine th/test))) (setq place (let*
> ((v (company-ispell))) (\(setf\ quote\) (cons place 'v) v))))
> (progn (let ((place (assoc 'company-tabnine th/test))) (setq place
> (let* ((v (company-ispell))) (\(setf\ quote\) (cons place 'v) v)))))
> elisp--eval-last-sexp(nil)
> eval-last-sexp(nil)
> funcall-interactively(eval-last-sexp nil)
> command-execute(eval-last-sexp)
>
> HZ
--
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
- Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/25
- Re: Add/remove an element into/from a cons., Tassilo Horn, 2021/10/26
- Re: Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/26
- Re: Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/26
- Re: Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/26
- Re: Add/remove an element into/from a cons., Tassilo Horn, 2021/10/26
- Re: Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/26
- Re: Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/26
- Re: Add/remove an element into/from a cons., Tassilo Horn, 2021/10/26
- Re: Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/26
- Re: Add/remove an element into/from a cons.,
Hongyi Zhao <=
- Re: Add/remove an element into/from a cons., Tassilo Horn, 2021/10/26
- Re: Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/26
- Re: Add/remove an element into/from a cons., Tassilo Horn, 2021/10/26
- Re: Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/26
- Re: Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/26
- Re: Add/remove an element into/from a cons., Tassilo Horn, 2021/10/26
- Re: Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/26
- Re: Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/27
- Re: Add/remove an element into/from a cons., Hongyi Zhao, 2021/10/27
- Re: Add/remove an element into/from a cons., Tassilo Horn, 2021/10/27