* Bind two commands to one key to toggle between them for the same local keymap.
@ 2021-10-22 5:42 Hongyi Zhao
2021-10-22 6:17 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-22 5:42 UTC (permalink / raw)
To: help-gnu-emacs
I installed company with use-package, and want to bind the "<tab>" key
to the following commands when the local keymaps are
company-search-map or company-active-map to toggle between them:
("<tab>" . company-search-candidates)
and
("<tab>" . company-search-abort)
If the company-search-candidates command is in active, then run
company-search-abort when hitting <tab>, and vice versa.
How can this be achieved?
Regards
--
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
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 5:42 Bind two commands to one key to toggle between them for the same local keymap Hongyi Zhao
@ 2021-10-22 6:17 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 7:34 ` Hongyi Zhao
0 siblings, 1 reply; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-22 6:17 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
> I installed company with use-package, and want to bind the
> "<tab>" key to the following commands when the local keymaps
> are company-search-map or company-active-map to toggle
> between them:
>
> ("<tab>" . company-search-candidates)
>
> and
>
> ("<tab>" . company-search-abort)
>
> If the company-search-candidates command is in active, then
> run company-search-abort when hitting <tab>, and vice versa.
If you have two (several) keymaps, set the key one by one to
whatever you want should happen.
If you have one (1) keymap ... set the key to a function that
branches on some condition and does different things based
on that.
Post the code here ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 6:17 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-22 7:34 ` Hongyi Zhao
2021-10-22 7:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 17:37 ` [External] : " Drew Adams
0 siblings, 2 replies; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-22 7:34 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Fri, Oct 22, 2021 at 2:20 PM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > I installed company with use-package, and want to bind the
> > "<tab>" key to the following commands when the local keymaps
> > are company-search-map or company-active-map to toggle
> > between them:
> >
> > ("<tab>" . company-search-candidates)
> >
> > and
> >
> > ("<tab>" . company-search-abort)
> >
> > If the company-search-candidates command is in active, then
> > run company-search-abort when hitting <tab>, and vice versa.
>
> If you have two (several) keymaps, set the key one by one to
> whatever you want should happen.
>
> If you have one (1) keymap ... set the key to a function that
> branches on some condition and does different things based
> on that.
>
> Post the code here ...
`C-h o company-search-mode RET' gives me the following explanation:
------------------
company-search-mode is an interactive Lisp closure in ‘company.el’.
(company-search-mode &optional ARG)
Search mode for completion candidates.
Don’t start this directly, use ‘company-search-candidates’ or
‘company-filter-candidates’.
This is a minor mode. If called interactively, toggle the
‘Company-Search mode’ mode. If the prefix argument is positive,
enable the mode, and if it is zero or negative, disable the mode.
If called from Lisp, toggle the mode if ARG is ‘toggle’. Enable
the mode if ARG is nil, omitted, or is a positive number.
Disable the mode if ARG is a negative number.
To check whether the minor mode is enabled in the current buffer,
evaluate ‘company-search-mode’.
The mode’s hook is called both when the mode is enabled and when
it is disabled.
------------------
So, I tried with the following use-package binding configuration, but
it doesn't work:
("<tab>" . (lamda () (if (company-search-mode) #'company-search-abort
#'company-search-candidates)))
What's the problem?
Regards,
HZ
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 7:34 ` Hongyi Zhao
@ 2021-10-22 7:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 7:57 ` Hongyi Zhao
2021-10-22 17:37 ` [External] : " Drew Adams
1 sibling, 1 reply; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-22 7:39 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
> ("<tab>" . (lamda () (if (company-search-mode) #'company-search-abort
> #'company-search-candidates)))
>
> What's the problem?
Several :)
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 7:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-22 7:57 ` Hongyi Zhao
2021-10-22 8:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-22 7:57 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Fri, Oct 22, 2021 at 3:40 PM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > ("<tab>" . (lamda () (if (company-search-mode) #'company-search-abort
> > #'company-search-candidates)))
> >
> > What's the problem?
>
> Several :)
I'm at the end of my rope :-(
HZ
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 7:57 ` Hongyi Zhao
@ 2021-10-22 8:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 9:15 ` Hongyi Zhao
0 siblings, 1 reply; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-22 8:33 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
>>> ("<tab>" . (lamda () (if (company-search-mode)
>>> #'company-search-abort
>>> #'company-search-candidates)))
>>>
>>> What's the problem?
>>
>> Several :)
>
> I'm at the end of my rope
Without knowing the situation ...
(require 'company)
(defun company-search-hz ()
(interactive)
(if (eq major-mode 'company-search-mode)
(company-search-abort)
(company-search-candidates) ))
(define-key company-mode-map "\t" #'company-search-hz)
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 8:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-22 9:15 ` Hongyi Zhao
2021-10-22 9:25 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 9:26 ` Hongyi Zhao
0 siblings, 2 replies; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-22 9:15 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Fri, Oct 22, 2021 at 4:34 PM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> >>> ("<tab>" . (lamda () (if (company-search-mode)
> >>> #'company-search-abort
> >>> #'company-search-candidates)))
> >>>
> >>> What's the problem?
> >>
> >> Several :)
> >
> > I'm at the end of my rope
>
> Without knowing the situation ...
>
> (require 'company)
>
> (defun company-search-hz ()
> (interactive)
> (if (eq major-mode 'company-search-mode)
> (company-search-abort)
> (company-search-candidates) ))
>
> (define-key company-mode-map "\t" #'company-search-hz)
Thank you for your idea. `company-search-mode' is a minor mode, and
according to the notes here [1], I changed your function to the
following:
(defun hz-company-search ()
(interactive)
(if (bound-and-true-p company-search-mode)
(company-search-abort)
(company-search-candidates)))
(define-key company-mode-map "\t" #'hz-company-search)
Based on my testing, it doesn't work as expected.
[1] https://stackoverflow.com/questions/10088168/how-to-check-whether-a-minor-mode-e-g-flymake-mode-is-on
HZ
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 9:15 ` Hongyi Zhao
@ 2021-10-22 9:25 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 9:46 ` Hongyi Zhao
2021-10-22 9:26 ` Hongyi Zhao
1 sibling, 1 reply; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-22 9:25 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
> Thank you for your idea. `company-search-mode' is a minor
> mode
Okay, my mistake, then just use the variable, i.e.
`company-search-mode'.
(if company-search-mode ... )
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 9:15 ` Hongyi Zhao
2021-10-22 9:25 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-22 9:26 ` Hongyi Zhao
2021-10-22 9:32 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 1 reply; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-22 9:26 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Fri, Oct 22, 2021 at 5:15 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Fri, Oct 22, 2021 at 4:34 PM Emanuel Berg via Users list for the
> GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
> >
> > Hongyi Zhao wrote:
> >
> > >>> ("<tab>" . (lamda () (if (company-search-mode)
> > >>> #'company-search-abort
> > >>> #'company-search-candidates)))
> > >>>
> > >>> What's the problem?
> > >>
> > >> Several :)
> > >
> > > I'm at the end of my rope
> >
> > Without knowing the situation ...
> >
> > (require 'company)
> >
> > (defun company-search-hz ()
> > (interactive)
> > (if (eq major-mode 'company-search-mode)
> > (company-search-abort)
> > (company-search-candidates) ))
> >
> > (define-key company-mode-map "\t" #'company-search-hz)
>
> Thank you for your idea. `company-search-mode' is a minor mode, and
> according to the notes here [1], I changed your function to the
> following:
>
> (defun hz-company-search ()
> (interactive)
> (if (bound-and-true-p company-search-mode)
> (company-search-abort)
> (company-search-candidates)))
>
> (define-key company-mode-map "\t" #'hz-company-search)
>
> Based on my testing, it doesn't work as expected.
I mean, it works differently from the behavior given by the following
use-packatge configuration:
(use-package company
:bind
(:map company-active-map
("<tab>" . company-search-candidates)
("<f1>" . company-search-abort)
:map company-search-map
("<tab>" . company-search-candidates)
("<f1>" . company-search-abort))
With the above configuration, "<tab>" and "<f1>" will call the
corresponding interactive Lisp closure correctly, but I have to use
two different keys.
HZ
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 9:26 ` Hongyi Zhao
@ 2021-10-22 9:32 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 9:40 ` Hongyi Zhao
0 siblings, 1 reply; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-22 9:32 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
>>>>>> ("<tab>" . (lamda () (if (company-search-mode)
>>>>>> #'company-search-abort
>>>>>> #'company-search-candidates)))
>>>>>>
>>>>>> What's the problem?
>>>>>
>>>>> Several :)
>>>>
>>> > I'm at the end of my rope
>>>
>>> Without knowing the situation ...
>>>
>>> (require 'company)
>>>
>>> (defun company-search-hz ()
>>> (interactive)
>>> (if (eq major-mode 'company-search-mode)
>>> (company-search-abort)
>>> (company-search-candidates) ))
>>>
>>> (define-key company-mode-map "\t" #'company-search-hz)
>>
>> Thank you for your idea. `company-search-mode' is a minor mode, and
>> according to the notes here [1], I changed your function to the
>> following:
>>
>> (defun hz-company-search ()
>> (interactive)
>> (if (bound-and-true-p company-search-mode)
>> (company-search-abort)
>> (company-search-candidates)))
>>
>> (define-key company-mode-map "\t" #'hz-company-search)
>>
>> Based on my testing, it doesn't work as expected.
>
> I mean, it works differently from the behavior given by the
> following use-packatge configuration:
>
> (use-package company
> :bind
> (:map company-active-map
> ("<tab>" . company-search-candidates)
> ("<f1>" . company-search-abort)
>
> :map company-search-map
> ("<tab>" . company-search-candidates)
> ("<f1>" . company-search-abort))
>
> With the above configuration, "<tab>" and "<f1>" will call
> the corresponding interactive Lisp closure correctly, but
> I have to use two different keys.
company-active-map ... that's yet another one!
Use 'C-h k' to see what happens ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 9:32 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-22 9:40 ` Hongyi Zhao
2021-10-22 9:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-22 9:40 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Fri, Oct 22, 2021 at 5:33 PM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
> company-active-map ... that's yet another one!
>
> Use 'C-h k' to see what happens ...
If the corresponding keymap is not activated, 'C-h k <tab>' or 'C-h k
<f1>' won't give the relevant info at all. I'm really stuck here. See
the following:
'C-h k <tab>':
TAB (translated from <tab>) runs the command indent-for-tab-command
(found in global-map), which is an interactive compiled Lisp function
in ‘indent.el’.
It is bound to TAB.
(indent-for-tab-command &optional ARG)
'C-h k <f1>': nothing is given.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 9:25 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-22 9:46 ` Hongyi Zhao
2021-10-22 9:52 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 9:55 ` Hongyi Zhao
0 siblings, 2 replies; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-22 9:46 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Fri, Oct 22, 2021 at 5:26 PM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > Thank you for your idea. `company-search-mode' is a minor
> > mode
>
> Okay, my mistake, then just use the variable, i.e.
> `company-search-mode'.
>
> (if company-search-mode ... )
I changed to the following code snippet, but got the same result:
(defun hz-company-search ()
(interactive)
(if company-search-mode
(company-search-abort)
(company-search-candidates)))
(define-key company-active-map "\t" #'hz-company-search)
(define-key company-search-map "\t" #'hz-company-search)
HZ
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 9:40 ` Hongyi Zhao
@ 2021-10-22 9:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 10:04 ` Hongyi Zhao
0 siblings, 1 reply; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-22 9:48 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
> If the corresponding keymap is not activated, 'C-h k <tab>'
> or 'C-h k <f1>' won't give the relevant info at all
That info is relevant to the current keymap.
To test if your function shows up, go to where the keymap is
that you want to change ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 9:46 ` Hongyi Zhao
@ 2021-10-22 9:52 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 10:02 ` Hongyi Zhao
2021-10-22 9:55 ` Hongyi Zhao
1 sibling, 1 reply; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-22 9:52 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
> I changed to the following code snippet, but got the same
> result:
>
> (defun hz-company-search ()
> (interactive)
> (if company-search-mode
> (company-search-abort)
> (company-search-candidates)))
>
> (define-key company-active-map "\t" #'hz-company-search)
> (define-key company-search-map "\t" #'hz-company-search)
Hm ... shouldn't it be `company-search-abort' in
`company-search-map'?
But if the function is correct it should work if/where these
maps are active ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 9:46 ` Hongyi Zhao
2021-10-22 9:52 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-22 9:55 ` Hongyi Zhao
1 sibling, 0 replies; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-22 9:55 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Fri, Oct 22, 2021 at 5:46 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Fri, Oct 22, 2021 at 5:26 PM Emanuel Berg via Users list for the
> GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
> >
> > Hongyi Zhao wrote:
> >
> > > Thank you for your idea. `company-search-mode' is a minor
> > > mode
> >
> > Okay, my mistake, then just use the variable, i.e.
> > `company-search-mode'.
> >
> > (if company-search-mode ... )
>
> I changed to the following code snippet, but got the same result:
>
> (defun hz-company-search ()
> (interactive)
> (if company-search-mode
> (company-search-abort)
> (company-search-candidates)))
>
> (define-key company-active-map "\t" #'hz-company-search)
> (define-key company-search-map "\t" #'hz-company-search)
I brought up the discussion here [1].
[1] https://github.com/company-mode/company-mode/discussions/1244
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 9:52 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-22 10:02 ` Hongyi Zhao
2021-10-22 11:04 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-22 10:02 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Fri, Oct 22, 2021 at 5:55 PM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > I changed to the following code snippet, but got the same
> > result:
> >
> > (defun hz-company-search ()
> > (interactive)
> > (if company-search-mode
> > (company-search-abort)
> > (company-search-candidates)))
> >
> > (define-key company-active-map "\t" #'hz-company-search)
> > (define-key company-search-map "\t" #'hz-company-search)
>
> Hm ... shouldn't it be `company-search-abort' in
> `company-search-map'?
The following version was tried but got the same behavior:
(defun hz-company-search ()
(interactive)
(if company-search-abort
(company-search-abort)
(company-search-candidates)))
(define-key company-active-map "\t" #'hz-company-search)
(define-key company-search-map "\t" #'hz-company-search)
> But if the function is correct it should work if/where these
> maps are active ...
I'm puzzled by it.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 9:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-22 10:04 ` Hongyi Zhao
0 siblings, 0 replies; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-22 10:04 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Fri, Oct 22, 2021 at 5:49 PM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > If the corresponding keymap is not activated, 'C-h k <tab>'
> > or 'C-h k <f1>' won't give the relevant info at all
>
> That info is relevant to the current keymap.
>
> To test if your function shows up, go to where the keymap is
> that you want to change ...
The keymap is enabled when company popup the completion frame and
active in it. I don't know how to test it.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 10:02 ` Hongyi Zhao
@ 2021-10-22 11:04 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 11:22 ` Hongyi Zhao
0 siblings, 1 reply; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-22 11:04 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
> (defun hz-company-search ()
> (interactive)
> (if company-search-abort
> (company-search-abort)
> (company-search-candidates)))
>
> (define-key company-active-map "\t" #'hz-company-search)
> (define-key company-search-map "\t" #'hz-company-search)
That's a function so if anything it should be
(company-search-abort) ... but it doesn't seem to work like
that, in the `if' setting you want something that always is, or
can be interpreted as, t or nil ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 11:04 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-22 11:22 ` Hongyi Zhao
2021-10-22 11:30 ` Hongyi Zhao
2021-10-23 18:01 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 2 replies; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-22 11:22 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Fri, Oct 22, 2021 at 7:05 PM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > (defun hz-company-search ()
> > (interactive)
> > (if company-search-abort
> > (company-search-abort)
> > (company-search-candidates)))
> >
> > (define-key company-active-map "\t" #'hz-company-search)
> > (define-key company-search-map "\t" #'hz-company-search)
>
> That's a function so if anything it should be
> (company-search-abort)
Tried the following, but doesn't work again:
(defun hz-company-search ()
(interactive)
(if (company-search-abort)
(company-search-abort)
(company-search-candidates)))
> ... but it doesn't seem to work like
> that, in the `if' setting you want something that always is, or
> can be interpreted as, t or nil ...
What's the trick?
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 11:22 ` Hongyi Zhao
@ 2021-10-22 11:30 ` Hongyi Zhao
2021-10-23 18:01 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 0 replies; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-22 11:30 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Fri, Oct 22, 2021 at 7:22 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Fri, Oct 22, 2021 at 7:05 PM Emanuel Berg via Users list for the
> GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
> >
> > Hongyi Zhao wrote:
> >
> > > (defun hz-company-search ()
> > > (interactive)
> > > (if company-search-abort
> > > (company-search-abort)
> > > (company-search-candidates)))
> > >
> > > (define-key company-active-map "\t" #'hz-company-search)
> > > (define-key company-search-map "\t" #'hz-company-search)
> >
> > That's a function so if anything it should be
> > (company-search-abort)
>
> Tried the following, but doesn't work again:
>
> (defun hz-company-search ()
> (interactive)
> (if (company-search-abort)
> (company-search-abort)
> (company-search-candidates)))
>
> > ... but it doesn't seem to work like
> > that, in the `if' setting you want something that always is, or
> > can be interpreted as, t or nil ...
>
> What's the trick?
I also tried the following, but still failed:
(defun hz-company-search ()
(interactive)
(cond ((bound-and-true-p company-search-abort) (company-search-candidates))
((bound-and-true-p company-search-candidates) (company-search-abort))
))
^ permalink raw reply [flat|nested] 44+ messages in thread
* RE: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 7:34 ` Hongyi Zhao
2021-10-22 7:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-22 17:37 ` Drew Adams
2021-10-23 1:45 ` Hongyi Zhao
1 sibling, 1 reply; 44+ messages in thread
From: Drew Adams @ 2021-10-22 17:37 UTC (permalink / raw)
To: Hongyi Zhao, Emanuel Berg, help-gnu-emacs
> I tried with the following use-package binding configuration, but
> it doesn't work:
>
> ("<tab>" . (lamda () (if (company-search-mode) #'company-search-
> abort
> #'company-search-candidates)))
To start with (I see you corrected these things
later, but just in case the reminder helps someone):
1. lambda vs lamda
2. Your anonymous function isn't a command.
It needs `interactive'.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 17:37 ` [External] : " Drew Adams
@ 2021-10-23 1:45 ` Hongyi Zhao
2021-10-23 8:18 ` Michael Heerdegen
2021-10-23 8:57 ` Kevin Vigouroux via Users list for the GNU Emacs text editor
0 siblings, 2 replies; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-23 1:45 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs, Emanuel Berg
On Sat, Oct 23, 2021 at 1:38 AM Drew Adams <drew.adams@oracle.com> wrote:
>
> > I tried with the following use-package binding configuration, but
> > it doesn't work:
> >
> > ("<tab>" . (lamda () (if (company-search-mode) #'company-search-
> > abort
> > #'company-search-candidates)))
>
> To start with (I see you corrected these things
> later, but just in case the reminder helps someone):
>
> 1. lambda vs lamda
>
> 2. Your anonymous function isn't a command.
> It needs `interactive'.
Thank you for your correction. I've tried the following but still
can't get the same effect as using two different keys:
(use-package company
:bind
(:map company-active-map
;; ("<tab>" . company-search-candidates)
;; ("<f1>" . company-search-abort)
("<tab>" . (lambda ()
(interactive)
(if (company--active-p) #'company-search-abort
#'company-search-candidates)))
:map company-search-map
;; ("<tab>" . company-search-candidates)
;; ("<f1>" . company-search-abort)
("<tab>" . (lambda ()
(interactive)
(if (company-search-mode) #'company-search-abort
#'company-search-candidates)))))
Dmitry Gutov told me the following fact [1]:
company-search-candidates is incremental (like isearch), so it's not
going to exit when you call it a second time.
You can write your own command easily enough, though.
But I still can’t find an effective solution that uses only one key to
get exactly the same behavior given by two separate keys.
[1] https://github.com/company-mode/company-mode/discussions/1244#discussioncomment-1521667
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
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-23 1:45 ` Hongyi Zhao
@ 2021-10-23 8:18 ` Michael Heerdegen
2021-10-23 8:48 ` Hongyi Zhao
2021-10-23 8:57 ` Kevin Vigouroux via Users list for the GNU Emacs text editor
1 sibling, 1 reply; 44+ messages in thread
From: Michael Heerdegen @ 2021-10-23 8:18 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> ("<tab>" . (lambda ()
> (interactive)
> (if (company--active-p) #'company-search-abort
> #'company-search-candidates)))
Your lambda only returns a command name, but it doesn't call any
command. It will just do "nothing".
Michael.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-23 8:18 ` Michael Heerdegen
@ 2021-10-23 8:48 ` Hongyi Zhao
2021-10-23 9:20 ` Michael Heerdegen
0 siblings, 1 reply; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-23 8:48 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
On Sat, Oct 23, 2021 at 4:20 PM Michael Heerdegen
<michael_heerdegen@web.de> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > ("<tab>" . (lambda ()
> > (interactive)
> > (if (company--active-p) #'company-search-abort
> > #'company-search-candidates)))
>
> Your lambda only returns a command name, but it doesn't call any
> command. It will just do "nothing".
I'm in a confusion for this problem. The fix?
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-23 1:45 ` Hongyi Zhao
2021-10-23 8:18 ` Michael Heerdegen
@ 2021-10-23 8:57 ` Kevin Vigouroux via Users list for the GNU Emacs text editor
1 sibling, 0 replies; 44+ messages in thread
From: Kevin Vigouroux via Users list for the GNU Emacs text editor @ 2021-10-23 8:57 UTC (permalink / raw)
To: help-gnu-emacs
A new interactive function must be designed for this, because the
problem is not related to bindings.
--
Best regards,
Kevin Vigouroux
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-23 8:48 ` Hongyi Zhao
@ 2021-10-23 9:20 ` Michael Heerdegen
2021-10-23 11:58 ` Hongyi Zhao
0 siblings, 1 reply; 44+ messages in thread
From: Michael Heerdegen @ 2021-10-23 9:20 UTC (permalink / raw)
To: Hongyi Zhao; +Cc: help-gnu-emacs
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> > Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> >
> > > ("<tab>" . (lambda ()
> > > (interactive)
> > > (if (company--active-p) #'company-search-abort
> > > #'company-search-candidates)))
> >
> > Your lambda only returns a command name, but it doesn't call any
> > command. It will just do "nothing".
>
> I'm in a confusion for this problem. The fix?
If it's not obvious to you why this does nothing, you need to learn more
basics. Let's name the command:
(defun my-command ()
(interactive)
(if (company--active-p) #'company-search-abort
#'company-search-candidates))
When you eval that definition and do M-x my-command, what would you
expect to happen?
Michael.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-23 9:20 ` Michael Heerdegen
@ 2021-10-23 11:58 ` Hongyi Zhao
2021-10-23 12:07 ` Michael Heerdegen
0 siblings, 1 reply; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-23 11:58 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
On Sat, Oct 23, 2021 at 5:20 PM Michael Heerdegen
<michael_heerdegen@web.de> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > > Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> > >
> > > > ("<tab>" . (lambda ()
> > > > (interactive)
> > > > (if (company--active-p) #'company-search-abort
> > > > #'company-search-candidates)))
> > >
> > > Your lambda only returns a command name, but it doesn't call any
> > > command. It will just do "nothing".
> >
> > I'm in a confusion for this problem. The fix?
>
> If it's not obvious to you why this does nothing, you need to learn more
> basics. Let's name the command:
>
> (defun my-command ()
> (interactive)
> (if (company--active-p) #'company-search-abort
> #'company-search-candidates))
>
> When you eval that definition and do M-x my-command, what would you
> expect to happen?
I changed to the following form, but it still does nothing:
(defun my-command ()
(interactive)
(if (company--active-p) (company-search-abort)
(company-search-candidates)))
HZ
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-23 11:58 ` Hongyi Zhao
@ 2021-10-23 12:07 ` Michael Heerdegen
2021-10-23 12:24 ` Hongyi Zhao
0 siblings, 1 reply; 44+ messages in thread
From: Michael Heerdegen @ 2021-10-23 12:07 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> I changed to the following form, but it still does nothing:
>
> (defun my-command ()
> (interactive)
> (if (company--active-p) (company-search-abort)
> (company-search-candidates)))
Is your command called at all?
Michael.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-23 12:07 ` Michael Heerdegen
@ 2021-10-23 12:24 ` Hongyi Zhao
2021-10-23 12:50 ` Michael Heerdegen
0 siblings, 1 reply; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-23 12:24 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 424 bytes --]
On Sat, Oct 23, 2021 at 8:07 PM Michael Heerdegen
<michael_heerdegen@web.de> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > I changed to the following form, but it still does nothing:
> >
> > (defun my-command ()
> > (interactive)
> > (if (company--active-p) (company-search-abort)
> > (company-search-candidates)))
>
> Is your command called at all?
See the attached file for more detailed info.
HZ
[-- Attachment #2: lambda-function.png --]
[-- Type: image/png, Size: 64889 bytes --]
[-- Attachment #3: separate-keybinding.png --]
[-- Type: image/png, Size: 54398 bytes --]
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-23 12:24 ` Hongyi Zhao
@ 2021-10-23 12:50 ` Michael Heerdegen
2021-10-23 13:17 ` Hongyi Zhao
0 siblings, 1 reply; 44+ messages in thread
From: Michael Heerdegen @ 2021-10-23 12:50 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> > Is your command called at all?
>
> See the attached file for more detailed info.
Sorry, I don't use company. Does that mean "yes" or "no"? That bit of
information tells me more than "example doesn't work as expected".
Michael.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-23 12:50 ` Michael Heerdegen
@ 2021-10-23 13:17 ` Hongyi Zhao
2021-10-23 21:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-23 13:17 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
On Sat, Oct 23, 2021 at 8:51 PM Michael Heerdegen
<michael_heerdegen@web.de> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > > Is your command called at all?
> >
> > See the attached file for more detailed info.
>
> Sorry, I don't use company. Does that mean "yes" or "no"? That bit of
> information tells me more than "example doesn't work as expected".
As you can see, the lambda function based method doesn't take effect
for the company-search-mode, i.e., the candidates list hasn't been
searched incrementally, as the separated key binding does.
HZ
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-22 11:22 ` Hongyi Zhao
2021-10-22 11:30 ` Hongyi Zhao
@ 2021-10-23 18:01 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-24 0:32 ` Hongyi Zhao
1 sibling, 1 reply; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-23 18:01 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
>> That's a function so if anything it should be
>> (company-search-abort)
>
> Tried the following, but doesn't work again:
>
> (defun hz-company-search ()
> (interactive)
> (if (company-search-abort)
> (company-search-abort)
> (company-search-candidates)))
>
>> ... but it doesn't seem to work like that, in the `if'
>> setting you want something that always is, or can be
>> interpreted as, t or nil ...
>
> What's the trick?
I'm not aware of a general method - read the documentation,
maybe - but in this case you can just type in in the source
buffer and evaluate it, then you see that it isn't what you
look for.
(company-search-abort)
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [External] : Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-23 13:17 ` Hongyi Zhao
@ 2021-10-23 21:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-23 21:56 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
>> Sorry, I don't use company. Does that mean "yes" or "no"?
>> That bit of information tells me more than "example doesn't
>> work as expected".
>
> As you can see, the lambda function based method doesn't
> take effect for the company-search-mode, i.e., the
> candidates list hasn't been searched incrementally, as the
> separated key binding does.
Write a dummy function, see if it gets called at all ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-23 18:01 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-24 0:32 ` Hongyi Zhao
2021-10-24 1:17 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-24 9:03 ` Michael Heerdegen
0 siblings, 2 replies; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-24 0:32 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Sun, Oct 24, 2021 at 2:01 AM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> >> That's a function so if anything it should be
> >> (company-search-abort)
> >
> > Tried the following, but doesn't work again:
> >
> > (defun hz-company-search ()
> > (interactive)
> > (if (company-search-abort)
> > (company-search-abort)
> > (company-search-candidates)))
> >
> >> ... but it doesn't seem to work like that, in the `if'
> >> setting you want something that always is, or can be
> >> interpreted as, t or nil ...
> >
> > What's the trick?
>
> I'm not aware of a general method - read the documentation,
> maybe - but in this case you can just type in in the source
> buffer and evaluate it, then you see that it isn't what you
> look for.
>
> (company-search-abort)
`C-x C-e` the above command gives the following:
if: Company not in search mode
HZ
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-24 0:32 ` Hongyi Zhao
@ 2021-10-24 1:17 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-24 2:32 ` Hongyi Zhao
2021-10-24 9:03 ` Michael Heerdegen
1 sibling, 1 reply; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-24 1:17 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
>> (company-search-abort)
>
> `C-x C-e` the above command gives the following:
>
> if: Company not in search mode
So not useful as the `if' COND ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-24 1:17 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-24 2:32 ` Hongyi Zhao
2021-10-24 5:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-24 2:32 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Sun, Oct 24, 2021 at 9:20 AM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> >> (company-search-abort)
> >
> > `C-x C-e` the above command gives the following:
> >
> > if: Company not in search mode
>
> So not useful as the `if' COND ...
Not sure what your actual suggestion is.
HZ
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-24 2:32 ` Hongyi Zhao
@ 2021-10-24 5:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-24 5:39 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
>>>> (company-search-abort)
>>>
>>> `C-x C-e` the above command gives the following:
>>>
>>> if: Company not in search mode
>>
>> So not useful as the `if' COND ...
>
> Not sure what your actual suggestion is.
It won't work with `if' ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-24 0:32 ` Hongyi Zhao
2021-10-24 1:17 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-24 9:03 ` Michael Heerdegen
2021-10-25 14:52 ` Hongyi Zhao
1 sibling, 1 reply; 44+ messages in thread
From: Michael Heerdegen @ 2021-10-24 9:03 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> > > (defun hz-company-search ()
> > > (interactive)
> > > (if (company-search-abort)
> > > (company-search-abort)
> > > (company-search-candidates)))
Your test obviously raises an error. Find one that works.
Michael.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-24 9:03 ` Michael Heerdegen
@ 2021-10-25 14:52 ` Hongyi Zhao
2021-10-25 15:10 ` Michael Heerdegen
2021-10-25 17:54 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 2 replies; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-25 14:52 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
On Sun, Oct 24, 2021 at 5:03 PM Michael Heerdegen
<michael_heerdegen@web.de> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > > > (defun hz-company-search ()
> > > > (interactive)
> > > > (if (company-search-abort)
> > > > (company-search-abort)
> > > > (company-search-candidates)))
>
> Your test obviously raises an error. Find one that works.
Thank you for your comment. I checked the definitions of these two functions:
```emacs-lisp
(defun company-search-abort ()
"Abort searching the completion candidates."
(interactive)
(company--search-assert-enabled)
(company-search-mode 0)
(company-set-selection company--search-old-selection t)
(setq company-selection-changed company--search-old-changed))
(defun company-search-candidates ()
"Start searching the completion candidates incrementally.
\\<company-search-map>Search can be controlled with the commands:
- `company-search-repeat-forward' (\\[company-search-repeat-forward])
- `company-search-repeat-backward' (\\[company-search-repeat-backward])
- `company-search-abort' (\\[company-search-abort])
- `company-search-delete-char' (\\[company-search-delete-char])
Regular characters are appended to the search string.
Customize `company-search-regexp-function' to change how the input
is interpreted when searching.
The command `company-search-toggle-filtering'
(\\[company-search-toggle-filtering])
uses the search string to filter the completion candidates."
(interactive)
(company-search-mode 1))
```
And figured out the following solution:
```emacs-lisp
(use-package company
:bind (
:map company-active-map
("<tab>" . (lambda ()
(interactive)
(if company-search-mode (company-search-abort)
(company-search-candidates))))
:map company-search-map
("<tab>" . (lambda ()
(interactive)
(if company-search-mode (company-search-abort)
(company-search-candidates))))
)
```
HZ
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-25 14:52 ` Hongyi Zhao
@ 2021-10-25 15:10 ` Michael Heerdegen
2021-10-25 17:51 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-25 17:54 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 1 reply; 44+ messages in thread
From: Michael Heerdegen @ 2021-10-25 15:10 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> [...]
> And figured out the following solution:
>
> ```emacs-lisp
> (use-package company
> :bind (
> :map company-active-map
> ("<tab>" . (lambda ()
> (interactive)
> (if company-search-mode (company-search-abort)
> (company-search-candidates))))
>
> :map company-search-map
> ("<tab>" . (lambda ()
> (interactive)
> (if company-search-mode (company-search-abort)
> (company-search-candidates))))
> )
And it does what you want?
If you are done you can factor out the two identical interactive lambdas
as a named function (using `defun').
Michael.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-25 15:10 ` Michael Heerdegen
@ 2021-10-25 17:51 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-26 1:44 ` Hongyi Zhao
0 siblings, 1 reply; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-25 17:51 UTC (permalink / raw)
To: help-gnu-emacs
Michael Heerdegen wrote:
> And it does what you want?
>
> If you are done you can factor out the two identical
> interactive lambdas as a named function (using `defun').
And put (company-search-abort) on its own line ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-25 14:52 ` Hongyi Zhao
2021-10-25 15:10 ` Michael Heerdegen
@ 2021-10-25 17:54 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-26 1:49 ` Hongyi Zhao
1 sibling, 1 reply; 44+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-25 17:54 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
> (company-set-selection company--search-old-selection t)
> (setq company-selection-changed company--search-old-changed))
You have to do that manually?
> :map company-search-map
> ("<tab>" . (lambda ()
> (interactive)
> (if company-search-mode (company-search-abort)
> (company-search-candidates))))
Yeah, but that looks weird ... the map is like 1/3 a mode.
You have to check for the major-mode now in its own map?
I wrote one major mode ...
There it looks like this only.
(defvar fpscalc-mode-map
(let ((the-map (make-keymap)))
(define-key the-map "\t" 'newline-and-indent)
the-map)
"`fpscalc-mode' keymap.")
Okay not quite 1/3 ...
https://dataswamp.org/~incal/fps/fpscalc.el
https://dataswamp.org/~incal/fps/fpscalc.png <-- cool B)
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-25 17:51 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-26 1:44 ` Hongyi Zhao
0 siblings, 0 replies; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-26 1:44 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Tue, Oct 26, 2021 at 1:57 AM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Michael Heerdegen wrote:
>
> > And it does what you want?
> >
> > If you are done you can factor out the two identical
> > interactive lambdas as a named function (using `defun').
>
> And put (company-search-abort) on its own line ...
(defun hz-company-search-toggle ()
(interactive)
(if company-search-mode
(company-search-abort)
(company-search-candidates)))
HZ
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Bind two commands to one key to toggle between them for the same local keymap.
2021-10-25 17:54 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-26 1:49 ` Hongyi Zhao
0 siblings, 0 replies; 44+ messages in thread
From: Hongyi Zhao @ 2021-10-26 1:49 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On Tue, Oct 26, 2021 at 2:03 AM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > (company-set-selection company--search-old-selection t)
> > (setq company-selection-changed company--search-old-changed))
>
> You have to do that manually?
This is the code provided in the company-mode package:
https://github.com/company-mode/company-mode/blob/811beeade86669e20da35efed5b00de6a5e305ab/company.el#L2343
> > :map company-search-map
> > ("<tab>" . (lambda ()
> > (interactive)
> > (if company-search-mode (company-search-abort)
> > (company-search-candidates))))
>
> Yeah, but that looks weird ...
As I've told, it really represents the expected behavior.
> the map is like 1/3 a mode.
> You have to check for the major-mode now in its own map?
I'm really puzzled by your comments and the following code snippet.
> I wrote one major mode ...
>
> There it looks like this only.
>
> (defvar fpscalc-mode-map
> (let ((the-map (make-keymap)))
> (define-key the-map "\t" 'newline-and-indent)
> the-map)
> "`fpscalc-mode' keymap.")
>
> Okay not quite 1/3 ...
>
> https://dataswamp.org/~incal/fps/fpscalc.el
>
> https://dataswamp.org/~incal/fps/fpscalc.png <-- cool B)
>
> --
> underground experts united
> https://dataswamp.org/~incal
>
>
^ permalink raw reply [flat|nested] 44+ messages in thread
end of thread, other threads:[~2021-10-26 1:49 UTC | newest]
Thread overview: 44+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-22 5:42 Bind two commands to one key to toggle between them for the same local keymap Hongyi Zhao
2021-10-22 6:17 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 7:34 ` Hongyi Zhao
2021-10-22 7:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 7:57 ` Hongyi Zhao
2021-10-22 8:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 9:15 ` Hongyi Zhao
2021-10-22 9:25 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 9:46 ` Hongyi Zhao
2021-10-22 9:52 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 10:02 ` Hongyi Zhao
2021-10-22 11:04 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 11:22 ` Hongyi Zhao
2021-10-22 11:30 ` Hongyi Zhao
2021-10-23 18:01 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-24 0:32 ` Hongyi Zhao
2021-10-24 1:17 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-24 2:32 ` Hongyi Zhao
2021-10-24 5:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-24 9:03 ` Michael Heerdegen
2021-10-25 14:52 ` Hongyi Zhao
2021-10-25 15:10 ` Michael Heerdegen
2021-10-25 17:51 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-26 1:44 ` Hongyi Zhao
2021-10-25 17:54 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-26 1:49 ` Hongyi Zhao
2021-10-22 9:55 ` Hongyi Zhao
2021-10-22 9:26 ` Hongyi Zhao
2021-10-22 9:32 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 9:40 ` Hongyi Zhao
2021-10-22 9:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-22 10:04 ` Hongyi Zhao
2021-10-22 17:37 ` [External] : " Drew Adams
2021-10-23 1:45 ` Hongyi Zhao
2021-10-23 8:18 ` Michael Heerdegen
2021-10-23 8:48 ` Hongyi Zhao
2021-10-23 9:20 ` Michael Heerdegen
2021-10-23 11:58 ` Hongyi Zhao
2021-10-23 12:07 ` Michael Heerdegen
2021-10-23 12:24 ` Hongyi Zhao
2021-10-23 12:50 ` Michael Heerdegen
2021-10-23 13:17 ` Hongyi Zhao
2021-10-23 21:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-23 8:57 ` Kevin Vigouroux via Users list for the GNU Emacs text editor
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.