forms-d2.el 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ;;; forms-d2.el --- demo forms-mode -*- no-byte-compile: t -*-
  2. ;; Copyright (C) 1991, 1994-1997, 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: Johan Vromans <jvromans@squirrel.nl>
  4. ;; Created: 1989
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; This sample forms exploit most of the features of forms mode.
  18. ;;; Code:
  19. ;; Set the name of the data file.
  20. (setq forms-file (expand-file-name "forms-d2.dat" data-directory))
  21. ;; Use 'forms-enumerate' to set field names and number thereof.
  22. (setq forms-number-of-fields
  23. (forms-enumerate
  24. '(arch-newsgroup ; 1
  25. arch-volume ; 2
  26. arch-issue ; and ...
  27. arch-article ; ... so
  28. arch-shortname ; ... ... on
  29. arch-parts
  30. arch-from
  31. arch-longname
  32. arch-keywords
  33. arch-date
  34. arch-remarks)))
  35. ;; The following functions are used by this form for layout purposes.
  36. ;;
  37. (defun arch-tocol (target &optional fill)
  38. "Produces a string to skip to column TARGET. Prepends newline if needed.
  39. The optional FILL should be a character, used to fill to the column."
  40. (if (null fill)
  41. (setq fill ?\s))
  42. (if (< target (current-column))
  43. (concat "\n" (make-string target fill))
  44. (make-string (- target (current-column)) fill)))
  45. ;;
  46. (defun arch-rj (target field &optional fill)
  47. "Produces a string to skip to column TARGET minus the width of field FIELD.
  48. Prepends newline if needed. The optional FILL should be a character,
  49. used to fill to the column."
  50. (arch-tocol (- target (length (nth field forms-fields))) fill))
  51. ;; Record filters.
  52. ;;
  53. (defun arch-new-record-filter (the-record)
  54. "Form a new record with some defaults."
  55. (aset the-record arch-from (user-full-name))
  56. (aset the-record arch-date (current-time-string))
  57. the-record ; return it
  58. )
  59. (setq forms-new-record-filter 'arch-new-record-filter)
  60. ;; The format list.
  61. (setq forms-format-list
  62. (list
  63. "====== Public Domain Software Archive ======\n\n"
  64. arch-shortname
  65. " - " arch-longname
  66. "\n\n"
  67. "Article: " arch-newsgroup
  68. "/" arch-article
  69. " "
  70. '(arch-tocol 40)
  71. "Issue: " arch-issue
  72. " "
  73. '(arch-rj 73 10)
  74. "Date: " arch-date
  75. "\n\n"
  76. "Submitted by: " arch-from
  77. "\n"
  78. '(arch-tocol 79 ?-)
  79. "\n"
  80. "Keywords: " arch-keywords
  81. "\n\n"
  82. "Parts: " arch-parts
  83. "\n\n====== Remarks ======\n\n"
  84. arch-remarks
  85. ))
  86. ;; That's all, folks!
  87. ;;; forms-d2.el ends here