-;;; edt.el --- enhanced EDT keypad mode emulation for GNU Emacs 19
+;;; edt.el --- enhanced EDT keypad mode emulation for GNU Emacs
-;; Copyright (C) 1986, 1992, 1993, 1994, 1995, 2000, 2001, 2002, 2003,
-;; 2004, 2005, 2006, 2007, 2008, 2009, 2010
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1986, 1992-1995, 2000-2013 Free Software Foundation,
+;; Inc.
;; Author: Kevin Gallagher <Kevin.Gallagher@boeing.com>
;; Maintainer: Kevin Gallagher <Kevin.Gallagher@boeing.com>
;;; Commentary:
;;
-;; This is Version 4.0 of the EDT Emulation for Emacs 19 and above.
+;; This is Version 4.0 of the EDT Emulation for Emacs.
;; It comes with special functions which replicate nearly all of EDT's
;; keypad mode behavior. It sets up default keypad and function key
;; bindings which closely match those found in EDT. Support is
;; You can have the EDT Emulation start up automatically, each time
;; you initiate a GNU Emacs session, by adding the following line to
-;; your .emacs file:
+;; your init file:
;;
;; (add-hook term-setup-hook 'edt-emulation-on)
;; default, this feature is enabled, with the top margin set to
;; 10% of the window and the bottom margin set to 15% of the
;; window. To change these settings, you can invoke the function
-;; edt-set-scroll-margins in your .emacs file. For example, the
+;; edt-set-scroll-margins in your init file. For example, the
;; following line
;;
;; (edt-set-scroll-margins "20%" "25%")
;; settings for that session.
;;
;; NOTE: Another way to set the scroll margins is to use the
-;; Emacs customization feature (not available in Emacs 19) to set
-;; the following two variables directly:
+;; Emacs customization feature to set the following two variables
+;; directly:
;;
;; edt-top-scroll-margin and edt-bottom-scroll-margin
;;
;;;
;;; (setq edt-keep-current-page-delimiter t)
;;;
-;;; in your .emacs file.
+;;; in your init file.
(defun edt-page-forward (num)
"Move forward to just after next page delimiter.
(goto-char (point-max))
(edt-line-to-bottom-of-window))
+(defmacro edt-with-position (&rest body)
+ "Execute BODY with some position-related variables bound."
+ `(let* ((left nil)
+ (beg (edt-current-line))
+ (height (window-height))
+ (top-percent
+ (if (zerop edt-top-scroll-margin) 10 edt-top-scroll-margin))
+ (bottom-percent
+ (if (zerop edt-bottom-scroll-margin) 15 edt-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)
+ (point-at-bol (1- height)))))
+ ,@body))
+
;;;
;;; FIND
;;;
"Find first occurrence of a string in forward direction and save it.
Optional argument FIND is t is this function is called from `edt-find'."
(interactive)
- (if (not find)
- (set 'edt-find-last-text (read-string "Search forward: ")))
- (let* ((left nil)
- (beg (edt-current-line))
- (height (window-height))
- (top-percent
- (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin))
- (bottom-percent
- (if (= 0 edt-bottom-scroll-margin) 15 edt-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))))
- (if (search-forward edt-find-last-text)
- (progn
- (search-backward edt-find-last-text)
- (edt-set-match)
- (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)))))))
+ (or find
+ (setq edt-find-last-text (read-string "Search forward: ")))
+ (edt-with-position
+ (when (search-forward edt-find-last-text) ; FIXME noerror?
+ (search-backward edt-find-last-text)
+ (edt-set-match)
+ (if (> (point) far)
+ (if (zerop (setq left (save-excursion (forward-line height))))
+ (recenter top-margin)
+ (recenter (- left bottom-up-margin)))
+ (and (> (point) bottom) (recenter bottom-margin)))))
(if (featurep 'xemacs) (setq zmacs-region-stays t)))
(defun edt-find-backward (&optional find)
"Find first occurrence of a string in the backward direction and save it.
Optional argument FIND is t if this function is called from `edt-find'."
(interactive)
- (if (not find)
- (set 'edt-find-last-text (read-string "Search backward: ")))
- (let* ((left nil)
- (beg (edt-current-line))
- (height (window-height))
- (top-percent
- (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin))
- (bottom-percent
- (if (= 0 edt-bottom-scroll-margin) 15 edt-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))))
- (if (search-backward edt-find-last-text)
- (edt-set-match))
- (and (< (point) top) (recenter (min beg top-margin))))
+ (or find
+ (setq edt-find-last-text (read-string "Search backward: ")))
+ (edt-with-position
+ (if (search-backward edt-find-last-text)
+ (edt-set-match))
+ (and (< (point) top) (recenter (min beg top-margin))))
(if (featurep 'xemacs) (setq zmacs-region-stays t)))
(defun edt-find ()
(defun edt-find-next-forward ()
"Find next occurrence of a string in forward direction."
(interactive)
- (let* ((left nil)
- (beg (edt-current-line))
- (height (window-height))
- (top-percent
- (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin))
- (bottom-percent
- (if (= 0 edt-bottom-scroll-margin) 15 edt-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))))
- (forward-char 1)
- (if (search-forward edt-find-last-text nil t)
- (progn
- (search-backward edt-find-last-text)
- (edt-set-match)
- (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)))))
- (progn
- (backward-char 1)
- (error "Search failed: \"%s\"" edt-find-last-text))))
+ (edt-with-position
+ (forward-char 1)
+ (if (search-forward edt-find-last-text nil t)
+ (progn
+ (search-backward edt-find-last-text)
+ (edt-set-match)
+ (if (> (point) far)
+ (if (zerop (setq left (save-excursion (forward-line height))))
+ (recenter top-margin)
+ (recenter (- left bottom-up-margin)))
+ (and (> (point) bottom) (recenter bottom-margin))))
+ (backward-char 1)
+ (error "Search failed: \"%s\"" edt-find-last-text)))
(if (featurep 'xemacs) (setq zmacs-region-stays t)))
(defun edt-find-next-backward ()
"Find next occurrence of a string in backward direction."
(interactive)
- (let* ((left nil)
- (beg (edt-current-line))
- (height (window-height))
- (top-percent
- (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin))
- (bottom-percent
- (if (= 0 edt-bottom-scroll-margin) 15 edt-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))))
- (if (not (search-backward edt-find-last-text nil t))
- (error "Search failed: \"%s\"" edt-find-last-text)
- (progn
- (edt-set-match)
- (and (< (point) top) (recenter (min beg top-margin))))))
+ (edt-with-position
+ (if (not (search-backward edt-find-last-text nil t))
+ (error "Search failed: \"%s\"" edt-find-last-text)
+ (edt-set-match)
+ (and (< (point) top) (recenter (min beg top-margin)))))
(if (featurep 'xemacs) (setq zmacs-region-stays t)))
(defun edt-find-next ()
Argument NUM is the positive number of sentences to move."
(interactive "p")
(edt-check-prefix num)
- (let* ((left nil)
- (beg (edt-current-line))
- (height (window-height))
- (top-percent
- (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin))
- (bottom-percent
- (if (= 0 edt-bottom-scroll-margin) 15 edt-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))))
- (if (eobp)
- (progn
- (error "End of buffer"))
- (progn
- (forward-sentence num)
- (forward-word 1)
- (backward-sentence)))
- (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)))))
+ (edt-with-position
+ (if (eobp)
+ (error "End of buffer")
+ (forward-sentence num)
+ (forward-word 1)
+ (backward-sentence))
+ (if (> (point) far)
+ (if (zerop (setq left (save-excursion (forward-line height))))
+ (recenter top-margin)
+ (recenter (- left bottom-up-margin)))
+ (and (> (point) bottom) (recenter bottom-margin))))
(if (featurep 'xemacs) (setq zmacs-region-stays t)))
(defun edt-sentence-backward (num)
Argument NUM is the positive number of sentences to move."
(interactive "p")
(edt-check-prefix num)
- (let* ((left nil)
- (beg (edt-current-line))
- (height (window-height))
- (top-percent
- (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin))
- (bottom-percent
- (if (= 0 edt-bottom-scroll-margin) 15 edt-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))))
- (if (eobp)
- (progn
- (error "End of buffer"))
- (backward-sentence num))
- (and (< (point) top) (recenter (min beg top-margin))))
+ (edt-with-position
+ (if (eobp)
+ (error "End of buffer")
+ (backward-sentence num))
+ (and (< (point) top) (recenter (min beg top-margin))))
(if (featurep 'xemacs) (setq zmacs-region-stays t)))
(defun edt-sentence (num)
Argument NUM is the positive number of paragraphs to move."
(interactive "p")
(edt-check-prefix num)
- (let* ((left nil)
- (beg (edt-current-line))
- (height (window-height))
- (top-percent
- (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin))
- (bottom-percent
- (if (= 0 edt-bottom-scroll-margin) 15 edt-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))))
- (while (> num 0)
- (forward-paragraph (+ num 1))
- (start-of-paragraph-text)
- (if (eolp)
- (forward-line 1))
- (setq num (1- 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)))))
+ (edt-with-position
+ (while (> num 0)
+ (forward-paragraph (+ num 1))
+ (start-of-paragraph-text)
+ (if (eolp)
+ (forward-line 1))
+ (setq num (1- num)))
+ (if (> (point) far)
+ (if (zerop (setq left (save-excursion (forward-line height))))
+ (recenter top-margin)
+ (recenter (- left bottom-up-margin)))
+ (and (> (point) bottom) (recenter bottom-margin))))
(if (featurep 'xemacs) (setq zmacs-region-stays t)))
(defun edt-paragraph-backward (num)
Argument NUM is the positive number of paragraphs to move."
(interactive "p")
(edt-check-prefix num)
- (let* ((left nil)
- (beg (edt-current-line))
- (height (window-height))
- (top-percent
- (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin))
- (bottom-percent
- (if (= 0 edt-bottom-scroll-margin) 15 edt-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))))
- (while (> num 0)
- (start-of-paragraph-text)
- (setq num (1- num)))
- (and (< (point) top) (recenter (min beg top-margin))))
+ (edt-with-position
+ (while (> num 0)
+ (start-of-paragraph-text)
+ (setq num (1- num)))
+ (and (< (point) top) (recenter (min beg top-margin))))
(if (featurep 'xemacs) (setq zmacs-region-stays t)))
(defun edt-paragraph (num)
Ack!! You're running the Enhanced EDT Emulation without loading an
EDT key mapping file. To create an EDT key mapping file, run the
edt-mapper program. It is safest to run it from an Emacs loaded
- without any of your own customizations found in your .emacs file, etc.
+ without any of your own customizations found in your init file, etc.
The reason for this is that some user customizations confuse edt-mapper.
You can do this by quitting Emacs and then invoking Emacs again as
follows:
emacs -q -l edt-mapper
- [NOTE: If you do nothing out of the ordinary in your .emacs file, and
+ [NOTE: If you do nothing out of the ordinary in your init file, and
the search for edt-mapper is successful, you can try running it now.]
The library edt-mapper includes these same directions on how to
(setq transient-mark-mode edt-orig-transient-mark-mode))
(message "Original key bindings restored; EDT Emulation disabled"))
+(defun edt-default-menu-bar-update-buffers ()
+ ;; Update edt-default-global-map with latest copy of
+ ;; `global-buffers-menu-map' each time `menu-bar-update-buffers'
+ ;; updates global-map.
+ (define-key edt-default-global-map [menu-bar buffer]
+ (cons "Buffers" global-buffers-menu-map)))
+
+(defun edt-user-menu-bar-update-buffers ()
+ ;; We need to update edt-user-global-map with latest copy of
+ ;; `global-buffers-menu-map' each time `menu-bar-update-buffers'
+ ;; updates global-map.
+ (define-key edt-user-global-map [menu-bar buffer]
+ (cons "Buffers" global-buffers-menu-map)))
+
(defun edt-default-emulation-setup (&optional user-setup)
"Setup emulation of DEC's EDT editor.
Optional argument USER-SETUP non-nil means called from function
(progn
(fset 'edt-emulation-on (symbol-function 'edt-select-default-global-map))
(edt-select-default-global-map)))
- ;; We need to share `global-buffers-menu-map' with the saved global
- ;; keymap, because `menu-bar-update-buffers' directly changes it.
- (define-key (current-global-map) [menu-bar buffer]
- (cons "Buffers" global-buffers-menu-map)))
+ ;; Keep the menu bar Buffers menu up-to-date in edt-default-global-map.
+ (add-hook 'menu-bar-update-hook 'edt-default-menu-bar-update-buffers))
(defun edt-user-emulation-setup ()
"Setup user custom emulation of DEC's EDT editor."
;; See Info node `edt' for more details, and sample edt-user.el file.
(if (fboundp 'edt-setup-user-bindings)
(edt-setup-user-bindings))
- (edt-select-user-global-map))
+ (edt-select-user-global-map)
+ ;; Keep the menu bar Buffers menu up-to-date in edt-user-global-map.
+ (add-hook 'menu-bar-update-hook 'edt-user-menu-bar-update-buffers))
(defun edt-select-default-global-map()
"Select default EDT emulation key bindings."
(edt-bind-gold-key-default "\C-h" 'help-for-help); Just in case.
(edt-bind-gold-key-default [f1] 'help-for-help)
(edt-bind-gold-key-default [help] 'help-for-help)
- (edt-bind-gold-key-default "\C-\\" 'split-window-vertically)
+ (edt-bind-gold-key-default "\C-\\" 'split-window-below)
;; GOLD bindings for regular keys.
(edt-bind-gold-key-default "a" 'edt-key-not-assigned)
F10: Cut Rectangle
G-F10: Paste Rectangle
F11: ESC
- F12: Begining of Line +----------+----------+----------+----------+
+ F12: Beginning of Line +----------+----------+----------+----------+
G-F12: Delete Other Windows | GOLD | HELP | FNDNXT | DEL L |
F13: Delete to Begin of Word | (PF1) | (PF2) | (PF3) | (PF4) |
HELP: Keypad Help |Mark Wisel|Desc Funct| FIND | UND L |
(provide 'edt)
-;; arch-tag: 18d1c54f-6900-4078-8bbc-7c2292f48941
;;; edt.el ends here