Mercurial > emacs
view lisp/emacs-lisp/ring.el @ 1710:26054080a152
* frame.h (struct frame): New fields `can_have_scrollbars' and
`has_vertical_scrollbars'.
(FRAME_CAN_HAVE_SCROLLBARS, FRAME_HAS_VERTICAL_SCROLLBARS): New
accessors, for both the MULTI_FRAME and non-MULTI_FRAME.
(VERTICAL_SCROLLBAR_WIDTH, WINDOW_VERTICAL_SCROLLBAR,
WINDOW_VERTICAL_SCROLLBAR_COLUMN,
WINDOW_VERTICAL_SCROLLBAR_HEIGHT): New macros.
* window.h (struct window): New field `vertical_scrollbar'.
* xterm.h (struct x_display): vertical_scrollbars,
judge_timestamp, vertical_scrollbar_extra: New fields.
(struct scrollbar): New struct.
(VERTICAL_SCROLLBAR_PIXEL_WIDTH, VERTICAL_SCROLLBAR_PIXEL_HEIGHT,
VERTICAL_SCROLLBAR_LEFT_BORDER, VERTICAL_SCROLLBAR_RIGHT_BORDER,
VERTICAL_SCROLLBAR_TOP_BORDER, VERTICAL_SCROLLBAR_BOTTOM_BORDER,
CHAR_TO_PIXEL_WIDTH, CHAR_TO_PIXEL_HEIGHT, PIXEL_TO_CHAR_WIDTH,
PIXEL_TO_CHAR_HEIGHT): New accessors and macros.
* frame.c (make_frame): Initialize the `can_have_scrollbars' and
`has_vertical_scrollbars' fields of the frame.
* term.c (term_init): Note that TERMCAP terminals don't support
scrollbars.
(mouse_position_hook): Document new args.
(set_vertical_scrollbar_hook, condemn_scrollbars_hook,
redeem_scrollbar_hook, judge_scrollbars_hook): New hooks.
* termhooks.h: Declare and document them.
(enum scrollbar_part): New type.
(struct input_event): Describe the new form of the scrollbar_click
event type. Change `part' from a Lisp_Object to an enum
scrollbar_part. Add a new field `scrollbar'.
* keyboard.c (kbd_buffer_get_event): Pass appropriate new
parameters to *mouse_position_hook, and make_lispy_movement.
* xfns.c (x_set_vertical_scrollbar): New function.
(x_figure_window_size): Use new macros to calculate frame size.
(Fx_create_frame): Note that X Windows frames do support scroll
bars. Default to "yes".
* xterm.c: #include <X11/cursorfont.h> and "window.h".
(x_vertical_scrollbar_cursor): New variable.
(x_term_init): Initialize it.
(last_mouse_bar, last_mouse_bar_frame, last_mouse_part,
last_mouse_scroll_range_start, last_mouse_scroll_range_end): New
variables.
(XTmouse_position): Use them to return scrollbar movement events.
Take new arguments, for that purpose.
(x_window_to_scrollbar, x_scrollbar_create,
x_scrollbar_set_handle, x_scrollbar_remove, x_scrollbar_move,
XTset_scrollbar, XTcondemn_scrollbars, XTredeem_scrollbar,
XTjudge_scrollbars, x_scrollbar_expose,
x_scrollbar_background_expose, x_scrollbar_handle_click,
x_scrollbar_handle_motion): New functions to implement scrollbars.
(x_term_init): Set the termhooks.h hooks to point to them.
(x_set_window_size): Use new macros to calculate frame size. Set
vertical_scrollbar_extra field.
(x_make_frame_visible): Use the frame accessor
FRAME_HAS_VERTICAL_SCROLLBARS to decide if we need to map the
frame's subwindows as well.
(XTread_socket): Use new size-calculation macros from xterm.h when
processing ConfigureNotify events.
(x_wm_set_size_hint): Use PIXEL_TO_CHAR_WIDTH and
PIXEL_TO_CHAR_HEIGHT macros.
* ymakefile (xdisp.o): This now depends on termhooks.h.
(xterm.o): This now depends on window.h.
Change the meaning of focus redirection to make switching windows
work properly. Fredirect_frame_focus has the details.
* frame.h (focus_frame): Doc fix.
[not MULTI_FRAME] (FRAME_FOCUS_FRAME): Make this Qnil, which
indicates no focus redirection, instead of zero, which is
selected_frame.
* frame.c (make_frame): Initialize f->focus_frame to Qnil, rather
than making it point to frame itself.
(Fselect_frame): If changing the selected frame from FOO to BAR,
make all redirections to FOO shift to BAR as well. Doc fix.
(Fredirect_frame_focus): Doc fix. Accept nil as a valid
redirection, not just as a default for FRAME.
(Fframe_focus): Doc fix.
* keyboard.c (kbd_buffer_store_event, kbd_buffer_get_event): Deal
with focus redirections being nil.
* xterm.c (XTframe_rehighlight): Doc fix. Deal with focus
redirections being nil.
It's a pain to remember that you can't assign to FRAME->visible.
Let's change all references to the `visible' member of struct
frame to use the accessor macros, and then write a setter for the
`visible' field that does the right thing.
* frame.h (FRAME_VISIBLE_P): Make this not an l-value.
(FRAME_SET_VISIBLE): New macro.
* frame.c (make_terminal_frame, Fdelete_frame): Use FRAME_SET_VISIBLE.
(Fframe_visible_p, Fvisible_frame_list): Use FRAME_VISIBLE_P and
FRAME_ICONIFIED_P.
* dispnew.c (Fredraw_display): Use the FRAME_VISIBLE_P and
FRAME_GARBAGED_P accessors.
* xdisp.c (redisplay): Use the FRAME_VISIBLE_P accessor.
* xfns.c (x_set_foreground_color, x_set_background_color,
x_set_cursor_color, x_set_border_pixel, x_set_icon_type): Use the
FRAME_VISIBLE_P accessor.
(Fx_create_frame): Use FRAME_SET_VISIBILITY.
* xterm.c (clear_cursor, x_display_bar_cursor,
x_display_box_cursor): Use FRAME_SET_VISIBILITY.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Thu, 24 Dec 1992 06:07:02 +0000 |
parents | 48e4034a2176 |
children | dbdccee84df3 |
line wrap: on
line source
;;; ring.el --- handle rings of marks ;; Copyright (C) 1992 Free Software Foundation, Inc. ;; Maintainer: FSF ;; Keywords: extensions ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. ;;; Commentary: ;;; This code defines a ring data structure. A ring is a ;;; (hd-index tl-index . vector) ;;; list. You can insert to, remove from, and rotate a ring. When the ring ;;; fills up, insertions cause the oldest elts to be quietly dropped. ;;; ;;; HEAD = index of the newest item on the ring. ;;; TAIL = index of the oldest item on the ring. ;;; ;;; These functions are used by the input history mechanism, but they can ;;; be used for other purposes as well. ;;; Code: (provide 'ring) ;;;###autoload (defun ring-p (x) "T if X is a ring; NIL otherwise." (and (consp x) (integerp (car x)) (consp (cdr x)) (integerp (car (cdr x))) (vectorp (cdr (cdr x))))) ;;;###autoload (defun make-ring (size) "Make a ring that can contain SIZE elts." (cons 1 (cons 0 (make-vector (+ size 1) nil)))) (defun ring-plus1 (index veclen) "INDEX+1, with wraparound" (let ((new-index (+ index 1))) (if (= new-index veclen) 0 new-index))) (defun ring-minus1 (index veclen) "INDEX-1, with wraparound" (- (if (= 0 index) veclen index) 1)) (defun ring-length (ring) "Number of elts in the ring." (let ((hd (car ring)) (tl (car (cdr ring))) (siz (length (cdr (cdr ring))))) (let ((len (if (<= hd tl) (+ 1 (- tl hd)) (+ 1 tl (- siz hd))))) (if (= len siz) 0 len)))) (defun ring-empty-p (ring) (= 0 (ring-length ring))) (defun ring-insert (ring item) "Insert a new item onto the ring. If the ring is full, dump the oldest item to make room." (let* ((vec (cdr (cdr ring))) (len (length vec)) (new-hd (ring-minus1 (car ring) len))) (setcar ring new-hd) (aset vec new-hd item) (if (ring-empty-p ring) ;overflow -- dump one off the tail. (setcar (cdr ring) (ring-minus1 (car (cdr ring)) len))))) (defun ring-remove (ring) "Remove the oldest item retained on the ring." (if (ring-empty-p ring) (error "Ring empty") (let ((tl (car (cdr ring))) (vec (cdr (cdr ring)))) (setcar (cdr ring) (ring-minus1 tl (length vec))) (aref vec tl)))) ;;; This isn't actually used in this package. I just threw it in in case ;;; someone else wanted it. If you want rotating-ring behavior on your history ;;; retrieval (analagous to kill ring behavior), this function is what you ;;; need. I should write the yank-input and yank-pop-input-or-kill to go with ;;; this, and not bind it to a key by default, so it would be available to ;;; people who want to bind it to a key. But who would want it? Blech. (defun ring-rotate (ring n) (if (not (= n 0)) (if (ring-empty-p ring) ;Is this the right error check? (error "ring empty") (let ((hd (car ring)) (tl (car (cdr ring))) (vec (cdr (cdr ring)))) (let ((len (length vec))) (while (> n 0) (setq tl (ring-plus1 tl len)) (aset ring tl (aref ring hd)) (setq hd (ring-plus1 hd len)) (setq n (- n 1))) (while (< n 0) (setq hd (ring-minus1 hd len)) (aset vec hd (aref vec tl)) (setq tl (ring-minus1 tl len)) (setq n (- n 1)))) (setcar ring hd) (setcar (cdr ring) tl))))) (defun ring-mod (n m) "Returns N mod M. M is positive. Answer is guaranteed to be non-negative, and less than m." (let ((n (% n m))) (if (>= n 0) n (+ n (if (>= m 0) m (- m)))))) ; (abs m) (defun ring-ref (ring index) (let ((numelts (ring-length ring))) (if (= numelts 0) (error "indexed empty ring") (let* ((hd (car ring)) (tl (car (cdr ring))) (vec (cdr (cdr ring))) (index (ring-mod index numelts)) (vec-index (ring-mod (+ index hd) (length vec)))) (aref vec vec-index))))) ;;; ring.el ends here