Mouse usage in Emacs by default is somewhat different than it is in most other applications, and it can be confusing for an EmacsNewbie.

== Fundamentals ==

A mouse is a type of [[WikiPedia:pointing device|pointing device]].  Any kind of pointing device (mice, touchpads, pointing sticks, trackballs, etc.) is considered a mouse by Emacs.

Emacs uses the [[mouse pointer]], a graphic indicator of the mouse position.  Common pointer symbols used in Emacs include an arrow, an hourglass, an I-bar, and a pointing finger.  Moving the mouse moves the pointer.

The mouse ''pointer'' should be distinguished from the ''text cursor'' and/or ''point''.  The [[text cursor]] is typically a blinking bar, box, or underline.  The text cursor indicates the location of [[point]].  Point is where text will be inserted, and where various other text operations occur.

== Button names ==

Emacs designates the primary mouse button as `mouse-1', and numbers them going up from there.  On a typical computer, `mouse-1' is the left mouse button.  (Left-handed people may have their computer set to swap the assignments of the left and right buttons.)

On a two-button mouse, the secondary (right) button is typically `mouse-3'.  (Number 2 is reserved for the middle button, even when not present.)

The middle button, if any, is `mouse-2'.  On a two-button mouse, you can generally simulate it by pressing the left and right buttons simultaniously.  On mice with a scroll wheel, pressing the wheel (like a button) usually sends `mouse-2'.





== Basic mouse actions ==

Exactly what each mouse button does, depends on the type of [[buffer]] you are working in, and any [[mode]]s that might be in effect.  The general behavior is:

Clicking `mouse-1' (left mouse button) will move [[point]] (and thus the text cursor) to that location.  This is similar to most software.

Drag (press and hold) `mouse-1' to define the [[region]] --- that is, to select/highlight text.  The spot where you started dragging becomes [[mark]]; point moves to the end (where you released the button).  Other operations (cut, copy, search, indent, etc.) can then be applied to the selected text region.

Click `mouse-2' (middle button) to [[CopyAndPaste|paste]] a copy of the selection.  If no region is active, Emacs uses the text of the last region you selected.  Text is inserted where you clicked.  Note that this does '''''not''''' paste the contents of the clipboard or kill ring.

A common technique is to select text by dragging with the left button, and then immediately paste it elsewhere by clicking there with the middle button.

Click `mouse-3' (right button) to ''relimit'' (extend or reduce) the selection/region.  If there is already a selection, this makes it larger or smaller, to include everything from the farthest end of the selection to where you click.  If there is no selection, this selects text from point to where you click, making it the active region.

Use `C-mouse-3' (hold Control and then right-click) to get a pop-up context menu.  This is equivalent to a plain right-click in most mainstream software.







== More mouse actions ==

Double-click `mouse-1' on a word to select it.  Triple-click to select a line of text.  Combine either of these with either a drag or a `mouse-3' click to extend the selection by whole words or lines.

Double-click `mouse-3' to kill the text from point to where you click.

A common technique is to move point to the start of some text by left clicking, and then cut that text by double-right-clicking the other end.  Optionally, one can then paste the cut text elsewhere by middle-clicking at the other location.

`C-mouse-1' pops up a menu with a list of buffers (open files).  Choose a menu entry to switch to that buffer.

Clicking `mouse-2' on a button or a link activates/follows it.

If option `mouse-1-click-follows-link' is non-nil (the default) then clicking `mouse-1' on a button or link acts the same as `mouse-2'.  If the option is nil then `mouse-1' just sets point to the clicked location, even if its on a button or link.

If `mouse-1-click-follows-link' is non-nil then you need to
press ''and hold'' `mouse-1' on a button or link to set point there instead of activating it.

Whether you use nil or non-nil `mouse-1-click-follows-link' generally depends on whether (a) you want both `mouse-1' and `mouse-2' to follow links, and you rarely want to set point on link text, or (b) you are content to use only `mouse-2' to follow links, and you want `mouse-1' to always set point, including on link text. 

A [[secondary selection]] is available by pressing and holding the [[Meta]] key during mouse actions.  (The Meta key is also known as the Alt key, and written as `M-'.)  For example, `M-' while dragging creates and extends the secondary selection.  `M-mouse-2' pastes the secondary selection (that is, click `mouse-2' while holding Meta/Alt).

Press and hold both Control ''and'' Meta/Alt while dragging to define a rectangular selection region.  Rectangle regions span multiple lines between the points clicked, without spilling over to the entire line.  This is useful for working with columns of text.





== Customization ==

Behavior of the mouse is most easily changed using the [[CustomizingAndSaving|Customization]] features of Emacs.  In the default graphical interface, click the ''Options'' menu, then ''Customize Emacs'' (at the bottom of the menu), and then ''Top-level Customization Group''.  That will load the main menu of the Customization subsystem.  Click the link for the ''Editing'' group.  On the resulting page, click ''Mouse'' in the list of subgroups.  Explore the settings there.  ''Apply'' lets you try them out, but does not save them after Emacs is closed.  ''Apply and Save'' keeps changes for the future.

For the most part, Emacs treats mouse buttons, scroll wheels, and other protuberances, like keyboard keys.  Changing what mouse buttons do is thus similar to assigning any other [[key binding]], just with its own MouseBindingNotation.

== Further reading ==

MouseGeneral is a top-level list of mouse topics.

[https://www.emacswiki.org/emacs?search=%22CategoryMouse%22 CategoryMouse] finds pages related to the mouse.

As always, the EmacsManual has more information.  In particular, see [[Manual:Mouse Commands]], and subsequent pages.

An r/emacs discussion that [[https://www.reddit.com/r/emacs/comments/uxh0dy/a_mousedriven_emacs/ talks about mouse driven Emacs actions]]

----
CategoryHelp
CategoryMouse
CategoryRegion
