home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3567 < prev    next >
Internet Message Format  |  1991-07-02  |  31KB

  1. From: jv@mh.nl (Johan Vromans)
  2. Newsgroups: gnu.emacs.sources,alt.sources
  3. Subject: GNU Emacs forms-mode version 1.2.7 (part 1 of 3)
  4. Message-ID: <1991Jul1.132132.10582@pronto.mh.nl>
  5. Date: 1 Jul 91 13:21:32 GMT
  6.  
  7.  
  8. This is GNU Emacs 'forms-mode', version 1.2 (patchlevel 7).
  9. It supercedes version 1.2.3 that was posted to the net some time ago.
  10. No diffs from 1.2.3, since the size of the diffs exceeds the size of the
  11. sources.
  12.  
  13. This GNU Emacs major mode implements editing a structured file (i.e. a
  14. file with 'records' and 'fields' in it) using a forms. 
  15. It is fully documented in the source file 'forms.el' and in the
  16. texinfo file 'forms.ti'.
  17.  
  18. Submitted-by: jv@mh.nl
  19. Archive-name: forms/part01
  20.  
  21. ---- Cut Here and feed the following to sh ----
  22. #!/bin/sh
  23. # This is forms, a shell archive (produced by shar 3.49)
  24. # To extract the files from this archive, save it to a file, remove
  25. # everything above the "!/bin/sh" line above, and type "sh file_name".
  26. #
  27. # made 07/01/1991 13:08 UTC by jv@mh.nl
  28. # Source directory /u1/users/jv/elisp/src/forms-mode/Work
  29. #
  30. # existing files will NOT be overwritten unless -c is specified
  31. #
  32. # This is part 1 of a multipart archive                                    
  33. # do not concatenate these parts, unpack them in order with /bin/sh        
  34. #
  35. # This shar contains:
  36. # length  mode       name
  37. # ------ ---------- ------------------------------------------
  38. #   3311 -r--r--r-- README
  39. #     47 -rw-r--r-- MANIFEST
  40. #    560 -rw-r--r-- demo1
  41. #   2402 -r--r--r-- demo2
  42. #    565 -rw-r--r-- demo2.dat
  43. #  28722 -r--r--r-- forms.ti
  44. #  41744 -r--r--r-- forms.el
  45. #
  46. if test -r _shar_seq_.tmp; then
  47.     echo 'Must unpack archives in sequence!'
  48.     echo Please unpack part `cat _shar_seq_.tmp` next
  49.     exit 1
  50. fi
  51. # ============= README ==============
  52. if test -f 'README' -a X"$1" != X"-c"; then
  53.     echo 'x - skipping README (File already exists)'
  54.     rm -f _shar_wnt_.tmp
  55. else
  56. > _shar_wnt_.tmp
  57. echo 'x - extracting README (Text)'
  58. sed 's/^X//' << 'SHAR_EOF' > 'README' &&
  59. This is GNU Emacs 'forms-mode', version 1.2 (patchlevel 7).
  60. X
  61. This GNU Emacs major mode implements editing a structured file (i.e. a
  62. file with 'records' and 'fields' in it) using a forms. 
  63. It is fully documented in the source file 'forms.el' and in the
  64. texinfo file 'forms.ti'.
  65. X
  66. This kit contains:
  67. X
  68. X    README        - this file
  69. X    MANIFEST    - list of files
  70. X    forms.el    - the lisp source
  71. X    forms.ti    - texinfo file
  72. X    demo1        - simple demo using /etc/passwd
  73. X    demo2        - advanced demo using 'demo2.dat'
  74. X    demo2.dat    - data for demo2
  75. X
  76. Load the lisp source, and execute
  77. X
  78. X    forms-find-file demo1
  79. X
  80. to look at your password file in a unconventional (but read-only) way.
  81. X
  82. X    forms-find-file demo2
  83. X
  84. gives you something to clobber with data and multi-line fields.
  85. X
  86. This program has been donated to the Free Software Foundation to be
  87. part of their GNU Emacs programming system.
  88. X
  89. Have fun!
  90. X
  91. X    Johan Vromans    <jv@mh.nl>
  92. X
  93. HISTORY
  94. -------
  95. X
  96. 1.2.7  Released: Jul 1, 1991
  97. X
  98. X New features:
  99. X  * Is it now possible to define a function
  100. X    `forms-modified-record-filter' in the control file, that gets
  101. X    called when a new record is created.  It can be used to change
  102. X    values in fields.
  103. X
  104. X  * The filter functions may also point to a function.
  105. X
  106. X  * Support for functions and lisp symbols in forms-format-list.
  107. X
  108. X  * Function forms-enumerate can be helpful when defining 'symbolic
  109. X    names' for fields.
  110. X
  111. X  * 'demo2' has been enhanced to exploit most of the new features.
  112. X
  113. X Misc.:
  114. X  * Internally optimized the forms-format-list.
  115. X
  116. X  * Added support for debugging.
  117. X
  118. X  * Stripped duplicate documentation.
  119. X
  120. 1.2.3  Released: May 21, 1991
  121. X
  122. X Fixed bug:
  123. X  * Make argument to scroll-{up,down} &optional.
  124. X
  125. 1.2.2  Released: May 20, 1991
  126. X
  127. X Fixed bug:
  128. X  * The modifications to the last field of a form were not handled
  129. X    correctly if that field was not followed by fixed text.
  130. X
  131. 1.2.1  Released: Sep 18, 1990
  132. X
  133. X New feature:
  134. X  * Is it now possible to define a function `forms-new-record-filter' in
  135. X    the control file, that gets called when a new record is created.
  136. X    It can be used to insert default values in fields.
  137. X    Thanks to Harald Hanche-Olsen <hanche@imf.unit.no> .
  138. X
  139. X Fixed bugs:
  140. X  * `save-buffer' was redefined as (interactive "P"). This should have
  141. X    been (interactive "p").
  142. X    Thanks to Jonathan Kamens <jik@pit-manager.MIT.EDU> .
  143. X  * `forms--checkmod' was not called often enough to prevent modified
  144. X    records from getting lost in spurious situations.
  145. X    Thanks to u502sou@mpirbn.uucp (Ignatios Souvatzis).
  146. X  * When updating a new record, sometimes it got prepended to the next
  147. X    record. 
  148. X    Thanks to several users.
  149. X
  150. X Other modifications:
  151. X  * Harald Hanche-Olsen <hanche@imf.unit.no> rewrote
  152. X    forms--make-format and forms--make-parser to use the more standard
  153. X    backquote construct.
  154. X
  155. X And finally:
  156. X  * Ignatios Souvatzis wrote a forms routine to sort a file on
  157. X    selected fields. I did not include it because I don't think that
  158. X    sorting belongs to the functionality of forms-mode. Ignatios
  159. X    wrote me:
  160. X
  161. X      as i didn't want to look up the man page for /bin/sort, i wrote
  162. X      a sort function for you forms mode. You may include it in your
  163. X      next distribution to the net or FSF, if you want (as long as
  164. X      there remains a trace of who wrote that ~30 lines). Else tell me
  165. X      please so that i can post the sort code myself.
  166. SHAR_EOF
  167. chmod 0444 README ||
  168. echo 'restore of README failed'
  169. Wc_c="`wc -c < 'README'`"
  170. test 3311 -eq "$Wc_c" ||
  171.     echo 'README: original size 3311, current size' "$Wc_c"
  172. rm -f _shar_wnt_.tmp
  173. fi
  174. # ============= MANIFEST ==============
  175. if test -f 'MANIFEST' -a X"$1" != X"-c"; then
  176.     echo 'x - skipping MANIFEST (File already exists)'
  177.     rm -f _shar_wnt_.tmp
  178. else
  179. > _shar_wnt_.tmp
  180. echo 'x - extracting MANIFEST (Text)'
  181. sed 's/^X//' << 'SHAR_EOF' > 'MANIFEST' &&
  182. README
  183. forms.el
  184. forms.ti
  185. demo1
  186. demo2
  187. demo2.dat
  188. SHAR_EOF
  189. chmod 0644 MANIFEST ||
  190. echo 'restore of MANIFEST failed'
  191. Wc_c="`wc -c < 'MANIFEST'`"
  192. test 47 -eq "$Wc_c" ||
  193.     echo 'MANIFEST: original size 47, current size' "$Wc_c"
  194. rm -f _shar_wnt_.tmp
  195. fi
  196. # ============= demo1 ==============
  197. if test -f 'demo1' -a X"$1" != X"-c"; then
  198.     echo 'x - skipping demo1 (File already exists)'
  199.     rm -f _shar_wnt_.tmp
  200. else
  201. > _shar_wnt_.tmp
  202. echo 'x - extracting demo1 (Text)'
  203. sed 's/^X//' << 'SHAR_EOF' > 'demo1' &&
  204. ;; demo for forms-mode    -*-emacs-lisp-*-
  205. ;;
  206. ;; This demo visits your passwd file.
  207. X
  208. ;; use yp if present
  209. (or (file-exists-p (setq forms-file "/var/yp/src/passwd"))
  210. X    (setq forms-file "/etc/passwd"))
  211. X
  212. (setq forms-read-only t)        ; to make sure
  213. (setq forms-field-sep ":")
  214. (setq forms-number-of-fields 7)
  215. X
  216. (setq forms-format-list
  217. X      (list
  218. X       "====== Visiting " forms-file " ======\n\n"
  219. X       "User : "    1
  220. X       "   Uid: "    3
  221. X       "   Gid: "    4
  222. X       "\n\n"
  223. X       "Name : "    5
  224. X       "\n\n"
  225. X       "Home : "    6
  226. X       "\n\n"
  227. X       "Shell: "    7
  228. X       "\n"))
  229. SHAR_EOF
  230. chmod 0644 demo1 ||
  231. echo 'restore of demo1 failed'
  232. Wc_c="`wc -c < 'demo1'`"
  233. test 560 -eq "$Wc_c" ||
  234.     echo 'demo1: original size 560, current size' "$Wc_c"
  235. rm -f _shar_wnt_.tmp
  236. fi
  237. # ============= demo2 ==============
  238. if test -f 'demo2' -a X"$1" != X"-c"; then
  239.     echo 'x - skipping demo2 (File already exists)'
  240.     rm -f _shar_wnt_.tmp
  241. else
  242. > _shar_wnt_.tmp
  243. echo 'x - extracting demo2 (Text)'
  244. sed 's/^X//' << 'SHAR_EOF' > 'demo2' &&
  245. ;; demo2 -- demo forms-mode    -*- emacs-lisp -*-
  246. X
  247. ;; SCCS Status     : @(#)@ demo2    1.1.2
  248. ;; Author          : Johan Vromans
  249. ;; Created On      : 1989
  250. ;; Last Modified By: Johan Vromans
  251. ;; Last Modified On: Mon Jul  1 13:56:31 1991
  252. ;; Update Count    : 2
  253. ;; Status          : OK
  254. ;; 
  255. ;; This sample forms exploit most of the features of forms mode.
  256. X
  257. ;; Set the name of the data file.
  258. (setq forms-file "demo2.dat")
  259. X
  260. ;; Use 'forms-enumerate' to set field names and number thereof.
  261. (setq forms-number-of-fields
  262. X      (forms-enumerate
  263. X       '(arch-newsgroup            ; 1
  264. X     arch-volume            ; 2
  265. X     arch-issue            ; and ...
  266. X     arch-article            ; ... so
  267. X     arch-shortname            ; ... ... on
  268. X     arch-parts
  269. X     arch-from
  270. X     arch-longname
  271. X     arch-keywords
  272. X     arch-date
  273. X     arch-remarks)))
  274. X
  275. ;; The following functions are used by this form for layout purposes.
  276. ;;
  277. (defun arch-tocol (target &optional fill)
  278. X  "Produces a string to skip to column TARGET. Prepends newline if needed.
  279. The optional FILL should be a character, used to fill to the column."
  280. X  (if (null fill)
  281. X      (setq fill ? ))
  282. X  (if (< target (current-column))
  283. X      (concat "\n" (make-string target fill))
  284. X    (make-string (- target (current-column)) fill)))
  285. ;;
  286. (defun arch-rj (target field &optional fill) 
  287. X  "Produces a string to skip to column TARGET minus the width of field FIELD.
  288. Prepends newline if needed. The optional FILL should be a character,
  289. used to fill to the column."
  290. X  (arch-tocol (- target (length (nth field forms-fields))) fill))
  291. X
  292. ;; Record filters.
  293. ;; This example uses the (defun ...) method of defining.
  294. ;;
  295. (defun forms-new-record-filter (the-record)
  296. X  "Form a new record with some defaults."
  297. X  (aset the-record arch-from (user-full-name))
  298. X  (aset the-record arch-date (current-time-string))
  299. X  the-record                ; return it
  300. )
  301. X
  302. ;; The format list.
  303. (setq forms-format-list
  304. X     (list
  305. X       "====== Public Domain Software Archive ======\n\n"
  306. X       arch-shortname
  307. X       " - "            arch-longname
  308. X       "\n\n"
  309. X       "Article: "        arch-newsgroup
  310. X       "/"            arch-article
  311. X       " "
  312. X       '(arch-tocol 40)
  313. X       "Issue: "        arch-issue
  314. X       " "
  315. X       '(arch-rj 73 10)
  316. X       "Date: "            arch-date
  317. X       "\n\n"
  318. X       "Submitted by: "        arch-from
  319. X       "\n"
  320. X       '(arch-tocol 79 ?-)
  321. X       "\n"
  322. X       "Keywords: "        arch-keywords
  323. X       "\n\n"
  324. X       "Parts: "        arch-parts
  325. X       "\n\n====== Remarks ======\n\n"
  326. X       arch-remarks
  327. X     ))
  328. X
  329. ;; That's all, folks!
  330. SHAR_EOF
  331. chmod 0444 demo2 ||
  332. echo 'restore of demo2 failed'
  333. Wc_c="`wc -c < 'demo2'`"
  334. test 2402 -eq "$Wc_c" ||
  335.     echo 'demo2: original size 2402, current size' "$Wc_c"
  336. rm -f _shar_wnt_.tmp
  337. fi
  338. # ============= demo2.dat ==============
  339. if test -f 'demo2.dat' -a X"$1" != X"-c"; then
  340.     echo 'x - skipping demo2.dat (File already exists)'
  341.     rm -f _shar_wnt_.tmp
  342. else
  343. > _shar_wnt_.tmp
  344. echo 'x - extracting demo2.dat (Text)'
  345. sed 's/^X//' << 'SHAR_EOF' > 'demo2.dat' &&
  346. comp.sources.unix        v11i008    269    getty-enable    1    tron@sc.nsc.com (Ronald S. Karr)    Getty on/off programs for 4.[23] BSD        890505    This program can be used to dynamically enable / disable terminallines on a BSD system.
  347. comp.sources.unix    11    v11i022    283    syslog    1    emory!arnold (Arnold D. Robbins {EUCC})    Development version of syslog(3), for ATT, too        28/08/1987    
  348. comp.sources.unix    11    v11i033    290    less3    3    sun!intsc!convgt!mark    The 'less' pager        02/09/1987    
  349. comp.sources.unix    11    v11i036    293    test.el    3    "Mark A. Ardis" <maa@sei.cmu.edu>    Test system for GNU Emacs        10/09/1987    
  350. SHAR_EOF
  351. chmod 0644 demo2.dat ||
  352. echo 'restore of demo2.dat failed'
  353. Wc_c="`wc -c < 'demo2.dat'`"
  354. test 565 -eq "$Wc_c" ||
  355.     echo 'demo2.dat: original size 565, current size' "$Wc_c"
  356. rm -f _shar_wnt_.tmp
  357. fi
  358. # ============= forms.ti ==============
  359. if test -f 'forms.ti' -a X"$1" != X"-c"; then
  360.     echo 'x - skipping forms.ti (File already exists)'
  361.     rm -f _shar_wnt_.tmp
  362. else
  363. > _shar_wnt_.tmp
  364. echo 'x - extracting forms.ti (Text)'
  365. sed 's/^X//' << 'SHAR_EOF' > 'forms.ti' &&
  366. \input texinfo            @c -*-texinfo-*-
  367. X
  368. @c  forms.ti -- documentation for forms-mode
  369. @c  SCCS Status     : @(#)@ forms    1.2.7
  370. @c  Author          : Johan Vromans
  371. @c  Created On      : 1989
  372. @c  Last Modified By: Johan Vromans
  373. @c  Last Modified On: Mon Jul  1 14:54:22 1991
  374. @c  Update Count    : 16
  375. @c  Status          : OK
  376. X
  377. @c  HISTORY 
  378. @c  1-Jul-1991        Johan Vromans    
  379. @c     Restructured parts of the doc.
  380. @c  30-Jun-1991        Johan Vromans    
  381. @c     Add doc for forms-modified-record-filter.
  382. @c     Doc that the filters may be the name of a function.
  383. @c     Clarified the use of quoted lists and symbols in
  384. @c     forms-format-list.
  385. @c
  386. @c  29-Jun-1991         Johan Vromans   
  387. @c     Inserted these headers.
  388. @c     Added doc to use lisp lists and symbols in forms-forms-list. 
  389. X
  390. @comment %**start of header (This is for running Texinfo on a region.)
  391. @setfilename forms.info
  392. @settitle Forms Mode User's Manual
  393. @iftex
  394. @finalout
  395. @setchapternewpage odd
  396. @end iftex
  397. @c      @smallbook
  398. @comment %**end of header (This is for running Texinfo on a region.)
  399. X
  400. @tex
  401. \global\chapno=30
  402. @end tex
  403. X
  404. @ifinfo
  405. This file documents forms-mode, a forms based major mode for GNU Emacs.
  406. X
  407. Permission is granted to make and distribute verbatim copies of this
  408. manual provided the copyright notice and this permission notice are
  409. preserved on all copies.
  410. X
  411. @ignore
  412. Permission is granted to process this file through TeX and print the
  413. results, provided the printed document carries copying permission notice
  414. identical to this one except for the removal of this paragraph (this
  415. paragraph not being relevant to the printed manual).
  416. X
  417. @end ignore
  418. @end ifinfo
  419. X
  420. @iftex
  421. @titlepage
  422. @sp 6
  423. @center @titlefont{Forms Mode User's Manual}
  424. @sp 4
  425. @center Forms-Mode version 1.2, patchlevel 7
  426. @sp 1
  427. @center July 1991
  428. @sp 5
  429. @center Johan Vromans
  430. @center @i{jv@@mh.nl}
  431. @page
  432. X
  433. @vskip 0pt plus 1filll
  434. Copyright @copyright{} 1989,1990,1991 Free Software Foundation, Inc.
  435. X
  436. Permission is granted to make and distribute verbatim copies of
  437. this manual provided the copyright notice and this permission notice
  438. are preserved on all copies.
  439. X
  440. @end titlepage
  441. @page
  442. @end iftex
  443. X
  444. @ifinfo
  445. @node Top, What is in a Forms, , (DIR)
  446. @end ifinfo
  447. X
  448. @iftex
  449. @chapter Forms mode
  450. @end iftex
  451. X
  452. Forms mode is an Emacs major mode for working with simple plain-text
  453. databases in a forms-oriented manner. In forms mode, the information in
  454. these files is presented in an Emacs window in a user-defined format,
  455. one record at a time. Forms can be inspected read-only (viewing) or
  456. modified and updated.
  457. @cindex forms-mode
  458. X
  459. Forms mode is not a simple major mode, but requires two files to do its
  460. job: a control file and a data file. The data file holds the
  461. actual data which will be presented. The control file describes
  462. how it will be presented.
  463. X
  464. @menu
  465. * What is in a Forms::    Introduction.
  466. * Data File Format::    How to format the data file.
  467. * Control File Format::    How to control forms mode.
  468. * Forms Format Description::
  469. X            How to define the forms layout.
  470. * Modifying Forms Contents::
  471. X            How to modify.
  472. * Forms Mode Commands::    The commands available, and how to use them.
  473. * Key Bindings::    Which keys are bound to what commands.
  474. * Miscellaneous::    Forms mode messages and other remarks.
  475. * Examples::        Some examples.
  476. * Credits::        Thanks everyone.
  477. * Concept Index::    Index of Concepts
  478. * Variable Index::    Index of Variables.
  479. * Function Index::    Index of Functions.
  480. @end menu
  481. X
  482. @node What is in a Forms, Data File Format, Top, Top
  483. @section What is in a forms
  484. X
  485. Let's illustrate forms mode with an example. Suppose you are looking at
  486. your @file{/etc/passwd} file, and your screen looks as follows:
  487. X
  488. @example
  489. ====== /etc/passwd ======
  490. X
  491. User : root   Uid: 0   Gid: 1
  492. X
  493. Name : Super User
  494. X
  495. Home : /
  496. X
  497. Shell: /bin/sh
  498. @end example
  499. X
  500. As you can see, the familiar fields from the entry for the super user
  501. are all there, but instead of being colon-separated on one single line,
  502. they make up a forms.
  503. X
  504. The contents of the forms consists of the contents of the fields of the
  505. record (e.g. ``root'', ``0'', ``1'', ``Super User'')
  506. interspersed with normal text (e.g ``User : '', ``Uid: '').
  507. X
  508. You can define yourself how text and fields will be used to make up the
  509. forms.
  510. X
  511. When you modifiy the contents of the forms, it will be analyzed and the
  512. new contents of the fields of this record will be extracted. It
  513. possible, the file will be updated with the new contents.
  514. X
  515. @node Data File Format, Control File Format, What is in a Forms, Top
  516. @section Data file format
  517. X
  518. Files for use with forms mode are very simple -- each record (line)
  519. forms the contents one form.  Each record is supposed to consist of a
  520. number of fields. These fields are separated by the value of the string
  521. @code{forms-field-sep}, which is a @code{TAB} by default.
  522. X
  523. @cindex pseudo-newline
  524. Fields may contain text which shows up in the forms in multiple lines.
  525. These lines are separated in the field using a @var{pseudo-newline}
  526. character which is defined by the value of the string
  527. @code{forms-multi-line}. Its default value is a Control-K character. If
  528. it is set to @code{nil} multiple line fields are prohibited.
  529. X
  530. @node Control File Format, Forms Format Description, Data File Format, Top
  531. @section Control file format
  532. X
  533. The control file serves two purposes.
  534. X
  535. First, it defines the data file to use, and its properties.
  536. X
  537. Second, the Emacs buffer it occupies will be used by the forms mode to
  538. display the forms.
  539. X
  540. @findex eval-current-buffer
  541. The contents of the control file are evaluated using the Emacs command
  542. @code{eval-current-buffer}, hence must contain valid Emacs-lisp expressions.
  543. These expressions must set the following lisp variables to a suitable
  544. value:
  545. X
  546. @table @code
  547. @vindex forms-file
  548. @item forms-file
  549. This variable must be set to the name of the data file.@*
  550. Example:
  551. @example
  552. (setq forms-file "my/data-file")
  553. @end example
  554. X
  555. @vindex forms-format-list
  556. @item forms-format-list
  557. This variable describes the way the fields of the record are formatted on
  558. the screen. See the next section for details.
  559. X
  560. @vindex forms-number-of-fields
  561. @item forms-number-of-fields
  562. This variable holds the number of fields in each record of the data
  563. file.@*
  564. Example:
  565. @example
  566. (setq forms-number-of-fields 10)
  567. @end example
  568. X
  569. @end table
  570. X
  571. An error will be given if one of the above values has not been set.
  572. X
  573. Other variables that may be set from the control file are optional. Most
  574. of them have suitable default values.
  575. X
  576. @table @code
  577. @vindex forms-field-sep
  578. @item forms-field-sep
  579. This variable may be used to designate the string which separates the fields
  580. in the records of the data file. If not set, it defaults to a string
  581. containing a single @code{TAB} character. @*
  582. Example:
  583. @example
  584. (setq forms-field-sep "\t")
  585. @end example
  586. X
  587. @vindex forms-read-only
  588. @item forms-read-only
  589. If set to a value other than @code{nil}, the data file is treated
  590. read-only. If the data file can not be written into, read-only mode is
  591. enforced. The default value for @code{forms-read-only} is derieved from
  592. the access permissions of the data file.@*
  593. Example:
  594. @example
  595. (set forms-read-only t)
  596. @end example
  597. X
  598. @vindex forms-multi-line
  599. @item forms-multi-line
  600. This variable may be set to allow multi-line text in fields. It should
  601. be set to a string of one character, which denotes the pseudo new-line
  602. character to be used to separate the text lines.@*
  603. Its default value is Control-K (octal 013). If set to @code{nil},
  604. multi-line text fields are prohibited.@*
  605. It may not be a character contained in @code{forms-field-sep}.@*
  606. Example:
  607. @example
  608. (setq forms-multi-line "\C-k")
  609. @end example
  610. X
  611. @vindex forms-forms-scroll
  612. @item forms-forms-scroll
  613. @xref{Forms Mode Commands} for the description.
  614. X
  615. @vindex forms-forms-jump
  616. @item forms-forms-jump
  617. @xref{Forms Mode Commands} for the description.
  618. X
  619. @findex{forms-new-record-filter}
  620. @item forms-new-record-filter
  621. The control file may define a function @code{forms-new-record-filter},
  622. or set @code{forms-new-record-filter} to such a function. If so, this
  623. function is called when a new record is created to supply default values
  624. for fields.
  625. X
  626. @findex{forms-modified-record-filter}
  627. @item  forms-modified-record-filter
  628. The control file may define a function
  629. @code{forms-modified-record-filter}, or set
  630. @code{forms-modified-record-filter} to such a function.  If so, this
  631. function is called when a record is modified, just before writing the
  632. modified record back to the data file.
  633. X
  634. @end table
  635. X
  636. @node Forms Format Description, Modifying Forms Contents, Control File Format, Top
  637. @section The forms format description
  638. X
  639. @vindex forms-format-list
  640. The value of the variable @code{forms-format-list} is used to specify
  641. the format of the forms. It must be a list of formatting elements, each
  642. of which can be a string, number, lisp list or a lisp symbol that
  643. evaluates to one of these. The formatting elements are processed in the
  644. order they appear in the list.
  645. X
  646. A @code{string} formatting element is inserted in the forms ``as is''.
  647. X
  648. A @code{number} element selects a field of the record. The contents of
  649. this field are inserted. The first field of the record has number 1
  650. (one).
  651. X
  652. A @code{lisp list} specifies a function call. This function is called
  653. every time a record is displayed, and its result, that must be a
  654. string, is inserted in the forms. The function should do nothing
  655. but returning a string. The fields of the record being displayed are
  656. @vindex forms-fields
  657. available to this function as the list @code{forms-fields} and can be
  658. accessed using @code{(nth }@var{FIELD NUMBER}@code{ forms-fields)}.
  659. Fields are numbered starting from 1 (one).
  660. X
  661. A @code{lisp symbol} must evaluate to one of the above possibilities.
  662. X
  663. If a record does not contain the number of fields as specified in
  664. @code{forms-number-of-fields}, a warning message will be printed. Excess
  665. fields are ignored, missing fields are set to empty.
  666. X
  667. The control file which shows your @file{/etc/passwd} file as demonstrated
  668. in the beginning of this document might look as follows:
  669. @example
  670. ;; This demo visits /etc/passwd.
  671. X
  672. (setq forms-file "/etc/passwd")
  673. (setq forms-number-of-fields 7)
  674. (setq forms-read-only t)                 ; to make sure
  675. (setq forms-field-sep ":")
  676. (setq forms-multi-line nil)              ; not allowed
  677. X
  678. (setq forms-format-list
  679. X      (list
  680. X       "====== /etc/passwd ======\n\n"
  681. X       "User : "    1
  682. X       "   Uid: "   3
  683. X       "   Gid: "   4
  684. X       "\n\n"
  685. X       "Name : "    5
  686. X       "\n\n"
  687. X       "Home : "    6
  688. X       "\n\n"
  689. X       "Shell: "    7
  690. X       "\n"))
  691. @end example
  692. X
  693. When functions are to be used in @code{forms-format-list} they must be
  694. quoted to prevent them from being evaluated too early:
  695. X
  696. @example
  697. (setq forms-format-list
  698. X      (list
  699. X       "====== " forms-file " ======\n\n"
  700. X       "User : "    1
  701. X       '(make-string 20 ?-)
  702. X       ...
  703. X      ))
  704. @end example
  705. X
  706. Alternativily, instead of quoting the functions, the whole list may be
  707. quoted: 
  708. X
  709. @example
  710. (setq forms-format-list
  711. X     '(
  712. X       "====== " forms-file " ======\n\n"
  713. X       "User : "    1
  714. X       (make-string 20 ?-)
  715. X       ...
  716. X      ))
  717. @end example
  718. X
  719. Upon startup, the contents of @code{forms-format-list} are
  720. validated. If errors are encountered, processing is aborted with 
  721. an error message which includes a descriptive text. @xref{Error
  722. Messages}, for a detailed list of error messages.
  723. X
  724. @node Modifying Forms Contents, Forms Mode Commands, Forms Format Description, Top
  725. @section Modifying The Forms Contents
  726. X
  727. If a forms is not read-only, it's contents can be modified.
  728. X
  729. All normal editor commands may be used to change the forms. There is no
  730. distinction between the ``fixed'' text and the text from the fields of
  731. the records. However, upon completion, the forms is parsed to extract
  732. the new contents of the fields. The ``fixed'' portions of the forms are
  733. used to delimit the fields, these portions should therefore not be
  734. modified to avoid the risk that the field contents cannot be determined.
  735. Moreover, ambiguous field contents, which can not be discriminated from
  736. ``fixed'' text, must be avoided.
  737. X
  738. If the contents of the forms cannot be recognized properly, this is
  739. signaled using a descriptive text. @xref{Error Messages}, for more info.
  740. The cursor will indicate the last part of the forms which was
  741. successfully parsed.
  742. X
  743. @findex{forms-modified-record-filter}
  744. If @code{forms-modified-record-filter} has been set, this function is
  745. called before the new data is written to the data file. The function
  746. is called with one argument: a vector that contains the contents of the
  747. fields of the record. Fields can referenced or modified using the lisp
  748. functions @code{aref} and @code{aset}. The first field has number 1
  749. (one). The function must return the (possibly modified) vector to the
  750. calling environment.
  751. X
  752. @example
  753. (defun my-modified-record-filter (record)
  754. X  ;; modify second field
  755. X  (aset record 2 (current-time-string))
  756. X  record        ; return it
  757. )
  758. (setq forms-modified-record-filter 'my-modified-record-filter)
  759. @end example
  760. X
  761. @node Forms Mode Commands, Key Bindings, Modifying Forms Contents, Top
  762. @section Forms mode commands
  763. X
  764. @table @kbd
  765. @findex forms-find-file
  766. @item M-x forms-find-file @var{file}
  767. @end table
  768. X
  769. Visits @var{file}, runs @code{eval-current-buffer} on it, and puts the
  770. buffer into forms-mode. The first record of the data file will be loaded
  771. and shown.
  772. X
  773. The modeline will display the major mode @code{"Forms"} followed by the
  774. minor mode @code{"View"} if the file is visited read-only.  The number
  775. of the current record (@var{n}) and the total number of records
  776. (@var{t}) in the file is shown in the modeline as @code{"n/t"}.@*
  777. For example:
  778. @example
  779. --%%-Emacs: passwd-demo          (Forms View 1/54)----All-------
  780. @end example
  781. X
  782. @table @kbd
  783. @findex forms-find-file-other-window
  784. @item M-x forms-find-file-other-window @var{file}
  785. @end table
  786. X
  787. This command is similar to @code{forms-find-file}, but visits the file
  788. in another window.
  789. X
  790. If the buffer is not read-only, you may change the buffer to modify the
  791. fields in the record. When the current record is left, e.g. by switching
  792. to another record, the contents of the buffer are parsed using the
  793. specifications in @code{forms-format-list}, and a new record is constructed
  794. which replaces the current record in the data file. Fields of the record
  795. which are not shown in the forms are not modified; they retain their
  796. original contents.
  797. X
  798. Most forms mode commands are bound to keys, and are accessible with the
  799. conventional @code{C-c} prefix. In read-only mode this prefix is not used.
  800. @xref{Key Bindings}, for the default key bindigs used by forms mode.
  801. X
  802. The following commands are available within forms mode.
  803. X
  804. @table @kbd
  805. @findex forms-next-record
  806. @item forms-next-record
  807. shows the next record. With a prefix argument, show the n-th next
  808. record.
  809. X
  810. @findex forms-prev-record
  811. @item forms-prev-record
  812. shows the previous record. With a prefix argument, show the n-th previous
  813. record.
  814. X
  815. @findex forms-jump-record
  816. @item forms-jump-record
  817. jumps to a record by number. A prefix argument is used for the record
  818. number to jump to. If no prefix argument is supplied, a record number is
  819. asked for in the minibuffer.@*
  820. If an invalid record number is supplied, an error message is displayed
  821. reading the offending record number, and the allowable range of numbers.
  822. X
  823. @findex forms-first-record
  824. @item forms-first-record
  825. jumps to the first record.
  826. X
  827. @findex forms-last-record
  828. @item forms-last-record
  829. jumps to the last record. Also re-counts the number of records in the data
  830. file.
  831. X
  832. @findex forms-next-field
  833. @item forms-next-field
  834. jumps to the next field in the forms. With a numeric argument: jumps
  835. that many fields, or to the first field if there are not that many
  836. fields left.
  837. X
  838. Jumping to fields is implemented using markers, which are placed
  839. in front of the fields. If the contents of the forms are modified, the
  840. markers are adjusted. However, if text around a marker has been deleted
  841. from the screen and inserted again it is possible that this marker no
  842. longer points at its field correctly.
  843. @xref{Markers,,Markers, emacs, the GNU Emacs Lisp Manual}, for more
  844. information on markers.
  845. X
  846. @findex forms-view-mode
  847. @item forms-view-mode
  848. switches to read-only mode. Forms mode commands may no longer be prefixed
  849. with @code{C-c}.
  850. X
  851. @findex forms-edit-mode
  852. @item forms-edit-mode
  853. switches to edit mode. Forms mode commands must be prefixed with
  854. @code{C-c}.@*
  855. Switching to edit mode is only possible if write access to the data
  856. file is allowed.
  857. X
  858. @findex forms-insert-record
  859. @item forms-insert-record
  860. create a new record, which is inserted before the current record. An
  861. empty form is presented, which can be filled in using familiar editor
  862. commands. With a prefix argument: the new record is created @i{after} the
  863. current one.
  864. X
  865. If a function @code{forms-new-record-filter} was defined in the control
  866. file, this function is called to fill in default values for fields. The
  867. function is passed a vector of empty strings, one for each field. For
  868. convenience, an additional element is added so the numbers of the
  869. elements are the same as the numbers used in the forms description. The
  870. function must return the (updated) vector.
  871. X
  872. Instead of defining the function, @code{forms-new-record-filter} may be
  873. set to a function.
  874. X
  875. Example:
  876. @example
  877. (defun my-new-record-filter (fields)
  878. X  (aset fields 5 (login-name))
  879. X  (aset fields 1 (current-time-string))
  880. X  ;; and return it
  881. X  fields)
  882. (setq forms-new-record-filter 'my-new-record-filter)
  883. @end example
  884. X
  885. @findex forms-delete-record
  886. @item forms-delete-record
  887. deletes the current record. You are prompted for confirmation before the
  888. record is deleted unless a prefix argument has been provided.
  889. X
  890. @findex forms-search
  891. @item forms-search @var{regexp}
  892. searches for @var{regexp} in all records following this one. If found,
  893. this record is shown.@*
  894. The next time it is invoked, the previous regexp is the default, so you
  895. can do repeated searches by simply pressing @key{RET} in response to the
  896. prompt.
  897. X
  898. @findex revert-buffer
  899. @item revert-buffer
  900. reverts a possibly modified forms to its original state. It only affect
  901. the record currently in the forms.
  902. X
  903. @findex forms-exit
  904. @item forms-exit
  905. terminates forms processing. The data file is saved
  906. if it has been modified.
  907. X
  908. @findex forms-exit-no-save
  909. @item forms-exit-no-save
  910. aborts forms processing. If the data file has been modified Emacs will
  911. ask questions.
  912. X
  913. @findex describe-mode
  914. @item describe-mode
  915. gives additional help.
  916. X
  917. @findex save-buffer
  918. @item save-buffer
  919. saves the changes in the data file, if modified.
  920. X
  921. @end table
  922. X
  923. @vindex forms-forms-scroll
  924. @findex scroll-up
  925. @findex scroll-down
  926. If the variable @code{forms-forms-scrolls} is set to a value other
  927. than @code{nil} (which it is, by default), the Emacs functions
  928. @code{scroll-up} and @code{scroll-down} will perform a
  929. @code{forms-next-record} and @code{forms-prev-record} when in forms
  930. mode.  So you can use your favourite page commands to page through the
  931. data file.
  932. X
  933. @vindex forms-forms-jump
  934. @findex beginning-of-buffer
  935. @findex end-of-buffer
  936. Likewise, if the variable @code{forms-forms-jump} is not @code{nil}
  937. (which it is, by default), Emacs functions @code{beginning-of-buffer}
  938. and @code{end-of-buffer} will perform @code{forms-first-record} and
  939. @code{forms-last-record} when in forms mode.
  940. X
  941. @vindex forms-mode-hooks
  942. After forms mode is entered, functions contained in
  943. @code{forms-mode-hooks} are executed to perform user defined customization.
  944. X
  945. @node Key Bindings, Miscellaneous, Forms Mode Commands, Top
  946. SHAR_EOF
  947. true || echo 'restore of forms.ti failed'
  948. fi
  949. echo 'End of forms part 1'
  950. echo 'File forms.ti is continued in part 2'
  951. echo 2 > _shar_seq_.tmp
  952. exit 0
  953. -- 
  954. Johan Vromans                       jv@mh.nl via internet backbones
  955. Multihouse Automatisering bv               uucp: ..!{uunet,hp4nl}!mh.nl!jv
  956. Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62911/62500
  957. ------------------------ "Arms are made for hugging" -------------------------
  958.