Skip to content
TheChatArchiveThe Chat Archive
o4-mini-2025-04-16· OpenAIHugging Face LMArena Human Preference 140K

In Emacs, how do I bind the <tab> key to the function "complete-symbol" in certain modes…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmistral-medium-2505’s answer.
  1. User

    In Emacs, how do I bind the key to the function "complete-symbol" in certain modes such as lisp-mode?

  2. Assistant

    Here’s a quick recipe to make TAB run complete-symbol only in your Lisp buffers:

    ;; 1. Use a mode‐hook to bind TAB locally:
    (defun my-lisp-completion-setup ()
      (local-set-key (kbd "TAB") #'complete-symbol))
    
    (add-hook 'emacs-lisp-mode-hook  #'my-lisp-completion-setup)
    (add-hook 'lisp-mode-hook        #'my-lisp-completion-setup)
    (add-hook 'inferior-lisp-mode-hook #'my-lisp-completion-setup)
    

    Or, if you prefer to tweak the keymap directly after it’s loaded:

    (with-eval-after-load 'lisp-mode
      (define-key lisp-mode-map (kbd "TAB") #'complete-symbol))
    
    (with-eval-after-load 'emacs-lisp
      (define-key emacs-lisp-mode-map (kbd "TAB") #'complete-symbol))
    

    Explanation:

    • local-set-key in a hook only affects the current buffer’s keymap.
    • with-eval-after-load ensures that the mode’s keymap exists before you redefine it.

    Now when you hit TAB in any of those Lisp modes, Emacs will try complete-symbol instead of the usual indent or yasnippet trigger. 🚀

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.