unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* after-load-hook
@ 2009-09-11 20:53 Juanma Barranquero
  2009-09-12  4:16 ` after-load-hook Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Juanma Barranquero @ 2009-09-11 20:53 UTC (permalink / raw)
  To: Emacs developers

In the thread for bug#4287 I proposed adding an after-load-hook hook
to `load' (obviously :-).

Stefan said:

> We could replace the call from C to do-after-load-evaluation by
> Frun_hooks(Qafter-load-functions), either passing it the file name
> explicitly or making sure load-file-name is still set.

The following patch adds `after-load-hook'.

Comments:

 - It is not `after-load-functions', because it is a normal hook
(though `load-file-name' is set when the hook runs).
 - I haven't touched do-after-load-evaluation because I don't
understand what Stefan means by "replace" in this case.
 - No NEWS or info yet.

    Juanma



2009-09-11  Juanma Barranquero  <lekktu@gmail.com>

	* lread.c (Qafter_load_hook): New constant.
	(Fload): Run hook.
	(syms_of_lread): Intern and staticpro Qafter_load_hook.

2009-09-11  Juanma Barranquero  <lekktu@gmail.com>

	* subr.el (after-load-hook): New variable.
	* international/mule.el (load-with-code-conversion):
	Run `after-load-hook'.




Index: src/lread.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/lread.c,v
retrieving revision 1.412
diff -u -2 -r1.412 lread.c
--- src/lread.c	5 Sep 2009 00:45:08 -0000	1.412
+++ src/lread.c	11 Sep 2009 20:09:18 -0000
@@ -96,4 +96,5 @@
 Lisp_Object Qeval_buffer_list, Veval_buffer_list;
 Lisp_Object Qfile_truename, Qdo_after_load_evaluation; /* ACM 2006/5/16 */
+Lisp_Object Qafter_load_hook;

 /* Used instead of Qget_file_char while loading *.elc files compiled
@@ -1277,4 +1278,8 @@
 		    0, Qnil, Qnil, Qnil, Qnil);
     }
+
+  /* Run hook while Qload_file_name is non-nil */
+  Frun_hooks (1, &Qafter_load_hook);
+
   unbind_to (count, Qnil);

@@ -4525,4 +4530,7 @@
   staticpro (&Qdo_after_load_evaluation) ;

+  Qafter_load_hook = intern ("after-load-hook");
+  staticpro (&Qafter_load_hook);
+
   staticpro (&dump_path);

Index: lisp/subr.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/subr.el,v
retrieving revision 1.650
diff -u -2 -r1.650 subr.el
--- lisp/subr.el	10 Sep 2009 18:19:06 -0000	1.650
+++ lisp/subr.el	11 Sep 2009 20:06:57 -0000
@@ -2277,4 +2277,9 @@
 mode.")

+(defvar after-load-hook nil
+  "Normal hook run by `load' after loading a file.
+When the hook runs, `load-file-name' contains the full name
+of the file just loaded.")
+
 ;; Avoid compiler warnings about this variable,
 ;; which has a special meaning on certain system types.
Index: lisp/international/mule.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/international/mule.el,v
retrieving revision 1.289
diff -u -2 -r1.289 mule.el
--- lisp/international/mule.el	3 Sep 2009 06:43:33 -0000	1.289
+++ lisp/international/mule.el	11 Sep 2009 20:06:57 -0000
@@ -354,4 +354,6 @@
 	(let (kill-buffer-hook kill-buffer-query-functions)
 	  (kill-buffer buffer)))
+
+      (run-hooks 'after-load-hook)
       (unless purify-flag
  	(do-after-load-evaluation fullname))




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: after-load-hook
  2009-09-11 20:53 after-load-hook Juanma Barranquero
@ 2009-09-12  4:16 ` Stefan Monnier
  2009-09-12 11:19   ` after-load-hook Juanma Barranquero
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2009-09-12  4:16 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Emacs developers

> In the thread for bug#4287 I proposed adding an after-load-hook hook
> to `load' (obviously :-).

Funny, I just wrote the following patch earlier today.


        Stefan


Index: lisp/subr.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/subr.el,v
retrieving revision 1.652
diff -u -r1.652 subr.el
--- lisp/subr.el	12 Sep 2009 03:55:50 -0000	1.652
+++ lisp/subr.el	12 Sep 2009 04:13:28 -0000
@@ -1670,6 +1674,11 @@
 	  (featurep file))
 	(eval form))))
 
+(defvar after-load-functions nil
+  "Special hook run after loading a file.
+Each function there is called with a single argument, the absolute
+name of the file just loaded.")
+
 (defun do-after-load-evaluation (abs-file)
   "Evaluate all `eval-after-load' forms, if any, for ABS-FILE.
 ABS-FILE, a string, should be the absolute true name of a file just loaded.
@@ -1690,7 +1699,9 @@
                       (message "Package %s is obsolete!"
                                (substring file 0
                                           (string-match "\\.elc?\\>" file))))
-                    (file-name-nondirectory abs-file))))
+                    (file-name-nondirectory abs-file)))
+  ;; Finally, run any other hook.
+  (run-hook-with-args 'after-load-functions abs-file))
 
 (defun eval-next-after-load (file)
   "Read the following input sexp, and run it whenever FILE is loaded.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: after-load-hook
  2009-09-12  4:16 ` after-load-hook Stefan Monnier
@ 2009-09-12 11:19   ` Juanma Barranquero
  0 siblings, 0 replies; 3+ messages in thread
From: Juanma Barranquero @ 2009-09-12 11:19 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs developers

On Sat, Sep 12, 2009 at 06:16, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> Funny, I just wrote the following patch earlier today.

Yours is better; forget my patch.

    Juanma




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-09-12 11:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-11 20:53 after-load-hook Juanma Barranquero
2009-09-12  4:16 ` after-load-hook Stefan Monnier
2009-09-12 11:19   ` after-load-hook Juanma Barranquero

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).