AhLeung
AhLeung

Reputation: 207

Programmatically do shift selection

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.

Upvotes: 1

Views: 93

Answers (1)

Stefan
Stefan

Reputation: 28531

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.

Upvotes: 2

Related Questions