summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/generate-lisp-file.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-06-05 17:48:29 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-06-05 17:48:39 +0200
commit98d454627ca2e9a6cdb906895b044e7221db3f2f (patch)
treef264b97e754941b55a9bfa6b65c330e46fecfe42 /lisp/emacs-lisp/generate-lisp-file.el
parente8a941cf705f26cf9571e1eba4d23bbc63a056e4 (diff)
downloademacs-98d454627ca2e9a6cdb906895b044e7221db3f2f.tar.gz
Rename generate-file to generate-lisp-file
* lisp/url/url-cookie.el (url-cookie-write-file): * lisp/international/titdic-cnv.el (tit-process-header) (miscdic-convert): * lisp/international/ja-dic-cnv.el (skkdic-convert): * lisp/international/emoji.el (emoji--generate-file): * lisp/emacs-lisp/loaddefs-gen.el (loaddefs-generate--rubric): * admin/unidata/unidata-gen.el (unidata-gen-file) (unidata-gen-charprop): Adjust callers. * lisp/emacs-lisp/generate-lisp-file.el: Renamed from generate-file.el. Also rename some keyword parameters and require a generator function.
Diffstat (limited to 'lisp/emacs-lisp/generate-lisp-file.el')
-rw-r--r--lisp/emacs-lisp/generate-lisp-file.el113
1 files changed, 113 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/generate-lisp-file.el b/lisp/emacs-lisp/generate-lisp-file.el
new file mode 100644
index 00000000000..8896a3f7019
--- /dev/null
+++ b/lisp/emacs-lisp/generate-lisp-file.el
@@ -0,0 +1,113 @@
+;;; generate-lisp-file.el --- utility functions for generated files -*- lexical-binding: t -*-
+
+;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+;; Keywords: maint
+;; Package: emacs
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(eval-when-compile (require 'cl-lib))
+
+(cl-defun generate-lisp-file-heading (file generator
+ &key title commentary (code t))
+ "Insert a standard header for FILE created by GENERATOR.
+This header will specify that this is a generated file that
+should not be edited.
+
+If `standard-output' is bound to a buffer, insert in that buffer.
+If no, insert at point in the current buffer.
+
+TITLE (if any) will be used in the first line.
+
+COMMENTARY (if given) will be inserted as a comment.
+
+If CODE is non-nil (which is the default), a Code: line is
+inserted."
+ (with-current-buffer (if (bufferp standard-output)
+ standard-output
+ (current-buffer))
+ (insert ";;; " (file-name-nondirectory file)
+ " --- "
+ (or title "automatically generated")
+ " (do not edit) "
+ " -*- lexical-binding: t -*-\n"
+ (format ";; Generated by the `%s' function.\n\n" generator)
+ ";; This file is part of GNU Emacs.\n\n")
+ (when commentary
+ (insert ";;; Commentary:\n\n")
+ (let ((start (point))
+ (fill-prefix ";; "))
+ (insert ";; " commentary)
+ (fill-region start (point))))
+ (ensure-empty-lines 1)
+ (when code
+ (insert ";;; Code:\n\n"))))
+
+(cl-defun generate-lisp-file-trailer (file &key version inhibit-provide
+ (coding 'utf-8-emacs-unix) autoloads
+ compile provide)
+ "Insert a standard trailer for FILE.
+By default, this trailer inhibits version control, byte
+compilation, updating autoloads, and uses a `utf-8-emacs-unix'
+coding system. These can be inhibited by providing non-nil
+values to the VERSION, NO-PROVIDE, AUTOLOADS and COMPILE
+keyword arguments.
+
+CODING defaults to `utf-8-emacs-unix'. Use a nil value to
+inhibit generating this setting, or a coding system value to use
+that.
+
+If PROVIDE is non-nil, use that in the `provide' statement
+instead of using FILE as the basis.
+
+If `standard-output' is bound to a buffer, insert in that buffer.
+If no, insert at point in the current buffer."
+ (with-current-buffer (if (bufferp standard-output)
+ standard-output
+ (current-buffer))
+ (ensure-empty-lines 1)
+ (unless inhibit-provide
+ (insert (format "(provide '%s)\n\n"
+ (or provide
+ (file-name-sans-extension
+ (file-name-nondirectory file))))))
+ ;; Some of the strings below are chopped into bits to inhibit
+ ;; automatic scanning tools from thinking that they are actual
+ ;; directives.
+ (insert ";; Local " "Variables:\n")
+ (unless version
+ (insert ";; version-control: never\n"))
+ (unless compile
+ (insert ";; no-byte-" "compile: t\n")) ;; #$ is byte-compiled into nil.
+ (unless autoloads
+ (insert ";; no-update-autoloads: t\n"))
+ (when coding
+ (insert (format ";; coding: %s\n"
+ (if (eq coding t)
+ 'utf-8-emacs-unix
+ coding))))
+ (insert
+ ";; End:\n\n"
+ ";;; " (file-name-nondirectory file) " ends here\n")))
+
+(provide 'generate-lisp-file)
+
+;;; generate-lisp-file.el ends here