Mercurial > emacs
view lisp/emulation/tpu-extras.el @ 81166:4c7d6994e8d6
(org-export-region-as-html, org-replace-region-by-html)
(org-number-to-letters, org-table-fedit-finish)
(org-normalize-color, org-table-fedit-ref-right)
(org-date-to-gregorian, org-table-fedit-move)
(org-table-convert-refs-to-rc, org-calendar-holiday)
(org-table-fedit-toggle-ref-type, org-write-agenda)
(org-colgroup-info-to-vline-list, org-agenda-todo-previousset)
(org-defkey, org-encode-for-stdout)
(org-indent-line-function, org-export-as-html-to-buffer)
(org-store-agenda-views, org-update-mode-line)
(org-find-if, org-delete-all)
(org-table-fedit-convert-buffer, org-emphasize)
(org-uniquify, org-table-fedit-lisp-indent)
(org-table-fedit-scroll, org-get-todo-sequence-head)
(org-table-fedit-scroll-down, org-table-fedit-line-down)
(org-table-fedit-ref-left, org-agenda-export-csv-mapper)
(org-table-fedit-toggle-coordinates, org-dvipng-color)
(org-table-fedit-line-up, org-table-fedit-ref-down)
(org-table-formula-from-user, org-mode-flyspell-verify)
(org-cycle-show-empty-lines, org-ctrl-c-ret)
(org-table-formula-to-user, org-diary-to-ical-string)
(orgtbl-export, org-table-fedit-post-command)
(org-closed-in-range, org-shiftcontrolright)
(org-table-convert-refs-to-an, org-table-hline-and-move)
(org-table-formula-less-p, org-format-table-ascii)
(org-agenda-get-sexps, org-shift-refpart)
(org-diary-sexp-entry, org-time-string-to-absolute)
(org-table-show-reference, org-letters-to-number)
(org-fix-agenda-info, org-table-fedit-ref-up)
(org-table-fedit-shift-reference, org-table-fedit-abort)
(org-closest-date, org-shiftcontrolleft)
(org-at-heading-or-item-p, org-rematch-and-replace)
(org-agenda-todo-nextset, org-export-grab-title-from-buffer): New
function.
(org-table-edit-scroll-down, org-finish-edit-formulas)
(org-table-edit-next-field, org-abort-edit-formulas)
(org-font-lock-level, org-export-find-first-heading-line)
(org-table-edit-line-down, org-table-edit-backward-field)
(org-edit-formula-lisp-indent, org-table-edit-move)
(org-check-log-option, org-this-word)
(org-table-edit-line-up, org-table-edit-formulas-post-command)
(org-agenda-file-to-end, org-expand-file-name)
(org-fake-empty-table-line, org-table-edit-scroll)
(org-toggle-log-option, org-show-reference): Function removed.
(org-inhibit-invisibility, org-table-formula-make-cmp-string): New
defsubst.
(org-unmodified, org-batch-store-agenda-views)
(org-batch-agenda-csv): New macro.
(org-agenda-export): New customization group.
(org-agenda-skip-deadline-if-done, org-agenda-remove-tags)
(org-highest-priority, org-agenda-exporter-settings)
(org-log-done-with-time, org-replace-disputed-keys)
(org-format-latex-header, org-export-table-header-tags)
(org-cycle-separator-lines, org-export-table-data-tags)
(org-icalendar-include-sexps)
(org-empty-line-terminates-plain-lists)
(org-log-repeat, org-special-ctrl-a)
(org-table-use-standard-references, org-disputed-keys)
(org-export-skip-text-before-1st-heading, org-agenda-with-colors)
(org-agenda-export-html-style): New option.
(org-allow-auto-repeat, org-agenda-remove-tags-when-in-prefix)
(org-CUA-compatible): Option removed.
(org-agenda-structure, org-sexp-date): New face.
(org-todo-keywords-for-agenda, org-not-done-keywords)
(org-planning-or-clock-line-re, org-agenda-name)
(org-table-colgroup-info, org-todo-sets)
(constants-unit-system, org-clock-mode-line-entry)
(org-mode-line-timer, org-table-current-begin-pos)
(org-todo-keywords-1, org-mode-line-string)
(org-table-clean-did-remove-column, org-table-fedit-map)
(org-clock-heading, org-table-buffer-is-an)
(org-agenda-info, org-done-keywords)
(org-done-keywords-for-agenda, org-todo-heads)
(org-todo-kwd-alist, org-clock-start-time): New variable.
(org-todo-kwd-priority-p, org-edit-formulas-map)
(org-repeat-re, org-todo-kwd-max-priority)
(org-version, org-done-string)
(org-table-clean-did-remove-column-1, org-disputed-keys): Variable
removed.
(org-table-translate-regexp, org-repeat-re, org-version): New
constant.
(org-ts-lengths): Constant removed.
(org-follow-gnus-link): Don't ask how many articles to read.
(org-export-find-first-export-line): Renamed from
`org-export-find-first-heading'. Use
`org-export-skip-text-before-1st-heading'.
(org-table-fedit-post-command): Renamed from
`org-table-edit-formulas-post-command'.
(org-table-fedit-finish): Renamed from `org-finish-edit-formulas'.
(org-table-fedit-abort): Renamed from `org-abort-edit-formulas'.
(org-table-fedit-lisp-indent): Renamed from
`org-edit-formula-lisp-indent'.
(org-table-show-reference): Renamed from `org-show-reference'.
(org-table-store-formulas): Use `org-table-formula-less-p'.
(org-table-edit-formulas): Position cursor to current field
equation.
(org-update-checkbox-count, org-hide-archived-subtrees)
(org-timestamp-up-day, org-timestamp-down-day)
(org-shiftmetaleft, org-shiftmetaright, org-shiftmetaup)
(org-shiftmetadown, org-metaleft, org-metaright, org-metaup)
(org-metadown, org-shiftup, org-shiftdown, org-shiftright)
(org-shiftleft, org-ctrl-c-ctrl-c, org-context): Let
`org-on-heading-p' also check for invisible heading.
(org-read-date): Match am/pm times.
(org-eval-in-calendar): Fix default date in prompt.
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Wed, 06 Jun 2007 15:13:27 +0000 |
parents | 7a3f13e2dd57 |
children | ac0efac52065 95d0cdf160ea |
line wrap: on
line source
;;; tpu-extras.el --- scroll margins and free cursor mode for TPU-edt ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002, 2003, 2004, ;; 2005, 2006, 2007 Free Software Foundation, Inc. ;; Author: Rob Riepel <riepel@networking.stanford.edu> ;; Maintainer: Rob Riepel <riepel@networking.stanford.edu> ;; Keywords: emulations ;; 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, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; 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: ;; 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. ;; It's actually not known whether the overhead associated with scroll ;; margin support is significant. If you find that it is, please send ;; 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: ;;; Gotta have tpu-edt (require 'tpu-edt) ;;; Customization variables (defcustom tpu-top-scroll-margin 0 "*Scroll margin at the top of the screen. Interpreted as a percent of the current window size." :type 'integer :group 'tpu) (defcustom tpu-bottom-scroll-margin 0 "*Scroll margin at the bottom of the screen. Interpreted as a percent of the current window size." :type 'integer :group 'tpu) (defcustom tpu-backward-char-like-tpu t "*If non-nil, in free cursor mode backward-char (left-arrow) works just like TPU/edt. Otherwise, backward-char will move to the end of the previous line when starting from a line beginning." :type 'boolean :group 'tpu) ;;; Global variables (defvar tpu-cursor-free nil "If non-nil, let the cursor roam free.") ;;; Hooks -- Set cursor free in picture mode. ;;; Clean up when writing a file from cursor free mode. (add-hook 'picture-mode-hook 'tpu-set-cursor-free) (defun tpu-write-file-hook nil "Eliminate whitespace at ends of lines, if the cursor is free." (if (and (buffer-modified-p) tpu-cursor-free) (tpu-trim-line-ends))) (or (memq 'tpu-write-file-hook write-file-functions) (setq write-file-functions (cons 'tpu-write-file-hook write-file-functions))) ;;; 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") (if tpu-cursor-free (picture-forward-column num) (forward-char num))) (defun tpu-backward-char (num) "Move left ARG characters (right if ARG is negative)." (interactive "p") (cond ((not tpu-cursor-free) (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))) (if tpu-cursor-free (or (eobp) (picture-move-down num)) (next-line-internal num)) (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))) (if tpu-cursor-free (picture-move-up num) (next-line-internal (- num))) (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) (forward-visible-line (- 1 num)) (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))) (cond (tpu-cursor-free (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))) (cond (tpu-cursor-free (picture-end-of-line (- 1 num))) (t (end-of-line (- 1 num)))) (tpu-top-check beg num))) (defun tpu-current-end-of-line nil "Move point to end of current line." (interactive) (let ((beg (point))) (if tpu-cursor-free (picture-end-of-line) (end-of-line)) (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))) (next-line-internal num) (tpu-bottom-check beg num) (beginning-of-line))) (defun tpu-backward-line (num) "Move to beginning of previous line. Prefix argument serves as repeat count." (interactive "p") (let ((beg (tpu-current-line))) (or (bolp) (>= 0 num) (setq num (- num 1))) (next-line-internal (- num)) (tpu-top-check beg num) (beginning-of-line))) ;;; 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)))) (next-line-internal (- lines)) (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)))) (next-line-internal lines) (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) (if tpu-searching-forward (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)))))) ;;; Replace the newline, newline-and-indent, and do-auto-fill functions (or (fboundp 'tpu-old-newline) (fset 'tpu-old-newline (symbol-function 'newline))) (or (fboundp 'tpu-old-do-auto-fill) (fset 'tpu-old-do-auto-fill (symbol-function 'do-auto-fill))) (or (fboundp 'tpu-old-newline-and-indent) (fset 'tpu-old-newline-and-indent (symbol-function 'newline-and-indent))) (defun newline (&optional num) "Insert a newline. With arg, insert that many newlines. In Auto Fill mode, can break the preceding line if no numeric arg. This is the TPU-edt version that respects the bottom scroll margin." (interactive "p") (let ((beg (tpu-current-line))) (or num (setq num 1)) (tpu-old-newline num) (tpu-bottom-check beg num))) (defun newline-and-indent nil "Insert a newline, then indent according to major mode. Indentation is done using the current indent-line-function. In programming language modes, this is the same as TAB. In some text modes, where TAB inserts a tab, this indents to the specified left-margin column. This is the TPU-edt version that respects the bottom scroll margin." (interactive) (let ((beg (tpu-current-line))) (tpu-old-newline-and-indent) (tpu-bottom-check beg 1))) (defun do-auto-fill nil "TPU-edt version that respects the bottom scroll margin." (let ((beg (tpu-current-line))) (tpu-old-do-auto-fill) (tpu-bottom-check beg 1))) ;;; Function to set scroll margins ;;;###autoload (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 "") (if (string= "%" (substring top -1)) (setq tpu-top-scroll-margin (string-to-number top)) (setq tpu-top-scroll-margin (/ (1- (+ (* (string-to-number top) 100) (window-height))) (window-height))))) ;; set bottom scroll margin (or (string= bottom "") (if (string= "%" (substring bottom -1)) (setq tpu-bottom-scroll-margin (string-to-number bottom)) (setq tpu-bottom-scroll-margin (/ (1- (+ (* (string-to-number bottom) 100) (window-height))) (window-height))))) ;; 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 ;;;###autoload (defun tpu-set-cursor-free nil "Allow the cursor to move freely about the screen." (interactive) (setq tpu-cursor-free t) (substitute-key-definition 'tpu-set-cursor-free 'tpu-set-cursor-bound GOLD-map) (message "The cursor will now move freely about the screen.")) ;;;###autoload (defun tpu-set-cursor-bound nil "Constrain the cursor to the flow of the text." (interactive) (tpu-trim-line-ends) (setq tpu-cursor-free nil) (substitute-key-definition 'tpu-set-cursor-bound 'tpu-set-cursor-free GOLD-map) (message "The cursor is now bound to the flow of your text.")) ;;; arch-tag: 89676fa4-33ec-48cb-9135-6f3bf230ab1a ;;; tpu-extras.el ends here