简体   繁体   中英

Why the (set-mark-command) throw errors?

I custom my forward-word as vim-like 'w' follow this , this works fine except that MSf 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:

在此输入图像描述

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

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 .

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM