Emacs: xah-get-thing.el

By Xah Lee. Date: . Last updated: .

xah-get-thing.el is a emacs lisp utility for grabbing text under cursor.


github: https://github.com/xahlee/xah-get-thing-or-selection

On MELPA http://melpa.org/#/xah-get-thing [see Emacs: How to Install Packages Using ELPA, MELPA]


The package gives you the following functions:

They are useful for writing commands that act on text selection if there's one, or current {symbol, block, …} under cursor.

This package is similar to emac's builtin thing-at-point package thingatpt.el. [see Elisp: Using thing-at-point]

The main differences are:

  1. Is not based on syntax table. So, the “thing” are predicable in any major mode.
  2. provides the 'block, which is similar to emacs's 'paragraph, but strictly defined by between blank lines.
  3. xah-get-bounds-of-thing-or-region Returns the boundary of region, if active. This saves you few lines of code.
  4. Thing 'url and 'filepath, are rather different from how thingatpt.el determines them, and, again, is not based on syntax table, but based on regex of likely characters. Also, result is never modified version of what's in the buffer. For example, if 'url, the http prefix is not automatically added if it doesn't exist in buffer.
  5. Thing 'line never includes newline character. This avoid inconsistency when line is last line.

The return values of these functions is the same format as emacs's thingatpt.el, so you can just drop-in replace by changing the function names in your code.

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp