edt.el 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608
  1. ;;; edt.el --- enhanced EDT keypad mode emulation for GNU Emacs
  2. ;; Copyright (C) 1986, 1992-1995, 2000-2012 Free Software Foundation, Inc.
  3. ;; Author: Kevin Gallagher <Kevin.Gallagher@boeing.com>
  4. ;; Maintainer: Kevin Gallagher <Kevin.Gallagher@boeing.com>
  5. ;; Keywords: emulations
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;;
  19. ;; This is Version 4.0 of the EDT Emulation for Emacs.
  20. ;; It comes with special functions which replicate nearly all of EDT's
  21. ;; keypad mode behavior. It sets up default keypad and function key
  22. ;; bindings which closely match those found in EDT. Support is
  23. ;; provided so that users may reconfigure most keypad and function key
  24. ;; bindings to their own liking.
  25. ;; NOTE: Version 4.0 contains several enhancements. See the
  26. ;; Enhancement section below for the details.
  27. ;; Getting Started:
  28. ;; To start the EDT Emulation, first start Emacs and then enter
  29. ;;
  30. ;; M-x edt-emulation-on
  31. ;;
  32. ;; to begin the emulation. After initialization is complete, the
  33. ;; following message will appear below the status line informing you
  34. ;; that the emulation has been enabled: "Default EDT keymap active".
  35. ;; You can have the EDT Emulation start up automatically, each time
  36. ;; you initiate a GNU Emacs session, by adding the following line to
  37. ;; your .emacs file:
  38. ;;
  39. ;; (add-hook term-setup-hook 'edt-emulation-on)
  40. ;; IMPORTANT: Be sure to read the Info node `edt' for more details.
  41. ;; It contains very helpful user information.
  42. ;; The EDT emulation consists of the following files:
  43. ;;
  44. ;; edt.texi - User manual
  45. ;; edt-user.el - Sample Customization File
  46. ;; edt.el - EDT Emulation Functions and Default Configuration
  47. ;; edt-lk201.el - Built-in support for DEC LK-201 Keyboards
  48. ;; edt-vt100.el - Built-in support for DEC VT-100 (and above) terminals
  49. ;; edt-pc.el - Built-in support for PC 101 Keyboards under MS-DOS
  50. ;; edt-mapper.el - Create an EDT LK-201 Map File for Keyboards Without
  51. ;; Built-in Support
  52. ;; Enhancements:
  53. ;; Version 4.0 contains the following enhancements:
  54. ;; 1. Scroll margins at the top and bottom of the window are now
  55. ;; supported. (The design was copied from tpu-extras.el.) By
  56. ;; default, this feature is enabled, with the top margin set to
  57. ;; 10% of the window and the bottom margin set to 15% of the
  58. ;; window. To change these settings, you can invoke the function
  59. ;; edt-set-scroll-margins in your .emacs file. For example, the
  60. ;; following line
  61. ;;
  62. ;; (edt-set-scroll-margins "20%" "25%")
  63. ;;
  64. ;; sets the top margin to 20% of the window and the bottom margin
  65. ;; to 25% of the window. To disable this feature, set each
  66. ;; margin to 0%. You can also invoke edt-set-scroll-margins
  67. ;; interactively while EDT Emulation is active to change the
  68. ;; settings for that session.
  69. ;;
  70. ;; NOTE: Another way to set the scroll margins is to use the
  71. ;; Emacs customization feature to set the following two variables
  72. ;; directly:
  73. ;;
  74. ;; edt-top-scroll-margin and edt-bottom-scroll-margin
  75. ;;
  76. ;; Enter the Emacs `customize' command. First select the Editing
  77. ;; group and then select the Emulations group. Finally, select
  78. ;; the Edt group and follow the directions.
  79. ;;
  80. ;; 2. The SUBS command is now supported and bound to GOLD-Enter by
  81. ;; default. (This design was copied from tpu-edt.el.) Note, in
  82. ;; earlier versions of EDT Emulation, GOLD-Enter was assigned to
  83. ;; the Emacs function `query-replace'. The binding of
  84. ;; `query-replace' has been moved to GOLD-/. If you prefer to
  85. ;; restore `query-replace' to GOLD-Enter, then use an EDT user
  86. ;; customization file, edt-user.el, to do this.
  87. ;; See Info node `edt' for more details.
  88. ;; 3. EDT Emulation now also works in XEmacs, including the
  89. ;; highlighting of selected text.
  90. ;; 4. If you access a workstation using an X Server, observe that
  91. ;; the initialization file generated by edt-mapper.el will now
  92. ;; contain the name of the X Server vendor. This is a
  93. ;; convenience for those who have access to their Unix account
  94. ;; from more than one type of X Server. Since different X
  95. ;; Servers typically require different EDT emulation
  96. ;; initialization files, edt-mapper.el will now generate these
  97. ;; different initialization files and save them with different
  98. ;; names. Then, the correct initialization file for the
  99. ;; particular X server in use is loaded correctly automatically.
  100. ;; 5. Also, edt-mapper.el is now capable of binding an ASCII key
  101. ;; sequence, providing the ASCII key sequence prefix is already
  102. ;; known by Emacs to be a prefix. As a result of providing this
  103. ;; support, some terminal/keyboard/window system configurations,
  104. ;; which don't have a complete set of sensible function key
  105. ;; bindings built into Emacs in `function-key-map', can still be
  106. ;; configured for use with EDT Emulation. (Note: In a few rare
  107. ;; circumstances this does not work properly. In particular, it
  108. ;; does not work if a subset of the leading ASCII characters in a
  109. ;; key sequence are recognized by Emacs as having an existing
  110. ;; binding. For example, if the keypad 7 (KP-7) key generates
  111. ;; the sequence \"<ESC>Ow\" and \"<ESC>O\" is already bound to a
  112. ;; function, pressing KP-7 when told to do so by edt-mapper.el
  113. ;; will result in edt-mapper.el incorrectly mapping \"<ESC>O\" to
  114. ;; KP-7 and \"w\" to KP-8. If something like this happens to
  115. ;; you, it is probably a bug in the support for your keyboard
  116. ;; within Emacs OR a bug in the Unix termcap/terminfo support for
  117. ;; your terminal OR a bug in the terminal emulation software you
  118. ;; are using.)
  119. ;; 6. The edt-quit function (bound to GOLD-q by default) has been
  120. ;; modified to warn the user when file-related buffer
  121. ;; modifications exist. It now cautions the user that those
  122. ;; modifications will be lost if the user quits without saving
  123. ;; those buffers.
  124. ;;; History:
  125. ;;
  126. ;; Version 4.0 2000 Added New Features and Fixed a Few Bugs
  127. ;;
  128. ;;; Code:
  129. ;;; Electric Help functions are used for keypad help displays. A few
  130. ;;; picture functions are used in rectangular cut and paste commands.
  131. (require 'ehelp)
  132. (require 'picture)
  133. ;;;;
  134. ;;;; VARIABLES and CONSTANTS
  135. ;;;;
  136. (defgroup edt nil
  137. "Emacs emulating EDT."
  138. :prefix "edt-"
  139. :group 'emulations)
  140. ;; To silence the byte-compiler
  141. (defvar *EDT-keys*)
  142. (defvar edt-default-global-map)
  143. (defvar edt-last-copied-word)
  144. (defvar edt-learn-macro-count)
  145. (defvar edt-orig-page-delimiter)
  146. (defvar edt-orig-transient-mark-mode)
  147. (defvar edt-rect-start-point)
  148. (defvar edt-user-global-map)
  149. (defvar rect-start-point)
  150. (defvar time-string)
  151. (defvar zmacs-region-stays)
  152. ;;;
  153. ;;; Version Information
  154. ;;;
  155. (defconst edt-version "4.0" "EDT Emulation version number.")
  156. ;;;
  157. ;;; User Configurable Variables
  158. ;;;
  159. (defcustom edt-keep-current-page-delimiter nil
  160. "Emacs MUST be restarted for a change in value to take effect!
  161. Non-nil leaves Emacs value of `page-delimiter' unchanged within EDT
  162. Emulation. If set to nil (the default), the `page-delimiter' variable
  163. is set to \"\\f\" when edt-emulation-on is first invoked. This
  164. setting replicates EDT's page delimiter behavior. The original value
  165. is restored when edt-emulation-off is called."
  166. :type 'boolean
  167. :group 'edt)
  168. (defcustom edt-use-EDT-control-key-bindings nil
  169. "Emacs MUST be restarted for a change in value to take effect!
  170. Non-nil causes the control key bindings to be replaced with EDT
  171. bindings. If set to nil (the default), EDT control key bindings are
  172. not used and the current Emacs control key bindings are retained for
  173. use within the EDT emulation."
  174. :type 'boolean
  175. :group 'edt)
  176. (defcustom edt-word-entities '(?\t)
  177. "Specifies the list of EDT word entity characters.
  178. The default list, (\?\\t), contains just the TAB character, which
  179. emulates EDT. Characters are specified in the list using their
  180. decimal ASCII values. A question mark, followed by the actual
  181. character, can be used to indicate the numerical value of the
  182. character, instead of the actual decimal value. So, ?A means the
  183. numerical value for the letter A, \?/ means the numerical value for /,
  184. etc. Several unprintable and special characters have special
  185. representations, which you can also use:
  186. \?\\b specifies BS, C-h
  187. \?\\t specifies TAB, C-i
  188. \?\\n specifies LFD, C-j
  189. \?\\v specifies VTAB, C-k
  190. \?\\f specifies FF, C-l
  191. \?\\r specifies CR, C-m
  192. \?\\e specifies ESC, C-[
  193. \?\\\\ specifies \\
  194. In EDT Emulation movement-by-word commands, each character in the list
  195. will be treated as if it were a separate word."
  196. :type '(repeat integer)
  197. :group 'edt)
  198. (defcustom edt-top-scroll-margin 10
  199. "Scroll margin at the top of the screen.
  200. Interpreted as a percent of the current window size with a default
  201. setting of 10%. If set to 0, top scroll margin is disabled."
  202. :type 'integer
  203. :group 'edt)
  204. (defcustom edt-bottom-scroll-margin 15
  205. "Scroll margin at the bottom of the screen.
  206. Interpreted as a percent of the current window size with a default
  207. setting of 15%. If set to 0, bottom scroll margin is disabled."
  208. :type 'integer
  209. :group 'edt)
  210. ;;;
  211. ;;; Internal Variables
  212. ;;;
  213. (defvar edt-last-deleted-lines ""
  214. "Last text deleted by the EDT emulation DEL L command.")
  215. (defvar edt-last-deleted-words ""
  216. "Last text deleted by the EDT emulation DEL W command.")
  217. (defvar edt-last-deleted-chars ""
  218. "Last text deleted by the EDT emulation DEL C command.")
  219. (defvar edt-find-last-text ""
  220. "Last text found by the EDT emulation FIND command.")
  221. (defvar edt-match-beginning-mark (make-marker)
  222. "Used internally by the EDT emulation SUBS command.")
  223. (defvar edt-match-end-mark (make-marker)
  224. "Used internally by the EDT emulation SUBS command.")
  225. (defvar edt-last-replaced-key-definition nil
  226. "Key definition replaced with `edt-define-key' or `edt-learn' command.")
  227. (defvar edt-direction-string ""
  228. "String indicating current direction of movement.")
  229. (defvar edt-select-mode nil
  230. "Non-nil means select mode is active.")
  231. (defvar edt-select-mode-current ""
  232. "Text displayed in mode line to indicate the state of EDT select mode.
  233. When select mode is inactive, it is set to an empty string.")
  234. (defconst edt-select-mode-string " Select"
  235. "Used in mode line to indicate select mode is active.")
  236. (defconst edt-forward-string " ADVANCE"
  237. "Direction string in mode line to indicate forward movement.")
  238. (defconst edt-backward-string " BACKUP"
  239. "Direction string in mode line to indicate backward movement.")
  240. (defvar edt-default-map-active nil
  241. "Non-nil indicates that default EDT emulation key bindings are active.
  242. nil means user-defined custom bindings are active.")
  243. (defvar edt-user-map-configured nil
  244. "Non-nil indicates that user custom EDT key bindings are configured.
  245. This means that an edt-user.el file was found in the user's `load-path'.")
  246. (defvar edt-term nil
  247. "Specifies the terminal type, if applicable.")
  248. ;;;
  249. ;;; Emacs version identifiers - currently referenced by
  250. ;;;
  251. ;;; o edt-emulation-on o edt-load-keys
  252. ;;;
  253. (defconst edt-emacs-variant (if (featurep 'emacs) "gnu" "xemacs")
  254. "Indicates Emacs variant: GNU Emacs or XEmacs \(aka Lucid Emacs\).")
  255. (defconst edt-window-system (if (featurep 'emacs) window-system (console-type))
  256. "Indicates window system \(in GNU Emacs\) or console type \(in XEmacs\).")
  257. (declare-function x-server-vendor "xfns.c" (&optional terminal))
  258. (defconst edt-xserver (when (eq edt-window-system 'x)
  259. ;; The Cygwin window manager has a `/' in its
  260. ;; name, which breaks the generated file name of
  261. ;; the custom key map file. Replace `/' with a
  262. ;; `-' to work around that.
  263. (if (featurep 'xemacs)
  264. (replace-in-string (x-server-vendor) "[ /]" "-")
  265. (replace-regexp-in-string "[ /]" "-"
  266. (x-server-vendor))))
  267. "Indicates X server vendor name, if applicable.")
  268. (defvar edt-keys-file nil
  269. "User's custom keypad and function keys mappings to emulate LK-201 keyboard.")
  270. (defvar edt-last-copied-word nil
  271. "Last word that the user copied.")
  272. ;;;;
  273. ;;;; EDT Emulation Commands
  274. ;;;;
  275. ;;; Almost all of EDT's keypad mode commands have equivalent Emacs
  276. ;;; function counterparts. But many of these counterparts behave
  277. ;;; somewhat differently in Emacs.
  278. ;;;
  279. ;;; So, the following Emacs functions emulate, where practical, the
  280. ;;; exact behavior of the corresponding EDT keypad mode commands. In
  281. ;;; a few cases, the emulation is not exact, but it should be close
  282. ;;; enough for most EDT die-hards.
  283. ;;;
  284. ;;;
  285. ;;; PAGE
  286. ;;;
  287. ;;; Emacs uses the regexp assigned to page-delimiter to determine what
  288. ;;; marks a page break. This is normally "^\f", which causes the
  289. ;;; edt-page command to ignore form feeds not located at the beginning
  290. ;;; of a line. To emulate the EDT PAGE command exactly,
  291. ;;; page-delimiter is set to "\f" when EDT emulation is turned on, and
  292. ;;; restored to its original value when EDT emulation is turned off.
  293. ;;; But this can be overridden if the EDT definition is not desired by
  294. ;;; placing
  295. ;;;
  296. ;;; (setq edt-keep-current-page-delimiter t)
  297. ;;;
  298. ;;; in your .emacs file.
  299. (defun edt-page-forward (num)
  300. "Move forward to just after next page delimiter.
  301. Argument NUM is the number of page delimiters to move."
  302. (interactive "p")
  303. (edt-check-prefix num)
  304. (if (eobp)
  305. (error "End of buffer")
  306. (progn
  307. (forward-page num)
  308. (if (eobp)
  309. (edt-line-to-bottom-of-window)
  310. (edt-line-to-top-of-window)))))
  311. (defun edt-page-backward (num)
  312. "Move backward to just after previous page delimiter.
  313. Argument NUM is the number of page delimiters to move."
  314. (interactive "p")
  315. (edt-check-prefix num)
  316. (if (bobp)
  317. (error "Beginning of buffer")
  318. (progn
  319. (backward-page num)
  320. (edt-line-to-top-of-window)
  321. (if (featurep 'xemacs) (setq zmacs-region-stays t)))))
  322. (defun edt-page (num)
  323. "Move in current direction to next page delimiter.
  324. Argument NUM is the number of page delimiters to move."
  325. (interactive "p")
  326. (if (equal edt-direction-string edt-forward-string)
  327. (edt-page-forward num)
  328. (edt-page-backward num)))
  329. ;;;
  330. ;;; SECT
  331. ;;;
  332. ;;; EDT defaults a section size to be 16 lines of its one and only
  333. ;;; 24-line window. That's two-thirds of the window at a time. The
  334. ;;; EDT SECT commands moves the cursor, not the window.
  335. ;;;
  336. ;;; This emulation of EDT's SECT moves the cursor approximately
  337. ;;; two-thirds of the current window at a time.
  338. (defun edt-sect-forward (num)
  339. "Move cursor forward two-thirds of a window's number of lines.
  340. Argument NUM is the number of sections to move."
  341. (interactive "p")
  342. (edt-check-prefix num)
  343. (edt-line-forward (* (* (/ (- (window-height) 1) 3) 2) num)))
  344. (defun edt-sect-backward (num)
  345. "Move cursor backward two-thirds of a window.
  346. Argument NUM is the number of sections to move."
  347. (interactive "p")
  348. (edt-check-prefix num)
  349. (edt-line-backward (* (* (/ (- (window-height) 1) 3) 2) num)))
  350. (defun edt-sect (num)
  351. "Move in current direction a full window.
  352. Argument NUM is the number of sections to move."
  353. (interactive "p")
  354. (if (equal edt-direction-string edt-forward-string)
  355. (edt-sect-forward num)
  356. (edt-sect-backward num)))
  357. ;;;
  358. ;;; BEGINNING OF LINE
  359. ;;;
  360. ;;; EDT's beginning-of-line command is not affected by current
  361. ;;; direction, for some unknown reason.
  362. (defun edt-beginning-of-line (num)
  363. "Move backward to next beginning of line mark.
  364. Argument NUM is the number of BOL marks to move."
  365. (interactive "p")
  366. (edt-check-prefix num)
  367. (let ((beg (edt-current-line)))
  368. (if (bolp)
  369. (forward-line (* -1 num))
  370. (progn
  371. (setq num (1- num))
  372. (forward-line (* -1 num))))
  373. (edt-top-check beg num))
  374. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  375. ;;;
  376. ;;; EOL (End of Line)
  377. ;;;
  378. (defun edt-end-of-line-forward (num)
  379. "Move forward to next end of line mark.
  380. Argument NUM is the number of EOL marks to move."
  381. (interactive "p")
  382. (edt-check-prefix num)
  383. (let ((beg (edt-current-line)))
  384. (forward-char)
  385. (end-of-line num)
  386. (edt-bottom-check beg num))
  387. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  388. (defun edt-end-of-line-backward (num)
  389. "Move backward to next end of line mark.
  390. Argument NUM is the number of EOL marks to move."
  391. (interactive "p")
  392. (edt-check-prefix num)
  393. (let ((beg (edt-current-line)))
  394. (end-of-line (1- num))
  395. (edt-top-check beg num))
  396. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  397. (defun edt-end-of-line (num)
  398. "Move in current direction to next end of line mark.
  399. Argument NUM is the number of EOL marks to move."
  400. (interactive "p")
  401. (if (equal edt-direction-string edt-forward-string)
  402. (edt-end-of-line-forward num)
  403. (edt-end-of-line-backward num)))
  404. ;;;
  405. ;;; WORD
  406. ;;;
  407. ;;; This one is a tad messy. To emulate EDT's behavior everywhere in
  408. ;;; the file (beginning of file, end of file, beginning of line, end
  409. ;;; of line, etc.) it takes a bit of special handling.
  410. ;;;
  411. ;;; The variable edt-word-entities contains a list of characters which
  412. ;;; are to be viewed as distinct words where ever they appear in the
  413. ;;; buffer. This emulates the EDT line mode command SET ENTITY WORD.
  414. (defun edt-one-word-forward ()
  415. "Move forward to first character of next word."
  416. (interactive)
  417. (if (eobp)
  418. (error "End of buffer"))
  419. (if (eolp)
  420. (forward-char)
  421. (progn
  422. (if (memq (following-char) edt-word-entities)
  423. (forward-char)
  424. (while (and
  425. (not (eolp))
  426. (not (eobp))
  427. (not (eq ?\ (char-syntax (following-char))))
  428. (not (memq (following-char) edt-word-entities)))
  429. (forward-char)))
  430. (while (and
  431. (not (eolp))
  432. (not (eobp))
  433. (eq ?\ (char-syntax (following-char)))
  434. (not (memq (following-char) edt-word-entities)))
  435. (forward-char))))
  436. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  437. (defun edt-one-word-backward ()
  438. "Move backward to first character of previous word."
  439. (interactive)
  440. (if (bobp)
  441. (error "Beginning of buffer"))
  442. (if (bolp)
  443. (backward-char)
  444. (progn
  445. (backward-char)
  446. (while (and
  447. (not (bolp))
  448. (not (bobp))
  449. (eq ?\ (char-syntax (following-char)))
  450. (not (memq (following-char) edt-word-entities)))
  451. (backward-char))
  452. (if (not (memq (following-char) edt-word-entities))
  453. (while (and
  454. (not (bolp))
  455. (not (bobp))
  456. (not (eq ?\ (char-syntax (preceding-char))))
  457. (not (memq (preceding-char) edt-word-entities)))
  458. (backward-char)))))
  459. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  460. (defun edt-word-forward (num)
  461. "Move forward to first character of next word.
  462. Argument NUM is the number of words to move."
  463. (interactive "p")
  464. (edt-check-prefix num)
  465. (while (> num 0)
  466. (edt-one-word-forward)
  467. (setq num (1- num))))
  468. (defun edt-word-backward (num)
  469. "Move backward to first character of previous word.
  470. Argument NUM is the number of words to move."
  471. (interactive "p")
  472. (edt-check-prefix num)
  473. (while (> num 0)
  474. (edt-one-word-backward)
  475. (setq num (1- num))))
  476. (defun edt-word (num)
  477. "Move in current direction to first character of next word.
  478. Argument NUM is the number of words to move."
  479. (interactive "p")
  480. (if (equal edt-direction-string edt-forward-string)
  481. (edt-word-forward num)
  482. (edt-word-backward num)))
  483. ;;;
  484. ;;; CHAR
  485. ;;;
  486. (defun edt-character (num)
  487. "Move in current direction to next character.
  488. Argument NUM is the number of characters to move."
  489. (interactive "p")
  490. (edt-check-prefix num)
  491. (if (equal edt-direction-string edt-forward-string)
  492. (forward-char num)
  493. (backward-char num))
  494. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  495. ;;;
  496. ;;; LINE
  497. ;;;
  498. ;;; When direction is set to BACKUP, LINE behaves just like BEGINNING
  499. ;;; OF LINE in EDT. So edt-line-backward is not really needed as a
  500. ;;; separate function.
  501. (defun edt-line-backward (num)
  502. "Move backward to next beginning of line mark.
  503. Argument NUM is the number of BOL marks to move."
  504. (interactive "p")
  505. (edt-beginning-of-line num))
  506. (defun edt-line-forward (num)
  507. "Move forward to next beginning of line mark.
  508. Argument NUM is the number of BOL marks to move."
  509. (interactive "p")
  510. (edt-check-prefix num)
  511. (let ((beg (edt-current-line)))
  512. (forward-line num)
  513. (edt-bottom-check beg num))
  514. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  515. (defun edt-line (num)
  516. "Move in current direction to next beginning of line mark.
  517. Argument NUM is the number of BOL marks to move."
  518. (interactive "p")
  519. (if (equal edt-direction-string edt-forward-string)
  520. (edt-line-forward num)
  521. (edt-line-backward num)))
  522. ;;;
  523. ;;; UP and DOWN Arrows
  524. ;;;
  525. (defun edt-next-line (num)
  526. "Move cursor down one line.
  527. Argument NUM is the number of lines to move."
  528. (interactive "p")
  529. (edt-check-prefix num)
  530. (let ((beg (edt-current-line)))
  531. ;; We're deliberately using next-line instead of forward-line.
  532. (with-no-warnings (next-line num))
  533. (edt-bottom-check beg num))
  534. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  535. (defun edt-previous-line (num)
  536. "Move cursor up one line.
  537. Argument NUM is the number of lines to move."
  538. (interactive "p")
  539. (edt-check-prefix num)
  540. (let ((beg (edt-current-line)))
  541. ;; We're deliberately using previous-line instead of forward-line.
  542. (with-no-warnings (previous-line num))
  543. (edt-top-check beg num))
  544. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  545. ;;;
  546. ;;; TOP
  547. ;;;
  548. (defun edt-top ()
  549. "Move cursor to the beginning of buffer."
  550. (interactive)
  551. (goto-char (point-min))
  552. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  553. ;;;
  554. ;;; BOTTOM
  555. ;;;
  556. (defun edt-bottom ()
  557. "Move cursor to the end of buffer."
  558. (interactive)
  559. (goto-char (point-max))
  560. (edt-line-to-bottom-of-window))
  561. (defmacro edt-with-position (&rest body)
  562. "Execute BODY with some position-related variables bound."
  563. `(let* ((left nil)
  564. (beg (edt-current-line))
  565. (height (window-height))
  566. (top-percent
  567. (if (zerop edt-top-scroll-margin) 10 edt-top-scroll-margin))
  568. (bottom-percent
  569. (if (zerop edt-bottom-scroll-margin) 15 edt-bottom-scroll-margin))
  570. (top-margin (/ (* height top-percent) 100))
  571. (bottom-up-margin (1+ (/ (* height bottom-percent) 100)))
  572. (bottom-margin (max beg (- height bottom-up-margin 1)))
  573. (top (save-excursion (move-to-window-line top-margin) (point)))
  574. (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
  575. (far (save-excursion
  576. (goto-char bottom)
  577. (point-at-bol (1- height)))))
  578. ,@body))
  579. ;;;
  580. ;;; FIND
  581. ;;;
  582. (defun edt-find-forward (&optional find)
  583. "Find first occurrence of a string in forward direction and save it.
  584. Optional argument FIND is t is this function is called from `edt-find'."
  585. (interactive)
  586. (or find
  587. (setq edt-find-last-text (read-string "Search forward: ")))
  588. (edt-with-position
  589. (when (search-forward edt-find-last-text) ; FIXME noerror?
  590. (search-backward edt-find-last-text)
  591. (edt-set-match)
  592. (if (> (point) far)
  593. (if (zerop (setq left (save-excursion (forward-line height))))
  594. (recenter top-margin)
  595. (recenter (- left bottom-up-margin)))
  596. (and (> (point) bottom) (recenter bottom-margin)))))
  597. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  598. (defun edt-find-backward (&optional find)
  599. "Find first occurrence of a string in the backward direction and save it.
  600. Optional argument FIND is t if this function is called from `edt-find'."
  601. (interactive)
  602. (or find
  603. (setq edt-find-last-text (read-string "Search backward: ")))
  604. (edt-with-position
  605. (if (search-backward edt-find-last-text)
  606. (edt-set-match))
  607. (and (< (point) top) (recenter (min beg top-margin))))
  608. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  609. (defun edt-find ()
  610. "Find first occurrence of string in current direction and save it."
  611. (interactive)
  612. (set 'edt-find-last-text (read-string "Search: "))
  613. (if (equal edt-direction-string edt-forward-string)
  614. (edt-find-forward t)
  615. (edt-find-backward t)))
  616. ;;;
  617. ;;; FNDNXT
  618. ;;;
  619. (defun edt-find-next-forward ()
  620. "Find next occurrence of a string in forward direction."
  621. (interactive)
  622. (edt-with-position
  623. (forward-char 1)
  624. (if (search-forward edt-find-last-text nil t)
  625. (progn
  626. (search-backward edt-find-last-text)
  627. (edt-set-match)
  628. (if (> (point) far)
  629. (if (zerop (setq left (save-excursion (forward-line height))))
  630. (recenter top-margin)
  631. (recenter (- left bottom-up-margin)))
  632. (and (> (point) bottom) (recenter bottom-margin))))
  633. (backward-char 1)
  634. (error "Search failed: \"%s\"" edt-find-last-text)))
  635. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  636. (defun edt-find-next-backward ()
  637. "Find next occurrence of a string in backward direction."
  638. (interactive)
  639. (edt-with-position
  640. (if (not (search-backward edt-find-last-text nil t))
  641. (error "Search failed: \"%s\"" edt-find-last-text)
  642. (edt-set-match)
  643. (and (< (point) top) (recenter (min beg top-margin)))))
  644. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  645. (defun edt-find-next ()
  646. "Find next occurrence of a string in current direction."
  647. (interactive)
  648. (if (equal edt-direction-string edt-forward-string)
  649. (edt-find-next-forward)
  650. (edt-find-next-backward)))
  651. ;;;
  652. ;;; APPEND
  653. ;;;
  654. (defun edt-append ()
  655. "Append this kill region to last killed region."
  656. (interactive "*")
  657. (edt-check-selection)
  658. (append-next-kill)
  659. (kill-region (mark) (point))
  660. (message "Selected text APPENDED to kill ring"))
  661. ;;;
  662. ;;; DEL L
  663. ;;;
  664. (defun edt-delete-line (num)
  665. "Delete from cursor up to and including the end of line mark.
  666. Argument NUM is the number of lines to delete."
  667. (interactive "*p")
  668. (edt-check-prefix num)
  669. (let ((beg (point)))
  670. (forward-line num)
  671. (if (not (eq (preceding-char) ?\n))
  672. (insert "\n"))
  673. (setq edt-last-deleted-lines
  674. (buffer-substring beg (point)))
  675. (delete-region beg (point))))
  676. ;;;
  677. ;;; DEL EOL
  678. ;;;
  679. (defun edt-delete-to-end-of-line (num)
  680. "Delete from cursor up to but excluding the end of line mark.
  681. Argument NUM is the number of lines to delete."
  682. (interactive "*p")
  683. (edt-check-prefix num)
  684. (let ((beg (point)))
  685. (forward-char 1)
  686. (end-of-line num)
  687. (setq edt-last-deleted-lines
  688. (buffer-substring beg (point)))
  689. (delete-region beg (point))))
  690. ;;;
  691. ;;; SELECT
  692. ;;;
  693. (defun edt-select-mode (arg)
  694. "Turn EDT select mode off if ARG is nil; otherwise, turn EDT select mode on.
  695. In select mode, selected text is highlighted."
  696. (if arg
  697. (progn
  698. (set (make-local-variable 'edt-select-mode) 'edt-select-mode-current)
  699. (setq rect-start-point (window-point)))
  700. (progn
  701. (kill-local-variable 'edt-select-mode)))
  702. (force-mode-line-update))
  703. (defun edt-select ()
  704. "Set mark at cursor and start text selection."
  705. (interactive)
  706. (set-mark-command nil))
  707. (defun edt-reset ()
  708. "Cancel text selection."
  709. (interactive)
  710. (if (featurep 'emacs)
  711. (deactivate-mark)
  712. (zmacs-deactivate-region)))
  713. ;;;
  714. ;;; CUT
  715. ;;;
  716. (defun edt-cut ()
  717. "Deletes selected text but copies to kill ring."
  718. (interactive "*")
  719. (edt-check-selection)
  720. (kill-region (mark) (point))
  721. (message "Selected text CUT to kill ring"))
  722. ;;;
  723. ;;; DELETE TO BEGINNING OF LINE
  724. ;;;
  725. (defun edt-delete-to-beginning-of-line (num)
  726. "Delete from cursor to beginning of line.
  727. Argument NUM is the number of lines to delete."
  728. (interactive "*p")
  729. (edt-check-prefix num)
  730. (let ((beg (point)))
  731. (edt-beginning-of-line num)
  732. (setq edt-last-deleted-lines
  733. (buffer-substring (point) beg))
  734. (delete-region beg (point))))
  735. ;;;
  736. ;;; DEL W
  737. ;;;
  738. (defun edt-delete-word (num)
  739. "Delete from cursor up to but excluding first character of next word.
  740. Argument NUM is the number of words to delete."
  741. (interactive "*p")
  742. (edt-check-prefix num)
  743. (let ((beg (point)))
  744. (edt-word-forward num)
  745. (setq edt-last-deleted-words (buffer-substring beg (point)))
  746. (delete-region beg (point))))
  747. ;;;
  748. ;;; DELETE TO BEGINNING OF WORD
  749. ;;;
  750. (defun edt-delete-to-beginning-of-word (num)
  751. "Delete from cursor to beginning of word.
  752. Argument NUM is the number of words to delete."
  753. (interactive "*p")
  754. (edt-check-prefix num)
  755. (let ((beg (point)))
  756. (edt-word-backward num)
  757. (setq edt-last-deleted-words (buffer-substring (point) beg))
  758. (delete-region beg (point))))
  759. ;;;
  760. ;;; DEL C
  761. ;;;
  762. (defun edt-delete-character (num)
  763. "Delete character under cursor.
  764. Argument NUM is the number of characters to delete."
  765. (interactive "*p")
  766. (edt-check-prefix num)
  767. (setq edt-last-deleted-chars
  768. (buffer-substring (point) (min (point-max) (+ (point) num))))
  769. (delete-region (point) (min (point-max) (+ (point) num))))
  770. ;;;
  771. ;;; DELETE CHAR
  772. ;;;
  773. (defun edt-delete-previous-character (num)
  774. "Delete character in front of cursor.
  775. Argument NUM is the number of characters to delete."
  776. (interactive "*p")
  777. (edt-check-prefix num)
  778. (setq edt-last-deleted-chars
  779. (buffer-substring (max (point-min) (- (point) num)) (point)))
  780. (delete-region (max (point-min) (- (point) num)) (point)))
  781. ;;;
  782. ;;; UND L
  783. ;;;
  784. (defun edt-undelete-line ()
  785. "Undelete previous deleted line(s)."
  786. (interactive "*")
  787. (point-to-register 1)
  788. (insert edt-last-deleted-lines)
  789. (register-to-point 1))
  790. ;;;
  791. ;;; UND W
  792. ;;;
  793. (defun edt-undelete-word ()
  794. "Undelete previous deleted word(s)."
  795. (interactive "*")
  796. (point-to-register 1)
  797. (insert edt-last-deleted-words)
  798. (register-to-point 1))
  799. ;;;
  800. ;;; UND C
  801. ;;;
  802. (defun edt-undelete-character ()
  803. "Undelete previous deleted character(s)."
  804. (interactive "*")
  805. (point-to-register 1)
  806. (insert edt-last-deleted-chars)
  807. (register-to-point 1))
  808. ;;;
  809. ;;; REPLACE
  810. ;;;
  811. (defun edt-replace ()
  812. "Replace marked section with last CUT (killed) text."
  813. (interactive "*")
  814. (if (edt-check-match)
  815. (replace-match (car kill-ring-yank-pointer))
  816. (progn
  817. (exchange-point-and-mark)
  818. (let ((beg (point)))
  819. (exchange-point-and-mark)
  820. (delete-region beg (point)))
  821. (yank))))
  822. ;;;
  823. ;;; SUBS
  824. ;;;
  825. (defun edt-substitute (num)
  826. "Replace the selected region with the contents of the CUT buffer and.
  827. Repeat the most recent FIND command. (The Emacs kill ring is used as
  828. the CUT buffer.)
  829. Argument NUM is the repeat count. A positive value indicates the of times
  830. to repeat the substitution. A negative argument means replace all occurrences
  831. of the search text."
  832. (interactive "p")
  833. (cond ((or edt-select-mode (edt-check-match))
  834. (while (and (not (= num 0)) (or edt-select-mode (edt-check-match)))
  835. (edt-replace)
  836. (edt-find-next)
  837. (setq num (1- num))))
  838. (t
  839. (error "No selection active"))))
  840. (defun edt-set-match nil
  841. "Set markers at match beginning and end."
  842. ;; Add one to beginning mark so it stays with the first character of
  843. ;; the string even if characters are added just before the string.
  844. (setq edt-match-beginning-mark (copy-marker (1+ (match-beginning 0))))
  845. (setq edt-match-end-mark (copy-marker (match-end 0))))
  846. (defun edt-unset-match nil
  847. "Unset match beginning and end markers."
  848. (set-marker edt-match-beginning-mark nil)
  849. (set-marker edt-match-end-mark nil))
  850. (defun edt-match-beginning nil
  851. "Return the location of the last match beginning."
  852. (1- (marker-position edt-match-beginning-mark)))
  853. (defun edt-match-end nil
  854. "Return the location of the last match end."
  855. (marker-position edt-match-end-mark))
  856. (defun edt-check-match nil
  857. "Return t if point is between edt-match markers.
  858. Otherwise sets the edt-match markers to nil and returns nil."
  859. ;; make sure 1- marker is in this buffer
  860. ;; 2- point is at or after beginning marker
  861. ;; 3- point is before ending marker, or in the case of
  862. ;; zero length regions (like bol, or eol) that the
  863. ;; beginning, end, and point are equal.
  864. (cond ((and
  865. (equal (marker-buffer edt-match-beginning-mark) (current-buffer))
  866. (>= (point) (1- (marker-position edt-match-beginning-mark)))
  867. (or
  868. (< (point) (marker-position edt-match-end-mark))
  869. (and (= (1- (marker-position edt-match-beginning-mark))
  870. (marker-position edt-match-end-mark))
  871. (= (marker-position edt-match-end-mark) (point))))) t)
  872. (t
  873. (edt-unset-match) nil)))
  874. (defun edt-show-match-markers nil
  875. "Show the values of the match markers."
  876. (interactive)
  877. (if (markerp edt-match-beginning-mark)
  878. (let ((beg (marker-position edt-match-beginning-mark)))
  879. (message "(%s, %s) in %s -- current %s in %s"
  880. (if beg (1- beg) nil)
  881. (marker-position edt-match-end-mark)
  882. (marker-buffer edt-match-end-mark)
  883. (point) (current-buffer)))))
  884. ;;;
  885. ;;; ADVANCE
  886. ;;;
  887. (defun edt-advance ()
  888. "Set movement direction forward.
  889. Also, execute command specified if in Minibuffer."
  890. (interactive)
  891. (setq edt-direction-string edt-forward-string)
  892. (force-mode-line-update)
  893. (if (string-equal " *Minibuf"
  894. (substring (buffer-name) 0 (min (length (buffer-name)) 9)))
  895. (exit-minibuffer))
  896. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  897. ;;;
  898. ;;; BACKUP
  899. ;;;
  900. (defun edt-backup ()
  901. "Set movement direction backward.
  902. Also, execute command specified if in Minibuffer."
  903. (interactive)
  904. (setq edt-direction-string edt-backward-string)
  905. (force-mode-line-update)
  906. (if (string-equal " *Minibuf"
  907. (substring (buffer-name) 0 (min (length (buffer-name)) 9)))
  908. (exit-minibuffer))
  909. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  910. ;;;
  911. ;;; CHNGCASE
  912. ;;;
  913. ;; This function is based upon Jeff Kowalski's case-flip function in his
  914. ;; tpu.el.
  915. (defun edt-change-case (num)
  916. "Change the case of specified characters.
  917. If text selection IS active, then characters between the cursor and mark are
  918. changed. If text selection is NOT active, there are two cases. First, if the
  919. current direction is ADVANCE, then the prefix number of character(s) under and
  920. following cursor are changed. Second, if the current direction is BACKUP, then
  921. the prefix number of character(s) before the cursor are changed. Accepts a
  922. positive prefix for the number of characters to change, but the prefix is
  923. ignored if text selection is active.
  924. Argument NUM is the numbers of consecutive characters to change."
  925. (interactive "*p")
  926. (edt-check-prefix num)
  927. (if edt-select-mode
  928. (let ((end (max (mark) (point)))
  929. (point-save (point)))
  930. (goto-char (min (point) (mark)))
  931. (while (not (eq (point) end))
  932. (funcall (if (<= ?a (following-char))
  933. 'upcase-region 'downcase-region)
  934. (point) (1+ (point)))
  935. (forward-char 1))
  936. (goto-char point-save))
  937. (progn
  938. (if (string= edt-direction-string edt-backward-string)
  939. (backward-char num))
  940. (while (> num 0)
  941. (funcall (if (<= ?a (following-char))
  942. 'upcase-region 'downcase-region)
  943. (point) (1+ (point)))
  944. (forward-char 1)
  945. (setq num (1- num))))))
  946. ;;;
  947. ;;; DEFINE KEY
  948. ;;;
  949. (defun edt-define-key ()
  950. "Assign an interactively-callable function to a specified key sequence.
  951. The current key definition is saved in `edt-last-replaced-key-definition'.
  952. Use `edt-restore-key' to restore last replaced key definition."
  953. (interactive)
  954. (if (featurep 'xemacs) (setq zmacs-region-stays t))
  955. (let (edt-function
  956. edt-key-definition)
  957. (setq edt-key-definition
  958. (read-key-sequence "Press the key to be defined: "))
  959. (if (if (featurep 'emacs)
  960. (string-equal "\C-m" edt-key-definition)
  961. (string-equal "\C-m" (events-to-keys edt-key-definition)))
  962. (message "Key not defined")
  963. (progn
  964. (setq edt-function (read-command "Enter command name: "))
  965. (if (string-equal "" edt-function)
  966. (message "Key not defined")
  967. (progn
  968. (setq edt-last-replaced-key-definition
  969. (lookup-key (current-global-map) edt-key-definition))
  970. (define-key (current-global-map)
  971. edt-key-definition edt-function)))))))
  972. ;;;
  973. ;;; FORM FEED INSERT
  974. ;;;
  975. (defun edt-form-feed-insert (num)
  976. "Insert form feed character at cursor position.
  977. Argument NUM is the number of form feeds to insert."
  978. (interactive "*p")
  979. (edt-check-prefix num)
  980. (while (> num 0)
  981. (insert ?\f)
  982. (setq num (1- num))))
  983. ;;;
  984. ;;; TAB INSERT
  985. ;;;
  986. (defun edt-tab-insert (num)
  987. "Insert tab character at cursor position.
  988. Argument NUM is the number of tabs to insert."
  989. (interactive "*p")
  990. (edt-check-prefix num)
  991. (while (> num 0)
  992. (insert ?\t)
  993. (setq num (1- num))))
  994. ;;;
  995. ;;; Check Prefix
  996. ;;;
  997. (defun edt-check-prefix (num)
  998. "Indicate error if prefix is not positive.
  999. Argument NUM is the prefix value tested."
  1000. (if (<= num 0)
  1001. (error "Prefix must be positive")))
  1002. ;;;
  1003. ;;; Check Selection
  1004. ;;;
  1005. (defun edt-check-selection ()
  1006. "Indicate error if EDT selection is not active."
  1007. (if (not edt-select-mode)
  1008. (error "Selection NOT active")))
  1009. ;;;
  1010. ;;; Scroll Margins
  1011. ;;;
  1012. (defun edt-top-check (beg lines)
  1013. "Enforce scroll margin at the top of screen.
  1014. Argument BEG is the starting line number before cursor was moved.
  1015. Argument LINES is the number of lines the cursor moved toward the top."
  1016. (let ((margin (/ (* (window-height) edt-top-scroll-margin) 100)))
  1017. (cond ((< beg margin) (recenter beg))
  1018. ((< (- beg lines) margin) (recenter margin)))))
  1019. (defun edt-bottom-check (beg lines)
  1020. "Enforce scroll margin at the bottom of screen.
  1021. Argument BEG is the starting line number before cursor was moved.
  1022. Argument LINES is the number of lines the cursor moved toward the bottom."
  1023. (let* ((height (window-height))
  1024. (margin (+ 1 (/ (* height edt-bottom-scroll-margin) 100)))
  1025. ;; subtract 1 from height because it includes mode line
  1026. (difference (- height margin 1)))
  1027. (cond ((> beg difference) (recenter beg))
  1028. ((and (featurep 'xemacs) (> (+ beg lines 1) difference))
  1029. (recenter (- margin)))
  1030. ((> (+ beg lines) difference) (recenter (- margin))))))
  1031. (defun edt-current-line nil
  1032. "Return the vertical position of point in the selected window.
  1033. Top line is 0. Counts each text line only once, even if it wraps."
  1034. (+ (count-lines (window-start) (point)) (if (= (current-column) 0) 1 0) -1))
  1035. ;;;###autoload
  1036. (defun edt-set-scroll-margins (top bottom)
  1037. "Set scroll margins.
  1038. Argument TOP is the top margin in number of lines or percent of window.
  1039. Argument BOTTOM is the bottom margin in number of lines or percent of window."
  1040. (interactive
  1041. "sEnter top scroll margin (N lines or N%% or RETURN for current value): \
  1042. \nsEnter bottom scroll margin (N lines or N%% or RETURN for current value): ")
  1043. ;; set top scroll margin
  1044. (or (string= top "")
  1045. (if (string= "%" (substring top -1))
  1046. (setq edt-top-scroll-margin (string-to-number top))
  1047. (setq edt-top-scroll-margin
  1048. (/ (1- (+ (* (string-to-number top) 100) (window-height)))
  1049. (window-height)))))
  1050. ;; set bottom scroll margin
  1051. (or (string= bottom "")
  1052. (if (string= "%" (substring bottom -1))
  1053. (setq edt-bottom-scroll-margin (string-to-number bottom))
  1054. (setq edt-bottom-scroll-margin
  1055. (/ (1- (+ (* (string-to-number bottom) 100) (window-height)))
  1056. (window-height)))))
  1057. ;; report scroll margin settings if running interactively
  1058. (and (called-interactively-p 'interactive)
  1059. (message "Scroll margins set. Top = %s%%, Bottom = %s%%"
  1060. edt-top-scroll-margin edt-bottom-scroll-margin)))
  1061. ;;;;
  1062. ;;;; ENHANCEMENTS AND ADDITIONS FOR EDT KEYPAD MODE
  1063. ;;;;
  1064. ;;;
  1065. ;;; Several enhancements and additions to EDT keypad mode commands are
  1066. ;;; provided here. Some of these have been motivated by similar
  1067. ;;; TPU/EVE and EVE-Plus commands. Others are new.
  1068. ;;;
  1069. ;;; CHANGE DIRECTION
  1070. ;;;
  1071. (defun edt-change-direction ()
  1072. "Toggle movement direction."
  1073. (interactive)
  1074. (if (equal edt-direction-string edt-forward-string)
  1075. (edt-backup)
  1076. (edt-advance)))
  1077. ;;;
  1078. ;;; TOGGLE SELECT
  1079. ;;;
  1080. (defun edt-toggle-select ()
  1081. "Toggle to start (or cancel) text selection."
  1082. (interactive)
  1083. (if edt-select-mode
  1084. (edt-reset)
  1085. (edt-select)))
  1086. ;;;
  1087. ;;; SENTENCE
  1088. ;;;
  1089. (defun edt-sentence-forward (num)
  1090. "Move forward to start of next sentence.
  1091. Argument NUM is the positive number of sentences to move."
  1092. (interactive "p")
  1093. (edt-check-prefix num)
  1094. (edt-with-position
  1095. (if (eobp)
  1096. (error "End of buffer")
  1097. (forward-sentence num)
  1098. (forward-word 1)
  1099. (backward-sentence))
  1100. (if (> (point) far)
  1101. (if (zerop (setq left (save-excursion (forward-line height))))
  1102. (recenter top-margin)
  1103. (recenter (- left bottom-up-margin)))
  1104. (and (> (point) bottom) (recenter bottom-margin))))
  1105. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1106. (defun edt-sentence-backward (num)
  1107. "Move backward to next sentence beginning.
  1108. Argument NUM is the positive number of sentences to move."
  1109. (interactive "p")
  1110. (edt-check-prefix num)
  1111. (edt-with-position
  1112. (if (eobp)
  1113. (error "End of buffer")
  1114. (backward-sentence num))
  1115. (and (< (point) top) (recenter (min beg top-margin))))
  1116. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1117. (defun edt-sentence (num)
  1118. "Move in current direction to next sentence.
  1119. Argument NUM is the positive number of sentences to move."
  1120. (interactive "p")
  1121. (if (equal edt-direction-string edt-forward-string)
  1122. (edt-sentence-forward num)
  1123. (edt-sentence-backward num)))
  1124. ;;;
  1125. ;;; PARAGRAPH
  1126. ;;;
  1127. (defun edt-paragraph-forward (num)
  1128. "Move forward to beginning of paragraph.
  1129. Argument NUM is the positive number of paragraphs to move."
  1130. (interactive "p")
  1131. (edt-check-prefix num)
  1132. (edt-with-position
  1133. (while (> num 0)
  1134. (forward-paragraph (+ num 1))
  1135. (start-of-paragraph-text)
  1136. (if (eolp)
  1137. (forward-line 1))
  1138. (setq num (1- num)))
  1139. (if (> (point) far)
  1140. (if (zerop (setq left (save-excursion (forward-line height))))
  1141. (recenter top-margin)
  1142. (recenter (- left bottom-up-margin)))
  1143. (and (> (point) bottom) (recenter bottom-margin))))
  1144. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1145. (defun edt-paragraph-backward (num)
  1146. "Move backward to beginning of paragraph.
  1147. Argument NUM is the positive number of paragraphs to move."
  1148. (interactive "p")
  1149. (edt-check-prefix num)
  1150. (edt-with-position
  1151. (while (> num 0)
  1152. (start-of-paragraph-text)
  1153. (setq num (1- num)))
  1154. (and (< (point) top) (recenter (min beg top-margin))))
  1155. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1156. (defun edt-paragraph (num)
  1157. "Move in current direction to next paragraph.
  1158. Argument NUM is the positive number of paragraphs to move."
  1159. (interactive "p")
  1160. (if (equal edt-direction-string edt-forward-string)
  1161. (edt-paragraph-forward num)
  1162. (edt-paragraph-backward num)))
  1163. ;;;
  1164. ;;; RESTORE KEY
  1165. ;;;
  1166. (defun edt-restore-key ()
  1167. "Restore last replaced key definition.
  1168. Definition is stored in `edt-last-replaced-key-definition'."
  1169. (interactive)
  1170. (if (featurep 'xemacs) (setq zmacs-region-stays t))
  1171. (if edt-last-replaced-key-definition
  1172. (progn
  1173. (let (edt-key-definition)
  1174. (set 'edt-key-definition
  1175. (read-key-sequence "Press the key to be restored: "))
  1176. (if (if (featurep 'emacs)
  1177. (string-equal "\C-m" edt-key-definition)
  1178. (string-equal "\C-m" (events-to-keys edt-key-definition)))
  1179. (message "Key not restored")
  1180. (progn
  1181. (define-key (current-global-map)
  1182. edt-key-definition edt-last-replaced-key-definition)
  1183. (if (featurep 'emacs)
  1184. (message "Key definition for %s has been restored."
  1185. edt-key-definition)
  1186. (message "Key definition for %s has been restored."
  1187. (events-to-keys edt-key-definition)))))))
  1188. (error "No replaced key definition to restore!")))
  1189. ;;;
  1190. ;;; WINDOW TOP
  1191. ;;;
  1192. (defun edt-window-top ()
  1193. "Move the cursor to the top of the window."
  1194. (interactive)
  1195. (let ((start-column (current-column)))
  1196. (move-to-window-line 0)
  1197. (move-to-column start-column))
  1198. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1199. ;;;
  1200. ;;; WINDOW BOTTOM
  1201. ;;;
  1202. (defun edt-window-bottom ()
  1203. "Move the cursor to the bottom of the window."
  1204. (interactive)
  1205. (let ((start-column (current-column)))
  1206. (move-to-window-line (- (window-height) 2))
  1207. (move-to-column start-column))
  1208. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1209. ;;;
  1210. ;;; SCROLL WINDOW LINE
  1211. ;;;
  1212. (defun edt-scroll-window-forward-line ()
  1213. "Move window forward one line leaving cursor at position in window."
  1214. (interactive)
  1215. (scroll-up 1)
  1216. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1217. (defun edt-scroll-window-backward-line ()
  1218. "Move window backward one line leaving cursor at position in window."
  1219. (interactive)
  1220. (scroll-down 1)
  1221. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1222. (defun edt-scroll-line ()
  1223. "Move window one line in current direction."
  1224. (interactive)
  1225. (if (equal edt-direction-string edt-forward-string)
  1226. (edt-scroll-window-forward-line)
  1227. (edt-scroll-window-backward-line)))
  1228. ;;;
  1229. ;;; SCROLL WINDOW
  1230. ;;;
  1231. ;;; Scroll a window (less one line) at a time. Leave cursor in center of
  1232. ;;; window.
  1233. (defun edt-scroll-window-forward (num)
  1234. "Scroll forward one window in buffer, less one line.
  1235. Argument NUM is the positive number of windows to move."
  1236. (interactive "p")
  1237. (edt-check-prefix num)
  1238. (scroll-up (- (* (window-height) num) 2))
  1239. (edt-line-forward (/ (- (window-height) 1) 2)))
  1240. (defun edt-scroll-window-backward (num)
  1241. "Scroll backward one window in buffer, less one line.
  1242. Argument NUM is the positive number of windows to move."
  1243. (interactive "p")
  1244. (edt-check-prefix num)
  1245. (scroll-down (- (* (window-height) num) 2))
  1246. (edt-line-backward (/ (- (window-height) 1) 2)))
  1247. (defun edt-scroll-window (num)
  1248. "Scroll one window in buffer, less one line, in current direction.
  1249. Argument NUM is the positive number of windows to move."
  1250. (interactive "p")
  1251. (if (equal edt-direction-string edt-forward-string)
  1252. (edt-scroll-window-forward num)
  1253. (edt-scroll-window-backward num)))
  1254. ;;;
  1255. ;;; LINE TO BOTTOM OF WINDOW
  1256. ;;;
  1257. (defun edt-line-to-bottom-of-window ()
  1258. "Move the current line to the bottom of the window."
  1259. (interactive)
  1260. (recenter -1)
  1261. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1262. ;;;
  1263. ;;; LINE TO TOP OF WINDOW
  1264. ;;;
  1265. (defun edt-line-to-top-of-window ()
  1266. "Move the current line to the top of the window."
  1267. (interactive)
  1268. (recenter 0)
  1269. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1270. ;;;
  1271. ;;; LINE TO MIDDLE OF WINDOW
  1272. ;;;
  1273. (defun edt-line-to-middle-of-window ()
  1274. "Move window so line with cursor is in the middle of the window."
  1275. (interactive)
  1276. (recenter '(4))
  1277. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1278. ;;;
  1279. ;;; GOTO PERCENTAGE
  1280. ;;;
  1281. (defun edt-goto-percentage (num)
  1282. "Move to specified percentage in buffer from top of buffer.
  1283. Argument NUM is the percentage into the buffer to move."
  1284. (interactive "NGoto-percentage: ")
  1285. (if (or (> num 100) (< num 0))
  1286. (error "Percentage %d out of range 0 < percent < 100" num)
  1287. (goto-char (/ (* (point-max) num) 100)))
  1288. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1289. ;;;
  1290. ;;; FILL REGION
  1291. ;;;
  1292. (defun edt-fill-region ()
  1293. "Fill selected text."
  1294. (interactive "*")
  1295. (edt-check-selection)
  1296. (fill-region (point) (mark)))
  1297. ;;;
  1298. ;;; INDENT OR FILL REGION
  1299. ;;;
  1300. (defun edt-indent-or-fill-region ()
  1301. "Fill region in text modes, indent region in programming language modes."
  1302. (interactive "*")
  1303. (if (string= paragraph-start "$\\|\f")
  1304. (indent-region (point) (mark) nil)
  1305. (fill-region (point) (mark))))
  1306. (declare-function c-mark-function "cc-cmds" ())
  1307. ;;;
  1308. ;;; MARK SECTION WISELY
  1309. ;;;
  1310. (defun edt-mark-section-wisely ()
  1311. "Mark the section in a manner consistent with the `major-mode'.
  1312. Uses `mark-defun' for Emacs-Lisp and Lisp, and for Fortran,
  1313. `c-mark-function' for C,
  1314. and `mark-paragraph' for other modes."
  1315. (interactive)
  1316. (if edt-select-mode
  1317. (progn
  1318. (edt-reset))
  1319. (progn
  1320. (cond ((or (eq major-mode 'emacs-lisp-mode)
  1321. (eq major-mode 'fortran-mode)
  1322. (eq major-mode 'lisp-mode))
  1323. (mark-defun)
  1324. (message "Lisp defun selected"))
  1325. ((eq major-mode 'c-mode)
  1326. (c-mark-function)
  1327. (message "C function selected"))
  1328. (t (mark-paragraph)
  1329. (message "Paragraph selected"))))))
  1330. ;;;
  1331. ;;; COPY
  1332. ;;;
  1333. (defun edt-copy ()
  1334. "Copy selected region to kill ring, but don't delete it!"
  1335. (interactive)
  1336. (edt-check-selection)
  1337. (copy-region-as-kill (mark) (point))
  1338. (edt-reset)
  1339. (message "Selected text COPIED to kill ring"))
  1340. ;;;
  1341. ;;; CUT or COPY
  1342. ;;;
  1343. (defun edt-cut-or-copy ()
  1344. "Cuts (or copies) selected text to kill ring.
  1345. Cuts selected text if `buffer-read-only' is nil.
  1346. Copies selected text if `buffer-read-only' is t."
  1347. (interactive)
  1348. (if buffer-read-only
  1349. (edt-copy)
  1350. (edt-cut)))
  1351. ;;;
  1352. ;;; DELETE ENTIRE LINE
  1353. ;;;
  1354. (defun edt-delete-entire-line ()
  1355. "Delete entire line regardless of cursor position in the line."
  1356. (interactive "*")
  1357. (beginning-of-line)
  1358. (edt-delete-line 1))
  1359. ;;;
  1360. ;;; DUPLICATE LINE
  1361. ;;;
  1362. (defun edt-duplicate-line (num)
  1363. "Duplicate the line of text containing the cursor.
  1364. Argument NUM is the number of times to duplicate the line."
  1365. (interactive "*p")
  1366. (edt-check-prefix num)
  1367. (let ((old-column (current-column))
  1368. (count num))
  1369. (edt-delete-entire-line)
  1370. (edt-undelete-line)
  1371. (while (> count 0)
  1372. (edt-undelete-line)
  1373. (setq count (1- count)))
  1374. (edt-line-forward num)
  1375. (move-to-column old-column)))
  1376. ;;;
  1377. ;;; DUPLICATE WORD
  1378. ;;;
  1379. (defun edt-duplicate-word()
  1380. "Duplicate word (or rest of word) found directly above cursor, if any."
  1381. (interactive "*")
  1382. (let ((start (point))
  1383. (start-column (current-column)))
  1384. (forward-line -1)
  1385. (move-to-column start-column)
  1386. (if (and (not (equal start (point)))
  1387. (not (eolp)))
  1388. (progn
  1389. (if (and (equal ?\t (preceding-char))
  1390. (< start-column (current-column)))
  1391. (backward-char))
  1392. (let ((beg (point)))
  1393. (edt-one-word-forward)
  1394. (setq edt-last-copied-word (buffer-substring beg (point))))
  1395. (forward-line)
  1396. (move-to-column start-column)
  1397. (insert edt-last-copied-word))
  1398. (progn
  1399. (if (not (equal start (point)))
  1400. (forward-line))
  1401. (move-to-column start-column)
  1402. (error "Nothing to duplicate!")))))
  1403. ;;;
  1404. ;;; KEY NOT ASSIGNED
  1405. ;;;
  1406. (defun edt-key-not-assigned ()
  1407. "Displays message that key has not been assigned to a function."
  1408. (interactive)
  1409. (error "Key not assigned"))
  1410. ;;;
  1411. ;;; TOGGLE CAPITALIZATION OF WORD
  1412. ;;;
  1413. (defun edt-toggle-capitalization-of-word ()
  1414. "Toggle the capitalization of the current word and move forward to next."
  1415. (interactive "*")
  1416. (edt-one-word-forward)
  1417. (edt-one-word-backward)
  1418. (edt-change-case 1)
  1419. (edt-one-word-backward)
  1420. (edt-one-word-forward))
  1421. ;;;
  1422. ;;; ELIMINATE ALL TABS
  1423. ;;;
  1424. (defun edt-eliminate-all-tabs ()
  1425. "Convert all tabs to spaces in the entire buffer."
  1426. (interactive "*")
  1427. (untabify (point-min) (point-max))
  1428. (message "TABS converted to SPACES"))
  1429. ;;;
  1430. ;;; DISPLAY THE TIME
  1431. ;;;
  1432. (defun edt-display-the-time ()
  1433. "Display the current time."
  1434. (interactive)
  1435. (if (featurep 'xemacs) (setq zmacs-region-stays t))
  1436. (message "%s" (current-time-string)))
  1437. ;;;
  1438. ;;; LEARN
  1439. ;;;
  1440. (defun edt-learn ()
  1441. "Learn a sequence of key strokes to bind to a key."
  1442. (interactive)
  1443. (if (eq defining-kbd-macro t)
  1444. (edt-remember)
  1445. (start-kbd-macro nil)))
  1446. ;;;
  1447. ;;; REMEMBER
  1448. ;;;
  1449. (defun edt-remember ()
  1450. "Store the sequence of key strokes started by `edt-learn' to a key."
  1451. (interactive)
  1452. (if (eq defining-kbd-macro nil)
  1453. (error "Nothing to remember!")
  1454. (progn
  1455. (end-kbd-macro nil)
  1456. (let (edt-key-definition)
  1457. (set 'edt-key-definition
  1458. (read-key-sequence "Enter key for binding: "))
  1459. (if (if (featurep 'emacs)
  1460. (string-equal "\C-m" edt-key-definition)
  1461. (string-equal "\C-m" (events-to-keys edt-key-definition)))
  1462. (message "Key sequence not remembered")
  1463. (progn
  1464. (set 'edt-learn-macro-count (+ edt-learn-macro-count 1))
  1465. (setq edt-last-replaced-key-definition
  1466. (lookup-key (current-global-map)
  1467. edt-key-definition))
  1468. (define-key (current-global-map) edt-key-definition
  1469. (name-last-kbd-macro
  1470. (intern (concat "last-learned-sequence-"
  1471. (int-to-string edt-learn-macro-count)))))))))))
  1472. ;;;
  1473. ;;; EXIT
  1474. ;;;
  1475. (defun edt-exit ()
  1476. "Save current buffer, ask to save other buffers, and then exit Emacs."
  1477. (interactive)
  1478. (save-buffer)
  1479. (save-buffers-kill-emacs))
  1480. ;;;
  1481. ;;; QUIT
  1482. ;;;
  1483. (defun edt-quit ()
  1484. "Quit Emacs without saving buffer modifications.
  1485. Warn user that modifications will be lost."
  1486. (interactive)
  1487. (let ((list (buffer-list))
  1488. (working t))
  1489. (while (and list working)
  1490. (let ((buffer (car list)))
  1491. (if (and (buffer-file-name buffer) (buffer-modified-p buffer))
  1492. (if (edt-y-or-n-p
  1493. "Modifications will not be saved, continue quitting? ")
  1494. (kill-emacs)
  1495. (setq working nil)))
  1496. (setq list (cdr list))))
  1497. (if working (kill-emacs))))
  1498. ;;;
  1499. ;;; SPLIT WINDOW
  1500. ;;;
  1501. (defun edt-split-window ()
  1502. "Split current window and place cursor in the new window."
  1503. (interactive)
  1504. (split-window)
  1505. (other-window 1)
  1506. (if (featurep 'xemacs) (setq zmacs-region-stays t)))
  1507. ;;;
  1508. ;;; COPY RECTANGLE
  1509. ;;;
  1510. (defun edt-copy-rectangle ()
  1511. "Copy a rectangle of text between mark and cursor to register."
  1512. (interactive)
  1513. (edt-check-selection)
  1514. (copy-rectangle-to-register 3 (region-beginning) (region-end) nil)
  1515. (edt-reset)
  1516. (message "Selected rectangle COPIED to register"))
  1517. ;;;
  1518. ;;; CUT RECTANGLE
  1519. ;;;
  1520. (defun edt-cut-rectangle-overstrike-mode ()
  1521. "Cut a rectangle of text between mark and cursor to register.
  1522. Replace cut characters with spaces and moving cursor back to
  1523. upper left corner."
  1524. (interactive "*")
  1525. (edt-check-selection)
  1526. (setq edt-rect-start-point (region-beginning))
  1527. (picture-clear-rectangle-to-register (region-beginning) (region-end) 3)
  1528. (set-window-point (get-buffer-window (window-buffer)) edt-rect-start-point)
  1529. (message "Selected rectangle CUT to register"))
  1530. (defun edt-cut-rectangle-insert-mode ()
  1531. "Cut a rectangle of text between mark and cursor to register.
  1532. Move cursor back to upper left corner."
  1533. (interactive "*")
  1534. (edt-check-selection)
  1535. (setq edt-rect-start-point (region-beginning))
  1536. (picture-clear-rectangle-to-register (region-beginning) (region-end) 3 t)
  1537. (fixup-whitespace)
  1538. (set-window-point (get-buffer-window (window-buffer)) edt-rect-start-point)
  1539. (message "Selected rectangle CUT to register"))
  1540. (defun edt-cut-rectangle ()
  1541. "Cut a rectangular region of text to register.
  1542. If overwrite mode is active, cut text is replaced with whitespace."
  1543. (interactive "*")
  1544. (if overwrite-mode
  1545. (edt-cut-rectangle-overstrike-mode)
  1546. (edt-cut-rectangle-insert-mode)))
  1547. ;;;
  1548. ;;; PASTE RECTANGLE
  1549. ;;;
  1550. (defun edt-paste-rectangle-overstrike-mode ()
  1551. "Paste a rectangular region of text from register, replacing text at cursor."
  1552. (interactive "*")
  1553. (picture-yank-rectangle-from-register 3))
  1554. (defun edt-paste-rectangle-insert-mode ()
  1555. "Paste previously deleted rectangular region, inserting text at cursor."
  1556. (interactive "*")
  1557. (picture-yank-rectangle-from-register 3 t))
  1558. (defun edt-paste-rectangle ()
  1559. "Paste a rectangular region of text.
  1560. If overwrite mode is active, existing text is replace with text from register."
  1561. (interactive)
  1562. (if overwrite-mode
  1563. (edt-paste-rectangle-overstrike-mode)
  1564. (edt-paste-rectangle-insert-mode)))
  1565. ;;;
  1566. ;;; DOWNCASE REGION
  1567. ;;;
  1568. (defun edt-lowercase ()
  1569. "Change specified characters to lower case.
  1570. If text selection IS active, then characters between the cursor and
  1571. mark are changed. If text selection is NOT active, there are two
  1572. situations. If the current direction is ADVANCE, then the word under
  1573. the cursor is changed to lower case and the cursor is moved to rest at
  1574. the beginning of the next word. If the current direction is BACKUP,
  1575. the word prior to the word under the cursor is changed to lower case
  1576. and the cursor is left to rest at the beginning of that word."
  1577. (interactive "*")
  1578. (if edt-select-mode
  1579. (progn
  1580. (downcase-region (mark) (point)))
  1581. (progn
  1582. ;; Move to beginning of current word.
  1583. (if (and
  1584. (not (bobp))
  1585. (not (eobp))
  1586. (not (bolp))
  1587. (not (eolp))
  1588. (not (eq ?\ (char-syntax (preceding-char))))
  1589. (not (memq (preceding-char) edt-word-entities))
  1590. (not (memq (following-char) edt-word-entities)))
  1591. (edt-one-word-backward))
  1592. (if (equal edt-direction-string edt-backward-string)
  1593. (edt-one-word-backward))
  1594. (let ((beg (point)))
  1595. (edt-one-word-forward)
  1596. (downcase-region beg (point)))
  1597. (if (equal edt-direction-string edt-backward-string)
  1598. (edt-one-word-backward)))))
  1599. ;;;
  1600. ;;; UPCASE REGION
  1601. ;;;
  1602. (defun edt-uppercase ()
  1603. "Change specified characters to upper case.
  1604. If text selection IS active, then characters between the cursor and
  1605. mark are changed. If text selection is NOT active, there are two
  1606. situations. If the current direction is ADVANCE, then the word under
  1607. the cursor is changed to upper case and the cursor is moved to rest at
  1608. the beginning of the next word. If the current direction is BACKUP,
  1609. the word prior to the word under the cursor is changed to upper case
  1610. and the cursor is left to rest at the beginning of that word."
  1611. (interactive "*")
  1612. (if edt-select-mode
  1613. (progn
  1614. (upcase-region (mark) (point)))
  1615. (progn
  1616. ;; Move to beginning of current word.
  1617. (if (and
  1618. (not (bobp))
  1619. (not (eobp))
  1620. (not (bolp))
  1621. (not (eolp))
  1622. (not (eq ?\ (char-syntax (preceding-char))))
  1623. (not (memq (preceding-char) edt-word-entities))
  1624. (not (memq (following-char) edt-word-entities)))
  1625. (edt-one-word-backward))
  1626. (if (equal edt-direction-string edt-backward-string)
  1627. (edt-one-word-backward))
  1628. (let ((beg (point)))
  1629. (edt-one-word-forward)
  1630. (upcase-region beg (point)))
  1631. (if (equal edt-direction-string edt-backward-string)
  1632. (edt-one-word-backward)))))
  1633. ;;;
  1634. ;;; Functions used in loading LK-201 key mapping file.
  1635. ;;;
  1636. (defvar edt-last-answer nil
  1637. "Most recent response to `edt-y-or-n-p'.")
  1638. (defun edt-y-or-n-p (prompt &optional not-yes)
  1639. "Prompt for a y or n answer with positive default.
  1640. Like Emacs `y-or-n-p', also accepts space as y and DEL as n.
  1641. Argument PROMPT is the prompt string.
  1642. Optional argument NOT-YES changes the default to negative."
  1643. (message "%s[%s]" prompt (if not-yes "n" "y"))
  1644. (let ((doit t))
  1645. (while doit
  1646. (setq doit nil)
  1647. (let ((ans (read-char)))
  1648. (cond ((or (= ans ?y) (= ans ?Y) (= ans ?\ ))
  1649. (setq edt-last-answer t))
  1650. ((or (= ans ?n) (= ans ?N) (= ans ?\C-?))
  1651. (setq edt-last-answer nil))
  1652. ((= ans ?\r) (setq edt-last-answer (not not-yes)))
  1653. (t
  1654. (setq doit t) (beep)
  1655. (message "Please answer y or n. %s[%s]"
  1656. prompt (if not-yes "n" "y")))))))
  1657. edt-last-answer)
  1658. ;;;
  1659. ;;; INITIALIZATION COMMANDS.
  1660. ;;;
  1661. ;;;
  1662. ;;; Function used to load LK-201 key mapping file generated by edt-mapper.el.
  1663. ;;;
  1664. (defun edt-load-keys (file)
  1665. "Load the LK-201 key mapping FILE generated by edt-mapper.el.
  1666. If FILE is nil, which is the normal case, try to load a default file.
  1667. The default file names are based upon the window system, terminal
  1668. type, and version of Emacs in use: GNU Emacs or XEmacs (aka Lucid
  1669. Emacs). If a default file does not exist, ask user if one should be
  1670. created."
  1671. (interactive "fKey definition file: ")
  1672. (cond (file
  1673. (setq file (expand-file-name file)))
  1674. (edt-keys-file
  1675. (setq file (expand-file-name edt-keys-file)))
  1676. (t
  1677. (setq file
  1678. (expand-file-name
  1679. (concat
  1680. "~/.edt-" edt-emacs-variant
  1681. (if edt-term (concat "-" edt-term))
  1682. (if edt-xserver (concat "-" edt-xserver))
  1683. (if edt-window-system
  1684. (concat "-" (upcase (symbol-name edt-window-system))))
  1685. "-keys")))))
  1686. (cond ((file-readable-p file)
  1687. (load-file file))
  1688. (t
  1689. (switch-to-buffer "*scratch*")
  1690. (erase-buffer)
  1691. (insert "
  1692. Ack!! You're running the Enhanced EDT Emulation without loading an
  1693. EDT key mapping file. To create an EDT key mapping file, run the
  1694. edt-mapper program. It is safest to run it from an Emacs loaded
  1695. without any of your own customizations found in your .emacs file, etc.
  1696. The reason for this is that some user customizations confuse edt-mapper.
  1697. You can do this by quitting Emacs and then invoking Emacs again as
  1698. follows:
  1699. emacs -q -l edt-mapper
  1700. [NOTE: If you do nothing out of the ordinary in your .emacs file, and
  1701. the search for edt-mapper is successful, you can try running it now.]
  1702. The library edt-mapper includes these same directions on how to
  1703. use it! Perhaps it's lying around here someplace. \n ")
  1704. (let ((path (locate-library
  1705. "edt-mapper"
  1706. nil (append (list default-directory) load-path))))
  1707. (if path
  1708. (progn
  1709. (insert (format
  1710. "Ah yes, there it is, in \n\n %s \n\n" path))
  1711. (if (edt-y-or-n-p "Do you want to run it now? ")
  1712. (load-file path)
  1713. (error "EDT Emulation not configured")))
  1714. (insert "Nope, I can't seem to find it. :-(\n\n")
  1715. (sit-for 20)
  1716. (error "EDT Emulation not configured"))))))
  1717. ;;;
  1718. ;;; Turning the EDT Emulation on and off.
  1719. ;;;
  1720. ;;;###autoload
  1721. (defun edt-emulation-on ()
  1722. "Turn on EDT Emulation."
  1723. (interactive)
  1724. ;; If using pc window system (MS-DOS), set terminal type to pc.
  1725. ;; If not a window system (GNU) or a tty window system (XEmacs),
  1726. ;; get terminal type.
  1727. (if (eq edt-window-system 'pc)
  1728. (setq edt-term "pc")
  1729. (if (or (not edt-window-system) (eq edt-window-system 'tty))
  1730. (setq edt-term (getenv "TERM"))))
  1731. ;; Look for a terminal configuration file for this terminal type.
  1732. ;; Otherwise, load the user's custom configuration file.
  1733. (if (or (not edt-window-system) (memq edt-window-system '(pc tty)))
  1734. (progn
  1735. ;; Load terminal-specific configuration file, if it exists for this
  1736. ;; terminal type. Note: All DEC VT series terminals are supported
  1737. ;; by the same terminal configuration file: edt-vt100.el.
  1738. (if (string-equal "vt" (substring edt-term 0 (min (length edt-term) 2)))
  1739. (setq edt-term "vt100"))
  1740. (let ((term edt-term)
  1741. hyphend)
  1742. (while (and term
  1743. (not (load (concat "edt-" term) t t)))
  1744. ;; Strip off last hyphen and what follows, then try again
  1745. (if (setq hyphend (string-match "[-_][^-_]+$" term))
  1746. (setq term (substring term 0 hyphend))
  1747. (setq term nil)))
  1748. ;; If no terminal-specific configuration file exists, load user's
  1749. ;; custom EDT terminal configuration file.
  1750. ;; If this is a pc running MS-DOS, then custom configuration files
  1751. ;; are not supported. So, if the file is missing, issue an error
  1752. ;; message.
  1753. (if (null term)
  1754. (if (equal edt-term "pc")
  1755. (error "Unable to find EDT terminal specific file edt-pc.el")
  1756. (edt-load-keys nil))
  1757. (setq edt-term term))))
  1758. (edt-load-keys nil))
  1759. ;; Make highlighting of selected text work properly for EDT commands.
  1760. (if (featurep 'emacs)
  1761. (progn
  1762. (setq edt-orig-transient-mark-mode transient-mark-mode)
  1763. (add-hook 'activate-mark-hook
  1764. (function
  1765. (lambda ()
  1766. (edt-select-mode t))))
  1767. (add-hook 'deactivate-mark-hook
  1768. (function
  1769. (lambda ()
  1770. (edt-select-mode nil)))))
  1771. (progn
  1772. (add-hook 'zmacs-activate-region-hook
  1773. (function
  1774. (lambda ()
  1775. (edt-select-mode t))))
  1776. (add-hook 'zmacs-deactivate-region-hook
  1777. (function
  1778. (lambda ()
  1779. (edt-select-mode nil))))))
  1780. ;; Load user's EDT custom key bindings file, if it exists.
  1781. ;; Otherwise, use the default bindings.
  1782. (if (load "edt-user" t t)
  1783. (edt-user-emulation-setup)
  1784. (edt-default-emulation-setup)))
  1785. (defun edt-emulation-off()
  1786. "Select original global key bindings, disabling EDT Emulation."
  1787. (interactive)
  1788. (use-global-map global-map)
  1789. (if (not edt-keep-current-page-delimiter)
  1790. (setq page-delimiter edt-orig-page-delimiter))
  1791. (setq edt-direction-string "")
  1792. (setq edt-select-mode-current nil)
  1793. (edt-reset)
  1794. (force-mode-line-update t)
  1795. (if (featurep 'emacs)
  1796. (setq transient-mark-mode edt-orig-transient-mark-mode))
  1797. (message "Original key bindings restored; EDT Emulation disabled"))
  1798. (defun edt-default-emulation-setup (&optional user-setup)
  1799. "Setup emulation of DEC's EDT editor.
  1800. Optional argument USER-SETUP non-nil means called from function
  1801. `edt-user-emulation-setup'."
  1802. ;; Setup default EDT global map by copying global map bindings.
  1803. ;; This preserves ESC and C-x prefix bindings and other bindings we
  1804. ;; wish to retain in EDT emulation mode keymaps. It also permits
  1805. ;; customization of these bindings in the EDT global maps without
  1806. ;; disturbing the original bindings in global-map.
  1807. (fset 'edt-default-ESC-prefix (copy-keymap 'ESC-prefix))
  1808. (setq edt-default-global-map (copy-keymap (current-global-map)))
  1809. (if (featurep 'emacs)
  1810. (define-key edt-default-global-map "\e" 'edt-default-ESC-prefix)
  1811. (define-key edt-default-global-map [escape] 'edt-default-ESC-prefix))
  1812. (define-prefix-command 'edt-default-gold-map)
  1813. (edt-setup-default-bindings)
  1814. ;; If terminal has additional function keys, the terminal-specific
  1815. ;; initialization file can assign bindings to them via the optional
  1816. ;; function edt-setup-extra-default-bindings.
  1817. (if (fboundp 'edt-setup-extra-default-bindings)
  1818. (edt-setup-extra-default-bindings))
  1819. ;; Variable needed by edt-learn.
  1820. (setq edt-learn-macro-count 0)
  1821. ;; Display EDT text selection active within the mode line
  1822. (or (assq 'edt-select-mode minor-mode-alist)
  1823. (setq minor-mode-alist
  1824. (cons '(edt-select-mode edt-select-mode) minor-mode-alist)))
  1825. ;; Display EDT direction of motion within the mode line
  1826. (or (assq 'edt-direction-string minor-mode-alist)
  1827. (setq minor-mode-alist
  1828. (cons
  1829. '(edt-direction-string edt-direction-string) minor-mode-alist)))
  1830. (if user-setup
  1831. (progn
  1832. (setq edt-user-map-configured t)
  1833. (fset 'edt-emulation-on (symbol-function 'edt-select-user-global-map)))
  1834. (progn
  1835. (fset 'edt-emulation-on (symbol-function 'edt-select-default-global-map))
  1836. (edt-select-default-global-map)))
  1837. ;; We need to share `global-buffers-menu-map' with the saved global
  1838. ;; keymap, because `menu-bar-update-buffers' directly changes it.
  1839. (define-key (current-global-map) [menu-bar buffer]
  1840. (cons "Buffers" global-buffers-menu-map)))
  1841. (defun edt-user-emulation-setup ()
  1842. "Setup user custom emulation of DEC's EDT editor."
  1843. ;; Initialize EDT default bindings.
  1844. (edt-default-emulation-setup t)
  1845. ;; Setup user EDT global map by copying default EDT global map bindings.
  1846. (fset 'edt-user-ESC-prefix (copy-keymap 'edt-default-ESC-prefix))
  1847. (setq edt-user-global-map (copy-keymap edt-default-global-map))
  1848. (if (featurep 'emacs)
  1849. (define-key edt-user-global-map "\e" 'edt-user-ESC-prefix)
  1850. (define-key edt-user-global-map [escape] 'edt-user-ESC-prefix))
  1851. ;; If terminal has additional function keys, the user's initialization
  1852. ;; file can assign bindings to them via the optional
  1853. ;; function edt-setup-extra-default-bindings.
  1854. (define-prefix-command 'edt-user-gold-map)
  1855. (fset 'edt-user-gold-map (copy-keymap 'edt-default-gold-map))
  1856. ;; This is a function that the user can define for custom bindings.
  1857. ;; See Info node `edt' for more details, and sample edt-user.el file.
  1858. (if (fboundp 'edt-setup-user-bindings)
  1859. (edt-setup-user-bindings))
  1860. (edt-select-user-global-map))
  1861. (defun edt-select-default-global-map()
  1862. "Select default EDT emulation key bindings."
  1863. (interactive)
  1864. (if (featurep 'emacs)
  1865. (transient-mark-mode 1))
  1866. (use-global-map edt-default-global-map)
  1867. (if (not edt-keep-current-page-delimiter)
  1868. (progn
  1869. (setq edt-orig-page-delimiter page-delimiter)
  1870. (setq page-delimiter "\f")))
  1871. (setq edt-default-map-active t)
  1872. (edt-advance)
  1873. (setq edt-select-mode-current 'edt-select-mode-string)
  1874. (edt-reset)
  1875. (message "Default EDT keymap active"))
  1876. (defun edt-select-user-global-map()
  1877. "Select user EDT emulation custom key bindings."
  1878. (interactive)
  1879. (if edt-user-map-configured
  1880. (progn
  1881. (if (featurep 'emacs)
  1882. (transient-mark-mode 1))
  1883. (use-global-map edt-user-global-map)
  1884. (if (not edt-keep-current-page-delimiter)
  1885. (progn
  1886. (setq edt-orig-page-delimiter page-delimiter)
  1887. (setq page-delimiter "\f")))
  1888. (setq edt-default-map-active nil)
  1889. (edt-advance)
  1890. (setq edt-select-mode-current 'edt-select-mode-string)
  1891. (edt-reset)
  1892. (message "User EDT custom keymap active"))
  1893. (error "User EDT custom keymap NOT configured!")))
  1894. (defun edt-switch-global-maps ()
  1895. "Toggle between default EDT keymap and user EDT keymap."
  1896. (interactive)
  1897. (if edt-default-map-active
  1898. (edt-select-user-global-map)
  1899. (edt-select-default-global-map)))
  1900. ;;
  1901. ;; Functions used to set up DEFAULT bindings to EDT emulation functions.
  1902. ;;
  1903. (defun edt-bind-function-key-default (function-key binding gold-binding)
  1904. "Binds LK-201 function keys to default bindings in the EDT Emulator.
  1905. Argument FUNCTION-KEY is the name of the function key or keypad function key.
  1906. Argument BINDING is the Emacs function to be bound to <KEY>.
  1907. Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
  1908. (let ((key (cdr (assoc function-key *EDT-keys*))))
  1909. (if (and key (not (equal key "")))
  1910. (progn
  1911. (define-key edt-default-global-map key binding)
  1912. (define-key 'edt-default-gold-map key gold-binding)))))
  1913. (defun edt-bind-key-default (key binding)
  1914. "Bind key sequences to default bindings in the EDT Emulator.
  1915. Argument KEY is the name of a standard key or a function key.
  1916. Argument BINDING is the Emacs function to be bound to <KEY>."
  1917. (define-key edt-default-global-map key binding))
  1918. (defun edt-bind-gold-key-default (key gold-binding)
  1919. "Binds <GOLD> key sequences to default bindings in the EDT Emulator.
  1920. Argument KEY is the name of a standard key or a function key.
  1921. Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
  1922. (define-key 'edt-default-gold-map key gold-binding))
  1923. ;;
  1924. ;; Functions used to set up USER CUSTOM bindings to EDT emulation functions.
  1925. ;;
  1926. (defun edt-bind-function-key (function-key binding gold-binding)
  1927. "Binds LK-201 function keys to custom bindings in the EDT Emulator.
  1928. Argument FUNCTION-KEY is the name of the function key or keypad function key.
  1929. Argument BINDING is the Emacs function to be bound to <KEY>.
  1930. Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
  1931. (let ((key (cdr (assoc function-key *EDT-keys*))))
  1932. (if (and key (not (equal key "")))
  1933. (progn
  1934. (define-key edt-user-global-map key binding)
  1935. (define-key 'edt-user-gold-map key gold-binding)))))
  1936. (defun edt-bind-key (key binding)
  1937. "Bind standard key sequences to custom bindings in the EDT Emulator.
  1938. Argument KEY is the name of a key. It can be a standard key or a function key.
  1939. Argument BINDING is the Emacs function to be bound to <KEY>."
  1940. (define-key edt-user-global-map key binding))
  1941. ;; For backward compatibility to existing edt-user.el files.
  1942. (fset 'edt-bind-standard-key (symbol-function 'edt-bind-key))
  1943. (defun edt-bind-gold-key (key gold-binding)
  1944. "Binds <GOLD> standard key sequences to custom bindings in the EDT Emulator.
  1945. Argument KEY is the name of a standard key or a function key.
  1946. Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
  1947. (define-key 'edt-user-gold-map key gold-binding))
  1948. (defun edt-setup-default-bindings ()
  1949. "Assigns default EDT Emulation keyboard bindings."
  1950. ;; Function Key Bindings: Regular and GOLD.
  1951. ;; VT100/VT200/VT300 PF1 (GOLD), PF2, PF3, PF4 Keys
  1952. (edt-bind-function-key-default "PF1"
  1953. 'edt-default-gold-map 'edt-mark-section-wisely)
  1954. (edt-bind-function-key-default "PF2"
  1955. 'edt-electric-keypad-help 'describe-function)
  1956. (edt-bind-function-key-default "PF3" 'edt-find-next 'edt-find)
  1957. (edt-bind-function-key-default "PF4" 'edt-delete-line 'edt-undelete-line)
  1958. ;; VT100/VT200/VT300 Arrow Keys
  1959. (edt-bind-function-key-default "UP" 'edt-previous-line 'edt-window-top)
  1960. (edt-bind-function-key-default "DOWN" 'edt-next-line 'edt-window-bottom)
  1961. (edt-bind-function-key-default "LEFT" 'backward-char 'edt-sentence-backward)
  1962. (edt-bind-function-key-default "RIGHT" 'forward-char 'edt-sentence-forward)
  1963. ;; VT100/VT200/VT300 Keypad Keys
  1964. (edt-bind-function-key-default "KP0" 'edt-line 'open-line)
  1965. (edt-bind-function-key-default "KP1" 'edt-word 'edt-change-case)
  1966. (edt-bind-function-key-default "KP2"
  1967. 'edt-end-of-line 'edt-delete-to-end-of-line)
  1968. (edt-bind-function-key-default "KP3" 'edt-character 'quoted-insert)
  1969. (edt-bind-function-key-default "KP4" 'edt-advance 'edt-bottom)
  1970. (edt-bind-function-key-default "KP5" 'edt-backup 'edt-top)
  1971. (edt-bind-function-key-default "KP6" 'edt-cut 'yank)
  1972. (edt-bind-function-key-default "KP7" 'edt-page 'execute-extended-command)
  1973. (edt-bind-function-key-default "KP8" 'edt-sect 'edt-fill-region)
  1974. (edt-bind-function-key-default "KP9" 'edt-append 'edt-replace)
  1975. (edt-bind-function-key-default "KP-" 'edt-delete-word 'edt-undelete-word)
  1976. (edt-bind-function-key-default "KP,"
  1977. 'edt-delete-character 'edt-undelete-character)
  1978. (edt-bind-function-key-default "KPP" 'edt-select 'edt-reset)
  1979. (edt-bind-function-key-default "KPE" 'other-window 'edt-substitute)
  1980. ;; VT200/VT300 Function Keys
  1981. ;; (F1 through F5, on the VT220, are not programmable, so we skip
  1982. ;; making default bindings to those keys.
  1983. (edt-bind-function-key-default "FIND" 'edt-find-next 'edt-find)
  1984. (edt-bind-function-key-default "INSERT" 'yank 'edt-key-not-assigned)
  1985. (edt-bind-function-key-default "REMOVE" 'edt-cut 'edt-copy)
  1986. (edt-bind-function-key-default "SELECT"
  1987. 'edt-toggle-select 'edt-key-not-assigned)
  1988. (edt-bind-function-key-default "NEXT"
  1989. 'edt-sect-forward 'edt-key-not-assigned)
  1990. (edt-bind-function-key-default "PREVIOUS"
  1991. 'edt-sect-backward 'edt-key-not-assigned)
  1992. (edt-bind-function-key-default "F6"
  1993. 'edt-key-not-assigned 'edt-key-not-assigned)
  1994. (edt-bind-function-key-default "F7"
  1995. 'edt-copy-rectangle 'edt-key-not-assigned)
  1996. (edt-bind-function-key-default "F8"
  1997. 'edt-cut-rectangle-overstrike-mode 'edt-paste-rectangle-overstrike-mode)
  1998. (edt-bind-function-key-default "F9"
  1999. 'edt-cut-rectangle-insert-mode 'edt-paste-rectangle-insert-mode)
  2000. (edt-bind-function-key-default "F10" 'edt-cut-rectangle 'edt-paste-rectangle)
  2001. ;; Under X, the F11 key can be bound. If using a VT-200 or higher terminal,
  2002. ;; the default emacs terminal support causes the VT F11 key to seem as if it
  2003. ;; is an ESC key when in emacs.
  2004. (edt-bind-function-key-default "F11"
  2005. 'edt-key-not-assigned 'edt-key-not-assigned)
  2006. (edt-bind-function-key-default "F12"
  2007. 'edt-beginning-of-line 'delete-other-windows) ;BS
  2008. (edt-bind-function-key-default "F13"
  2009. 'edt-delete-to-beginning-of-word 'edt-key-not-assigned) ;LF
  2010. (edt-bind-function-key-default "F14"
  2011. 'edt-key-not-assigned 'edt-key-not-assigned)
  2012. (edt-bind-function-key-default "HELP"
  2013. 'edt-electric-keypad-help 'edt-key-not-assigned)
  2014. (edt-bind-function-key-default "DO"
  2015. 'execute-extended-command 'edt-key-not-assigned)
  2016. (edt-bind-function-key-default "F17"
  2017. 'edt-key-not-assigned 'edt-key-not-assigned)
  2018. (edt-bind-function-key-default "F18"
  2019. 'edt-key-not-assigned 'edt-key-not-assigned)
  2020. (edt-bind-function-key-default "F19"
  2021. 'edt-key-not-assigned 'edt-key-not-assigned)
  2022. (edt-bind-function-key-default "F20"
  2023. 'edt-key-not-assigned 'edt-key-not-assigned)
  2024. ;; Control key bindings: Regular and GOLD
  2025. ;;
  2026. ;; Standard EDT control key bindings conflict with standard Emacs
  2027. ;; control key bindings. Normally, the standard Emacs control key
  2028. ;; bindings are left unchanged in the default EDT mode. However, if
  2029. ;; the variable edt-use-EDT-control-key-bindings is set to true
  2030. ;; before invoking edt-emulation-on for the first time, then the
  2031. ;; standard EDT bindings (with some enhancements) as defined here are
  2032. ;; used, instead.
  2033. (if edt-use-EDT-control-key-bindings
  2034. (progn
  2035. (edt-bind-key-default "\C-a" 'edt-key-not-assigned)
  2036. (edt-bind-key-default "\C-b" 'edt-key-not-assigned)
  2037. ;; Leave binding of C-c to an Emacs prefix key.
  2038. (edt-bind-key-default "\C-d" 'edt-key-not-assigned)
  2039. (edt-bind-key-default "\C-e" 'edt-key-not-assigned)
  2040. (edt-bind-key-default "\C-f" 'edt-key-not-assigned)
  2041. ;; Leave binding of C-g to the Emacs keyboard-quit
  2042. (edt-bind-key-default "\C-h" 'edt-beginning-of-line)
  2043. (edt-bind-key-default "\C-i" 'edt-tab-insert)
  2044. (edt-bind-key-default "\C-j" 'edt-delete-to-beginning-of-word)
  2045. (edt-bind-key-default "\C-k" 'edt-define-key)
  2046. (edt-bind-gold-key-default "\C-k" 'edt-restore-key)
  2047. (edt-bind-key-default "\C-l" 'edt-form-feed-insert)
  2048. ;; Leave binding of C-m to newline.
  2049. (edt-bind-key-default "\C-n" 'edt-set-screen-width-80)
  2050. (edt-bind-key-default "\C-o" 'edt-key-not-assigned)
  2051. (edt-bind-key-default "\C-p" 'edt-key-not-assigned)
  2052. (edt-bind-key-default "\C-q" 'edt-key-not-assigned)
  2053. ;; Leave binding of C-r to isearch-backward.
  2054. ;; Leave binding of C-s to isearch-forward.
  2055. (edt-bind-key-default "\C-t" 'edt-display-the-time)
  2056. (edt-bind-key-default "\C-u" 'edt-delete-to-beginning-of-line)
  2057. (edt-bind-key-default "\C-v" 'redraw-display)
  2058. (edt-bind-key-default "\C-w" 'edt-set-screen-width-132)
  2059. ;; Leave binding of C-x as original prefix key.
  2060. (edt-bind-key-default "\C-y" 'edt-key-not-assigned)
  2061. ;; Leave binding of C-z to suspend-emacs.
  2062. )
  2063. )
  2064. ;; GOLD bindings for a few keys.
  2065. (edt-bind-gold-key-default "\C-g" 'keyboard-quit); Just in case.
  2066. (edt-bind-gold-key-default "\C-h" 'help-for-help); Just in case.
  2067. (edt-bind-gold-key-default [f1] 'help-for-help)
  2068. (edt-bind-gold-key-default [help] 'help-for-help)
  2069. (edt-bind-gold-key-default "\C-\\" 'split-window-below)
  2070. ;; GOLD bindings for regular keys.
  2071. (edt-bind-gold-key-default "a" 'edt-key-not-assigned)
  2072. (edt-bind-gold-key-default "A" 'edt-key-not-assigned)
  2073. (edt-bind-gold-key-default "b" 'buffer-menu)
  2074. (edt-bind-gold-key-default "B" 'buffer-menu)
  2075. (edt-bind-gold-key-default "c" 'compile)
  2076. (edt-bind-gold-key-default "C" 'compile)
  2077. (edt-bind-gold-key-default "d" 'delete-window)
  2078. (edt-bind-gold-key-default "D" 'delete-window)
  2079. (edt-bind-gold-key-default "e" 'edt-exit)
  2080. (edt-bind-gold-key-default "E" 'edt-exit)
  2081. (edt-bind-gold-key-default "f" 'find-file)
  2082. (edt-bind-gold-key-default "F" 'find-file)
  2083. (edt-bind-gold-key-default "g" 'find-file-other-window)
  2084. (edt-bind-gold-key-default "G" 'find-file-other-window)
  2085. (edt-bind-gold-key-default "h" 'edt-electric-keypad-help)
  2086. (edt-bind-gold-key-default "H" 'edt-electric-keypad-help)
  2087. (edt-bind-gold-key-default "i" 'insert-file)
  2088. (edt-bind-gold-key-default "I" 'insert-file)
  2089. (edt-bind-gold-key-default "j" 'edt-key-not-assigned)
  2090. (edt-bind-gold-key-default "J" 'edt-key-not-assigned)
  2091. (edt-bind-gold-key-default "k" 'edt-toggle-capitalization-of-word)
  2092. (edt-bind-gold-key-default "K" 'edt-toggle-capitalization-of-word)
  2093. (edt-bind-gold-key-default "l" 'edt-lowercase)
  2094. (edt-bind-gold-key-default "L" 'edt-lowercase)
  2095. (edt-bind-gold-key-default "m" 'save-some-buffers)
  2096. (edt-bind-gold-key-default "M" 'save-some-buffers)
  2097. (edt-bind-gold-key-default "n" 'next-error)
  2098. (edt-bind-gold-key-default "N" 'next-error)
  2099. (edt-bind-gold-key-default "o" 'switch-to-buffer-other-window)
  2100. (edt-bind-gold-key-default "O" 'switch-to-buffer-other-window)
  2101. (edt-bind-gold-key-default "p" 'edt-key-not-assigned)
  2102. (edt-bind-gold-key-default "P" 'edt-key-not-assigned)
  2103. (edt-bind-gold-key-default "q" 'edt-quit)
  2104. (edt-bind-gold-key-default "Q" 'edt-quit)
  2105. (edt-bind-gold-key-default "r" 'revert-buffer)
  2106. (edt-bind-gold-key-default "R" 'revert-buffer)
  2107. (edt-bind-gold-key-default "s" 'save-buffer)
  2108. (edt-bind-gold-key-default "S" 'save-buffer)
  2109. (edt-bind-gold-key-default "t" 'edt-key-not-assigned)
  2110. (edt-bind-gold-key-default "T" 'edt-key-not-assigned)
  2111. (edt-bind-gold-key-default "u" 'edt-uppercase)
  2112. (edt-bind-gold-key-default "U" 'edt-uppercase)
  2113. (edt-bind-gold-key-default "v" 'find-file-other-window)
  2114. (edt-bind-gold-key-default "V" 'find-file-other-window)
  2115. (edt-bind-gold-key-default "w" 'write-file)
  2116. (edt-bind-gold-key-default "W" 'write-file)
  2117. (edt-bind-gold-key-default "x" 'edt-key-not-assigned)
  2118. (edt-bind-gold-key-default "X" 'edt-key-not-assigned)
  2119. (edt-bind-gold-key-default "y" 'edt-emulation-off)
  2120. (edt-bind-gold-key-default "Y" 'edt-emulation-off)
  2121. (edt-bind-gold-key-default "z" 'edt-switch-global-maps)
  2122. (edt-bind-gold-key-default "Z" 'edt-switch-global-maps)
  2123. (edt-bind-gold-key-default "1" 'delete-other-windows)
  2124. (edt-bind-gold-key-default "!" 'edt-key-not-assigned)
  2125. (edt-bind-gold-key-default "2" 'edt-split-window)
  2126. (edt-bind-gold-key-default "@" 'edt-key-not-assigned)
  2127. (edt-bind-gold-key-default "3" 'edt-key-not-assigned)
  2128. (edt-bind-gold-key-default "#" 'edt-key-not-assigned)
  2129. (edt-bind-gold-key-default "4" 'edt-key-not-assigned)
  2130. (edt-bind-gold-key-default "$" 'edt-key-not-assigned)
  2131. (edt-bind-gold-key-default "5" 'edt-key-not-assigned)
  2132. (edt-bind-gold-key-default "%" 'edt-goto-percentage)
  2133. (edt-bind-gold-key-default "6" 'edt-key-not-assigned)
  2134. (edt-bind-gold-key-default "^" 'edt-key-not-assigned)
  2135. (edt-bind-gold-key-default "7" 'edt-key-not-assigned)
  2136. (edt-bind-gold-key-default "&" 'edt-key-not-assigned)
  2137. (edt-bind-gold-key-default "8" 'edt-key-not-assigned)
  2138. (edt-bind-gold-key-default "*" 'edt-key-not-assigned)
  2139. (edt-bind-gold-key-default "9" 'edt-key-not-assigned)
  2140. (edt-bind-gold-key-default "(" 'edt-key-not-assigned)
  2141. (edt-bind-gold-key-default "0" 'edt-key-not-assigned)
  2142. (edt-bind-gold-key-default ")" 'edt-key-not-assigned)
  2143. (edt-bind-gold-key-default " " 'undo)
  2144. (edt-bind-gold-key-default "," 'edt-key-not-assigned)
  2145. (edt-bind-gold-key-default "<" 'edt-key-not-assigned)
  2146. (edt-bind-gold-key-default "." 'edt-key-not-assigned)
  2147. (edt-bind-gold-key-default ">" 'edt-key-not-assigned)
  2148. (edt-bind-gold-key-default "/" 'query-replace)
  2149. (edt-bind-gold-key-default "?" 'edt-key-not-assigned)
  2150. (edt-bind-gold-key-default "\\" 'edt-key-not-assigned)
  2151. (edt-bind-gold-key-default "|" 'edt-key-not-assigned)
  2152. (edt-bind-gold-key-default ";" 'edt-key-not-assigned)
  2153. (edt-bind-gold-key-default ":" 'edt-key-not-assigned)
  2154. (edt-bind-gold-key-default "'" 'edt-key-not-assigned)
  2155. (edt-bind-gold-key-default "\"" 'edt-key-not-assigned)
  2156. (edt-bind-gold-key-default "-" 'edt-key-not-assigned)
  2157. (edt-bind-gold-key-default "_" 'edt-key-not-assigned)
  2158. (edt-bind-gold-key-default "=" 'goto-line)
  2159. (edt-bind-gold-key-default "+" 'edt-key-not-assigned)
  2160. (edt-bind-gold-key-default "[" 'edt-key-not-assigned)
  2161. (edt-bind-gold-key-default "{" 'edt-key-not-assigned)
  2162. (edt-bind-gold-key-default "]" 'edt-key-not-assigned)
  2163. (edt-bind-gold-key-default "}" 'edt-key-not-assigned)
  2164. (edt-bind-gold-key-default "`" 'what-line)
  2165. (edt-bind-gold-key-default "~" 'edt-key-not-assigned)
  2166. )
  2167. ;;;
  2168. ;;; DEFAULT EDT KEYPAD HELP
  2169. ;;;
  2170. ;;
  2171. ;; Upper case commands in the keypad diagram below indicate that the
  2172. ;; emulation should look and feel very much like EDT. Lower case
  2173. ;; commands are enhancements and/or additions to the EDT keypad
  2174. ;; commands or are native Emacs commands.
  2175. ;;
  2176. (defun edt-keypad-help ()
  2177. "DEFAULT EDT Keypad Active.
  2178. F7: Copy Rectangle +----------+----------+----------+----------+
  2179. F8: Cut Rect Overstrike |Prev Line |Next Line |Bkwd Char |Frwd Char |
  2180. G-F8: Paste Rect Overstrike | (UP) | (DOWN) | (LEFT) | (RIGHT) |
  2181. F9: Cut Rect Insert |Window Top|Window Bot|Bkwd Sent |Frwd Sent |
  2182. G-F9: Paste Rect Insert +----------+----------+----------+----------+
  2183. F10: Cut Rectangle
  2184. G-F10: Paste Rectangle
  2185. F11: ESC
  2186. F12: Beginning of Line +----------+----------+----------+----------+
  2187. G-F12: Delete Other Windows | GOLD | HELP | FNDNXT | DEL L |
  2188. F13: Delete to Begin of Word | (PF1) | (PF2) | (PF3) | (PF4) |
  2189. HELP: Keypad Help |Mark Wisel|Desc Funct| FIND | UND L |
  2190. G-HELP: Emacs Help +----------+----------+----------+----------+
  2191. DO: Execute extended command | PAGE | SECT | APPEND | DEL W |
  2192. C-g: Keyboard Quit | (7) | (8) | (9) | (-) |
  2193. G-C-g: Keyboard Quit |Ex Ext Cmd|Fill Regio| REPLACE | UND W |
  2194. C-h: Beginning of Line +----------+----------+----------+----------+
  2195. G-C-h: Emacs Help | ADVANCE | BACKUP | CUT | DEL C |
  2196. C-i: Tab Insert | (4) | (5) | (6) | (,) |
  2197. C-j: Delete to Begin of Word | BOTTOM | TOP | Yank | UND C |
  2198. C-k: Define Key +----------+----------+----------+----------+
  2199. G-C-k: Restore Key | WORD | EOL | CHAR | Next |
  2200. C-l: Form Feed Insert | (1) | (2) | (3) | Window |
  2201. C-n: Set Screen Width 80 | CHNGCASE | DEL EOL |Quoted Ins| !
  2202. C-r: Isearch Backward +---------------------+----------+ (ENTER) |
  2203. C-s: Isearch Forward | LINE | SELECT | !
  2204. C-t: Display the Time | (0) | (.) | SUBS |
  2205. C-u: Delete to Begin of Line | Open Line | RESET | |
  2206. C-v: Redraw Display +---------------------+----------+----------+
  2207. C-w: Set Screen Width 132
  2208. C-z: Suspend Emacs +----------+----------+----------+
  2209. G-C-\\: Split Window | FNDNXT | Yank | CUT |
  2210. | (FIND) | (INSERT) | (REMOVE) |
  2211. G-b: Buffer Menu | FIND | | COPY |
  2212. G-c: Compile +----------+----------+----------+
  2213. G-d: Delete Window |SELECT/RES|SECT BACKW|SECT FORWA|
  2214. G-e: Exit | (SELECT) |(PREVIOUS)| (NEXT) |
  2215. G-f: Find File | | | |
  2216. G-g: Find File Other Window +----------+----------+----------+
  2217. G-h: Keypad Help
  2218. G-i: Insert File
  2219. G-k: Toggle Capitalization Word
  2220. G-l: Downcase Region
  2221. G-m: Save Some Buffers
  2222. G-n: Next Error
  2223. G-o: Switch to Next Window
  2224. G-q: Quit
  2225. G-r: Revert File
  2226. G-s: Save Buffer
  2227. G-u: Upcase Region
  2228. G-v: Find File Other Window
  2229. G-w: Write file
  2230. G-y: EDT Emulation OFF
  2231. G-z: Switch to User EDT Key Bindings
  2232. G-1: Delete Other Windows
  2233. G-2: Split Window
  2234. G-%: Go to Percentage
  2235. G- : Undo (GOLD Spacebar)
  2236. G-=: Go to Line
  2237. G-`: What line
  2238. G-/: Query-Replace"
  2239. (interactive)
  2240. (describe-function 'edt-keypad-help))
  2241. (defun edt-electric-helpify (fun)
  2242. (let ((name "*Help*"))
  2243. (if (save-window-excursion
  2244. (let* ((p (symbol-function 'help-print-return-message))
  2245. (b (get-buffer name))
  2246. (m (buffer-modified-p b)))
  2247. (and b (not (get-buffer-window b))
  2248. (setq b nil))
  2249. (unwind-protect
  2250. (progn
  2251. (message "%s..." (capitalize (symbol-name fun)))
  2252. (and b
  2253. (with-current-buffer b
  2254. (set-buffer-modified-p t)))
  2255. (fset 'help-print-return-message 'ignore)
  2256. (call-interactively fun)
  2257. (and (get-buffer name)
  2258. (get-buffer-window (get-buffer name))
  2259. (or (not b)
  2260. (not (eq b (get-buffer name)))
  2261. (not (buffer-modified-p b)))))
  2262. (fset 'help-print-return-message p)
  2263. (and b (buffer-name b)
  2264. (with-current-buffer b
  2265. (set-buffer-modified-p m))))))
  2266. (with-electric-help 'delete-other-windows name t))))
  2267. (defun edt-electric-keypad-help ()
  2268. "Display default EDT bindings."
  2269. (interactive)
  2270. (edt-electric-helpify 'edt-keypad-help))
  2271. (defun edt-electric-user-keypad-help ()
  2272. "Display user custom EDT bindings."
  2273. (interactive)
  2274. (edt-electric-helpify 'edt-user-keypad-help))
  2275. ;;;
  2276. ;;; EDT emulation screen width commands.
  2277. ;;
  2278. ;; Some terminals require modification of terminal attributes when
  2279. ;; changing the number of columns displayed, hence the fboundp tests
  2280. ;; below. These functions are defined in the corresponding terminal
  2281. ;; specific file, if needed.
  2282. (defun edt-set-screen-width-80 ()
  2283. "Set screen width to 80 columns."
  2284. (interactive)
  2285. (if (fboundp 'edt-set-term-width-80)
  2286. (edt-set-term-width-80))
  2287. (set-frame-width nil 80)
  2288. (message "Terminal width 80"))
  2289. (defun edt-set-screen-width-132 ()
  2290. "Set screen width to 132 columns."
  2291. (interactive)
  2292. (if (fboundp 'edt-set-term-width-132)
  2293. (edt-set-term-width-132))
  2294. (set-frame-width nil 132)
  2295. (message "Terminal width 132"))
  2296. (provide 'edt)
  2297. ;;; edt.el ends here