delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2015/07/16/03:09:55

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
X-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=date:from:to:cc:subject:message-id:mail-followup-to:references
:mime-version:content-type:content-disposition:in-reply-to
:user-agent;
bh=G26DoWPu9OwG8NvSIBjD7K4wwerxZbOeJVwpVGOBYMg=;
b=f1B3AfzM8rZYNlcgZmHHAU3vDmUl02UKnvGrObe0AXGH4ilvUvR9uv9HKqVV92MPvq
FnT9FJeaf3sxki0TmIhFtGXuQsc/50Y3ApD3bHI5uSgEwLRUTdxUx45ZKvwntAF94k/x
3f5dwkqaItWwPPzzAkg/HyxLuHr1QBXFCBYXXDzJl0m31x8a3EkswVy88HhHhSQZxQID
yATcB5gweg+pqvUN/P397TUC2jaCSgfp4CBnl0yHAOZGzcXXVBMHT4YR3clMaC+gRFsQ
o00l31VhbN13zmrDIbrpgqhz4qBIst1JZ9GcOYCQnr+6sKGJBSpLrG0uqxXRi2eS5Xbk
AZ8Q==
X-Received: by 10.152.88.42 with SMTP id bd10mr3908349lab.112.1437030577021;
Thu, 16 Jul 2015 00:09:37 -0700 (PDT)
Date: Thu, 16 Jul 2015 10:09:34 +0300
From: "Vladimir Zhbanov (vzhbanov AT gmail DOT com) [via geda-user AT delorie DOT com]" <geda-user AT delorie DOT com>
To: "Ala'a Mohammad" <amalawi AT gmail DOT com>
Cc: geda-user AT delorie DOT com
Subject: [geda-user] gschem hooks
Message-ID: <20150716070933.GA14277@localhost.localdomain>
Mail-Followup-To: Ala'a Mohammad <amalawi AT gmail DOT com>, geda-user AT delorie DOT com
References: <CAM2RGhQNdDJH6NRDOF1mEY6kxajRBESwr5HZ7eRJ0UpJfA5=Dw AT mail DOT gmail DOT com>
<201507120012 DOT t6C0CfnW014811 AT envy DOT delorie DOT com>
<CAM2RGhSM+iSS8Ysw+esVM=AGsWL=L3KMgKCjw+Ham_nYQ0pUWA AT mail DOT gmail DOT com>
<CAM2RGhSHaBjVM1D_6ZX_A4DeMuAo01X6BXpgzJnxq9w+CGfC9A AT mail DOT gmail DOT com>
<201507120145 DOT t6C1jnc8020051 AT envy DOT delorie DOT com>
<1436950214 DOT 2876 DOT 57 DOT camel AT linetec>
<20150715202828 DOT GA17392 AT localhost DOT localdomain>
<CAJ--6mZUzizkneaLCKVHX0nXYU5oSNkLZxQha13B9Fv3zQ1_QQ AT mail DOT gmail DOT com>
<20150715211802 DOT GB17392 AT localhost DOT localdomain>
<CAJ--6mYxT-sibJiJ_rWo0FkBpO3uryhOkn3Z=0gA4qPOiiowZw AT mail DOT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <CAJ--6mYxT-sibJiJ_rWo0FkBpO3uryhOkn3Z=0gA4qPOiiowZw@mail.gmail.com>
User-Agent: Mutt/1.5.23 (2014-03-12)
Reply-To: geda-user AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: geda-user AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Hi, Ala'a,
On Thu, Jul 16, 2015 at 02:00:10AM +0400, Ala'a Mohammad wrote:

> Double checking the src there is only 14 public hooks, of which only
> copy-objects-hook is missing
Yes, if you try in the repository
  find gschem/ -type f -name '*.scm' -o -name '*.c'| xargs grep -l copy-objects-hook

it outputs
  gschem/scheme/gschem/hook.scm
  gschem/src/g_hook.c
  gschem/src/o_copy.c
  gschem/src/o_buffer.c

Looking through the sources you'll see that g_hook.c is the place
where all gschem hooks are defined using the C analog for the
Guile expression '(define hook-name (make-hook arity))' where
'arity' is the number of hook arguments, and hook.scm is the place
where they become available for Guile/Scheme code.

> 
> Checking the code, copy-objects-hook is called into two places one I
> can understand (at the coping points), the other is confusion (I'm a
> beginner) since it is called in o_buffer_paste_start function
> explaining that 'next paste operation is a copy of these objects'?!!
Don't worry, we're all sort of beginners here :)

It's not me, who wrote this. Looking at this I found it is a
rather new addition, see commit f45be69.

Look, copy-objects-hook is a hook for the start of a copy
operation, while paste-objects-hook is for its end. When we add an
object to a buffer, it is in essence the same operation as a copy,
with the only difference that we can copy the same object (from
the buffer) once again. But we still need to do some operation at
the start of the copy, and it would be better to do it once while
copying the object _to_ the buffer rather than every time we make
a copy of the object in the buffer in order to paste it _from_ the
buffer to a page. The same is for an operation which we have to do
with the object after its pasting, though here we operate on
different copies of the objects so we need to do
paste-objects-hook every time we insert a copy from the buffer.

Plain copy:
  object--->|start-hook|--->(moving)--->|end-hook|--->object_copy

1 option:
  Buffer copy (with C-c):
    object--->buffer_object_copy
  After inserting (with C-v) we have:
    buffer_object_copy_instance1--->|start-hook|--->(moving)--->|end-hook|--->object_copy1
    buffer_object_copy_instance2--->|start-hook|--->(moving)--->|end-hook|--->object_copy2
    ...

2 option:
  Buffer copy (with C-c):
    object--->|start-hook|--->buffer_object_copy
  After inserting we have (with C-V):
    buffer_object_copy_instance1--->(moving)--->|end-hook|--->object_copy1
    buffer_object_copy_instance2--->(moving)--->|end-hook|--->object_copy2
    ...

The author has chosen the option 2.  Feel the difference :)

But wait...


> Sorry to bother you but the following also confused me more. Any hint
> on how to navigate the source and everything fits together? apology if
> I'm asking newbie question!!!
> 
> o_copy_start calls %copy-objects-hook  ;;; ok
> o_buffer_copy calls %copy-objects-hook ;;; ok
> o_buffer_paste_starts calls %copy-objects-hook ;;; what??!!!

You've probably hit a bug :)
Let's change the code in gschemrc I've given before:

---------------------8<-----------------------------
  (use-modules (geda page))
  (use-modules (gschem selection))
  (use-modules (gschem hook))

  (define copied-objects '())

  (define (get-copied-objects)
    copied-objects)

  (define (set-copied-objects! ls)
    (set! copied-objects ls))

  (define my-selection-hook (make-hook))

  (add-hook! my-selection-hook
    (lambda ()
      (for-each select-object! (get-copied-objects))))

  (add-hook! copy-objects-hook
    (lambda (ls)
      (begin 
        (display "Copy-objects!\n")
        (for-each deselect-object! (page-selection (active-page)))
        (set-copied-objects! ls))))

  (add-hook! paste-objects-hook
    (lambda (ls)
      (display "Paste-objects!\n")
      (run-hook my-selection-hook)))
--------------------->8-----------------------------

I've added two (display ...), as you can see.
Let's try it in gschem. C-c to copy an object to the buffer, and
C-v to insert it, yields:
  Copy-objects!
  Copy-objects!
  Paste-objects!
And each time we hit C-v it yields:
  Copy-objects!
  Paste-objects!

We see the combination of the two options above. That's probably
not what we want.

What if some user wants to add a hook to rotate an object on each copy?
And another one wants to output a message dialog (say for using it
for hints) on each paste?

In the first case two rotations will be carried out instead of one.
In the second case the user will get false events she doesn't want.

Perhaps, we need to add some other hook which would be invoked
when the user copies objects to the buffer, or we have to somehow
change the existing hook to make it be aware of the target of
copying, that is a page or a buffer. (To generalize it more, I
thought of making buffers and clipboard a special kind of PAGE.)

> 
> o_copy_end calls %paste-objects-hook ;;; mmm okay for the moment!!!
> x_event_button_pressed calls if (event_state was 'PASTEMODE' && button
> was 1 && inside-action && place-list not empty)
Yes, this is how our state machine works now.

Cheers,
  Vladimir

P.S. I CC this back to the mailing list since I believe it could
     be useful for other members and for discussion.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019