1

Possible Duplicate:
How do I access the contents of the current region in Emacs Lisp?

(point) can be used to find the position of the cursor in elisp. Is there any similar function which returns the beginning and the ending point of a region of selected text?

Community
  • 1
  • 1
sudeepdino008
  • 3,194
  • 5
  • 39
  • 73

1 Answers1

4

In Emacs, "the region", which may or may not be highlighted, lies between (point) and (mark).

Since mark can be positioned before or after point, the utility functions region-beginning and region-end will return the smaller and the larger of the two, respectively.

(mark) will return nil if the mark has never been set in the buffer, in which case both region-beginning and region-end will signal an error. A non-nil value of mark doesn't imply that a region is currently highlighted. Whether the region is considered active is also affected by transient-mark-mode and mark-even-if-inactive options. The function use-region-p can be used to test whether it is appropriate to act on the region.

user4815162342
  • 141,790
  • 18
  • 296
  • 355