1

Given a beginning position (b) and an end position (e), I want to perform the same action that one does by hitting the movement keys with shift from b to e, but in elisp. The selection can be cancelled by any movement key without shift, so set-mark-command is not what I want.

Community
  • 1
  • 1
AhLeung
  • 207
  • 1
  • 5

1 Answers1

2

You can try:

(defun my-mark-region-as-shifted (other-end)
  (let ((pos (point)))
    (goto-char other-end)
    (setq-local transient-mark-mode
                (cons 'only
                      (unless (eq transient-mark-mode 'lambda)
                        transient-mark-mode)))
    (push-mark nil nil t)
    (goto-char pos)))

This code is mostly lifted from handle-shift-selection.

Stefan
  • 27,908
  • 4
  • 53
  • 82