English 中文(简体)
Custom Emacs key bindings are not working
原标题:

The key bindings I ve defined in my .emacs file aren t working. Here s the file:

;init modes
(menu-bar-mode 0)
(tool-bar-mode 0)
(cua-mode)
(column-number-mode)
(fset  perl-mode  cperl-mode)
(cperl-set-style PerlStyle)

;keymappings
(global-set-key [f12]  save-buffer)
(global-set-key [S-f12]  write-file)
(global-set-key [f7]  ispell)
(global-set-key [up]  scroll-one-line-up)
(global-set-key [down]  scroll-one-line-down)

;functions
(defun scroll-one-line-up (&optional arg)
  (interactive "p")
  (scroll-up (or arg 1)))
(defun scroll-one-line-down (&optional arg)
  (interactive "p")
  (scroll-down (or arg 1)))

I know Emacs parses the file since everything else seems to work. It s just that the keys are not being bound.

How can I make it work?

最佳回答

You have an error in your .emacs at line:

(cperl-set-style PerlStyle)

It should be written as:

(cperl-set-style  PerlStyle)

Since it raises an error that stops parsing .emacs at that point, your key bindings won t be evaluated.

问题回答

To follow up to my previous answer, you would have to change the binding in the local keymap using a hook variable. Here s an example that I use with java-mode:

(defun java-setup ()
   (setq tab-stop-list  (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92)
         indent-tabs-mode nil
         tab-width 4
         fill-column 96
         c-comment-start-regexp "\(@\|/\(/\|[*][*]?\)\)"))

 (add-hook  java-mode-hook  java-setup)

In your case you would use something like:

 (defun mysetup ()
    (define-key local-map [f12]  func))

 (add-hook  your-mode-hook  mysetup)

Also, fwiw, I do the following to define my global keys:

(defun function-key-help ()
  (interactive)
  (switch-to-buffer "*Help*")
  (erase-buffer)
  (insert-file (expand-file-name "~/lib/fkeys.help"))
  (message "Type C-x b <nl> to remove help window."))

(define-key global-map [f12]  function-key-help)

And it works perfectly in my Emacs 23 setup.

It is hard to say what your problem might be without more information, like is it all your keybindings or just one or two that do not work. I will hazard a guess that it is the last two ([up] and [down]). In those cases the on-line documentation below seems to indicate that you might be shadowing the global definitions with local ones defined by the mode.

global-set-key is an interactive compiled Lisp function in `subr.el .

(global-set-key key command)

Give key a global binding as command. command is the command definition to use; usually it is a symbol naming an interactively-callable function. key is a key sequence; noninteractively, it is a string or vector of characters or event types, and non-ASCII characters with codes above 127 (such as ISO Latin-1) can be included if you use a vector.

Note that if key has a local binding in the current buffer, that local binding will continue to shadow any global binding that you make with this function.





相关问题
How to go to an error using only the keyboard in Eclipse?

Let s say I have a file with 10 lines and I have a problem with the name of the package (or something) and the cursor is on the last line of the text. How can I go directly to that line to see what ...

Switching focus between editor and terminal in Kate

When working in Unix with various programming languages I often use Kate as my primary editor. It has a really nice function of being able to open a built-in terminal window which is quite useful. ...

Shortcuts to change the active tab in my application

My application has a main window that contain a TabControl with about 7 TabItems. Inside each tabItem I put a UserControl. I would like that (no matter the active tab, or control) when the user press ...

Keyboard shortcut to build only startup project?

I ve tried to find a keyboard shortcut to build only the startup project In VS2008. I only found a configurable shortcut to build the project which is currently viewed, which isn t as good. Any ...

Custom Emacs key bindings are not working

The key bindings I ve defined in my .emacs file aren t working. Here s the file: ;init modes (menu-bar-mode 0) (tool-bar-mode 0) (cua-mode) (column-number-mode) (fset perl-mode cperl-mode) (cperl-...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

热门标签