help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to bind isearch-repeat-forward to F3 in a certain mode only?


From: Marcin Borkowski
Subject: Re: How to bind isearch-repeat-forward to F3 in a certain mode only?
Date: Mon, 27 Jul 2015 23:13:55 +0200

On 2015-07-24, at 14:53, Michael Heerdegen <michael_heerdegen@web.de> wrote:

> Marcin Borkowski <mbork@mbork.pl> writes:
>
>> ,----
>> | (my-mode)
>> | (make-local-variable 'isearch-mode-map)
>> | (define-key isearch-mode-map (kbd "<F3>") #'isearch-repeat-forward)
>> `----
>>
>> but to no avail.  Inspecting `isearch-mode-map' implies that it was in
>> fact changed globally.  Pressing F3 while in isearch, though, starts
>> recording a keyboard macro anyway (both in my-mode and outside it).
>
> Your approach seems reasonable.  There are two errors in your code
> however:

Thanks for your response!

> 1. (kbd "<F3>") obviously doesn't return the key sequence you want.  I
> don't use `kbd'; I would just use [f3] instead.

Something is strange here.

(equal [f3] [f3]) => t
(equal [f3] [F3]) => nil
(equal (kbd "<f3>") [f3]) => t
(equal (kbd "<f3>") (kbd "<F3>")) => nil
(equal (kbd "<F3>") [F3]) => t
(kbd "<f3>") => [f3]
(kbd "<F3>") => [F3]
(kbd "<S-f3>") => [S-f3]
(kbd "<S-F3>") => [S-F3]
(equal [S-f3] [F3]) => nil

So, what is [F3] exactly and how it differs from [f3]?

> 2. Your change is "globally visible" because you missed that in Lisp,
> variables reference lists by reference, not by value.  Keymaps are lists
> in Elisp.
>
> So, in your code, you create a new (local) binding, but that binding
> still refers to the same object.  Use `copy-keymap' to fix that.  So at
> the end you would have something like
>
> (setq-local isearch-mode-map (copy-keymap isearch-mode-map))
> (define-key isearch-mode-map [f3] #'isearch-repeat-forward)
>
> You can do that in your `my-mode-hook' of course.

Do I get it right that I should be careful to execute those lines
exactly once per each buffer in my-mode?  Is there any reason to put in
in the hook and not in the command which will create that buffer and
enter that mode?

> Regards,
>
> Michael.

TIA,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



reply via email to

[Prev in Thread] Current Thread [Next in Thread]