Is it possible to define file specific key-bindings in emacs? I suppose it would be possible to create a minor mode and have it loaded when the particular file is open but for only one key-binding that seems overkill.
相关问题
- Symbol's function definition is void: declare-
- How can I set the SVN password with Emacs 23.1 bui
- Emacs shell: save commit message
- emacs bind key to the insertion of another
- Emacs - set mark on edit location
相关文章
- In IntelliJ IDEA, how can I create a key binding t
- ess-rdired: I get this error “no ESS process is as
- Emacs/xterm color annoyance on Linux
- Pipe less to Emacs
- Capturing the output of “diff” with org-babel
- emacs terminal mode: how to copy and paste efficie
- How to permanently enable the hs-minor-mode in ema
- Pipe emacs shell output to a new buffer
It smells like you are doing things wrong --- that's my guess. If you have a particular file buffer for which a given key binding is appropriate, then define a mode especially for it and bind the key in that mode's keymap. Let the mode inherit from any other mode you like.
You don't really describe anything about your context: how do you access this file (
C-x C-f
something else)?, why only this file -- what is special about it? what is the key used for? So it is hard to give you any helpful advice.If you really want to have some key act differently for this particular file, then maybe define a command that visits the file (however you want to visit it) and then creates an overlay over all of its text, and uses the overlay property
keymap
to add your binding everywhere. This of course sounds pretty silly, but as it stands now, so does your question.Emacs works with buffers. Buffers are in modes. A file has little meaning in this context. Once the file is visited, its buffer is what you want to work with.
That's why @Barmar tried to answer in terms of a buffer and its mode. You apparently don't want this to be for a given mode, unless, I guess, the mode is specific to that one file. In that case, define a mode that applies (only) to that file.
Clarify your question and perhaps we will be able to help you more.
(Sounds like this might be an XY problem.)
If you combine the code to
local-set-key
and Buffer-locally overriding minor-mode key bindings in Emacs then you could end up with something like this:and then, as per Barmar's answer:
Note that minor mode maps take precedence over the local map.
Use
eval:
in the File Local Variables section:Setting up a minor mode and loading it automatically when opening the specific file is actually simpler than I thought.
The mode file is something along these lines:
It has to be put somewhere the .emacs will look into and the following line is to be added to the .emacs:
Finally, the followingblock should be added at the end of the file that should use the specific commands: