1

I custom my forward-word as vim-like 'w' follow this, this works fine except that M-S-f no longer selects text.
So, I write the function:

(defun forward-to-word-with-selection (arg)
  (interactive "p")
  (if (not (eq last-command 'forward-to-word-with-selection))
      (progn (message "Mark Set")
             (set-mark-command))
    (forward-to-word arg)))

(global-set-key (kbd "M-F") 'forward-to-word-with-selection)

But, I got a messy error:

enter image description here

Then I run this function step-by-step(with C-c C-e, any other better debug approach is well come, since I'm newbie to elisp), this error due to the (set-mark-command).

Community
  • 1
  • 1
hbin
  • 2,657
  • 1
  • 23
  • 23

2 Answers2

2

You don't want to manipulate the mark yourself. Just specify "^" to interactive. I've filed a bug with patch to fix it in Emacs, but you can define your own wrapper:

(defun forward-to-word-w (arg)
  "wrapper to work with shift-select-mode"
  (interactive "^p")
  (forward-to-word arg))
event_jr
  • 17,467
  • 4
  • 47
  • 62
  • I means the highlighted code in the picture, like the `\205\202^@`. – hbin Aug 19 '12 at 02:43
  • I see. And can you tell how to debug the emacs with -Q? Currently I run each statement with `(C-c C-e)`. 谢谢~ – hbin Aug 19 '12 at 03:15
1

set-mark-command takes an argument containing the raw form of the prefix argument. That's how C-@ acts differently depending on the type of prefix argument you give it.

You probably don't want to call this function in your code, you probably want to use push-mark.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • But `push-mark` won't highlight the selection region as others' does. Otherwise after forward, I type C-x C-x – hbin Aug 18 '12 at 17:44
  • See the documentation of `push-mark` -- the third optional argument is whether to activate the region. – Barmar Aug 18 '12 at 17:51
  • Not perfect with the `push-mark`, if I press `forward-to-word-with-selection`, and following the original point motion, `M-S-e` for example, the region-beginning will be reset. – hbin Aug 19 '12 at 02:25