8

Given 2 absolute numbers (compatible with region-beginning, region-end).

How can these numbers be used to set the selection?


Edit: If you use evil mode you may want to check this question, at the time of asking I wasn't aware this required a different method in some cases.

1 Answer 1

9

The region is defined as the span of text between point and mark, therefore it's sufficient to adjust both to the numbers in question. The following uses point-min and point-max for that purpose:

(set-mark (point-min))
(goto-char (point-max))

However you mention "set the selection" afterwards, so perhaps you don't only want to change the region (as there is always a region), but activate it as well:

(activate-mark)
2
  • 1
    Maybe worth mentioning that (setq deactivate-mark nil) may need to be set in some cases (as you found when looking into why setting selection sometimes fails).
    – ideasman42
    Aug 15, 2017 at 2:03
  • Not really as activating the mark works, it's just that it's deactivated right afterwards. This is therefore material for a new question of the "Why is mark deactivated after a <...> command?" kind.
    – wasamasa
    Aug 15, 2017 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.