all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Line number where eval-after-load is defined in my .emacs file
@ 2013-11-13 16:42 Sebastien Vauban
  2013-11-13 17:05 ` William G. Gardella
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Sebastien Vauban @ 2013-11-13 16:42 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hello,

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:

--8<---------------cut here---------------start------------->8---
  ;; 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 ">>>"))))
--8<---------------cut here---------------end--------------->8---

I'd like to see:

--8<---------------cut here---------------start------------->8---
<<< Running code block specific to library `org' (at line 123)...
...
>>>
<<< Running code block specific to library `org' (at line 567)...
...
>>>
--8<---------------cut here---------------end--------------->8---

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?

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

Best regards,
  Seb

[1] The code for org-current-line is:

--8<---------------cut here---------------start------------->8---
  (defsubst org-current-line (&optional pos)
    (save-excursion
      (and pos (goto-char pos))
      ;; works also in narrowed buffer, because we start at 1, not point-min
      (+ (if (bolp) 1 0) (count-lines 1 (point)))))
--8<---------------cut here---------------end--------------->8---

-- 
Sebastien Vauban


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

* Re: Line number where eval-after-load is defined in my .emacs file
  2013-11-13 16:42 Line number where eval-after-load is defined in my .emacs file Sebastien Vauban
@ 2013-11-13 17:05 ` William G. Gardella
       [not found] ` <mailman.5986.1384362332.10748.help-gnu-emacs@gnu.org>
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: William G. Gardella @ 2013-11-13 17:05 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Seb,

"Sebastien Vauban" <sva-news@mygooglest.com>
writes:

[...]

> 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?
>
> Or is there some other way to get such more or less the same type of
> information?
>
> Best regards,
>   Seb

This seems analogous to the management problem that one can have after
putting a lot of lambdas which all look alike inside a hook variable.
Maybe a similar solution is warranted.  I would rewrite your
`eval-after-load' blocks such that each of them calls one named function
(instead of an anonymous `progn'), which in turn contains all the stuff
to be done inside that `eval-after-load'.  That way, when something goes
wrong, the backtrace will name the offending function.

Best,
WGG




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

* Re: Line number where eval-after-load is defined in my .emacs file
       [not found] ` <mailman.5986.1384362332.10748.help-gnu-emacs@gnu.org>
@ 2013-11-13 20:12   ` Sebastien Vauban
  2013-11-14  8:19     ` Thien-Thi Nguyen
       [not found]     ` <mailman.6043.1384418405.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Sebastien Vauban @ 2013-11-13 20:12 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hello William,

William G. Gardella wrote:
> "Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org> writes:
>>
>> 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?
>>
>> Or is there some other way to get such more or less the same type of
>> information?
>
> This seems analogous to the management problem that one can have after
> putting a lot of lambdas which all look alike inside a hook variable. Maybe a
> similar solution is warranted. I would rewrite your `eval-after-load' blocks
> such that each of them calls one named function (instead of an anonymous
> `progn'), which in turn contains all the stuff to be done inside that
> `eval-after-load'. That way, when something goes wrong, the backtrace will
> name the offending function.

I understand you workaround, but I'd prefer to hack `with-eval-after-load', if
possible, to give me the information I'm interested in. This would allow me to
have a .emacs file with less "fat", and to instantly be able to turn it off/on.

So the question boils down to: is it possible to access/save the line number of
where the macro is called (in my .emacs file)?

Best regards,
  Seb

-- 
Sebastien Vauban


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

* Re: Line number where eval-after-load is defined in my .emacs file
  2013-11-13 16:42 Line number where eval-after-load is defined in my .emacs file Sebastien Vauban
  2013-11-13 17:05 ` William G. Gardella
       [not found] ` <mailman.5986.1384362332.10748.help-gnu-emacs@gnu.org>
@ 2013-11-13 21:03 ` Sebastien Vauban
  2013-11-13 22:09   ` Stefan Monnier
  2013-11-13 23:26 ` Michael Heerdegen
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Sebastien Vauban @ 2013-11-13 21:03 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hello,

"Sebastien Vauban" wrote:
> 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 ">>>"))))
>
> It works well, except that line is always displayed as `1' in the Messages
> buffer.

I tried using the more "standard" function (defined in simple.el)
`line-number-at-pos', but that gives the same problem.

> 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?
>
> Or is there some other way to get such more or less the same type of
> information?

I'm sure what I ask (to access/save the line number of where the macro is
called) is possible, but there's something I clearly miss in the macro stuff...

Best regards,
  Seb

-- 
Sebastien Vauban


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

* Re: Line number where eval-after-load is defined in my .emacs file
  2013-11-13 21:03 ` Sebastien Vauban
@ 2013-11-13 22:09   ` Stefan Monnier
  0 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2013-11-13 22:09 UTC (permalink / raw)
  To: help-gnu-emacs

> I tried using the more "standard" function (defined in simple.el)
> `line-number-at-pos', but that gives the same problem.

That's because the current-buffer is *scratch* (or some other such
buffer), rather than being a buffer that holds the contents of the
.emacs file.

> I'm sure what I ask (to access/save the line number of where the macro
> is called) is possible, but there's something I clearly miss in the
> macro stuff...

In some situations, there's a way, indeed, but it's tricky/unreliable.


        Stefan




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

* Re: Line number where eval-after-load is defined in my .emacs file
  2013-11-13 16:42 Line number where eval-after-load is defined in my .emacs file Sebastien Vauban
                   ` (2 preceding siblings ...)
  2013-11-13 21:03 ` Sebastien Vauban
@ 2013-11-13 23:26 ` Michael Heerdegen
       [not found] ` <mailman.6018.1384385233.10748.help-gnu-emacs@gnu.org>
  2013-11-22 16:47 ` jack-mac
  5 siblings, 0 replies; 11+ messages in thread
From: Michael Heerdegen @ 2013-11-13 23:26 UTC (permalink / raw)
  To: help-gnu-emacs

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.




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

* Re: Line number where eval-after-load is defined in my .emacs file
  2013-11-13 20:12   ` Sebastien Vauban
@ 2013-11-14  8:19     ` Thien-Thi Nguyen
       [not found]     ` <mailman.6043.1384418405.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Thien-Thi Nguyen @ 2013-11-14  8:19 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: public-help-gnu-emacs-mXXj517/zsQ


[-- Attachment #1.1: Type: text/plain, Size: 300 bytes --]

() "Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org>
() Wed, 13 Nov 2013 21:12:30 +0100

   So the question boils down to: is it possible to access/save the line
   number of where the macro is called (in my .emacs file)?

Under some circumstances, yes.  Here is a quick sketch:


[-- Attachment #1.2: know-this.el --]
[-- Type: application/emacs-lisp, Size: 707 bytes --]

[-- Attachment #1.3: Type: text/plain, Size: 525 bytes --]


that demonstrates the basic technique, and illustrates the primary
shortcomings -- unreliability and imprecision (if you use it, you will
undoubtedly discover the other shortcomings, soon enough :-D).

To play, save to disk, ‘M-x load-file’ it, and then examine the
*Messages* buffer.

-- 
Thien-Thi Nguyen
   GPG key: 4C807502
   (if you're human and you know it)
      read my lisp: (responsep (questions 'technical)
                               (not (via 'mailing-list)))
                     => nil

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: Line number where eval-after-load is defined in my .emacs file
       [not found]     ` <mailman.6043.1384418405.10748.help-gnu-emacs@gnu.org>
@ 2013-11-15 13:43       ` Sebastien Vauban
  2013-11-16  1:40         ` Michael Heerdegen
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastien Vauban @ 2013-11-15 13:43 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hi Thien-Thi,

Thien-Thi Nguyen wrote:
> () "Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>
>
>    So the question boils down to: is it possible to access/save the line
>    number of where the macro is called (in my .emacs file)?
>
> Under some circumstances, yes.  Here is a quick sketch:
>
> that demonstrates the basic technique, and illustrates the primary
> shortcomings -- unreliability and imprecision (if you use it, you will
> undoubtedly discover the other shortcomings, soon enough :-D).
>
> To play, save to disk, ‘M-x load-file’ it, and then examine the
> *Messages* buffer.

This looks quite close to what I'm looking for -- thanks!

However, when trying to adapt it with the `eval-after-load' form:

--8<---------------cut here---------------start------------->8---
(defmacro my-with-eval-after-load (file &rest body)
  `(let ((loc (when (bufferp standard-input)
                (with-current-buffer standard-input
                  (save-excursion
                    (forward-sexp -1)
                    (when (search-forward "(my-with-eval-after-load" nil t)
                      (1+ (count-lines (point-min)
                                       (match-beginning 0)))))))))
     (eval-after-load ,file
       '(progn
         (message "BEG Running block at line %S..."
                  ,loc)
         ,@body
         (message "END Running block at line %S..."
                  ,loc)))))

(my-with-eval-after-load "org"
  (message "Quite early!"))

(progn
  (message "one...")
  (my-with-eval-after-load "org" (message "greetings earthlings"))
  (message "two...")
  (my-with-eval-after-load "org" (message "that's all for now"))
  (message "three..."))

(my-with-eval-after-load "org" (message "Quite late?"))
--8<---------------cut here---------------end--------------->8---

I do have the error:

  cons: Symbol's value as variable is void: loc

when evaluating it... and I don't understand what I got wrong.

Best regards,
  Seb

-- 
Sebastien Vauban


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

* Re: Line number where eval-after-load is defined in my .emacs file
       [not found] ` <mailman.6018.1384385233.10748.help-gnu-emacs@gnu.org>
@ 2013-11-15 13:46   ` Sebastien Vauban
  0 siblings, 0 replies; 11+ messages in thread
From: Sebastien Vauban @ 2013-11-15 13:46 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Michael, Stefan,

Thanks to you for the explanations...

Michael Heerdegen wrote:
>> 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.

Regarding this, note that I don't intend to use that in a "production" mode:
only when debugging my .emacs file, along with many other useful messages which
are enabled at the same time.

Best regards,
  Seb

-- 
Sebastien Vauban


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

* Re: Line number where eval-after-load is defined in my .emacs file
  2013-11-15 13:43       ` Sebastien Vauban
@ 2013-11-16  1:40         ` Michael Heerdegen
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Heerdegen @ 2013-11-16  1:40 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 320 bytes --]

Hi Sebastian,

>   cons: Symbol's value as variable is void: loc
>
> when evaluating it... and I don't understand what I got wrong.

Yip, writing macros is always fun -- read (info "(elisp) Macros") to
understand it better.

I tried to correct it.  Note that it doesn't work when you compile it.



Regards,

Michael.



[-- Attachment #2: my-weal.el --]
[-- Type: application/emacs-lisp, Size: 558 bytes --]

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

* Re: Line number where eval-after-load is defined in my .emacs file
  2013-11-13 16:42 Line number where eval-after-load is defined in my .emacs file Sebastien Vauban
                   ` (4 preceding siblings ...)
       [not found] ` <mailman.6018.1384385233.10748.help-gnu-emacs@gnu.org>
@ 2013-11-22 16:47 ` jack-mac
  5 siblings, 0 replies; 11+ messages in thread
From: jack-mac @ 2013-11-22 16:47 UTC (permalink / raw)
  To: help-gnu-emacs

Hello!

You might use this simple functions:

;;; ================================================================
;;; Static line number
;;; ================================================================

;;; From: https://groups.google.com/forum/#!topic/gnu.emacs.help/v1QdtBooy2k

(defvar jd-static-line-number-regexp "(jd-static-line-number \\([0-9]*\\))")

(defun jd-static-line-number (line-num)
  line-num)

;;; If you type anywhere in a file (either in code or comments) come text like
;;;    (jd-static-line-number X)    ; where X is the character 0 (or any number)
;;; and if you type M-x jd-static-line-renumber RET while inside this buffer
;;; then the number in this text will automagically be transformed into the current line number!
;;; Like this:
;;;     The current line number (in this line) is (jd-static-line-number 20)

(defun jd-static-line-renumber ()
  "Replace with the current line number the number X appearing in each occurrence of (jd-static-line-number X)."
  (interactive)
  (save-excursion
    (save-restriction
      (widen)
      (goto-char (point-min))
      (while (re-search-forward jd-static-line-number-regexp (not 'bound) 'noerror)
        (replace-match (number-to-string (count-lines (point-min) (point)))
                       'fixed-case 'literal (not 'string) 1)))))

(defmacro jd-with-eval-after-load (file line &rest body) 
  `(eval-after-load ,file 
       '(progn 
         (message "BEG Running block at line %S..." ,line)
         ,@body 
         (message "END Running block at line %S..." ,line))))


Then, you put this into your file:

(jd-with-eval-after-load "org" (jd-static-line-number 0)
  (message "Quite early!")) 

(progn 
  (message "one...") 
  (jd-with-eval-after-load "org" (jd-static-line-number 0) (message "greetings earthlings")) 
  (message "two...") 
  (jd-with-eval-after-load "org" (jd-static-line-number 0) (message "that's all for now")) 
  (message "three...")) 

(jd-with-eval-after-load "org" (jd-static-line-number 0) (message "Quite late?")) 

And then M-x jd-static-line-renumber RET in this buffer 
before evaluating/saving/loading the file.

HTH

)jack(


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

end of thread, other threads:[~2013-11-22 16:47 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-13 16:42 Line number where eval-after-load is defined in my .emacs file Sebastien Vauban
2013-11-13 17:05 ` William G. Gardella
     [not found] ` <mailman.5986.1384362332.10748.help-gnu-emacs@gnu.org>
2013-11-13 20:12   ` Sebastien Vauban
2013-11-14  8:19     ` Thien-Thi Nguyen
     [not found]     ` <mailman.6043.1384418405.10748.help-gnu-emacs@gnu.org>
2013-11-15 13:43       ` Sebastien Vauban
2013-11-16  1:40         ` Michael Heerdegen
2013-11-13 21:03 ` Sebastien Vauban
2013-11-13 22:09   ` Stefan Monnier
2013-11-13 23:26 ` Michael Heerdegen
     [not found] ` <mailman.6018.1384385233.10748.help-gnu-emacs@gnu.org>
2013-11-15 13:46   ` Sebastien Vauban
2013-11-22 16:47 ` jack-mac

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.