all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* help with c-mode-common-hook
@ 2007-05-02 18:00 Hadron
  2007-05-02 18:22 ` Robert Thorpe
  0 siblings, 1 reply; 11+ messages in thread
From: Hadron @ 2007-05-02 18:00 UTC (permalink / raw)
  To: help-gnu-emacs


This is one of those "used to work last time I tried but now it's
broken". Maybe I messed something up in the my-compile?

I have a function which sets the compile command per C file. If a
makefile exists, use it, else use gcc.

,----
| (defun my-compile ()
|   (message "in my-compile")
|   (lambda ()
|     (unless (file-exists-p "Makefile")
|       (set (make-local-variable 'compile-command)
| 	   ;; emulate make's .c.o implicit pattern rule, but with
| 	   ;; different defaults for the CC, CPPFLAGS, and CFLAGS
| 	   ;; variables:
| 	   ;; $(CC) -c -o $@ $(GTKFLAGS) $(CPPFLAGS) $(CFLAGS) $<
| 	   (let ((file (file-name-nondirectory buffer-file-name)))
| 	     (format "%s -o %s %s %s %s %s"
| 		     (or (getenv "CC") "gcc")
| 		     (file-name-sans-extension file)
| 		     (or (getenv "GTKFLAGS") "")
| 		     (or (getenv "CPPFLAGS")"-DDEBUG=9")
| 		     (or (getenv "CFLAGS") "-std=c99 -pedantic -Wall -Werror -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion  -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -g")
| 		     file)))))
|   )
`----

which is called from my c-init

,----
| (defun my-c-init()
| 
| ;; *SNIP*
| 
|   ;;  (defvar gud-gdb-command-name "gdb -q")
|   (setq gud-gdb-command-name "gdb -q")
|  
|   (my-compile)
| 
|   )
`----

my-c-init is in turn added as c file hook:

,----
| (add-hook 'c-mode-common-hook 'my-c-init)
`----

I put "message" calls in so I know the functions are calling each other
but for some reason the compile command is staying at the default "make
-k" even if there is no makefile in the c files directory. What have I
broken? It used to work. Or something similar used to work....

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

* Re: help with c-mode-common-hook
  2007-05-02 18:00 help with c-mode-common-hook Hadron
@ 2007-05-02 18:22 ` Robert Thorpe
  2007-05-02 18:37   ` Hadron
  0 siblings, 1 reply; 11+ messages in thread
From: Robert Thorpe @ 2007-05-02 18:22 UTC (permalink / raw)
  To: help-gnu-emacs

On May 2, 7:00 pm, Hadron <hadronqu...@gmail.com> wrote:
> I put "message" calls in so I know the functions are calling each other
> but for some reason the compile command is staying at the default "make
> -k" even if there is no makefile in the c files directory. What have I
> broken? It used to work. Or something similar used to work....

You're going to have to describe the problem more.  The code you've
shown doesn't change the command "M-x compile" as far as I can see.

Are the messages you put in seen?

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

* Re: help with c-mode-common-hook
  2007-05-02 18:22 ` Robert Thorpe
@ 2007-05-02 18:37   ` Hadron
  2007-05-03  0:24     ` Hadron
  0 siblings, 1 reply; 11+ messages in thread
From: Hadron @ 2007-05-02 18:37 UTC (permalink / raw)
  To: help-gnu-emacs

Robert Thorpe <rthorpe@realworldtech.com> writes:

> On May 2, 7:00 pm, Hadron <hadronqu...@gmail.com> wrote:
>> I put "message" calls in so I know the functions are calling each other
>> but for some reason the compile command is staying at the default "make
>> -k" even if there is no makefile in the c files directory. What have I
>> broken? It used to work. Or something similar used to work....
>
> You're going to have to describe the problem more.  The code you've
> shown doesn't change the command "M-x compile" as far as I can see.

It doesnt. It changes the compile-command variable. AFAIK - I am not a
lisp programmer.

>
> Are the messages you put in seen?
>

Yes - I mentioned that I think.

-- 

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

* Re: help with c-mode-common-hook
  2007-05-02 18:37   ` Hadron
@ 2007-05-03  0:24     ` Hadron
  2007-05-03  6:26       ` Kevin Rodgers
       [not found]       ` <mailman.158.1178174006.32220.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Hadron @ 2007-05-03  0:24 UTC (permalink / raw)
  To: help-gnu-emacs

Hadron <hadronquark@gmail.com> writes:

> Robert Thorpe <rthorpe@realworldtech.com> writes:
>
>> On May 2, 7:00 pm, Hadron <hadronqu...@gmail.com> wrote:
>>> I put "message" calls in so I know the functions are calling each other
>>> but for some reason the compile command is staying at the default "make
>>> -k" even if there is no makefile in the c files directory. What have I
>>> broken? It used to work. Or something similar used to work....
>>
>> You're going to have to describe the problem more.  The code you've
>> shown doesn't change the command "M-x compile" as far as I can see.
>
> It doesnt. It changes the compile-command variable. AFAIK - I am not a
> lisp programmer.
>
>>
>> Are the messages you put in seen?
>>
>
> Yes - I mentioned that I think.

To answer (or provide a solution) my own issue, it works now.

I simply added the my-compile extract directly as a c-mode-hook e.g

,----
| (add-hook 'c-mode-common-hook
|   (lambda ()
|     (unless (or (file-exists-p "makefile")
| 		(file-exists-p "Makefile"))
|       (set (make-local-variable 'compile-command)
| 	   ;; $(CC) -c -o $@ $(GTKFLAGS) $(CPPFLAGS) $(CFLAGS) $<
| 	   (let ((file (file-name-nondirectory buffer-file-name)))
| 	     (format "%s -o %s %s %s %s %s"
| 		     (or (getenv "CC") "gcc")
| 		     (file-name-sans-extension file)
| 		     (or (getenv "GTKFLAGS") "")
| 		     (or (getenv "CPPFLAGS")"-DDEBUG=9")
| 		     (or (getenv "CFLAGS") "-std=c99 -pedantic -Wall -Werror -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion  -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -g")
| 		     file)))))
| )
`----

Which suggests something strange with make-local-variable?

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

* Re: help with c-mode-common-hook
  2007-05-03  0:24     ` Hadron
@ 2007-05-03  6:26       ` Kevin Rodgers
       [not found]       ` <mailman.158.1178174006.32220.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2007-05-03  6:26 UTC (permalink / raw)
  To: help-gnu-emacs

Hadron wrote:
> To answer (or provide a solution) my own issue, it works now.
> 
> I simply added the my-compile extract directly as a c-mode-hook e.g
> 
> ,----
> | (add-hook 'c-mode-common-hook
> |   (lambda ()
> |     (unless (or (file-exists-p "makefile")
> | 		(file-exists-p "Makefile"))
> |       (set (make-local-variable 'compile-command)
> | 	   ;; $(CC) -c -o $@ $(GTKFLAGS) $(CPPFLAGS) $(CFLAGS) $<
> | 	   (let ((file (file-name-nondirectory buffer-file-name)))
> | 	     (format "%s -o %s %s %s %s %s"
> | 		     (or (getenv "CC") "gcc")
> | 		     (file-name-sans-extension file)
> | 		     (or (getenv "GTKFLAGS") "")
> | 		     (or (getenv "CPPFLAGS")"-DDEBUG=9")
> | 		     (or (getenv "CFLAGS") "-std=c99 -pedantic -Wall -Werror -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion  -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -g")
> | 		     file)))))
> | )
> `----
> 
> Which suggests something strange with make-local-variable?

No, the problem is simply with the definition of your function:

(defun my-compile ()
   (message "in my-compile")
   (lambda () ...))

The lambda form is self-evaluating and has no side-effect -- in
particular, the ellided body forms are not evaluated when my-compile
is called.

-- 
Kevin Rodgers
Denver, Colorado, USA

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

* Re: help with c-mode-common-hook
       [not found]       ` <mailman.158.1178174006.32220.help-gnu-emacs@gnu.org>
@ 2007-05-03 10:08         ` Hadron
  2007-05-03 14:09           ` Kai Grossjohann
       [not found]           ` <mailman.175.1178201800.32220.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Hadron @ 2007-05-03 10:08 UTC (permalink / raw)
  To: help-gnu-emacs

Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:

> Hadron wrote:
>> To answer (or provide a solution) my own issue, it works now.
>>
>> I simply added the my-compile extract directly as a c-mode-hook e.g
>>
>> ,----
>> | (add-hook 'c-mode-common-hook
>> |   (lambda ()
>> |     (unless (or (file-exists-p "makefile")
>> | 		(file-exists-p "Makefile"))
>> |       (set (make-local-variable 'compile-command)
>> | 	   ;; $(CC) -c -o $@ $(GTKFLAGS) $(CPPFLAGS) $(CFLAGS) $<
>> | 	   (let ((file (file-name-nondirectory buffer-file-name)))
>> | 	     (format "%s -o %s %s %s %s %s"
>> | 		     (or (getenv "CC") "gcc")
>> | 		     (file-name-sans-extension file)
>> | 		     (or (getenv "GTKFLAGS") "")
>> | 		     (or (getenv "CPPFLAGS")"-DDEBUG=9")
>> | 		     (or (getenv "CFLAGS") "-std=c99 -pedantic -Wall -Werror -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion  -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -g")
>> | 		     file)))))
>> | )
>> `----
>>
>> Which suggests something strange with make-local-variable?
>
> No, the problem is simply with the definition of your function:
>
> (defun my-compile ()
>   (message "in my-compile")
>   (lambda () ...))
>
> The lambda form is self-evaluating and has no side-effect -- in
> particular, the ellided body forms are not evaluated when my-compile
> is called.

I'm not sure what ellided means. But how come it works in my direct
add-hook then? The "old" way was working before (famous last words :-;).


-- 

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

* Re: help with c-mode-common-hook
  2007-05-03 10:08         ` Hadron
@ 2007-05-03 14:09           ` Kai Grossjohann
       [not found]           ` <mailman.175.1178201800.32220.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Kai Grossjohann @ 2007-05-03 14:09 UTC (permalink / raw)
  To: help-gnu-emacs

Hadron <hadronquark@gmail.com> writes:

> I'm not sure what ellided means. But how come it works in my direct
> add-hook then? The "old" way was working before (famous last words :-;).

The "direct" method works because you have different code in that
case.

To make the "direct" method fail, you need to do this:

(add-hook 'c-mode-common-hook 
          (lambda ()
            (lambda ()
              ...same code as before)))

As you can see, there is one lambda too many.

Kai

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

* Re: help with c-mode-common-hook
       [not found]           ` <mailman.175.1178201800.32220.help-gnu-emacs@gnu.org>
@ 2007-05-03 14:48             ` Hadron
  2007-05-03 15:42               ` Kai Grossjohann
                                 ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Hadron @ 2007-05-03 14:48 UTC (permalink / raw)
  To: help-gnu-emacs

Kai Grossjohann <kai@emptydomain.de> writes:

> Hadron <hadronquark@gmail.com> writes:
>
>> I'm not sure what ellided means. But how come it works in my direct
>> add-hook then? The "old" way was working before (famous last words :-;).
>
> The "direct" method works because you have different code in that
> case.
>
> To make the "direct" method fail, you need to do this:
>
> (add-hook 'c-mode-common-hook 
>           (lambda ()
>             (lambda ()
>               ...same code as before)))
>
> As you can see, there is one lambda too many.
>

But there wasnt 2 lambdas in my other way:

| (defun my-compile ()
|   (message "in my-compile")
|   (lambda ()
|     (unless (file-exists-p "Makefile")
|       (set (make-local-variable 'compile-command)
| 	   ;; emulate make's .c.o implicit pattern rule, but with
| 	   ;; different defaults for the CC, CPPFLAGS, and CFLAGS
| 	   ;; variables:
| 	   ;; $(CC) -c -o $@ $(GTKFLAGS) $(CPPFLAGS) $(CFLAGS) $<
| 	   (let ((file (file-name-nondirectory buffer-file-name)))
| 	     (format "%s -o %s %s %s %s %s"
| 		     (or (getenv "CC") "gcc")
| 		     (file-name-sans-extension file)
| 		     (or (getenv "GTKFLAGS") "")
| 		     (or (getenv "CPPFLAGS")"-DDEBUG=9")
| 		     (or (getenv "CFLAGS") "-std=c99 -pedantic -Wall -Werror -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion  -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -g")
| 		     file)))))
|   )

Am I missing something glaringly obvious here? I am more than willing to
believe I inadvertently broke my code when tidying up or something but I
cant see it. I just pasted the entire "original code" into the add-hook
call and it worked.

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

* Re: help with c-mode-common-hook
  2007-05-03 14:48             ` Hadron
@ 2007-05-03 15:42               ` Kai Grossjohann
  2007-05-03 17:11               ` Robert Thorpe
       [not found]               ` <mailman.180.1178207394.32220.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 11+ messages in thread
From: Kai Grossjohann @ 2007-05-03 15:42 UTC (permalink / raw)
  To: help-gnu-emacs

Hadron <hadronquark@gmail.com> writes:

> Kai Grossjohann <kai@emptydomain.de> writes:
>
>> Hadron <hadronquark@gmail.com> writes:
>>
>>> I'm not sure what ellided means. But how come it works in my direct
>>> add-hook then? The "old" way was working before (famous last words :-;).
>>
>> The "direct" method works because you have different code in that
>> case.
>>
>> To make the "direct" method fail, you need to do this:
>>
>> (add-hook 'c-mode-common-hook 
>>           (lambda ()
>>             (lambda ()
>>               ...same code as before)))
>>
>> As you can see, there is one lambda too many.
>>
>
> But there wasnt 2 lambdas in my other way:
>
> | (defun my-compile ()
> |   (message "in my-compile")
> |   (lambda () [...]
> |   )
>
> Am I missing something glaringly obvious here?

defun has an implicit lambda -- sorry if that wasn't clear.  Perhaps I
explain it with Scheme (Pidgin Scheme, I haven't used actual Scheme
for at least 15 years) first:

(define (foo) ...) is the same as (setq foo (lambda () ...)).  Thus,
(define (foo) (lambda () ...)) is the same as (setq foo (lambda ()
(lambda () ...))).

In Emacs Lisp, it looks less symmetric:

(defun foo () ...) is the same as (fset foo (lambda() ...)).  Thus,
(defun foo () (lambda () ...)) is the same as (fset foo (lambda ()
(lambda () ...))).

To be concrete: my-compile is a function that, when called, does the
following: first, it prints something.  Then it returns a function.
The function it returns would, if it were ever called, do useful
things.  However, it is never called -- the return value of my-compile
is discarded (when my-compile is added to a hook and then the hook is
run).

Kai

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

* Re: help with c-mode-common-hook
  2007-05-03 14:48             ` Hadron
  2007-05-03 15:42               ` Kai Grossjohann
@ 2007-05-03 17:11               ` Robert Thorpe
       [not found]               ` <mailman.180.1178207394.32220.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 11+ messages in thread
From: Robert Thorpe @ 2007-05-03 17:11 UTC (permalink / raw)
  To: help-gnu-emacs

On May 3, 3:48 pm, Hadron <hadronqu...@gmail.com> wrote:
> Am I missing something glaringly obvious here? I am more than willing to
> believe I inadvertently broke my code when tidying up or something but I
> cant see it. I just pasted the entire "original code" into the add-hook
> call and it worked.

Evaluate simply (my-compile) in *scratch* and you will see what Kai
means in his post.

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

* Re: help with c-mode-common-hook
       [not found]               ` <mailman.180.1178207394.32220.help-gnu-emacs@gnu.org>
@ 2007-05-06 18:29                 ` Hadron
  0 siblings, 0 replies; 11+ messages in thread
From: Hadron @ 2007-05-06 18:29 UTC (permalink / raw)
  To: help-gnu-emacs

Kai Grossjohann <kai@emptydomain.de> writes:

> Hadron <hadronquark@gmail.com> writes:
>
>> Kai Grossjohann <kai@emptydomain.de> writes:
>>
>>> Hadron <hadronquark@gmail.com> writes:
>>>
>>>> I'm not sure what ellided means. But how come it works in my direct
>>>> add-hook then? The "old" way was working before (famous last words :-;).
>>>
>>> The "direct" method works because you have different code in that
>>> case.
>>>
>>> To make the "direct" method fail, you need to do this:
>>>
>>> (add-hook 'c-mode-common-hook 
>>>           (lambda ()
>>>             (lambda ()
>>>               ...same code as before)))
>>>
>>> As you can see, there is one lambda too many.
>>>
>>
>> But there wasnt 2 lambdas in my other way:
>>
>> | (defun my-compile ()
>> |   (message "in my-compile")
>> |   (lambda () [...]
>> |   )
>>
>> Am I missing something glaringly obvious here?
>
> defun has an implicit lambda -- sorry if that wasn't clear.  Perhaps I
> explain it with Scheme (Pidgin Scheme, I haven't used actual Scheme
> for at least 15 years) first:
>
> (define (foo) ...) is the same as (setq foo (lambda () ...)).  Thus,
> (define (foo) (lambda () ...)) is the same as (setq foo (lambda ()
> (lambda () ...))).
>
> In Emacs Lisp, it looks less symmetric:
>
> (defun foo () ...) is the same as (fset foo (lambda() ...)).  Thus,
> (defun foo () (lambda () ...)) is the same as (fset foo (lambda ()
> (lambda () ...))).
>
> To be concrete: my-compile is a function that, when called, does the
> following: first, it prints something.  Then it returns a function.
> The function it returns would, if it were ever called, do useful
> things.  However, it is never called -- the return value of my-compile
> is discarded (when my-compile is added to a hook and then the hook is
> run).


Thanks - I finally got it!

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

end of thread, other threads:[~2007-05-06 18:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-02 18:00 help with c-mode-common-hook Hadron
2007-05-02 18:22 ` Robert Thorpe
2007-05-02 18:37   ` Hadron
2007-05-03  0:24     ` Hadron
2007-05-03  6:26       ` Kevin Rodgers
     [not found]       ` <mailman.158.1178174006.32220.help-gnu-emacs@gnu.org>
2007-05-03 10:08         ` Hadron
2007-05-03 14:09           ` Kai Grossjohann
     [not found]           ` <mailman.175.1178201800.32220.help-gnu-emacs@gnu.org>
2007-05-03 14:48             ` Hadron
2007-05-03 15:42               ` Kai Grossjohann
2007-05-03 17:11               ` Robert Thorpe
     [not found]               ` <mailman.180.1178207394.32220.help-gnu-emacs@gnu.org>
2007-05-06 18:29                 ` Hadron

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.