Search code examples
elisp

emacs lisp: how to set tab key to bind different function?


I'm trying to set the tab key to map a function. In my application, with tab I have to select next window in screen. I tried to define a simple function that displays a message; I used (global-set-key) to map this function on "M-h" (global-set-key (kbd "M-h") 'hello) It worked, message is displayed. Now, I tried same thing with tab-key (global-set-key "\t" 'hello) Apparently I don't receive any error. But, tab key doesn't display anything. I'm using emacs on windows, but tab key works correctly in other situations. Any suggestions?


Solution

  • Hmm, I'm not sure what's wrong, doing

    (defun hello () (interactive) (message "hi!"))
    
    (global-set-key "\t" 'hello)
    

    seems to work fine for me. Does your hello function look similar? The only thing I can think to suggest is trying (kbd "TAB") rather than "\t" in the call to global-set-key. A lot of code I've seen in the wild and that I've written in my config does this. I'm not sure if there's any difference, but it's worth a shot!