Mercurial > emacs
view lisp/rect.el @ 1310:8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
testing for EVENT_HAS_PARAMETERS; EVENT_HEAD works properly on
all sorts of events now.
(read_key_sequence): Use the new accessors to decide in which window
an event occurred.
* keyboard.c (Qevent_unmodified): Replaced by...
(Qevent_symbol_elements): New property.
(syms_of_keyboard): initialize and staticpro the latter, not the
former.
* keyboard.c (readable_events): This doesn't need to scan and
discard mouse release events anymore; it just uses
EVENT_QUEUES_EMPTY.
(kbd_buffer_get_event): No need to skip past mouse release events.
* keyboard.c (button_down_location): New variable, which
stores the location at which each button was pressed, so we
can build a complete drag event when the button is released.
(make_lispy_event): When a button is pressed, record its
location in button_down_location, and turn it into a `down'
event. When a button is released, compare its release
location with its press location, and decide whether to call
it a `click' or `drag' event.
Change mouse movement events to be arranged like click events.
(format_modifiers): Note that the click modifier has no
written representation.
(modifier_names, modifer_symbols): New variables, used to
create the Qevent_symbol_elements property.
(modify_event_symbol): Change the format of the modified
symbol cache; there are too many modifier bits now to use a
vector indexed by a modifier mask. Use an assoc-list instead.
Document the format of the cache.
Put the Qevent_symbol_elements property on each new symbol,
instead of a Qevent_unmodified property.
(symbols_of_keyboard): Put Qevent_symbol_elements properties on
the symbols specified in head_table, not Qevent_unmodifed properties.
Initialize and staticpro modifier_symbols, and staticpro the
window elements of button_down_location.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Fri, 02 Oct 1992 23:55:39 +0000 |
parents | 213978acbc1e |
children | 724b443e445d |
line wrap: on
line source
;;; rect.el --- rectangle functions for GNU Emacs. ;; Copyright (C) 1985 Free Software Foundation, Inc. ;; Maintainer: FSF ;; Keywords: internal ;; 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. ;;; Code: (defun operate-on-rectangle (function start end coerce-tabs) "Call FUNCTION for each line of rectangle with corners at START, END. If COERCE-TABS is non-nil, convert multi-column characters that span the starting or ending columns on any line to multiple spaces before calling FUNCTION. FUNCTION is called with three arguments: position of start of segment of this line within the rectangle, number of columns that belong to rectangle but are before that position, number of columns that belong to rectangle but are after point. Point is at the end of the segment of this line within the rectangle." (let (startcol startlinepos endcol endlinepos) (save-excursion (goto-char start) (setq startcol (current-column)) (beginning-of-line) (setq startlinepos (point))) (save-excursion (goto-char end) (setq endcol (current-column)) (forward-line 1) (setq endlinepos (point-marker))) (if (< endcol startcol) (let ((tem startcol)) (setq startcol endcol endcol tem))) (if (/= endcol startcol) (save-excursion (goto-char startlinepos) (while (< (point) endlinepos) (let (startpos begextra endextra) (move-to-column startcol) (and coerce-tabs (> (current-column) startcol) (rectangle-coerce-tab startcol)) (setq begextra (- (current-column) startcol)) (setq startpos (point)) (move-to-column endcol) (if (> (current-column) endcol) (if coerce-tabs (rectangle-coerce-tab endcol) (forward-char -1))) (setq endextra (- endcol (current-column))) (if (< begextra 0) (setq endextra (+ endextra begextra) begextra 0)) (funcall function startpos begextra endextra)) (forward-line 1)))) (- endcol startcol))) (defun delete-rectangle-line (startdelpos ignore ignore) (delete-region startdelpos (point))) (defun delete-extract-rectangle-line (startdelpos begextra endextra) (save-excursion (extract-rectangle-line startdelpos begextra endextra)) (delete-region startdelpos (point))) (defun extract-rectangle-line (startdelpos begextra endextra) (let ((line (buffer-substring startdelpos (point))) (end (point))) (goto-char startdelpos) (while (search-forward "\t" end t) (let ((width (- (current-column) (save-excursion (forward-char -1) (current-column))))) (setq line (concat (substring line 0 (- (point) end 1)) (spaces-string width) (substring line (+ (length line) (- (point) end))))))) (if (or (> begextra 0) (> endextra 0)) (setq line (concat (spaces-string begextra) line (spaces-string endextra)))) (setq lines (cons line lines)))) (defconst spaces-strings '["" " " " " " " " " " " " " " " " "]) (defun spaces-string (n) (if (<= n 8) (aref spaces-strings n) (let ((val "")) (while (> n 8) (setq val (concat " " val) n (- n 8))) (concat val (aref spaces-strings n))))) ;;;###autoload (defun delete-rectangle (start end) "Delete (don't save) text in rectangle with point and mark as corners. The same range of columns is deleted in each line starting with the line where the region begins and ending with the line where the region ends." (interactive "r") (operate-on-rectangle 'delete-rectangle-line start end t)) ;;;###autoload (defun delete-extract-rectangle (start end) "Delete contents of rectangle and return it as a list of strings. Arguments START and END are the corners of the rectangle. The value is list of strings, one for each line of the rectangle." (let (lines) (operate-on-rectangle 'delete-extract-rectangle-line start end t) (nreverse lines))) ;;;###autoload (defun extract-rectangle (start end) "Return contents of rectangle with corners at START and END. Value is list of strings, one for each line of the rectangle." (let (lines) (operate-on-rectangle 'extract-rectangle-line start end nil) (nreverse lines))) (defvar killed-rectangle nil "Rectangle for yank-rectangle to insert.") ;;;###autoload (defun kill-rectangle (start end) "Delete rectangle with corners at point and mark; save as last killed one. Calling from program, supply two args START and END, buffer positions. But in programs you might prefer to use `delete-extract-rectangle'." (interactive "r") (setq killed-rectangle (delete-extract-rectangle start end))) ;;;###autoload (defun yank-rectangle () "Yank the last killed rectangle with upper left corner at point." (interactive) (insert-rectangle killed-rectangle)) ;;;###autoload (defun insert-rectangle (rectangle) "Insert text of RECTANGLE with upper left corner at point. RECTANGLE's first line is inserted at point, its second line is inserted at a point vertically under point, etc. RECTANGLE should be a list of strings." (let ((lines rectangle) (insertcolumn (current-column)) (first t)) (while lines (or first (progn (forward-line 1) (or (bolp) (insert ?\n)) (move-to-column insertcolumn) (if (> (current-column) insertcolumn) (rectangle-coerce-tab insertcolumn)) (if (< (current-column) insertcolumn) (indent-to insertcolumn)))) (setq first nil) (insert (car lines)) (setq lines (cdr lines))))) ;;;###autoload (defun open-rectangle (start end) "Blank out rectangle with corners at point and mark, shifting text right. The text previously in the region is not overwritten by the blanks, but insted winds up to the right of the rectangle." (interactive "r") (operate-on-rectangle 'open-rectangle-line start end nil)) (defun open-rectangle-line (startpos begextra endextra) (let ((column (+ (current-column) begextra endextra))) (goto-char startpos) (let ((ocol (current-column))) (skip-chars-forward " \t") (setq column (+ column (- (current-column) ocol)))) (delete-region (point) (progn (skip-chars-backward " \t") (point))) (indent-to column))) ;;;###autoload (defun clear-rectangle (start end) "Blank out rectangle with corners at point and mark. The text previously in the region is overwritten by the blanks. When called from a program, requires two args which specify the corners." (interactive "r") (operate-on-rectangle 'clear-rectangle-line start end t)) (defun clear-rectangle-line (startpos begextra endextra) (skip-chars-forward " \t") (let ((column (+ (current-column) endextra))) (delete-region (point) (progn (goto-char startpos) (skip-chars-backward " \t") (point))) (indent-to column))) (defun rectangle-coerce-tab (column) (let ((aftercol (current-column)) (indent-tabs-mode nil)) (delete-char -1) (indent-to aftercol) (backward-char (- aftercol column)))) ;;; rect.el ends here