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 would allow-extend
be non nil
in this case? Also how does "P\np"
work here?