Emacs Select Word Command Problem
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:
Here is suggestion of a scheme that may replace or supplement the above system.
- We create a command that select the whole word.
- When repeated, it should select the next larger syntactic unit.
- In human languages, that would be sentence, then paragraph, then whole buffer.
- In computer languages, the sequence would be: current identifier or token, current expression, current construct (or line), current block or defun.
- If the lang is lisp, this simply means extending the selection to the next outer parens.
- For a illustrated example of this, see: A Text Editor Feature: Extend Selection by Semantic Unit
Here's the code that implements the above idea for lisp (or any simply nested syntax):
- Emacs: Select Line 🚀
- Emacs: Select Text Between Quotes 🚀
- Emacs: Select Text Block 🚀
- Emacs: Extend Selection 🚀
You should give these commands keys. 〔see Emacs Keys: Define Key〕.
I suggest:
- Alt+6
- Alt+7
- Alt+8
- Alt+9
these commands are in Emacs: Xah Fly Keys 📦
- In the above, 【Alt+8】 is assigned to the command, because selecting whole word is a commonly needed operation, and 【Alt+8】 is one key less than 【Alt+@】, and the finger used, the 3rd finger pressing on 8, is also easier than the 4th finger on 2, and 8 is right hand.
- Pressing 【Alt+8】 will select the current whole word.
- Press it again will extend the selection to the next outer parens.
- The above code effectively does extend selection to higher level of semantic unit for lisp or simply nested syntax.
- It does not work in more complicated nesting, such as HTML/XML.
- For the code to work in other langs like Java, Perl, Python, XML, it'll need some more work.
- Another frequently needed operation is to select text inside straight 'single' or "double" quotes.
- This is especially frequently needed for string datatype in popular languages such as C, C++, Java, JavaScript, Perl, Python, PHP, HTML/XML.
- Ideally, the “extend-selection” above should do it, by simply invoking the command twice, or just once when cursor is on the quote, but since the above code does not work outside of lisp syntax, so here's a additional command as a workaround to do the frequently needed operation of selecting text inside quote pairs.
- With both of the above defined, pressing 【Alt+8】 will select whole word (or extend current selection).
- Pressing 【Alt+*】 will select the text inside matching quotes.
This “extend-selection” scheme with “transient-mark-mode” on, should simplify and replace the functionality of {
• mark-word
• mark-sexp
• mark-paragraph
• mark-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
- Emacs Modernization: Simple Changes Emacs Should Adopt
- Why Emacs Keys are Painful
- Emacs: Problems of the Scratch Buffer
- Emacs Modernization: Meta Key Notation
- Emacs Menu Usability Problem
- Emacs Mode Line Problem
- Emacs cua-mode Problems
- Emacs: Inconsistency of Search Features
- Problems of grep in Emacs
- Emacs: Usability Problems of Mode Documentation
- Problems of Emacs Manual
- Emacs Manual Sucks by Examples
- Emacs: kill-buffer Induces Buffer Accumulation
- Emacs Spell Checker Problems
- Emacs: Form Feed ^L Problem
- Emacs: Single Key to Delete Whole Line
- Emacs HTML Mode Sucks
- Emacs Does Not Support Viewing Images Files In Windows
- Emacs Should Adopt HTML as Texinfo Replacement
- Emacs Should Support HTML Mail
- Problems of Emacs's “man” Command
- Emacs Lisp Mode Syntax Coloring Problem
- Emacs AutoHotkey Mode Problems
- Elisp: Syntax Table Sucks
- Emacs: Make elisp-index-search use Current Symbol
- Emacs GNU Texinfo Problems; Invalid HTML
- A Record of Frustration in IT Industry; Disappearing FSF URLs, 2006
- Emacs Manual Node Persistency Issues
- Emacs: dired-do-query-replace-regex Replace ALL (fixed)
- Problems of Emacs Supporting Obsolete Systems
- Elisp: Function to Copy/Delete a Dir Recursively (fixed)
- Thoughts on Common Lisp Scheme Lisp Based Emacs
- Text Editors Popularity and Market Research
- Text Editor's Cursor Movement Behavior (emacs, vi, Notepad++)
- Emacs: Usability Problems of Letter-Case Changing Commands
- Emacs Select Word Command Problem
- Emacs: Search Current Word 🚀
- Emacs fill-paragraph Problem