; elisp code for simulating ne (in fact, TurboText) under XEmacs ; ; Copyright (C) 2000 Sebastiano Vigna ; ; This file is part of ne, the nice editor. ; ; This program 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. ; ; This program 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 this program; see the file COPYING. If not, write to the Free ; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ; 02111-1307, USA. (defvar current-window-line 0 "Contains the current window line in which point is located. It is updated by the set of amiga-* functions.") (defun current-line () "Return the vertical position of point in the current window." (- (count-lines (window-start) (point)) (if (bolp) 0 1)) ) (defun last-command-vertical-move () (or (eq last-command 'amiga-previous-page) (eq last-command 'amiga-next-page) (eq last-command 'amiga-previous-line) (eq last-command 'amiga-next-line) (eq last-command 'amiga-scroll-one-up) (eq last-command 'amiga-scroll-one-down) (eq last-command 'previous-line) (eq last-command 'next-line)) ) (defun last-command-amiga-vertical-move () (or (eq last-command 'amiga-scroll-one-up) (eq last-command 'amiga-scroll-one-down) (eq last-command 'amiga-previous-page) (eq last-command 'amiga-next-page) (eq last-command 'amiga-previous-line) (eq last-command 'amiga-next-line)) ) (defun update-current-window-line () "Return the vertical position of point in the current window. Uses current-window-line instead of calling current-line if the last command is an amiga-* vertical move command. Otherwise, updates current-window-line using current-line." ;; (message "%d" current-window-line) (if (and (last-command-amiga-vertical-move) (<= current-window-line (window-displayed-height)) (>= current-window-line 0)) current-window-line (setq current-window-line (current-line))) ) (defun amiga-previous-page () (interactive "_") (update-current-window-line) (if (not (last-command-vertical-move)) (setq temporary-goal-column (current-column))) (if (eq current-window-line 0) (scroll-down) nil) (move-to-window-line 0) (setq current-window-line 0) (move-to-column temporary-goal-column) ) (defun amiga-next-page () (interactive "_") (update-current-window-line) (if (not (last-command-vertical-move)) (setq temporary-goal-column (current-column))) (if (eq current-window-line (- (window-displayed-height) 1)) (scroll-up)) (end-of-line) (setq last-line (eobp)) (goto-char (window-end nil 1)) (setq current-window-line (current-line)) (move-to-column temporary-goal-column) (if last-line (signal 'end-of-buffer nil)) ) (defun amiga-previous-line () (interactive "_") (update-current-window-line) (if (not (last-command-vertical-move)) (setq temporary-goal-column (current-column))) (when (zerop current-window-line) (scroll-down 1) (setq current-window-line 1) ) (previous-line 1) (setq current-window-line (- current-window-line 1)) ) (defun amiga-next-line () (interactive "_") (update-current-window-line) (if (not (last-command-vertical-move)) (setq temporary-goal-column (current-column))) (when (eq current-window-line (- (window-displayed-height) 1)) (scroll-up 1) (setq current-window-line (- (count-lines (window-start) (goto-char (window-end nil 1))) (if (bolp) 1 2))) (forward-line -1) (move-to-column temporary-goal-column) ) (next-line 1) (setq current-window-line (+ current-window-line 1)) ) (defun amiga-scroll-one-up () (interactive) (update-current-window-line) (if (not (last-command-vertical-move)) (setq temporary-goal-column (current-column))) (if (eq (point) (point-max)) (signal 'end-of-buffer nil) (progn (if (zerop current-window-line) (progn (amiga-next-line) (scroll-up 1) (setq current-window-line (- current-window-line 1)) ) (scroll-up 1) (setq current-window-line (- current-window-line 1)) (amiga-next-line) ) ) ) ) (defun amiga-scroll-one-down () (interactive) (update-current-window-line) (if (not (last-command-vertical-move)) (setq temporary-goal-column (current-column))) (if (eq (window-start) (point-min)) (signal 'beginning-of-buffer nil) (if (eq current-window-line (- (window-displayed-height) 1)) (progn (amiga-previous-line) (scroll-down 1) (setq current-window-line (+ current-window-line 1)) ) (scroll-down 1) (setq current-window-line (+ current-window-line 1)) (amiga-previous-line) ) ) ) ; Horrible hack: we remap ^x, ^c and ^d with keyboard-translate. There's ; no other way. We recover ^x through ^f10. We also kill all ^x commands. (map-keymap (function (lambda (keyseq binding) (if (equal 'control (car-safe keyseq)) (if (equal 'x (car-safe (cdr keyseq))) (global-set-key keyseq nil) ) ) )) global-map ) (keyboard-translate ?\^x 'cut) (keyboard-translate ?\^c 'copy) (keyboard-translate ?\^d ?\^c) (keyboard-translate 'f10 'x) (setq delete-key-deletes-forward t) (global-set-key "\C-@" 'kill-rectangle) (global-set-key "\C-b" 'set-mark-command) (global-set-key '(control B) 'mark-word) (global-set-key "\C-\M-b" (lambda () (interactive) (set-mark-command t))) (global-set-key 'copy 'copy-region-as-kill) (global-set-key "\C-f" 'isearch-forward) (global-set-key "\C-\M-f" 'isearch-forward-regexp) (global-set-key "\C-j" 'goto-line) (global-set-key "\C-l" 'quoted-insert) (global-set-key "\M-m" 'call-last-kbd-macro) (global-set-key "\C-\M-m" 'call-last-kbd-macro) (global-set-key "\C-n" 'isearch-repeat-forward) (global-set-key "\C-o" 'find-file) (global-set-key "\C-\M-o" 'find-file-other-window) (global-set-key "\C-p" '(lambda () (interactive) (fill-paragraph nil) (forward-sentence))) (global-set-key "\C-\M-p" (lambda () (interactive) (fill-paragraph nil) (forward-sentence))) (global-set-key "\C-q" (lambda () (interactive) (kill-buffer nil))) (global-set-key '(control Q) 'save-buffers-kill-emacs) (global-set-key "\C-r" 'query-replace) (global-set-key "\C-\M-r" 'query-replace-regexp) (global-set-key "\C-s" 'save-buffer) (global-set-key "\C-\M-s" 'write-file) (global-set-key "\C-t" (lambda () (interactive) (if (equal defining-kbd-macro nil) (start-kbd-macro nil) (end-kbd-macro)) )) (global-set-key "\C-v" 'yank) (global-set-key "\C-w" 'yank-rectangle) (global-set-key "\C-y" (lambda () (interactive) (beginning-of-line) (kill-line))) (global-set-key 'cut 'kill-region) (global-set-key "\C-\M-x" 'append-next-kill) (setq scroll-step 1) (global-set-key '(down) 'amiga-next-line) (global-set-key '(up) 'amiga-previous-line) (global-set-key '(shift left) 'backward-word) (global-set-key '(shift right) 'forward-word) (global-set-key '(shift up) 'amiga-previous-page) (global-set-key '(shift down) 'amiga-next-page) (global-set-key '(meta up) 'beginning-of-buffer) (global-set-key '(meta down) 'end-of-buffer) (global-set-key '(meta left) 'beginning-of-line) (global-set-key '(meta right) 'end-of-line) (global-set-key '(shift meta up) 'amiga-scroll-one-down) (global-set-key '(shift meta down) 'amiga-scroll-one-up) (global-set-key '(shift meta control up) 'scroll-other-window-down) (global-set-key '(shift meta control down) 'scroll-other-window) (global-set-key '(shift meta left) 'beginning-of-line-text) (global-set-key '(shift meta right) 'end-of-line) (global-set-key '(meta end) 'end-of-buffer) (global-set-key '(meta home) 'beginning-of-buffer) ;(global-set-key '(tab) 'self-insert-command) (global-set-key '(hpBackTab) (lambda () (interactive) (switch-to-other-buffer 0))) (global-set-key '(shift tab) (lambda () (interactive) (switch-to-other-buffer 0))) (global-set-key '(iso-left-tab) (lambda () (interactive) (switch-to-other-buffer 0))) (global-set-key '(control hpBackTab) 'switch-to-buffer-other-window) (global-set-key '(control shift tab) 'switch-to-buffer-other-window) (global-set-key '(control iso-left-tab) 'switch-to-buffer-other-window) (global-set-key '(prior) 'amiga-previous-page) (global-set-key '(next) 'amiga-next-page) (global-set-key '(shift backspace) 'backward-kill-word) (global-set-key '(shift delete) 'backward-or-forward-kill-word) (global-set-key '(meta backspace) (lambda () (interactive) (kill-line 0))) (global-set-key '(meta delete) 'kill-line) (global-set-key [f1] 'delete-other-windows) (global-set-key [f2] 'split-window-vertically) (global-set-key [f3] 'split-window-horizontally) (global-set-key [f4] 'delete-window) (global-set-key [f5] 'undo) (global-set-key [f9] 'call-last-kbd-macro) ;; This version of line-move uses last-command-vertical-move in order to ;; keep track of the temporary-goal-column, so it works also with all ;; amiga-* commands. (defun line-move (arg) ;; Don't run any point-motion hooks, and disregard intangibility, ;; for intermediate positions. (let ((inhibit-point-motion-hooks t) (opoint (point)) new) (unwind-protect (progn (if (not (last-command-vertical-move)) (setq temporary-goal-column (if (and track-eol (eolp) ;; Don't count beg of empty line as end of line ;; unless we just did explicit end-of-line. (or (not (bolp)) (eq last-command 'end-of-line))) 9999 (current-column)))) (if (and (not (integerp selective-display)) (not line-move-ignore-invisible)) ;; Use just newline characters. (or (if (> arg 0) (progn (if (> arg 1) (forward-line (1- arg))) ;; This way of moving forward ARG lines ;; verifies that we have a newline after the last one. ;; It doesn't get confused by intangible text. (end-of-line) (zerop (forward-line 1))) (and (zerop (forward-line arg)) (bolp))) (signal (if (< arg 0) 'beginning-of-buffer 'end-of-buffer) nil)) ;; Move by arg lines, but ignore invisible ones. (while (> arg 0) (end-of-line) (and (zerop (vertical-motion 1)) (signal 'end-of-buffer nil)) ;; If the following character is currently invisible, ;; skip all characters with that same `invisible' property value. (while (and (not (eobp)) (let ((prop (get-char-property (point) 'invisible))) (if (eq buffer-invisibility-spec t) prop (or (memq prop buffer-invisibility-spec) (assq prop buffer-invisibility-spec))))) (if (get-text-property (point) 'invisible) (goto-char (next-single-property-change (point) 'invisible)) (goto-char (next-extent-change (point))))) ; XEmacs (setq arg (1- arg))) (while (< arg 0) (beginning-of-line) (and (zerop (vertical-motion -1)) (signal 'beginning-of-buffer nil)) (while (and (not (bobp)) (let ((prop (get-char-property (1- (point)) 'invisible))) (if (eq buffer-invisibility-spec t) prop (or (memq prop buffer-invisibility-spec) (assq prop buffer-invisibility-spec))))) (if (get-text-property (1- (point)) 'invisible) (goto-char (previous-single-property-change (point) 'invisible)) (goto-char (previous-extent-change (point))))) ; XEmacs (setq arg (1+ arg)))) (move-to-column (or goal-column temporary-goal-column))) ;; Remember where we moved to, go back home, ;; then do the motion over again ;; in just one step, with intangibility and point-motion hooks ;; enabled this time. (setq new (point)) (goto-char opoint) (setq inhibit-point-motion-hooks nil) (goto-char new))) nil) (standard-display-european 1) (line-number-mode 1) (column-number-mode 1) (require 'paren) (paren-set-mode 'paren) (setq default-truncate-lines 1) (setq resize-minibuffer-mode nil) (setq TeX-auto-untabify nil)