Understanding Emacs CUA mode for shift click selection

744 Views Asked by At

I'm new to Emacs and figuring out how to enable shift-click selection. On the EmacsWiki page for CUA Mode, the following code snippet outlines how to do this:

;; shift + click select region
(define-key global-map (kbd "<S-down-mouse-1>") 'ignore) ; turn off font dialog
(define-key global-map (kbd "<S-mouse-1>") 'mouse-set-point)
(put 'mouse-set-point 'CUA 'move)

I don't understand how the last line enables selection. I've looked into the definition of put:

put is a built-in function in `C source code'.

(put SYMBOL PROPNAME VALUE)

Store SYMBOL's PROPNAME property with value VALUE.
It can be retrieved with `(get SYMBOL PROPNAME)'.

and the definition of mouse-set-point:

mouse-set-point is an interactive compiled Lisp function in
`mouse.el'.

It is bound to <S-mouse-1>, <triple-mouse-1>, <double-mouse-1>,
<mouse-1>.

(mouse-set-point EVENT)

Move point to the position clicked on with the mouse.
This should be bound to a mouse click event type.

but none of them give any clues. I can't find any variable nor function called move, and I've also looked into the source code of mouse.el, cua-base.el, cua-gmrk.el and cua-rect.el.

Would someone explain how the last line works, and how I can find more information by myself? Thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

I didn't dig much too deep into CUA mode, but I understand what you are looking for. 'put' is a function for property lists of symbols. In this case, the symbol is mouse-set-point, and you are setting the property 'CUA' of that symbol to the value 'move'. To read back a property value of a symbol, you can use the function 'get'. You can find more documentation with examples in Elisp reference manual on GNU's webpage.

I looked for references to the CUA property in cua-*.el, and sure enough, found one in cua-base.el: (I am using Emacs 23.3.1)

    (defun cua--pre-command-handler-1 ()
  ;; Cancel prefix key timeout if user enters another key.
  (when cua--prefix-override-timer
    (if (timerp cua--prefix-override-timer)
    (cancel-timer cua--prefix-override-timer))
    (setq cua--prefix-override-timer nil))

  (cond
   ;; Only symbol commands can have necessary properties
   ((not (symbolp this-command))
    nil)

   ;; Handle delete-selection property on non-movement commands
   ((not (eq (get this-command 'CUA) 'move))

I think you can figure it out from here on what the property is being used for. Hope this helps.