comparison lisp/subr.el @ 53132:20c6299bd4df

(event-start, event-end): Doc fix. (posn-window, posn-x-y, posn-timestamp): Simplify doc. (posn-area, posn-actual-col-row, posn-object): New defuns. (posn-col-row): Simplify doc. Rewrite to use cond. (posn-point): Also return buffer position for events outside text area (that info is now present in the event position).
author Kim F. Storm <storm@cua.dk>
date Sun, 23 Nov 2003 00:27:03 +0000
parents 5ce618af4f38
children 5f50db6e04c6
comparison
equal deleted inserted replaced
53131:c0ad5bc2f493 53132:20c6299bd4df
636 "Return the starting position of EVENT. 636 "Return the starting position of EVENT.
637 If EVENT is a mouse press or a mouse click, this returns the location 637 If EVENT is a mouse press or a mouse click, this returns the location
638 of the event. 638 of the event.
639 If EVENT is a drag, this returns the drag's starting position. 639 If EVENT is a drag, this returns the drag's starting position.
640 The return value is of the form 640 The return value is of the form
641 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP) 641 (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW))
642 The `posn-' functions access elements of such lists." 642 The `posn-' functions access elements of such lists."
643 (if (consp event) (nth 1 event) 643 (if (consp event) (nth 1 event)
644 (list (selected-window) (point) '(0 . 0) 0))) 644 (list (selected-window) (point) '(0 . 0) 0)))
645 645
646 (defsubst event-end (event) 646 (defsubst event-end (event)
647 "Return the ending location of EVENT. EVENT should be a click or drag event. 647 "Return the ending location of EVENT. EVENT should be a click or drag event.
648 If EVENT is a click event, this function is the same as `event-start'. 648 If EVENT is a click event, this function is the same as `event-start'.
649 The return value is of the form 649 The return value is of the form
650 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP) 650 (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW))
651 The `posn-' functions access elements of such lists." 651 The `posn-' functions access elements of such lists."
652 (if (consp event) (nth (if (consp (nth 2 event)) 2 1) event) 652 (if (consp event) (nth (if (consp (nth 2 event)) 2 1) event)
653 (list (selected-window) (point) '(0 . 0) 0))) 653 (list (selected-window) (point) '(0 . 0) 0)))
654 654
655 (defsubst event-click-count (event) 655 (defsubst event-click-count (event)
657 The return value is a positive integer." 657 The return value is a positive integer."
658 (if (and (consp event) (integerp (nth 2 event))) (nth 2 event) 1)) 658 (if (and (consp event) (integerp (nth 2 event))) (nth 2 event) 1))
659 659
660 (defsubst posn-window (position) 660 (defsubst posn-window (position)
661 "Return the window in POSITION. 661 "Return the window in POSITION.
662 POSITION should be a list of the form 662 POSITION should be a list of the form returned by the `event-start'
663 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP) 663 and `event-end' functions."
664 as returned by the `event-start' and `event-end' functions."
665 (nth 0 position)) 664 (nth 0 position))
665
666 (defsubst posn-area (position)
667 "Return the window area recorded in POSITION, or nil for the text area.
668 POSITION should be a list of the form returned by the `event-start'
669 and `event-end' functions."
670 (let ((area (if (consp (nth 1 position))
671 (car (nth 1 position))
672 (nth 1 position))))
673 (and (symbolp area) area)))
666 674
667 (defsubst posn-point (position) 675 (defsubst posn-point (position)
668 "Return the buffer location in POSITION. 676 "Return the buffer location in POSITION.
669 POSITION should be a list of the form 677 POSITION should be a list of the form returned by the `event-start'
670 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP) 678 and `event-end' functions."
671 as returned by the `event-start' and `event-end' functions." 679 (or (nth 5 position)
672 (if (consp (nth 1 position)) 680 (if (consp (nth 1 position))
673 (car (nth 1 position)) 681 (car (nth 1 position))
674 (nth 1 position))) 682 (nth 1 position))))
675 683
676 (defsubst posn-x-y (position) 684 (defsubst posn-x-y (position)
677 "Return the x and y coordinates in POSITION. 685 "Return the x and y coordinates in POSITION.
678 POSITION should be a list of the form 686 POSITION should be a list of the form returned by the `event-start'
679 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP) 687 and `event-end' functions."
680 as returned by the `event-start' and `event-end' functions."
681 (nth 2 position)) 688 (nth 2 position))
682 689
683 (defun posn-col-row (position) 690 (defun posn-col-row (position)
684 "Return the column and row in POSITION, measured in characters. 691 "Return the nominal column and row in POSITION, measured in characters.
685 POSITION should be a list of the form 692 The column and row values are approximations calculated from the x
686 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP) 693 and y coordinates in POSITION and the frame's default character width
687 as returned by the `event-start' and `event-end' functions. 694 and height.
688 For a scroll-bar event, the result column is 0, and the row 695 For a scroll-bar event, the result column is 0, and the row
689 corresponds to the vertical position of the click in the scroll bar." 696 corresponds to the vertical position of the click in the scroll bar.
690 (let* ((pair (nth 2 position)) 697 POSITION should be a list of the form returned by the `event-start'
691 (window (posn-window position))) 698 and `event-end' functions."
692 (if (eq (if (consp (nth 1 position)) 699 (let* ((pair (posn-x-y position))
693 (car (nth 1 position)) 700 (window (posn-window position))
694 (nth 1 position)) 701 (area (posn-area position)))
695 'vertical-scroll-bar) 702 (cond
696 (cons 0 (scroll-bar-scale pair (1- (window-height window)))) 703 ((null window)
697 (if (eq (if (consp (nth 1 position)) 704 '(0 . 0))
698 (car (nth 1 position)) 705 ((eq area 'vertical-scroll-bar)
699 (nth 1 position)) 706 (cons 0 (scroll-bar-scale pair (1- (window-height window)))))
700 'horizontal-scroll-bar) 707 ((eq area 'horizontal-scroll-bar)
701 (cons (scroll-bar-scale pair (window-width window)) 0) 708 (cons (scroll-bar-scale pair (window-width window)) 0))
702 (let* ((frame (if (framep window) window (window-frame window))) 709 (t
703 (x (/ (car pair) (frame-char-width frame))) 710 (let* ((frame (if (framep window) window (window-frame window)))
704 (y (/ (cdr pair) (+ (frame-char-height frame) 711 (x (/ (car pair) (frame-char-width frame)))
705 (or (frame-parameter frame 'line-spacing) 712 (y (/ (cdr pair) (+ (frame-char-height frame)
706 default-line-spacing 713 (or (frame-parameter frame 'line-spacing)
707 0))))) 714 default-line-spacing
708 (cons x y)))))) 715 0)))))
716 (cons x y))))))
717
718 (defun posn-actual-col-row (position)
719 "Return the actual column and row in POSITION, measured in characters.
720 These are the actual row number in the window and character number in that row.
721 Return nil if POSITION does not contain the actual position; in that case
722 `posn-col-row' can be used to get approximate values.
723 POSITION should be a list of the form returned by the `event-start'
724 and `event-end' functions."
725 (nth 6 position))
709 726
710 (defsubst posn-timestamp (position) 727 (defsubst posn-timestamp (position)
711 "Return the timestamp of POSITION. 728 "Return the timestamp of POSITION.
712 POSITION should be a list of the form 729 POSITION should be a list of the form returned by the `event-start'
713 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP) 730 and `event-end' functions."
714 as returned by the `event-start' and `event-end' functions."
715 (nth 3 position)) 731 (nth 3 position))
732
733 (defsubst posn-object (position)
734 "Return the object of POSITION.
735 POSITION should be a list of the form returned by the `event-start'
736 and `event-end' functions."
737 (nth 4 position))
716 738
717 739
718 ;;;; Obsolescent names for functions. 740 ;;;; Obsolescent names for functions.
719 741
720 (defalias 'dot 'point) 742 (defalias 'dot 'point)