1

I slightly simplified the keys for backward-paragraph and forward-paragraph:

(global-unset-key (kbd "M-{"))  ;; originally backward-paragraph
(global-unset-key (kbd "M-}"))  ;; originally forward-paragraph
(global-set-key (kbd "M-[") 'backward-paragraph)
(global-set-key (kbd "M-]") 'forward-paragraph)

These work, but I was hoping to get Shift Selection for free. In particular, the official manual says:

If you hold down the shift key while typing a cursor motion command, this sets the mark before moving point, so that the region extends from the original position of point to its new position. This feature is referred to as shift-selection. It is similar to the way text is selected in other editors.

...

Shift-selection only works if the shifted cursor motion key is not already bound to a separate command (see Customization). For example, if you bind S-C-f to another command, typing S-C-f runs that command instead of performing a shift-selected version of C-f (forward-char).

I have shift-select-mode as its default value, which is t.

However, if I now press M-{, I just get M-{ is undefined in the echo area, instead of shift-selected backward-paragraph as I was hoping. This seems to contradict the passage from the manual above. Is this a bug or am I doing something wrong?

edit: I also tried the following, taken from a similar question:

(global-set-key (kbd "M-[")
        (lambda ()
          (interactive "^")
          (backward-paragraph)))

And this had the exact same result as my initial method; e.g. M-[ effectively acts as backward-paragraph, but M-{ just says undefined

  • Right, (interactive "^") only works for alphabet keybinding.. – AhLeung Oct 31 '19 at 5:39
0

This appears to be a bug in emacs; M-{ should just automatically work, if we take the manual at face value.

As a workaround, I took an [answer to a similar question](source: http://emacs.stackexchange.com/a/22166/93) and modified it:

(global-set-key (kbd "M-[") 'backward-paragraph)
(global-set-key (kbd "M-{") 'backward-paragraph-with-shift-select)
(global-set-key (kbd "M-]") 'forward-paragraph)
(global-set-key (kbd "M-}") 'forward-paragraph-with-shift-select)

(defun backward-paragraph-with-shift-select ()
  (interactive)
  (setq this-command-keys-shift-translated t)
  (call-interactively 'backward-paragraph))

(defun forward-paragraph-with-shift-select ()
  (interactive)
  (setq this-command-keys-shift-translated t)
  (call-interactively 'forward-paragraph))

This works perfectly.

| improve this answer | |
  • 1
    The manual page you've quoted is somewhat misleading in this respect. (elisp)Key Sequence Input has a more specific explanation: shift selection occurs when "an input character is upper-case (or has the shift modifier) and has no key binding, but its lower-case equivalent has one". The issue is that M-{ is not M-S-[. – phils Nov 1 '19 at 0:29

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.