forms-d2.el 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. ;;; forms-d2.el --- demo forms-mode
  2. ;; Copyright (C) 1991, 1994-1997, 2001-2015 Free Software Foundation,
  3. ;; Inc.
  4. ;; Author: Johan Vromans <jvromans@squirrel.nl>
  5. ;; Created: 1989
  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. ;; This sample forms exploit most of the features of forms mode.
  19. ;;; Code:
  20. ;; Set the name of the data file.
  21. (setq forms-file (expand-file-name "forms/forms-d2.dat" data-directory))
  22. ;; Use 'forms-enumerate' to set field names and number thereof.
  23. (setq forms-number-of-fields
  24. (forms-enumerate
  25. '(arch-newsgroup ; 1
  26. arch-volume ; 2
  27. arch-issue ; and ...
  28. arch-article ; ... so
  29. arch-shortname ; ... ... on
  30. arch-parts
  31. arch-from
  32. arch-longname
  33. arch-keywords
  34. arch-date
  35. arch-remarks)))
  36. ;; The following functions are used by this form for layout purposes.
  37. ;;
  38. (defun arch-tocol (target &optional fill)
  39. "Produces a string to skip to column TARGET. Prepends newline if needed.
  40. The optional FILL should be a character, used to fill to the column."
  41. (if (null fill)
  42. (setq fill ?\s))
  43. (if (< target (current-column))
  44. (concat "\n" (make-string target fill))
  45. (make-string (- target (current-column)) fill)))
  46. ;;
  47. (defun arch-rj (target field &optional fill)
  48. "Produces a string to skip to column TARGET minus the width of field FIELD.
  49. Prepends newline if needed. The optional FILL should be a character,
  50. used to fill to the column."
  51. (arch-tocol (- target (length (nth field forms-fields))) fill))
  52. ;; Record filters.
  53. ;;
  54. (defun arch-new-record-filter (the-record)
  55. "Form a new record with some defaults."
  56. (aset the-record arch-from (user-full-name))
  57. (aset the-record arch-date (current-time-string))
  58. the-record ; return it
  59. )
  60. (setq forms-new-record-filter 'arch-new-record-filter)
  61. ;; The format list.
  62. (setq forms-format-list
  63. (list
  64. "====== Public Domain Software Archive ======\n\n"
  65. arch-shortname
  66. " - " arch-longname
  67. "\n\n"
  68. "Article: " arch-newsgroup
  69. "/" arch-article
  70. " "
  71. '(arch-tocol 40)
  72. "Issue: " arch-issue
  73. " "
  74. '(arch-rj 73 10)
  75. "Date: " arch-date
  76. "\n\n"
  77. "Submitted by: " arch-from
  78. "\n"
  79. '(arch-tocol 79 ?-)
  80. "\n"
  81. "Keywords: " arch-keywords
  82. "\n\n"
  83. "Parts: " arch-parts
  84. "\n\n====== Remarks ======\n\n"
  85. arch-remarks
  86. ))
  87. ;; That's all, folks!
  88. ;;; forms-d2.el ends here