home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume13 / forms.el / part03 < prev    next >
Encoding:
Text File  |  1990-06-15  |  17.6 KB  |  544 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v13i051: Emacs forms mode 1.1 - part 03 of 03
  3. from: jv@mh.nl (Johan Vromans)
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 13, Issue 51
  7. Submitted-by: jv@mh.nl (Johan Vromans)
  8. Archive-name: forms.el/part03
  9.  
  10. ---- Cut Here and unpack ----
  11. #!/bin/sh
  12. # this is forms.03 (part 3 of a multipart archive)
  13. # do not concatenate these parts, unpack them in order with /bin/sh
  14. # file forms.ti continued
  15. #
  16. if touch 2>&1 | fgrep '[-amc]' > /dev/null
  17.  then TOUCH=touch
  18.  else TOUCH=true
  19. fi
  20. if test ! -r shar3_seq_.tmp; then
  21.     echo "Please unpack part 1 first!"
  22.     exit 1
  23. fi
  24. (read Scheck
  25.  if test "$Scheck" != 3; then
  26.     echo "Please unpack part $Scheck next!"
  27.     exit 1
  28.  else
  29.     exit 0
  30.  fi
  31. ) < shar3_seq_.tmp || exit 1
  32. echo "x - Continuing file forms.ti"
  33. sed 's/^X//' << 'SHAR_EOF' >> forms.ti &&
  34. Xeach of which can be either a @code{string} or a @code{number}. The
  35. Xformatting elements are processed in the order they appear in the list.
  36. X
  37. XA @code{string} formatting element is inserted in the forms ``as is''.
  38. X
  39. XA @code{number} element selects a field of the record. The contents of
  40. Xthis field are inserted. The first field of the record has number 1
  41. X(one).
  42. X
  43. XIf a record does not contain the number of fields as specified in
  44. X@code{forms-number-of-fields}, a warning message will be printed. Excess
  45. Xfields are ignored, missing fields are set to empty.
  46. X
  47. XThe control file which shows your @file{/etc/passwd} file as demonstrated
  48. Xin the beginning of this document looks as follows:
  49. X@example
  50. X;; This demo visits /etc/passwd.
  51. X
  52. X(setq forms-file "/etc/passwd")
  53. X(setq forms-number-of-fields 7)
  54. X(setq forms-read-only t)                 ; to make sure
  55. X(setq forms-field-sep ":")
  56. X(setq forms-multi-line nil)              ; not allowed
  57. X
  58. X(setq forms-format-list
  59. X     '("====== /etc/passwd ======\n\n"
  60. X       "User : "    1
  61. X       "   Uid: "   3
  62. X       "   Gid: "   4
  63. X       "\n\n"
  64. X       "Name : "    5
  65. X       "\n\n"
  66. X       "Home : "    6
  67. X       "\n\n"
  68. X       "Shell: "    7
  69. X       "\n"))
  70. X@end example
  71. X
  72. XUpon startup, the contents of @code{forms-format-list} are
  73. Xvalidated. If errors are encountered, processing is aborted with 
  74. Xan error message which includes a descriptive text. @xref{Error
  75. XMessages}, for a detailed list of error messages.
  76. X
  77. X@node Modifying Forms Contents, Forms Mode Commands, Forms Format Description, Top
  78. X@section Modifying The Forms Contents
  79. X
  80. XIf a forms is not read-only, it's contents can be modified.
  81. X
  82. XAll normal editor commands may be used to change the forms. There is no
  83. Xdistinction between the ``fixed'' text and the text from the fields of
  84. Xthe records. However, upon completion, the forms is parsed to extract
  85. Xthe new contents of the fields. The ``fixed'' portions of the forms are
  86. Xused to delimit the fields, these portions should therefore not be
  87. Xmodified to avoid the risk that the field contents cannot be determined.
  88. XMoreover, ambiguous field contents, which can not be discriminated from
  89. X``fixed'' text, must be avoided.
  90. X
  91. XIf the contents of the forms cannot be recognized properly, this is
  92. Xsignaled using a descriptive text. @xref{Error Messages}, for more info.
  93. XThe cursor will indicate the last part of the forms which was
  94. Xsuccessfully parsed.
  95. X
  96. X@node Forms Mode Commands, Key Bindings, Modifying Forms Contents, Top
  97. X@section Forms mode commands
  98. X
  99. X@table @kbd
  100. X@findex forms-find-file
  101. X@item M-x forms-find-file @var{file}
  102. X@end table
  103. X
  104. XVisits @var{file}, runs @code{eval-current-buffer} on it, and puts the
  105. Xbuffer into forms-mode. The first record of the data file will be loaded
  106. Xand shown.
  107. X
  108. XThe modeline will display the major mode @code{"Forms"} followed by the
  109. Xminor mode @code{"View"} if the file is visited read-only.  The number
  110. Xof the current record (@var{n}) and the total number of records
  111. X(@var{t}) in the file is shown in the modeline as @code{"n/t"}.@*
  112. XFor example:
  113. X@example
  114. X--%%-Emacs: passwd-demo          (Forms View 1/54)----All-------
  115. X@end example
  116. X
  117. X@table @kbd
  118. X@findex forms-find-file-other-window
  119. X@item M-x forms-find-file-other-window @var{file}
  120. X@end table
  121. X
  122. XThis command is similar to @code{forms-find-file}, but visits the file
  123. Xin another window.
  124. X
  125. XIf the buffer is not read-only, you may change the buffer to modify the
  126. Xfields in the record. When the current record is left, e.g. by switching
  127. Xto another record, the contents of the buffer are parsed using the
  128. Xspecifications in @code{forms-format-list}, and a new record is constructed
  129. Xwhich replaces the current record in the data file. Fields of the record
  130. Xwhich are not shown in the forms are not modified; they retain their
  131. Xoriginal contents.
  132. X
  133. XMost forms mode commands are bound to keys, and are accessible with the
  134. Xconventional @code{C-c} prefix. In read-only mode this prefix is not used.
  135. X@xref{Key Bindings}, for the default key bindigs used by forms mode.
  136. X
  137. XThe following commands are available within forms mode.
  138. X
  139. X@table @kbd
  140. X@findex forms-next-record
  141. X@item forms-next-record
  142. Xshows the next record. With a prefix argument, show the n-th next
  143. Xrecord.
  144. X
  145. X@findex forms-prev-record
  146. X@item forms-prev-record
  147. Xshows the previous record. With a prefix argument, show the n-th previous
  148. Xrecord.
  149. X
  150. X@findex forms-jump-record
  151. X@item forms-jump-record
  152. Xjumps to a record by number. A prefix argument is used for the record
  153. Xnumber to jump to. If no prefix argument is supplied, a record number is
  154. Xasked for in the minibuffer.@*
  155. XIf an invalid record number is supplied, an error message is displayed
  156. Xreading the offending record number, and the allowable range of numbers.
  157. X
  158. X@findex forms-first-record
  159. X@item forms-first-record
  160. Xjumps to the first record.
  161. X
  162. X@findex forms-last-record
  163. X@item forms-last-record
  164. Xjumps to the last record. Also re-counts the number of records in the data
  165. Xfile.
  166. X
  167. X@findex forms-next-field
  168. X@item forms-next-field
  169. Xjumps to the next field in the forms. With a numeric argument: jumps
  170. Xthat many fields, or to the first field if there are not that many
  171. Xfields left.
  172. X
  173. XJumping to fields is implemented using @var{markers}, which are placed
  174. Xin front of the fields. If the contents of the forms are modified, the
  175. Xmarkers are adjusted. However, if text around a marker has been deleted
  176. Xfrom the screen and inserted again it is possible that this marker no
  177. Xlonger points at its field correctly.
  178. X@xref{Markers,,Markers, emacs, the GNU Emacs Lisp Manual}, for more
  179. Xinformation on markers.
  180. X
  181. X@findex forms-view-mode
  182. X@item forms-view-mode
  183. Xswitches to read-only mode. Forms mode commands may no longer be prefixed
  184. Xwith @code{C-c}.
  185. X
  186. X@findex forms-edit-mode
  187. X@item forms-edit-mode
  188. Xswitches to edit mode. Forms mode commands must be prefixed with
  189. X@code{C-c}.@*
  190. XSwitching to edit mode is only possible if write access to the data
  191. Xfile is allowed.
  192. X
  193. X@findex forms-insert-record
  194. X@item forms-insert-record
  195. Xcreate a new record, which is inserted before the current record. An
  196. Xempty form is presented, which can be filled in using familiar editor
  197. Xcommands. With a prefix argument: the new record is created @i{after} the
  198. Xcurrent one.
  199. X
  200. X@findex forms-delete-record
  201. X@item forms-delete-record
  202. Xdeletes the current record. You are prompted for confirmation before the
  203. Xrecord is deleted unless a prefix argument has been provided.
  204. X
  205. X@findex forms-search
  206. X@item forms-search @var{regexp}
  207. Xsearches for @var{regexp} in all records following this one. If found,
  208. Xthis record is shown.@*
  209. XThe next time it is invoked, the previous regexp is the default, so you
  210. Xcan do repeated searches by simply pressing @key{RET} in response to the
  211. Xprompt.
  212. X
  213. X@findex revert-buffer
  214. X@item revert-buffer
  215. Xreverts a possibly modified forms to its original state. It only affect
  216. Xthe record currently in the forms.
  217. X
  218. X@findex forms-exit
  219. X@item forms-exit
  220. Xterminates forms processing. The data file is saved
  221. Xif it has been modified.
  222. X
  223. X@findex forms-exit-no-save
  224. X@item forms-exit-no-save
  225. Xaborts forms processing. If the data file has been modified Emacs will
  226. Xask questions.
  227. X
  228. X@findex describe-mode
  229. X@item describe-mode
  230. Xgives additional help.
  231. X
  232. X@findex save-buffer
  233. X@item save-buffer
  234. Xsaves the changes in the data file, if modified.
  235. X
  236. X@end table
  237. X
  238. X@vindex forms-forms-scroll
  239. X@findex scroll-up
  240. X@findex scroll-down
  241. XIf the variable @code{forms-forms-scrolls} is set to a value other
  242. Xthan @code{nil} (which it is, by default), the Emacs functions
  243. X@code{scroll-up} and @code{scroll-down} will perform a
  244. X@code{forms-next-record} and @code{forms-prev-record} when in forms
  245. Xmode.  So you can use your favourite page commands to page through the
  246. Xdata file.
  247. X
  248. X@vindex forms-forms-jump
  249. X@findex beginning-of-buffer
  250. X@findex end-of-buffer
  251. XLikewise, if the variable @code{forms-forms-jump} is not @code{nil}
  252. X(which it is, by default), Emacs functions @code{beginning-of-buffer}
  253. Xand @code{end-of-buffer} will perform @code{forms-first-record} and
  254. X@code{forms-last-record} when in forms mode.
  255. X
  256. X@vindex forms-mode-hooks
  257. XAfter forms mode is entered, functions contained in
  258. X@code{forms-mode-hooks} are executed to perform user defined customization.
  259. X
  260. X@node Key Bindings, Miscellaneous, Forms Mode Commands, Top
  261. X@section Key bindings
  262. X
  263. XThis section describes the key bindings as they are defined when
  264. Xinvoking forms mode.@*
  265. XAll commands must be prefixed with @kbd{C-c} when editing a forms. If a
  266. Xforms is read-only, @kbd{C-c} is not used.  The only exception to
  267. Xthis rule is @code{forms-next-field}, which is bound to @kbd{TAB} in all
  268. Xmaps.
  269. X
  270. X@table @kbd
  271. X
  272. X@itemx C-c @key{TAB}
  273. X@code{forms-next-field}
  274. X
  275. X@itemx C-c @key{SPC}
  276. X@code{forms-next-record}
  277. X
  278. X@itemx C-c <
  279. X@code{forms-first-record}
  280. X
  281. X@itemx C-c >
  282. X@code{forms-first-record}
  283. X
  284. Xv@itemx C-c d
  285. X@code{forms-delete-record}
  286. X
  287. X@itemx C-c e
  288. X@code{forms-edit-mode}
  289. X
  290. X@itemx C-c i
  291. X@code{forms-insert-record}
  292. X
  293. X@itemx C-c j
  294. X@code{forms-jump-record}
  295. X
  296. X@itemx C-c n
  297. X@code{forms-next-record}
  298. X
  299. X@itemx C-c p
  300. X@code{forms-prev-record}
  301. X
  302. X@itemx C-c q
  303. X@code{forms-exit}
  304. X
  305. X@itemx C-c s @var{regexp} 
  306. X@code{forms-search}
  307. X
  308. X@itemx C-c v
  309. X@code{forms-view-mode}
  310. X
  311. X@itemx C-c x
  312. X@code{forms-exit-no-save}
  313. X
  314. X@itemx C-c ?
  315. X@code{describe-mode}
  316. X
  317. X@itemx C-c @key{DEL}
  318. X@code{forms-prev-record}
  319. X
  320. X@end table
  321. X
  322. X@node Miscellaneous, Error Messages, Key Bindings, Top
  323. X@section Miscellaneous
  324. X
  325. X@vindex forms-version
  326. XA global variable @var{forms-version} holds the version information of
  327. Xthe current implementation of forms mode.
  328. X
  329. XCare has been taken to localize the current information of the forms
  330. Xmode, so it is possible to visit multiple files in forms mode
  331. Xsimultaneously, even if they have different properties.
  332. X
  333. XIf a control file is visited using the standard @code{find-file}
  334. Xcommands, forms mode can be enabled with the command @code{M-x forms-mode}.@*
  335. XForms mode will be automatically enabled if the file contains
  336. Xthe string @code{"-*- forms -*-"} somewhere in the first line. However,
  337. Xthis makes it hard to edit the control file itself so you'd better think
  338. Xtwice before using this.
  339. X
  340. XThe default format for the data file, using @key{TAB} to separate fields
  341. Xand @code{C-k} to separate multi-line fields, matches the file format of
  342. Xsome popular Macintosh database programs, e.g. FileMaker. So
  343. X@code{forms-mode} could decrease the need to use Apple computers.
  344. X
  345. X@node Error Messages, Credits, Miscellaneous, Top
  346. X@section Error Messages
  347. X
  348. XThis section describes all error messages which can be generated by
  349. Xforms mode.
  350. X
  351. X@table @code
  352. X@item 'forms-file' has not been set
  353. XThe variable @code{forms-file} was not set by the control file.
  354. X
  355. X@item 'forms-number-of-fields' has not been set
  356. XThe variable @code{forms-number-of-fields} was not set by the control
  357. Xfile.
  358. X
  359. X@item 'forms-number-of-fields' must be > 0
  360. XThe variable @code{forms-number-of-fields} did not contain a positive
  361. Xnumber. 
  362. X
  363. X@item 'forms-field-sep' is not a string
  364. X@itemx 'forms-multi-line' must be nil or a one-character string
  365. XThe variable @code{forms-multe-line} was set to something other than
  366. X@code{nil or} a single-character string.
  367. X
  368. X@item 'forms-multi-line' is equal to 'forms-field-sep'
  369. XThe variable @code{forms-multi-line} may not be equal to
  370. X@code{forms-field-sep} for this would make it impossible to distinguish
  371. Xfields and the lines in the fields.
  372. X
  373. X@item 'forms-format-list' has not been set
  374. X@itemx 'forms-format-list' is not a list
  375. XThe variable @code{forms-format-list} was not set to a lisp @code{list}
  376. Xby the control file.
  377. X
  378. X@item forms error: field number @var{XX} out of range 1..@var{NN}
  379. XA field number was supplied with a value of @var{XX}, which was not
  380. Xgreater that zero and smaller than or equal to the number of fields in the
  381. Xforms, @var{NN}.
  382. X
  383. X@item invalid element in 'forms-format-list': @var{XX}
  384. XA list element was supplied in @var{forms-format-list} which was not a
  385. X@code{string} nor a @code{number}.
  386. X
  387. X@item forms--make-format failed at @var{XX} [of @var{YY}]
  388. XAn internal error caused the generation of the format routine to fail.
  389. X
  390. X@item parse error: not looking at "@var{TEXT}"
  391. XWhen re-parsing the contents of a forms, the text @var{TEXT}, which
  392. Xstarts the forms, could not be found.
  393. X
  394. X@item parse error: cannot find "@var{TEXT}"
  395. XWhen re-parsing the contents of a forms, the text @var{TEXT}, which
  396. Xseparates two fields, could not be found.
  397. X
  398. X@item parse error: cannot parse adjacent fields @var{XX} and @var{YY}
  399. XFields @var{XX} and @var{YY} were not separated by text, so could not be
  400. Xparsed again.
  401. X
  402. X@item forms--make-parser failed - field @var{XX} pending
  403. X@itemx forms--make-parser failed - text @var{TEXT} pending
  404. X@itemx forms--make-parser failed at @var{XX} [of @var{YY}]
  405. XAn internal error caused the generation of the format routine to fail.
  406. X
  407. X@item Record has @var{XX} fields instead of @var{YY}
  408. XThe number of fields in this record in the data file did not match
  409. X@code{forms-number-of-fields}. Missing fields will be set to empty.
  410. X
  411. X@item Multi-line fields in this record - update refused!
  412. XThe current record contains newline characters, hance can not be written
  413. Xback to the data file, for it would corrupt it.@*
  414. Xprobably a field was set to a multi-line value, while the setting of
  415. X@code{forms-multi-line} prohibited this.
  416. X
  417. X@item Record number @var{XX} out of range 1..@var{YY}
  418. XA jump was made to non-existing record @var{XX}. @var{YY} denotes the
  419. Xnumber of records in the file.
  420. X
  421. X@item Stuck at record @var{XX}
  422. XAn internal error prevented a specific record from being retrieved.
  423. X
  424. X@end table
  425. X
  426. X@node Credits, Concept Index, Error Messages, Top
  427. X@section Credits
  428. X
  429. XForms mode is developed by Johan Vromans @code{<jv@@mh.nl>} at Multihouse
  430. XReseach in Gouda, the Netherlands. 
  431. X
  432. XThis documentation was slightly inspired by the documentation of ``rolo
  433. Xmode'' by Paul Davis at Schlumberger Cambridge Research
  434. X@code{<davis%scrsu1%sdr.slb.com@@relay.cs.net>}.
  435. X
  436. XNone of this would have been possible without GNU Emacs of the Free
  437. XSoftware Foundation. Thanks, Richard!
  438. X
  439. X@node Concept Index, Variable Index, Credits, Top
  440. X@unnumbered Concept Index
  441. X@printindex cp
  442. X
  443. X@node Variable Index, Function Index, Concept Index, Top
  444. X@unnumbered Variable Index
  445. X@printindex vr
  446. X
  447. X@node Function Index, , Variable Index, Top
  448. X@unnumbered Function Index
  449. X@printindex fn
  450. X
  451. X@contents
  452. X@bye
  453. SHAR_EOF
  454. echo "File forms.ti is complete" &&
  455. $TOUCH -am 0610122090 forms.ti &&
  456. chmod 0444 forms.ti ||
  457. echo "restore of forms.ti failed"
  458. set `wc -c forms.ti`;Wc_c=$1
  459. if test "$Wc_c" != "21254"; then
  460.     echo original size 21254, current size $Wc_c
  461. fi
  462. # ============= demo1 ==============
  463. echo "x - extracting demo1 (Text)"
  464. sed 's/^X//' << 'SHAR_EOF' > demo1 &&
  465. X;; demo for forms-mode
  466. X;;
  467. X;; This demo visits /etc/passwd.
  468. X
  469. X(setq forms-file "/etc/passwd")
  470. X(setq forms-read-only t)        ; to make sure
  471. X(setq forms-field-sep ":")
  472. X(setq forms-number-of-fields 7)
  473. X(setq forms-format-list
  474. X     '("====== Visiting /etc/passwd ======\n\n"
  475. X       "User : "    1
  476. X       "   Uid: "    3
  477. X       "   Gid: "    4
  478. X       "\n\n"
  479. X       "Name : "    5
  480. X       "\n\n"
  481. X       "Home : "    6
  482. X       "\n\n"
  483. X       "Shell: "    7
  484. X       "\n"))
  485. SHAR_EOF
  486. $TOUCH -am 0307144790 demo1 &&
  487. chmod 0644 demo1 ||
  488. echo "restore of demo1 failed"
  489. set `wc -c demo1`;Wc_c=$1
  490. if test "$Wc_c" != "436"; then
  491.     echo original size 436, current size $Wc_c
  492. fi
  493. # ============= demo2 ==============
  494. echo "x - extracting demo2 (Text)"
  495. sed 's/^X//' << 'SHAR_EOF' > demo2 &&
  496. X;; test forms-mode    -*- emacs-lisp -*-
  497. X;;
  498. X(setq forms-file "demo2.dat")
  499. X(setq forms-number-of-fields 11)
  500. X(setq forms-format-list
  501. X     '(
  502. X       "====== Public Domain Software Archive ======\n\n"    5
  503. X       " - "            8
  504. X       "\n\n"
  505. X       "Article: "        1
  506. X       "/"            4
  507. X       "    Issue: "        3
  508. X       "    Date: "        10
  509. X       "\n\n"
  510. X       "Submitted by: "        7
  511. X       "\n\n"
  512. X       "Keywords: "        9
  513. X       "\n\n"
  514. X       "Parts: "        6
  515. X       "\n\n====== Remarks ======\n\n"        11
  516. X     ))
  517. SHAR_EOF
  518. $TOUCH -am 0307144790 demo2 &&
  519. chmod 0644 demo2 ||
  520. echo "restore of demo2 failed"
  521. set `wc -c demo2`;Wc_c=$1
  522. if test "$Wc_c" != "475"; then
  523.     echo original size 475, current size $Wc_c
  524. fi
  525. # ============= demo2.dat ==============
  526. echo "x - extracting demo2.dat (Text)"
  527. sed 's/^X//' << 'SHAR_EOF' > demo2.dat &&
  528. Xcomp.sources.unix        v11i008    269    getty-enable    1    tron@sc.nsc.com (Ronald S. Karr)    Getty on/off programs for 4.[23] BSD        890505    
  529. Xcomp.sources.unix    11    v11i022    283    syslog    1    emory!arnold (Arnold D. Robbins {EUCC})    Development version of syslog(3), for ATT, too        28/08/1987    
  530. Xcomp.sources.unix    11    v11i033    290    less3    3    sun!intsc!convgt!mark    The 'less' pager        02/09/1987    
  531. Xcomp.sources.unix    11    v11i036    293    test.el    3    "Mark A. Ardis" <maa@sei.cmu.edu>    Test system for GNU Emacs        10/09/1987    
  532. SHAR_EOF
  533. $TOUCH -am 0307144790 demo2.dat &&
  534. chmod 0644 demo2.dat ||
  535. echo "restore of demo2.dat failed"
  536. set `wc -c demo2.dat`;Wc_c=$1
  537. if test "$Wc_c" != "476"; then
  538.     echo original size 476, current size $Wc_c
  539. fi
  540. rm -f shar3_seq_.tmp
  541. echo "You have unpacked the last part"
  542. exit 0
  543.  
  544.