10

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). Commented 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. Commented Aug 15, 2017 at 5:18

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.