30

How can mouse support be enabled in an Emacs terminal session started with emacs -nw? Is there a keyboard shortcut or a flag to do this? If not how can it be done in terminal emulators? I use Guake.

9
  • 1
    Are you running emacs in a GUI terminal emulator? What kind of support do you need? Placing the cursor? Copy/pasting? Commented Jan 3, 2016 at 11:52
  • 1
    Emacs: Using a Mouse in Text Terminals Commented Jan 3, 2016 at 11:56
  • 1
    @terdon I am using guake. Commented Jan 3, 2016 at 11:56
  • OK, please edit your question and add that information. Also explain exactly what type of mouse support you need. Commented Jan 3, 2016 at 11:57
  • 3
    @user Type ALT-X, then xterm-mouse-mode, then return. Commented Jan 3, 2016 at 12:03

3 Answers 3

31

Hit F10 to open the menu and use the arrow keys to navigate to “Options” → “Customize Emacs” → “All Settings Matching…”. Type mouse and Enter.

If your Emacs version doesn't have a menu when running in a terminal then run M-x customize. (This means: press Alt+X, type customize and press Enter.) Navigate to the search box, type mouse and press Enter.

Mouse support is called “Xterm Mouse mode”. You can find that in the manual. The manual also gives a way to turn it on (for the current session) — M-x xterm-mouse-mode.

In the Customize interface, on the setting you want to change, press Enter on “Show Value”. A “Toggle” button appears, press Enter on it. Then press Enter on the “State” box and choose either 0 for “Set for Current Session” or “1” for “Save for Future Sessions”. (You can choose 0 for now and come back there and choose 1 later if you're happy with the setting.)

1
  • Just a small point: It would be good to indicate that to "navigate" you need to use the TAB key Commented Dec 30, 2024 at 16:28
30

add (xterm-mouse-mode 1) to your ~/.emacs.d/init.el file.

1
  • Thanks! I was searching for that as my customizations menu is empty (I compiled it from the git sources, works well so far, so I'm happy with that) Commented Jul 31, 2023 at 9:42
0

add (xterm-mouse-mode 1) to your ~/.emacs.d/init.el file.

This may not work if you start emacs as a daemon (emacs --daemon). If you do this, and then start an emacsclient, the variable xterm-mouse-mode will have value t (indicating that x-term-mouse-mode is enabled) but mouse clicks will still not move the cursor. Evaluating (xterm-mouse-mode), or toggling the mode twice, will redress this.

xterm-mouse-mode is one of several settings that have this problem. The solution is to set them from a hook that is only run when there is a frame in a terminal, e.g:

(add-hook 'after-make-frame-functions                                                                                    
   (lambda ()                                                                                                   
     (xterm-mouse-mode 1))) 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.