2001-07-16 12:23:00 +00:00
|
|
|
;;; tpu-extras.el --- scroll margins and free cursor mode for TPU-edt
|
1993-08-10 04:18:07 +00:00
|
|
|
|
2006-12-07 05:06:17 +00:00
|
|
|
;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002, 2003, 2004,
|
2008-01-07 01:14:52 +00:00
|
|
|
;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
1993-08-02 19:11:20 +00:00
|
|
|
|
|
|
|
;; Author: Rob Riepel <riepel@networking.stanford.edu>
|
|
|
|
;; Maintainer: Rob Riepel <riepel@networking.stanford.edu>
|
1993-11-23 20:12:25 +00:00
|
|
|
;; Keywords: emulations
|
1993-08-02 19:11:20 +00:00
|
|
|
|
1993-08-04 08:20:00 +00:00
|
|
|
;; 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
|
2007-07-25 04:14:29 +00:00
|
|
|
;; the Free Software Foundation; either version 3, or (at your option)
|
1993-08-04 08:20:00 +00:00
|
|
|
;; any later version.
|
|
|
|
|
1993-08-02 19:11:20 +00:00
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
1993-08-04 08:20:00 +00:00
|
|
|
;; 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
|
1996-01-14 07:34:30 +00:00
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
2005-07-04 17:55:18 +00:00
|
|
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
1993-08-02 19:11:20 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
1995-07-27 07:37:53 +00:00
|
|
|
;; Use the functions defined here to customize TPU-edt to your tastes by
|
|
|
|
;; setting scroll margins and/or turning on free cursor mode. Here's an
|
|
|
|
;; example for your .emacs file.
|
|
|
|
|
|
|
|
;; (tpu-set-cursor-free) ; Set cursor free.
|
|
|
|
;; (tpu-set-scroll-margins "10%" "15%") ; Set scroll margins.
|
|
|
|
|
|
|
|
;; Scroll margins and cursor binding can be changed from within emacs using
|
|
|
|
;; the following commands:
|
|
|
|
|
|
|
|
;; tpu-set-scroll-margins or set scroll margins
|
|
|
|
;; tpu-set-cursor-bound or set cursor bound
|
|
|
|
;; tpu-set-cursor-free or set cursor free
|
|
|
|
|
|
|
|
;; Additionally, Gold-F toggles between bound and free cursor modes.
|
|
|
|
|
|
|
|
;; Note that switching out of free cursor mode or exiting TPU-edt while in
|
|
|
|
;; free cursor mode strips trailing whitespace from every line in the file.
|
|
|
|
|
|
|
|
|
|
|
|
;;; Details:
|
|
|
|
|
1993-08-02 19:11:20 +00:00
|
|
|
;; The functions contained in this file implement scroll margins and free
|
|
|
|
;; cursor mode. The following keys and commands are affected.
|
|
|
|
|
|
|
|
;; key/command function scroll cursor
|
|
|
|
|
|
|
|
;; Up-Arrow previous line x x
|
|
|
|
;; Down-Arrow next line x x
|
|
|
|
;; Right-Arrow next character x
|
|
|
|
;; Left-Arrow previous character x
|
|
|
|
;; KP0 next or previous line x
|
|
|
|
;; KP7 next or previous page x
|
|
|
|
;; KP8 next or previous screen x
|
|
|
|
;; KP2 next or previous end-of-line x x
|
|
|
|
;; Control-e current end-of-line x
|
|
|
|
;; Control-h previous beginning-of-line x
|
|
|
|
;; Next Scr next screen x
|
|
|
|
;; Prev Scr previous screen x
|
|
|
|
;; Search find a string x
|
|
|
|
;; Replace find and replace a string x
|
|
|
|
;; Newline insert a newline x
|
|
|
|
;; Paragraph next or previous paragraph x
|
|
|
|
;; Auto-Fill break lines on spaces x
|
|
|
|
|
|
|
|
;; These functions are not part of the base TPU-edt for the following
|
|
|
|
;; reasons:
|
|
|
|
|
|
|
|
;; Free cursor mode is implemented with the emacs picture-mode functions.
|
|
|
|
;; These functions support moving the cursor all over the screen, however,
|
|
|
|
;; when the cursor is moved past the end of a line, spaces or tabs are
|
|
|
|
;; appended to the line - even if no text is entered in that area. In
|
|
|
|
;; order for a free cursor mode to work exactly like TPU/edt, this trailing
|
|
|
|
;; whitespace needs to be dealt with in every function that might encounter
|
|
|
|
;; it. Such global changes are impractical, however, free cursor mode is
|
|
|
|
;; too valuable to abandon completely, so it has been implemented in those
|
|
|
|
;; functions where it serves best.
|
|
|
|
|
|
|
|
;; The implementation of scroll margins adds overhead to previously
|
|
|
|
;; simple and often used commands. These commands are now responsible
|
|
|
|
;; for their normal operation and part of the display function. There
|
|
|
|
;; is a possibility that this display overhead could adversely affect the
|
|
|
|
;; performance of TPU-edt on slower computers. In order to support the
|
|
|
|
;; widest range of computers, scroll margin support is optional.
|
|
|
|
|
1995-07-27 07:37:53 +00:00
|
|
|
;; It's actually not known whether the overhead associated with scroll
|
|
|
|
;; margin support is significant. If you find that it is, please send
|
1993-08-02 19:11:20 +00:00
|
|
|
;; a note describing the extent of the performance degradation. Be sure
|
|
|
|
;; to include a description of the platform where you're running TPU-edt.
|
|
|
|
;; Send your note to the address provided by Gold-V.
|
|
|
|
|
|
|
|
;; Even with these differences and limitations, these functions implement
|
|
|
|
;; important aspects of the real TPU/edt. Those who miss free cursor mode
|
|
|
|
;; and/or scroll margins will appreciate these implementations.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
1994-06-20 22:22:23 +00:00
|
|
|
;;; Gotta have tpu-edt
|
1993-08-02 19:11:20 +00:00
|
|
|
|
1994-06-20 22:22:23 +00:00
|
|
|
(require 'tpu-edt)
|
1993-08-02 19:11:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Customization variables
|
|
|
|
|
1998-04-17 17:24:17 +00:00
|
|
|
(defcustom tpu-top-scroll-margin 0
|
2007-08-14 00:51:09 +00:00
|
|
|
"Scroll margin at the top of the screen.
|
1998-04-17 17:24:17 +00:00
|
|
|
Interpreted as a percent of the current window size."
|
|
|
|
:type 'integer
|
|
|
|
:group 'tpu)
|
|
|
|
(defcustom tpu-bottom-scroll-margin 0
|
2007-08-14 00:51:09 +00:00
|
|
|
"Scroll margin at the bottom of the screen.
|
1998-04-17 17:24:17 +00:00
|
|
|
Interpreted as a percent of the current window size."
|
|
|
|
:type 'integer
|
|
|
|
:group 'tpu)
|
1993-08-02 19:11:20 +00:00
|
|
|
|
1998-04-17 17:24:17 +00:00
|
|
|
(defcustom tpu-backward-char-like-tpu t
|
2007-08-14 00:51:09 +00:00
|
|
|
"If non-nil, in free cursor mode backward-char (left-arrow) works
|
1993-08-02 19:11:20 +00:00
|
|
|
just like TPU/edt. Otherwise, backward-char will move to the end of
|
1998-04-17 17:24:17 +00:00
|
|
|
the previous line when starting from a line beginning."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'tpu)
|
1993-08-02 19:11:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Global variables
|
|
|
|
|
2007-08-14 00:51:09 +00:00
|
|
|
;;;###autoload
|
|
|
|
(define-minor-mode tpu-cursor-free-mode
|
|
|
|
"Minor mode to allow the cursor to move freely about the screen."
|
|
|
|
:init-value nil
|
|
|
|
(if (not tpu-cursor-free-mode)
|
|
|
|
(tpu-trim-line-ends)))
|
1993-08-02 19:11:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Hooks -- Set cursor free in picture mode.
|
|
|
|
;;; Clean up when writing a file from cursor free mode.
|
|
|
|
|
1995-04-26 04:03:10 +00:00
|
|
|
(add-hook 'picture-mode-hook 'tpu-set-cursor-free)
|
1993-08-02 19:11:20 +00:00
|
|
|
|
2007-08-14 00:51:09 +00:00
|
|
|
(defun tpu-trim-line-ends-if-needed ()
|
1993-08-02 19:11:20 +00:00
|
|
|
"Eliminate whitespace at ends of lines, if the cursor is free."
|
2007-08-14 00:51:09 +00:00
|
|
|
(if (and (buffer-modified-p) tpu-cursor-free-mode) (tpu-trim-line-ends)))
|
|
|
|
(add-hook 'before-save-hook 'tpu-trim-line-ends-if-needed)
|
1993-08-02 19:11:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Utility routines for implementing scroll margins
|
|
|
|
|
|
|
|
(defun tpu-top-check (beg lines)
|
|
|
|
"Enforce scroll margin at the top of screen."
|
|
|
|
(let ((margin (/ (* (window-height) tpu-top-scroll-margin) 100)))
|
|
|
|
(cond ((< beg margin) (recenter beg))
|
|
|
|
((< (- beg lines) margin) (recenter margin)))))
|
|
|
|
|
|
|
|
(defun tpu-bottom-check (beg lines)
|
|
|
|
"Enforce scroll margin at the bottom of screen."
|
|
|
|
(let* ((height (window-height))
|
|
|
|
(margin (+ 1 (/ (* height tpu-bottom-scroll-margin) 100)))
|
|
|
|
;; subtract 1 from height because it includes mode line
|
|
|
|
(difference (- height margin 1)))
|
|
|
|
(cond ((> beg difference) (recenter beg))
|
|
|
|
((> (+ beg lines) difference) (recenter (- margin))))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Movement by character
|
|
|
|
|
|
|
|
(defun tpu-forward-char (num)
|
|
|
|
"Move right ARG characters (left if ARG is negative)."
|
|
|
|
(interactive "p")
|
2007-08-14 00:51:09 +00:00
|
|
|
(if tpu-cursor-free-mode (picture-forward-column num) (forward-char num)))
|
1993-08-02 19:11:20 +00:00
|
|
|
|
|
|
|
(defun tpu-backward-char (num)
|
|
|
|
"Move left ARG characters (right if ARG is negative)."
|
|
|
|
(interactive "p")
|
2007-08-14 00:51:09 +00:00
|
|
|
(cond ((not tpu-cursor-free-mode)
|
1993-08-02 19:11:20 +00:00
|
|
|
(backward-char num))
|
|
|
|
(tpu-backward-char-like-tpu
|
|
|
|
(picture-backward-column num))
|
|
|
|
((bolp)
|
|
|
|
(backward-char 1)
|
|
|
|
(picture-end-of-line)
|
|
|
|
(picture-backward-column (1- num)))
|
|
|
|
(t
|
|
|
|
(picture-backward-column num))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Movement by line
|
|
|
|
|
|
|
|
(defun tpu-next-line (num)
|
|
|
|
"Move to next line.
|
|
|
|
Prefix argument serves as a repeat count."
|
|
|
|
(interactive "p")
|
|
|
|
(let ((beg (tpu-current-line)))
|
2007-08-14 00:51:09 +00:00
|
|
|
(if tpu-cursor-free-mode (or (eobp) (picture-move-down num))
|
|
|
|
(line-move num))
|
1993-08-02 19:11:20 +00:00
|
|
|
(tpu-bottom-check beg num)
|
|
|
|
(setq this-command 'next-line)))
|
|
|
|
|
|
|
|
(defun tpu-previous-line (num)
|
|
|
|
"Move to previous line.
|
|
|
|
Prefix argument serves as a repeat count."
|
|
|
|
(interactive "p")
|
|
|
|
(let ((beg (tpu-current-line)))
|
2007-08-14 00:51:09 +00:00
|
|
|
(if tpu-cursor-free-mode (picture-move-up num) (line-move (- num)))
|
1993-08-02 19:11:20 +00:00
|
|
|
(tpu-top-check beg num)
|
|
|
|
(setq this-command 'previous-line)))
|
|
|
|
|
|
|
|
(defun tpu-next-beginning-of-line (num)
|
|
|
|
"Move to beginning of line; if at beginning, move to beginning of next line.
|
|
|
|
Accepts a prefix argument for the number of lines to move."
|
|
|
|
(interactive "p")
|
|
|
|
(let ((beg (tpu-current-line)))
|
|
|
|
(backward-char 1)
|
2000-11-30 12:16:38 +00:00
|
|
|
(forward-visible-line (- 1 num))
|
1993-08-02 19:11:20 +00:00
|
|
|
(tpu-top-check beg num)))
|
|
|
|
|
|
|
|
(defun tpu-next-end-of-line (num)
|
|
|
|
"Move to end of line; if at end, move to end of next line.
|
|
|
|
Accepts a prefix argument for the number of lines to move."
|
|
|
|
(interactive "p")
|
|
|
|
(let ((beg (tpu-current-line)))
|
2007-08-14 00:51:09 +00:00
|
|
|
(cond (tpu-cursor-free-mode
|
1993-08-02 19:11:20 +00:00
|
|
|
(let ((beg (point)))
|
|
|
|
(if (< 1 num) (forward-line num))
|
|
|
|
(picture-end-of-line)
|
|
|
|
(if (<= (point) beg) (progn (forward-line) (picture-end-of-line)))))
|
|
|
|
(t
|
|
|
|
(forward-char)
|
|
|
|
(end-of-line num)))
|
|
|
|
(tpu-bottom-check beg num)))
|
|
|
|
|
|
|
|
(defun tpu-previous-end-of-line (num)
|
|
|
|
"Move EOL upward.
|
|
|
|
Accepts a prefix argument for the number of lines to move."
|
|
|
|
(interactive "p")
|
|
|
|
(let ((beg (tpu-current-line)))
|
2007-08-14 00:51:09 +00:00
|
|
|
(cond (tpu-cursor-free-mode
|
1993-08-02 19:11:20 +00:00
|
|
|
(picture-end-of-line (- 1 num)))
|
|
|
|
(t
|
|
|
|
(end-of-line (- 1 num))))
|
|
|
|
(tpu-top-check beg num)))
|
|
|
|
|
2007-08-06 16:20:10 +00:00
|
|
|
(defun tpu-current-end-of-line ()
|
1993-08-02 19:11:20 +00:00
|
|
|
"Move point to end of current line."
|
|
|
|
(interactive)
|
|
|
|
(let ((beg (point)))
|
2007-08-14 00:51:09 +00:00
|
|
|
(if tpu-cursor-free-mode (picture-end-of-line) (end-of-line))
|
1993-08-02 19:11:20 +00:00
|
|
|
(if (= beg (point)) (message "You are already at the end of a line."))))
|
|
|
|
|
|
|
|
(defun tpu-forward-line (num)
|
|
|
|
"Move to beginning of next line.
|
|
|
|
Prefix argument serves as a repeat count."
|
|
|
|
(interactive "p")
|
|
|
|
(let ((beg (tpu-current-line)))
|
2007-08-14 00:51:09 +00:00
|
|
|
(forward-line num)
|
|
|
|
(tpu-bottom-check beg num)))
|
1993-08-02 19:11:20 +00:00
|
|
|
|
|
|
|
(defun tpu-backward-line (num)
|
|
|
|
"Move to beginning of previous line.
|
|
|
|
Prefix argument serves as repeat count."
|
|
|
|
(interactive "p")
|
|
|
|
(let ((beg (tpu-current-line)))
|
1995-07-27 07:37:53 +00:00
|
|
|
(or (bolp) (>= 0 num) (setq num (- num 1)))
|
2007-08-14 00:51:09 +00:00
|
|
|
(forward-line (- num))
|
|
|
|
(tpu-top-check beg num)))
|
1993-08-02 19:11:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Movement by paragraph
|
|
|
|
|
|
|
|
(defun tpu-paragraph (num)
|
|
|
|
"Move to the next paragraph in the current direction.
|
|
|
|
A repeat count means move that many paragraphs."
|
|
|
|
(interactive "p")
|
|
|
|
(let* ((left nil)
|
|
|
|
(beg (tpu-current-line))
|
|
|
|
(height (window-height))
|
|
|
|
(top-percent
|
|
|
|
(if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin))
|
|
|
|
(bottom-percent
|
|
|
|
(if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin))
|
|
|
|
(top-margin (/ (* height top-percent) 100))
|
|
|
|
(bottom-up-margin (+ 1 (/ (* height bottom-percent) 100)))
|
|
|
|
(bottom-margin (max beg (- height bottom-up-margin 1)))
|
|
|
|
(top (save-excursion (move-to-window-line top-margin) (point)))
|
|
|
|
(bottom (save-excursion (move-to-window-line bottom-margin) (point)))
|
|
|
|
(far (save-excursion
|
|
|
|
(goto-char bottom) (forward-line (- height 2)) (point))))
|
|
|
|
(cond (tpu-advance
|
|
|
|
(tpu-next-paragraph num)
|
|
|
|
(cond((> (point) far)
|
|
|
|
(setq left (save-excursion (forward-line height)))
|
|
|
|
(if (= 0 left) (recenter top-margin)
|
|
|
|
(recenter (- left bottom-up-margin))))
|
|
|
|
(t
|
|
|
|
(and (> (point) bottom) (recenter bottom-margin)))))
|
|
|
|
(t
|
|
|
|
(tpu-previous-paragraph num)
|
|
|
|
(and (< (point) top) (recenter (min beg top-margin)))))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Movement by page
|
|
|
|
|
|
|
|
(defun tpu-page (num)
|
|
|
|
"Move to the next page in the current direction.
|
|
|
|
A repeat count means move that many pages."
|
|
|
|
(interactive "p")
|
|
|
|
(let* ((left nil)
|
|
|
|
(beg (tpu-current-line))
|
|
|
|
(height (window-height))
|
|
|
|
(top-percent
|
|
|
|
(if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin))
|
|
|
|
(bottom-percent
|
|
|
|
(if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin))
|
|
|
|
(top-margin (/ (* height top-percent) 100))
|
|
|
|
(bottom-up-margin (+ 1 (/ (* height bottom-percent) 100)))
|
|
|
|
(bottom-margin (max beg (- height bottom-up-margin 1)))
|
|
|
|
(top (save-excursion (move-to-window-line top-margin) (point)))
|
|
|
|
(bottom (save-excursion (move-to-window-line bottom-margin) (point)))
|
|
|
|
(far (save-excursion
|
|
|
|
(goto-char bottom) (forward-line (- height 2)) (point))))
|
|
|
|
(cond (tpu-advance
|
|
|
|
(forward-page num)
|
|
|
|
(cond((> (point) far)
|
|
|
|
(setq left (save-excursion (forward-line height)))
|
|
|
|
(if (= 0 left) (recenter top-margin)
|
|
|
|
(recenter (- left bottom-up-margin))))
|
|
|
|
(t
|
|
|
|
(and (> (point) bottom) (recenter bottom-margin)))))
|
|
|
|
(t
|
|
|
|
(backward-page num)
|
|
|
|
(and (< (point) top) (recenter (min beg top-margin)))))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Scrolling
|
|
|
|
|
|
|
|
(defun tpu-scroll-window-down (num)
|
|
|
|
"Scroll the display down to the next section.
|
|
|
|
A repeat count means scroll that many sections."
|
|
|
|
(interactive "p")
|
|
|
|
(let* ((beg (tpu-current-line))
|
|
|
|
(height (1- (window-height)))
|
|
|
|
(lines (* num (/ (* height tpu-percent-scroll) 100))))
|
2007-08-14 00:51:09 +00:00
|
|
|
(line-move (- lines))
|
1993-08-02 19:11:20 +00:00
|
|
|
(tpu-top-check beg lines)))
|
|
|
|
|
|
|
|
(defun tpu-scroll-window-up (num)
|
|
|
|
"Scroll the display up to the next section.
|
|
|
|
A repeat count means scroll that many sections."
|
|
|
|
(interactive "p")
|
|
|
|
(let* ((beg (tpu-current-line))
|
|
|
|
(height (1- (window-height)))
|
|
|
|
(lines (* num (/ (* height tpu-percent-scroll) 100))))
|
2007-08-14 00:51:09 +00:00
|
|
|
(line-move lines)
|
1993-08-02 19:11:20 +00:00
|
|
|
(tpu-bottom-check beg lines)))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Replace the TPU-edt internal search function
|
|
|
|
|
|
|
|
(defun tpu-search-internal (pat &optional quiet)
|
|
|
|
"Search for a string or regular expression."
|
|
|
|
(let* ((left nil)
|
|
|
|
(beg (tpu-current-line))
|
|
|
|
(height (window-height))
|
|
|
|
(top-percent
|
|
|
|
(if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin))
|
|
|
|
(bottom-percent
|
|
|
|
(if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin))
|
|
|
|
(top-margin (/ (* height top-percent) 100))
|
|
|
|
(bottom-up-margin (+ 1 (/ (* height bottom-percent) 100)))
|
|
|
|
(bottom-margin (max beg (- height bottom-up-margin 1)))
|
|
|
|
(top (save-excursion (move-to-window-line top-margin) (point)))
|
|
|
|
(bottom (save-excursion (move-to-window-line bottom-margin) (point)))
|
|
|
|
(far (save-excursion
|
|
|
|
(goto-char bottom) (forward-line (- height 2)) (point))))
|
|
|
|
(tpu-search-internal-core pat quiet)
|
1993-08-10 04:18:07 +00:00
|
|
|
(if tpu-searching-forward
|
1993-08-02 19:11:20 +00:00
|
|
|
(cond((> (point) far)
|
|
|
|
(setq left (save-excursion (forward-line height)))
|
|
|
|
(if (= 0 left) (recenter top-margin)
|
|
|
|
(recenter (- left bottom-up-margin))))
|
|
|
|
(t
|
|
|
|
(and (> (point) bottom) (recenter bottom-margin))))
|
|
|
|
(and (< (point) top) (recenter (min beg top-margin))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-08-06 16:20:10 +00:00
|
|
|
;; Advise the newline, newline-and-indent, and do-auto-fill functions.
|
|
|
|
(defadvice newline (around tpu-respect-bottom-scroll-margin activate disable)
|
|
|
|
"Respect `tpu-bottom-scroll-margin'."
|
|
|
|
(let ((beg (tpu-current-line))
|
|
|
|
(num (prefix-numeric-value (ad-get-arg 0))))
|
|
|
|
ad-do-it
|
1993-08-02 19:11:20 +00:00
|
|
|
(tpu-bottom-check beg num)))
|
|
|
|
|
2007-08-06 16:20:10 +00:00
|
|
|
(defadvice newline-and-indent (around tpu-respect-bottom-scroll-margin)
|
|
|
|
"Respect `tpu-bottom-scroll-margin'."
|
1993-08-02 19:11:20 +00:00
|
|
|
(let ((beg (tpu-current-line)))
|
2007-08-06 16:20:10 +00:00
|
|
|
ad-do-it
|
1993-08-02 19:11:20 +00:00
|
|
|
(tpu-bottom-check beg 1)))
|
|
|
|
|
2007-08-06 16:20:10 +00:00
|
|
|
(defadvice do-auto-fill (around tpu-respect-bottom-scroll-margin)
|
|
|
|
"Respect `tpu-bottom-scroll-margin'."
|
1993-08-02 19:11:20 +00:00
|
|
|
(let ((beg (tpu-current-line)))
|
2007-08-06 16:20:10 +00:00
|
|
|
ad-do-it
|
1993-08-02 19:11:20 +00:00
|
|
|
(tpu-bottom-check beg 1)))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Function to set scroll margins
|
|
|
|
|
1993-11-26 06:33:45 +00:00
|
|
|
;;;###autoload
|
1993-08-02 19:11:20 +00:00
|
|
|
(defun tpu-set-scroll-margins (top bottom)
|
|
|
|
"Set scroll margins."
|
|
|
|
(interactive
|
|
|
|
"sEnter top scroll margin (N lines or N%% or RETURN for current value): \
|
|
|
|
\nsEnter bottom scroll margin (N lines or N%% or RETURN for current value): ")
|
|
|
|
;; set top scroll margin
|
|
|
|
(or (string= top "")
|
2007-08-06 16:20:10 +00:00
|
|
|
(setq tpu-top-scroll-margin
|
|
|
|
(if (string= "%" (substring top -1))
|
|
|
|
(string-to-number top)
|
2005-05-16 11:34:49 +00:00
|
|
|
(/ (1- (+ (* (string-to-number top) 100) (window-height)))
|
1993-08-02 19:11:20 +00:00
|
|
|
(window-height)))))
|
|
|
|
;; set bottom scroll margin
|
|
|
|
(or (string= bottom "")
|
2007-08-06 16:20:10 +00:00
|
|
|
(setq tpu-bottom-scroll-margin
|
|
|
|
(if (string= "%" (substring bottom -1))
|
|
|
|
(string-to-number bottom)
|
2005-05-16 11:34:49 +00:00
|
|
|
(/ (1- (+ (* (string-to-number bottom) 100) (window-height)))
|
1993-08-02 19:11:20 +00:00
|
|
|
(window-height)))))
|
2007-08-06 16:20:10 +00:00
|
|
|
(dolist (f '(newline newline-and-indent do-auto-fill))
|
|
|
|
(ad-enable-advice f 'around 'tpu-respect-bottom-scroll-margin)
|
|
|
|
(ad-activate f))
|
1993-08-02 19:11:20 +00:00
|
|
|
;; report scroll margin settings if running interactively
|
|
|
|
(and (interactive-p)
|
|
|
|
(message "Scroll margins set. Top = %s%%, Bottom = %s%%"
|
|
|
|
tpu-top-scroll-margin tpu-bottom-scroll-margin)))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Functions to set cursor bound or free
|
|
|
|
|
1993-11-26 06:33:45 +00:00
|
|
|
;;;###autoload
|
2007-08-06 16:20:10 +00:00
|
|
|
(defun tpu-set-cursor-free ()
|
1993-08-02 19:11:20 +00:00
|
|
|
"Allow the cursor to move freely about the screen."
|
|
|
|
(interactive)
|
2007-08-14 00:51:09 +00:00
|
|
|
(tpu-cursor-free-mode 1)
|
1993-08-02 19:11:20 +00:00
|
|
|
(message "The cursor will now move freely about the screen."))
|
|
|
|
|
1993-11-26 06:33:45 +00:00
|
|
|
;;;###autoload
|
2007-08-06 16:20:10 +00:00
|
|
|
(defun tpu-set-cursor-bound ()
|
1993-08-02 19:11:20 +00:00
|
|
|
"Constrain the cursor to the flow of the text."
|
|
|
|
(interactive)
|
2007-08-14 00:51:09 +00:00
|
|
|
(tpu-cursor-free-mode -1)
|
1993-08-02 19:11:20 +00:00
|
|
|
(message "The cursor is now bound to the flow of your text."))
|
|
|
|
|
2007-08-14 00:51:09 +00:00
|
|
|
;; Local Variables:
|
|
|
|
;; generated-autoload-file: "tpu-edt.el"
|
|
|
|
;; End:
|
|
|
|
|
2007-08-06 16:20:10 +00:00
|
|
|
;; arch-tag: 89676fa4-33ec-48cb-9135-6f3bf230ab1a
|
1993-08-02 19:11:20 +00:00
|
|
|
;;; tpu-extras.el ends here
|