7

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.

8

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)
  • 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 '17 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 '17 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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