In Emacs, you may see your cursor referred to as “point”. But you may have likewise seen references to a cursor. So what’s the deal? Which is it, point or cursor? “Point” and “cursor” refer to slightly different things in Emacs but can both be used to generally describe the blinky thing where you type. Let’s get into it.
The Basic Difference
Point is the relative position of your cursor in an Emacs buffer. It’s like having the mathematical coordinates of your position on the globe rather than simply saying, “I’m in Florida!”
The cursor is the icon that represents the location of the point, so you know where you are. The cursor display is an option you can configure. For example, you can have a blinking cursor or a still one. And, for accurate typing, you are technically between two characters, right behind the one your cursor is sitting on.
So, basically point is a location, while the cursor is a visual display feature.
What’s The Point of Point?
Some functional examples:
thing-at-point
- Return the thing at point
bounds-of-thing-at-point
- Get start and end buffer location values for the thing at point
buffer-substring-no-properties
- Return contents between two points
Example Functions
(defun csm/get-current-word () "Prints the current word." (interactive) (message "%s" (thing-at-point 'word))) (defun csm/get-current-sentence () "prints current sentence to minibufer" (interactive) (message "Sentence is: %s" (thing-at-point 'sentence))) ;Xah function: ; (defun my-get-boundary-and-thing () "example of using `bounds-of-thing-at-point'" (interactive) (let (bounds pos1 pos2 mything) (setq bounds (bounds-of-thing-at-point 'symbol)) (setq pos1 (car bounds)) (setq pos2 (cdr bounds)) (setq mything (buffer-substring-no-properties pos1 pos2)) (message "thing begin at [%s], end at [%s], thing is [%s]" pos1 pos2 mything)))
Credit to Xah Lee for the “my-get-boundary-and-thing” function.
Leave a Reply