Emacs Select Word Command Problem

By Xah Lee. Date: . Last updated: .

Emacs has a command to select the current word, mark-word, with default shortcut of 【M-@】.

Selecting the current word is a frequently needed operation. However, emacs's mark-word command is inconvenient. It does not select the whole word. It only select from the cursor position to the end of the word. For example, if your word is “transmission”, and your cursor is at the “m”, then it will select just “mission”. To select the whole word, you need to move the cursor to the beginning of the word first.

Also, mark-word has a feature that if you repeat the command, then it extend the selection to the next word to the right. But again, you need first to move the cursor to the beginning of the word.

Emacs has in fact a whole system of selecting text:

emacs manual mark text 2023-11-14
emacs manual mark text 2023-11-14 Marking Objects (Emacs Manual)

Here is suggestion of a scheme that may replace or supplement the above system.

Here's the code that implements the above idea for lisp (or any simply nested syntax):

You should give these commands keys. [see Emacs Keys: Define Key].

I suggest:

these commands are in Emacs: Xah Fly Keys 📦

This “extend-selection” scheme with “transient-mark-mode” on, should simplify and replace the functionality of { • mark-wordmark-sexpmark-paragraphmark-defun }.

With just one command to remember, and more efficient to operate. The “mark-whole-buffer” can be replaced by a shortcut 【Ctrl+a】 to be compatible with modern UI standard, and “mark-page” is today rather obsolete because it depends on page marker char “^L” (ASCII 12), which is not used in most languages but only in older emacs lisp source code.

Emacs Modernization