I am switching from VIM to emacs for just a couple weeks and trying to write some elisp. Having difficulties to adapt, I am exploring different options to do marking and reached this function.
(defun mark-word (&optional arg allow-extend)
"Set mark ARG words away from point.
The place mark goes is the same place \\[forward-word] would
move to with the same argument.
Interactively, if this command is repeated
or (in Transient Mark mode) if the mark is active,
it marks the next ARG words after the ones already marked."
(interactive "P\np")
(cond ((and allow-extend
(or (and (eq last-command this-command) (mark t))
(region-active-p)))
(setq arg (if arg (prefix-numeric-value arg)
(if (< (mark) (point)) -1 1)))
(set-mark
(save-excursion
(goto-char (mark))
(forward-word arg)
(point))))
(t
(push-mark
(save-excursion
(forward-word (prefix-numeric-value arg))
(point))
nil t))))
it's pretty straight forward except allow-extend
. It seems to me for this function to work, allow-extend
needs to be empty. But when we do interaction, we don't really provide any prefix key to it. So why allow-extend
would be non nil
in this case? Also how "P\np"
works here?