From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/elisp/repeated-loading.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 devdocs/elisp/repeated-loading.html (limited to 'devdocs/elisp/repeated-loading.html') diff --git a/devdocs/elisp/repeated-loading.html b/devdocs/elisp/repeated-loading.html new file mode 100644 index 00000000..058db545 --- /dev/null +++ b/devdocs/elisp/repeated-loading.html @@ -0,0 +1,16 @@ +

Repeated Loading

You can load a given file more than once in an Emacs session. For example, after you have rewritten and reinstalled a function definition by editing it in a buffer, you may wish to return to the original version; you can do this by reloading the file it came from.

When you load or reload files, bear in mind that the load and load-library functions automatically load a byte-compiled file rather than a non-compiled file of similar name. If you rewrite a file that you intend to save and reinstall, you need to byte-compile the new version; otherwise Emacs will load the older, byte-compiled file instead of your newer, non-compiled file! If that happens, the message displayed when loading the file includes, ‘(compiled; note, source is newer)’, to remind you to recompile it.

When writing the forms in a Lisp library file, keep in mind that the file might be loaded more than once. For example, think about whether each variable should be reinitialized when you reload the library; defvar does not change the value if the variable is already initialized. (See Defining Variables.)

The simplest way to add an element to an alist is like this:

(push '(leif-mode " Leif") minor-mode-alist)
+
+

But this would add multiple elements if the library is reloaded. To avoid the problem, use add-to-list (see List Variables):

(add-to-list 'minor-mode-alist '(leif-mode " Leif"))
+
+

Occasionally you will want to test explicitly whether a library has already been loaded. If the library uses provide to provide a named feature, you can use featurep earlier in the file to test whether the provide call has been executed before (see Named Features). Alternatively, you could use something like this:

(defvar foo-was-loaded nil)
+
+(unless foo-was-loaded
+  execute-first-time-only
+  (setq foo-was-loaded t))
+
+
+

+ Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc.
Licensed under the GNU GPL license.
+ https://www.gnu.org/software/emacs/manual/html_node/elisp/Repeated-Loading.html +

+
-- cgit v1.2.3