all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Macro Problem
@ 2007-04-02 21:15 vy
  2007-04-03  8:11 ` Pascal Bourguignon
  0 siblings, 1 reply; 9+ messages in thread
From: vy @ 2007-04-02 21:15 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I'm trying to fix a macro for a simple task but still couldn't figure
out the solution to the problem emacs complains about. Here's the
related macro:

(defun adhoc-make-font-face (face spec)
  `(,face ((((class color)
              (min-colors 8))
             ,spec))))

(defmacro adhoc-custom-set-faces (faces)
  `(custom-set-faces
    ,@(loop for face in faces
            collect (adhoc-make-font-face (first face) (second
face)))))

(adhoc-custom-set-faces
 '((font-lock-builtin-face (:foreground "yellow"))
   (font-lock-comment-face (:foreground "red"))
   (font-lock-function-name-face (:foreground "cyan"
                                  :underline "cyan"))))

I'll be appreciated if anybody can give some hints about how to fix
the problem.


Regards.

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

* Re: Macro Problem
  2007-04-02 21:15 Macro Problem vy
@ 2007-04-03  8:11 ` Pascal Bourguignon
  2007-04-04  9:53   ` vy
  0 siblings, 1 reply; 9+ messages in thread
From: Pascal Bourguignon @ 2007-04-03  8:11 UTC (permalink / raw)
  To: help-gnu-emacs

"vy" <volkan.yazici@gmail.com> writes:

> Hi,
>
> I'm trying to fix a macro for a simple task but still couldn't figure
> out the solution to the problem emacs complains about. Here's the
> related macro:
>
> (defun adhoc-make-font-face (face spec)
>   `(,face ((((class color)
>               (min-colors 8))
>              ,spec))))
>
> (defmacro adhoc-custom-set-faces (faces)
>   `(custom-set-faces
>     ,@(loop for face in faces
>             collect (adhoc-make-font-face (first face) (second
> face)))))

This will try to _execute_ the value returned by adhoc-make-font-face.
But a face is not a function, so adhoc-make-font-face should not
return a function call with face as a function, but a quoted list:

 (defun adhoc-make-font-face (face spec)
   `(quote (,face ((((class color)
                     (min-colors 8))
                    ,spec)))))

Of course you can write it as:
 (defun adhoc-make-font-face (face spec)
   `'(,face ((((class color)
                     (min-colors 8))
                    ,spec))))


Also, since adhoc-custom-set-face is a macro that doesn't evaluate its
argument, you shouldn't quote it.

(macroexpand '
 (adhoc-custom-set-faces
  ((font-lock-builtin-face (:foreground "yellow"))
    (font-lock-comment-face (:foreground "red"))
    (font-lock-function-name-face (:foreground "cyan"
                                   :underline "cyan"))))
)
-->
(custom-set-faces
 (quote (font-lock-builtin-face ((#1=((class color) (min-colors 8)) (:foreground "yellow")))))
 (quote (font-lock-comment-face ((#1# (:foreground "red")))))
 (quote (font-lock-function-name-face ((#1# (:foreground "cyan" :underline "cyan"))))))

And if you used (&rest faces) instead of (faces) for
adhoc-custom-set-faces, you could lose one parenthesis:

 (defmacro adhoc-custom-set-faces (&rest faces)
   `(custom-set-faces
     ,@(loop for face in faces
             collect (adhoc-make-font-face (first face) (second face)))))

(macroexpand '
 (adhoc-custom-set-faces
    (font-lock-builtin-face       (:foreground "yellow"))
    (font-lock-comment-face       (:foreground "red"))
    (font-lock-function-name-face (:foreground "cyan"
                                   :underline "cyan")))
)

--> 
(custom-set-faces
 (quote (font-lock-builtin-face ((#1=((class color) (min-colors 8)) (:foreground "yellow")))))
 (quote (font-lock-comment-face ((#1# (:foreground "red")))))
 (quote (font-lock-function-name-face ((#1# (:foreground "cyan" :underline "cyan"))))))



But since custom-set-faces is a function, perhaps you don't want
macros at all! In that case you don't need to return a quoted list
from adhoc-make-font-face, since you won't be trying to execute it:

(defun adhoc-make-font-face (face spec)
  `(,face ((((class color)
              (min-colors 8))
             ,spec))))

(defun adhoc-custom-set-faces (faces)
  (apply (function custom-set-faces)
     (loop for face in faces
           collect (adhoc-make-font-face (first face) (second face)))))


and then indeed you'd call it as:

 (adhoc-custom-set-faces
  '((font-lock-builtin-face (:foreground "yellow"))
    (font-lock-comment-face (:foreground "red"))
    (font-lock-function-name-face (:foreground "cyan"
                                   :underline "cyan"))))



> I'll be appreciated if anybody can give some hints about how to fix
> the problem.

So the problem was that for some strange reason you used defmacro
instead of defun. ;-)


-- 
__Pascal Bourguignon__
http://www.informatimago.com
http://pjb.ogamita.org

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

* Re: Macro Problem
  2007-04-03  8:11 ` Pascal Bourguignon
@ 2007-04-04  9:53   ` vy
  0 siblings, 0 replies; 9+ messages in thread
From: vy @ 2007-04-04  9:53 UTC (permalink / raw)
  To: help-gnu-emacs

On Apr 3, 11:11 am, Pascal Bourguignon <p...@informatimago.com> wrote:
> This will try to _execute_ the value returned by adhoc-make-font-face.
> But a face is not a function, so adhoc-make-font-face should not
> return a function call with face as a function, but a quoted list:
>
>  (defun adhoc-make-font-face (face spec)
>    `(quote (,face ((((class color)
>                      (min-colors 8))
>                     ,spec)))))
>
> Of course you can write it as:
>  (defun adhoc-make-font-face (face spec)
>    `'(,face ((((class color)
>                      (min-colors 8))
>                     ,spec))))
>
> Also, since adhoc-custom-set-face is a macro that doesn't evaluate its
> argument, you shouldn't quote it.
>
> (macroexpand '
>  (adhoc-custom-set-faces
>   ((font-lock-builtin-face (:foreground "yellow"))
>     (font-lock-comment-face (:foreground "red"))
>     (font-lock-function-name-face (:foreground "cyan"
>                                    :underline "cyan"))))
> )
> -->
> (custom-set-faces
>  (quote (font-lock-builtin-face ((#1=((class color) (min-colors 8)) (:foreground "yellow")))))
>  (quote (font-lock-comment-face ((#1# (:foreground "red")))))
>  (quote (font-lock-function-name-face ((#1# (:foreground "cyan" :underline "cyan"))))))
>
> And if you used (&rest faces) instead of (faces) for
> adhoc-custom-set-faces, you could lose one parenthesis:
>
>  (defmacro adhoc-custom-set-faces (&rest faces)
>    `(custom-set-faces
>      ,@(loop for face in faces
>              collect (adhoc-make-font-face (first face) (second face)))))
>
> (macroexpand '
>  (adhoc-custom-set-faces
>     (font-lock-builtin-face       (:foreground "yellow"))
>     (font-lock-comment-face       (:foreground "red"))
>     (font-lock-function-name-face (:foreground "cyan"
>                                    :underline "cyan")))
> )
>
> -->
> (custom-set-faces
>  (quote (font-lock-builtin-face ((#1=((class color) (min-colors 8)) (:foreground "yellow")))))
>  (quote (font-lock-comment-face ((#1# (:foreground "red")))))
>  (quote (font-lock-function-name-face ((#1# (:foreground "cyan" :underline "cyan"))))))
>
> But since custom-set-faces is a function, perhaps you don't want
> macros at all! In that case you don't need to return a quoted list
> from adhoc-make-font-face, since you won't be trying to execute it:
>
> (defun adhoc-make-font-face (face spec)
>   `(,face ((((class color)
>               (min-colors 8))
>              ,spec))))
>
> (defun adhoc-custom-set-faces (faces)
>   (apply (function custom-set-faces)
>      (loop for face in faces
>            collect (adhoc-make-font-face (first face) (second face)))))
>
> and then indeed you'd call it as:
>
>  (adhoc-custom-set-faces
>   '((font-lock-builtin-face (:foreground "yellow"))
>     (font-lock-comment-face (:foreground "red"))
>     (font-lock-function-name-face (:foreground "cyan"
>                                    :underline "cyan"))))
>
> > I'll be appreciated if anybody can give some hints about how to fix
> > the problem.
>
> So the problem was that for some strange reason you used defmacro
> instead of defun. ;-)

Thanks so much for your detailed answer. I really appreciate it.

For about the reason of using a macro, I still don't have a sharp
distinction between where to use a macro and where to use a function.
But as much as I find myself in corner cases about the distinction of
a macro and function, as in this example, I learn more about their
functions.


Regards.

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

* Macro problem
@ 2018-05-13 20:22 Douglas Harter
  0 siblings, 0 replies; 9+ messages in thread
From: Douglas Harter @ 2018-05-13 20:22 UTC (permalink / raw)
  To: EMACS Help

One of my applications has commands attached to the F6-F12 keys. A friend &
I are having a problem with a macro made up of the F-keys. We had a macro
created with the F3 macro F4 sequence. The Macro was F8 F10 F10 F8 F7. It
executed fine for a few times then Emacs froze. I had to kill it. Running
Windows 10 and Emacs 25.3. Executing that same series of keys manually gives
us no problems.



Douglas J Harter





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

* Macro problem
@ 2018-05-15 15:01 Douglas Harter
  2018-05-15 17:13 ` John Mastro
  0 siblings, 1 reply; 9+ messages in thread
From: Douglas Harter @ 2018-05-15 15:01 UTC (permalink / raw)
  To: EMACS Help

I sent this over the weekend The only response was suggesting that Windows
was screwing with my .emacs, which didn't seem possible on 2 separate
computers, and also because my .emacs didn't change. 

One of my applications has commands attached to the F6-F12 keys. A friend &
I are having a problem with a macro made up of the F-keys. We had a macro
created with the F3 macro F4 sequence. The Macro was F8 F10 F10 F8 F7. It
executed fine for a few times then Emacs froze. I had to kill it. Running
Windows 10 and Emacs 25.3. Executing that same series of keys manually gives
us no problems.



Douglas J Harter





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

* Re: Macro problem
       [not found] <mailman.32.1526396527.20804.help-gnu-emacs@gnu.org>
@ 2018-05-15 15:32 ` Barry Margolin
  2018-05-15 16:20   ` Paw Writer
  0 siblings, 1 reply; 9+ messages in thread
From: Barry Margolin @ 2018-05-15 15:32 UTC (permalink / raw)
  To: help-gnu-emacs

In article <mailman.32.1526396527.20804.help-gnu-emacs@gnu.org>,
 "Douglas Harter" <dougharter@comcast.net> wrote:

> I sent this over the weekend The only response was suggesting that Windows
> was screwing with my .emacs, which didn't seem possible on 2 separate
> computers, and also because my .emacs didn't change. 
> 
> One of my applications has commands attached to the F6-F12 keys. A friend &
> I are having a problem with a macro made up of the F-keys. We had a macro
> created with the F3 macro F4 sequence. The Macro was F8 F10 F10 F8 F7. It
> executed fine for a few times then Emacs froze. I had to kill it. Running
> Windows 10 and Emacs 25.3. Executing that same series of keys manually gives
> us no problems.

Difficult to answer without knowing what all these keys do.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


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

* RE: Macro problem
  2018-05-15 15:32 ` Macro problem Barry Margolin
@ 2018-05-15 16:20   ` Paw Writer
  2018-05-15 17:13     ` Søren Pilgård
  0 siblings, 1 reply; 9+ messages in thread
From: Paw Writer @ 2018-05-15 16:20 UTC (permalink / raw)
  To: 'Barry Margolin', help-gnu-emacs

They execute a series of elisp commands.

-----Original Message-----
From: help-gnu-emacs <help-gnu-emacs-bounces+pawwriter=comcast.net@gnu.org>
On Behalf Of Barry Margolin
Sent: Tuesday, May 15, 2018 11:32 AM
To: help-gnu-emacs@gnu.org
Subject: Re: Macro problem

In article <mailman.32.1526396527.20804.help-gnu-emacs@gnu.org>,
 "Douglas Harter" <dougharter@comcast.net> wrote:

> I sent this over the weekend The only response was suggesting that 
> Windows was screwing with my .emacs, which didn't seem possible on 2 
> separate computers, and also because my .emacs didn't change.
> 
> One of my applications has commands attached to the F6-F12 keys. A 
> friend & I are having a problem with a macro made up of the F-keys. We 
> had a macro created with the F3 macro F4 sequence. The Macro was F8 
> F10 F10 F8 F7. It executed fine for a few times then Emacs froze. I 
> had to kill it. Running Windows 10 and Emacs 25.3. Executing that same 
> series of keys manually gives us no problems.

Difficult to answer without knowing what all these keys do.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***




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

* Re: Macro problem
  2018-05-15 15:01 Douglas Harter
@ 2018-05-15 17:13 ` John Mastro
  0 siblings, 0 replies; 9+ messages in thread
From: John Mastro @ 2018-05-15 17:13 UTC (permalink / raw)
  To: EMACS Help; +Cc: Douglas Harter

Douglas Harter <dougharter@comcast.net> wrote:
> I sent this over the weekend The only response was suggesting that Windows
> was screwing with my .emacs, which didn't seem possible on 2 separate
> computers, and also because my .emacs didn't change.
>
> One of my applications has commands attached to the F6-F12 keys. A friend &
> I are having a problem with a macro made up of the F-keys. We had a macro
> created with the F3 macro F4 sequence. The Macro was F8 F10 F10 F8 F7. It
> executed fine for a few times then Emacs froze. I had to kill it. Running
> Windows 10 and Emacs 25.3. Executing that same series of keys manually gives
> us no problems.

It's likely that the problem is related to one or more of the commands,
so it's hard for people to offer much advice without knowing what
specific commands are being run (preferably with a sample buffer so they
can reproduce the freeze).

However, two very general ideas that come to mind are:

- Try running the macro from "emacs -Q" with only the minimal
  setup/configuraton to make the macro runnable. If this doesn't get
  stuck, it implies some package or configuration is contributing to the
  issue.

- If you have some familiarity with debuggers, run emacs under GDB and
  then use "kill -TSTP PID" when emacs gets stuck, which will allow GDB
  to kick in. Then you can get a backtrace and see what's happening.

Hope that helps

        John



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

* Re: Macro problem
  2018-05-15 16:20   ` Paw Writer
@ 2018-05-15 17:13     ` Søren Pilgård
  0 siblings, 0 replies; 9+ messages in thread
From: Søren Pilgård @ 2018-05-15 17:13 UTC (permalink / raw)
  To: Paw Writer; +Cc: Help Gnu Emacs mailing list, Barry Margolin

On Tue, May 15, 2018 at 6:20 PM, Paw Writer <pawwriter@comcast.net> wrote:
> They execute a series of elisp commands.
>
> -----Original Message-----
> From: help-gnu-emacs <help-gnu-emacs-bounces+pawwriter=comcast.net@gnu.org>
> On Behalf Of Barry Margolin
> Sent: Tuesday, May 15, 2018 11:32 AM
> To: help-gnu-emacs@gnu.org
> Subject: Re: Macro problem
>
> In article <mailman.32.1526396527.20804.help-gnu-emacs@gnu.org>,
>  "Douglas Harter" <dougharter@comcast.net> wrote:
>
>> I sent this over the weekend The only response was suggesting that
>> Windows was screwing with my .emacs, which didn't seem possible on 2
>> separate computers, and also because my .emacs didn't change.
>>
>> One of my applications has commands attached to the F6-F12 keys. A
>> friend & I are having a problem with a macro made up of the F-keys. We
>> had a macro created with the F3 macro F4 sequence. The Macro was F8
>> F10 F10 F8 F7. It executed fine for a few times then Emacs froze. I
>> had to kill it. Running Windows 10 and Emacs 25.3. Executing that same
>> series of keys manually gives us no problems.
>
> Difficult to answer without knowing what all these keys do.
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
>
>

That is basically the definition of everything in Emacs...



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

end of thread, other threads:[~2018-05-15 17:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.32.1526396527.20804.help-gnu-emacs@gnu.org>
2018-05-15 15:32 ` Macro problem Barry Margolin
2018-05-15 16:20   ` Paw Writer
2018-05-15 17:13     ` Søren Pilgård
2018-05-15 15:01 Douglas Harter
2018-05-15 17:13 ` John Mastro
  -- strict thread matches above, loose matches on Subject: below --
2018-05-13 20:22 Douglas Harter
2007-04-02 21:15 Macro Problem vy
2007-04-03  8:11 ` Pascal Bourguignon
2007-04-04  9:53   ` vy

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.