help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Line number where eval-after-load is defined in my .emacs file


From: Michael Heerdegen
Subject: Re: Line number where eval-after-load is defined in my .emacs file
Date: Thu, 14 Nov 2013 00:26:34 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Hi Sebastien,

> As I do (sometimes) have -- for the same library -- multiple
> "eval-after-load"
> blocks of code at different spots of my .emacs file, I'd like to be able to
> identify which one was called at which point when reading the Messages
> buffer.
>
> To do so, I tried to (re-)define `with-eval-after-load' such as:
>
>   ;; wrapper around `eval-after-load'
>   (defmacro with-eval-after-load (mode &rest body)
>     "`eval-after-load' MODE evaluate BODY."
>     (declare (indent defun))
>     `(eval-after-load ,mode
>        '(progn
>           (message "<<< Running code block specific to library `%s' (at line 
> %d)..."
>                    ,mode
>                    ,(org-current-line)) ; [1]
>           ,@body
>           (message ">>>"))))

First, please do yourself a favor and don't redefine Emacs primitives or
macros that are used somewhere else in Emacs.  You may break Emacs in
unforeseeable ways, and finding out what goes wrong then will be much
harder than finding out which of your `eval-after-load' forms is buggy.

> I'd like to see:
>
> <<< Running code block specific to library `org' (at line 123)...
> ...
> >>>
> <<< Running code block specific to library `org' (at line 567)...
> ...
> >>>
>
> It works well, except that line is always displayed as `1' in the Messages
> buffer.
>
> Is there a way to "link" the messages to the `eval-after-load' blocks in my
> .emacs file by showing the line number where those blocks are defined?

As Stefan already said, there is no way out of the box.  Note that there
are two separate steps involved when loading a lisp file:

  - First, the code is read.  That means that the so called "reader"
    processes (parses) the text and returns a program, an expression -
    in the case of Emacs, this is a list structure.  This structure
    doesn't refer to the source code buffer in any way.

  - Secondly, the expression is evaluated.

You would have to manipulate the first step to get what you want.  You
can't do it with ordinary means, without fumbling around in the innards
of Emacs.

> Or is there some other way to get such more or less the same type of
> information?

Dunno.  Of course your macro could output the complete expression it
evaluates or something like that, or a tag you specify.  But that's
probably not what you want.  I can only repeat the tip to use named
functions or some kind of tags, or to output something in the code
itself.


Regards,

Michael.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]