[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Add/remove an element into/from a cons.
From: |
Tassilo Horn |
Subject: |
Re: Add/remove an element into/from a cons. |
Date: |
Tue, 26 Oct 2021 08:08:01 +0200 |
User-agent: |
mu4e 1.7.4; emacs 29.0.50 |
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---
Bye,
Tassilo
- 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 <=
- 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., 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