+;;;; Event manipulation functions.
+
+;; This code exists specifically to make sure that the
+;; resulting number does not appear in the .elc file.
+;; The number is negative on most machines, but not on all!
+(defconst listify-key-sequence-1
+ (lsh 1 7))
+(setq listify-key-sequence-1 (logior (lsh 1 23) listify-key-sequence-1))
+
+(defun listify-key-sequence (key)
+ "Convert a key sequence to a list of events."
+ (if (vectorp key)
+ (append key nil)
+ (mapcar (function (lambda (c)
+ (if (> c 127)
+ (logxor c listify-key-sequence-1)
+ c)))
+ (append key nil))))
+
+(defsubst eventp (obj)
+ "True if the argument is an event object."
+ (or (integerp obj)
+ (and (symbolp obj)
+ (get obj 'event-symbol-elements))
+ (and (consp obj)
+ (symbolp (car obj))
+ (get (car obj) 'event-symbol-elements))))
+
+(defun event-modifiers (event)
+ "Returns a list of symbols representing the modifier keys in event EVENT.
+The elements of the list may include `meta', `control',
+`shift', `hyper', `super', `alt', `click', `double', `triple', `drag',
+and `down'."
+ (let ((type event))
+ (if (listp type)
+ (setq type (car type)))
+ (if (symbolp type)
+ (cdr (get type 'event-symbol-elements))
+ (let ((list nil))
+ (or (zerop (logand type (lsh 1 23)))
+ (setq list (cons 'meta list)))
+ (or (and (zerop (logand type (lsh 1 22)))
+ (>= (logand type 127) 32))
+ (setq list (cons 'control list)))
+ (or (and (zerop (logand type (lsh 1 21)))
+ (= (logand type 255) (downcase (logand type 255))))
+ (setq list (cons 'shift list)))
+ (or (zerop (logand type (lsh 1 20)))
+ (setq list (cons 'hyper list)))
+ (or (zerop (logand type (lsh 1 19)))
+ (setq list (cons 'super list)))
+ (or (zerop (logand type (lsh 1 18)))
+ (setq list (cons 'alt list)))
+ list))))
+
+(defun event-basic-type (event)
+ "Returns the basic type of the given event (all modifiers removed).
+The value is an ASCII printing character (not upper case) or a symbol."
+ (if (consp event)
+ (setq event (car event)))
+ (if (symbolp event)
+ (car (get event 'event-symbol-elements))
+ (let ((base (logand event (1- (lsh 1 18)))))
+ (downcase (if (< base 32) (logior base 64) base)))))
+
+(defsubst mouse-movement-p (object)
+ "Return non-nil if OBJECT is a mouse movement event."
+ (and (consp object)
+ (eq (car object) 'mouse-movement)))
+
+(defsubst event-start (event)
+ "Return the starting position of EVENT.
+If EVENT is a mouse press or a mouse click, this returns the location
+of the event.
+If EVENT is a drag, this returns the drag's starting position.
+The return value is of the form
+ (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
+The `posn-' functions access elements of such lists."
+ (nth 1 event))
+
+(defsubst event-end (event)
+ "Return the ending location of EVENT. EVENT should be a click or drag event.
+If EVENT is a click event, this function is the same as `event-start'.
+The return value is of the form
+ (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
+The `posn-' functions access elements of such lists."
+ (nth (if (consp (nth 2 event)) 2 1) event))
+
+(defsubst event-click-count (event)
+ "Return the multi-click count of EVENT, a click or drag event.
+The return value is a positive integer."
+ (if (integerp (nth 2 event)) (nth 2 event) 1))
+
+(defsubst posn-window (position)
+ "Return the window in POSITION.
+POSITION should be a list of the form
+ (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
+as returned by the `event-start' and `event-end' functions."
+ (nth 0 position))
+
+(defsubst posn-point (position)
+ "Return the buffer location in POSITION.
+POSITION should be a list of the form
+ (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
+as returned by the `event-start' and `event-end' functions."
+ (if (consp (nth 1 position))
+ (car (nth 1 position))
+ (nth 1 position)))
+
+(defsubst posn-x-y (position)
+ "Return the x and y coordinates in POSITION.
+POSITION should be a list of the form
+ (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
+as returned by the `event-start' and `event-end' functions."
+ (nth 2 position))
+
+(defun posn-col-row (position)
+ "Return the column and row in POSITION, measured in characters.
+POSITION should be a list of the form
+ (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
+as returned by the `event-start' and `event-end' functions.
+For a scroll-bar event, the result column is 0, and the row
+corresponds to the vertical position of the click in the scroll bar."
+ (let ((pair (nth 2 position))
+ (window (posn-window position)))
+ (if (eq (if (consp (nth 1 position))
+ (car (nth 1 position))
+ (nth 1 position))
+ 'vertical-scroll-bar)
+ (cons 0 (scroll-bar-scale pair (1- (window-height window))))
+ (if (eq (if (consp (nth 1 position))
+ (car (nth 1 position))
+ (nth 1 position))
+ 'horizontal-scroll-bar)
+ (cons (scroll-bar-scale pair (window-width window)) 0)
+ (let* ((frame (if (framep window) window (window-frame window)))
+ (x (/ (car pair) (frame-char-width frame)))
+ (y (/ (cdr pair) (frame-char-height frame))))
+ (cons x y))))))
+
+(defsubst posn-timestamp (position)
+ "Return the timestamp of POSITION.
+POSITION should be a list of the form
+ (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
+as returned by the `event-start' and `event-end' functions."
+ (nth 3 position))
+
+\f
+;;;; Obsolescent names for functions.
+
+(defalias 'dot 'point)
+(defalias 'dot-marker 'point-marker)
+(defalias 'dot-min 'point-min)
+(defalias 'dot-max 'point-max)
+(defalias 'window-dot 'window-point)
+(defalias 'set-window-dot 'set-window-point)
+(defalias 'read-input 'read-string)
+(defalias 'send-string 'process-send-string)
+(defalias 'send-region 'process-send-region)
+(defalias 'show-buffer 'set-window-buffer)
+(defalias 'buffer-flush-undo 'buffer-disable-undo)
+(defalias 'eval-current-buffer 'eval-buffer)
+(defalias 'compiled-function-p 'byte-code-function-p)
+
+;; Some programs still use this as a function.
+(defun baud-rate ()
+ "Obsolete function returning the value of the `baud-rate' variable.
+Please convert your programs to use the variable `baud-rate' directly."
+ baud-rate)
+
+\f
+;;;; Alternate names for functions - these are not being phased out.
+
+(defalias 'string= 'string-equal)
+(defalias 'string< 'string-lessp)
+(defalias 'move-marker 'set-marker)
+(defalias 'eql 'eq)
+(defalias 'not 'null)
+(defalias 'rplaca 'setcar)
+(defalias 'rplacd 'setcdr)
+(defalias 'beep 'ding) ;preserve lingual purity
+(defalias 'indent-to-column 'indent-to)
+(defalias 'backward-delete-char 'delete-backward-char)
+(defalias 'search-forward-regexp (symbol-function 're-search-forward))
+(defalias 'search-backward-regexp (symbol-function 're-search-backward))
+(defalias 'int-to-string 'number-to-string)
+(defalias 'set-match-data 'store-match-data)
+
+;;; Should this be an obsolete name? If you decide it should, you get
+;;; to go through all the sources and change them.
+(defalias 'string-to-int 'string-to-number)
+\f
+;;;; Hook manipulation functions.
+