From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alin Soare Newsgroups: gmane.emacs.devel Subject: Re: Fwd: Tabs for console. Date: Tue, 7 Dec 2010 06:50:28 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=00151757463865b8a00496cabeee X-Trace: dough.gmane.org 1291697444 22313 80.91.229.12 (7 Dec 2010 04:50:44 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 7 Dec 2010 04:50:44 +0000 (UTC) Cc: Emacs Dev To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 07 05:50:38 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PPpVd-0003Uy-4J for ged-emacs-devel@m.gmane.org; Tue, 07 Dec 2010 05:50:38 +0100 Original-Received: from localhost ([127.0.0.1]:36369 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPpVc-0006c7-HI for ged-emacs-devel@m.gmane.org; Mon, 06 Dec 2010 23:50:36 -0500 Original-Received: from [140.186.70.92] (port=39644 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPpVX-0006Y0-Bo for emacs-devel@gnu.org; Mon, 06 Dec 2010 23:50:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPpVV-0007zC-Kf for emacs-devel@gnu.org; Mon, 06 Dec 2010 23:50:31 -0500 Original-Received: from mail-gx0-f180.google.com ([209.85.161.180]:54186) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPpVV-0007z3-D8 for emacs-devel@gnu.org; Mon, 06 Dec 2010 23:50:29 -0500 Original-Received: by gxk19 with SMTP id 19so7054251gxk.39 for ; Mon, 06 Dec 2010 20:50:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=VKfHutaqT8msOGqzd+LWjCl6ESW8rKWR4McaH6ZFV+w=; b=wmLfkL/gqfLiQByQOZBVXPxZdVIflJW7PXU5UAismsyVmwxjP4IA2N8iot22ljJYdL Ls9d/+7kI4Ma3I4qAQyiM/uYVDw+cPY877qcIiqQp9bU5tg7yUkriYz1d4E9348JAzbw mptRTtGrdtsKnM9SQljstehnwGLMtW6HbuRaQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=pDMPh/FR1OkXRKm9h1ZLp4dxZ1i8+EPKN9KWwKbo9fTGzClHxgNAizewM/BBLuQHxF JU2/Myu0oN9F/0yhHC8or2gq7Bj+ksyKDWvPsS+m9N0Nc/JrIomkgAGm3kNullAN1mE5 y1pFlP+CxVp8j9eTg3yWmIpQmIYQ5Rm6GPsZQ= Original-Received: by 10.151.110.10 with SMTP id n10mr973744ybm.160.1291697428739; Mon, 06 Dec 2010 20:50:28 -0800 (PST) Original-Received: by 10.150.218.9 with HTTP; Mon, 6 Dec 2010 20:50:28 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:133486 Archived-At: --00151757463865b8a00496cabeee Content-Type: text/plain; charset=UTF-8 Try also to install the patch from Saturday and execute the code, to see how the tab-local variables are used to communicate between :initcode, and :activationcode. I deactivated the :deactivationcode, because it is not useful for me, and I wanted to keep the code minimal. Alin 2010/12/7 Alin Soare > > > The idea is that I added to struct frame a list of tabs. >> >> Where is it? In the frame's parameters? Or is it accessed via a new >> frame-tabs and set-frame-tabs? >> >> struct frame > { > ... > /* > * an alist of the form ((alist_tab_parameters)) > */ > Lisp_Object tab_bar_items; > ... > } > > > >> In any case, how difficult would it be to generalize your code so the >> tabs can be attached to a window rather than a frame, or even to an >> internal window (i.e. internal windows are those that are somewhere >> along the window tree and hold various actual windows: currently your >> tabs are at the root internal window). >> >> > I did not think about. Not too difficult. > > > >> > A tab is an alist of >> >> > ( >> > (:name "string-name") >> > (:init-code (lambda () ... code) ) >> > (:activate-code (lambda() ... code) ) >> > (:deactivate-code ... ) >> > (:environment list-of-symbols) >> > ) >> >> What's the init-code for? >> > > The init code is executed only when the tab is created. In my script it is > used to memorize the current window config into a variable 'sym. The > variable sym must be tab-local during the tab existence. > > >> I suspect activate is run when you click on the tab and deactivate is >> run when you click on some other tab. >> What's environment and how is it used? >> >> > An environment keeps tab-local variables. For example , every tabmust know > about the window-configuration when it was created , and extract from its > own environment the value of that win config. > > No other tab needs to see its own windows config. > > >> > This is the function that defines a tab. It initialize a symbol sym with >> the >> > value of current-window-config. The symbol 'sym is passed to >> > (make-terminal-frame), that creates the tab. >> >> I don't understand this "symbol sym" business. >> >> > > I have just explained. It is not interned in the main obarray, and it is > passed to the environment of the tab. > > > >> > ;; this is a definition of a tab as a window configuration >> > (defun make-wc-tab (parms) >> > ;; save curent win config >> > (setq sym (make-symbol "winconfig")) >> >> Here, you're setting a global variable, which is wrong. It's also very >> unclear why you want a symbol here. >> > > It is not global. It is not interned, and it becomes tab-local. > > > >> > (set sym (current-window-configuration)) >> > ;; make a tab that keeps a window configuration. When it is created, >> > ;; it memorizes the current win config. When it is activated, it >> > ;; restores the memorized win config >> > (make-terminal-frame >> > (list '(tab . t) >> > '(tab:name . "WinC") >> > '(tab:activate >> > . >> > (lambda () >> > (set-window-configuration >> > (eval (cdr (assoc 'tab:env (frame-parameters) ) ) ) ) ) ) >> >> `eval' is bad. Stay very far away from it. >> >> > ;; save the current win config into the tab environment >> > (cons 'tab:env sym) ) ) ) >> >> How do "tab:activate" and friends relate to the >> previous :activate-code thingies? >> > > > Via tab-local variables. > > In this moment I added code to modify the environment of a tab only via the > initialization of the tab with make-terminal-frame, but I can add a function > to operate on tab-local variables even after the creation of a tab. > > For example, I did not add the tab:init code to tab's alist, because it is > runned only to creation, in make-tab, before calling make-terminal-frame. > > But if I want to be able to re-initialize a tab, then a function to operate > on tab's environment is required. > > >> >> I don't understand the above call to `make-terminal-frame': does it >> create a new frame, or just a new tab? If the first, then I don't >> understand how it works, and if the second, it's wrong because adding >> a tab should have nothing to do with frame creation. >> > > The fact that make-tab calls directly make-terminal-frame is just a legacy > of the old code, when a tab used to be just a frame. > > Imagine that emacs had lexical binding. Then we woud not need a tab > environment, because that environment would be included insode the > evaluation process, when the closure that represents the tab is initialized. > But because emacs is not able of closures, I need a tab environment, to be > able to communicate between the > > > (:init-code (lambda () ... code) ) > (:activate-code (lambda() ... code) ) > (:deactivate-code ... ) > > of the same tab, > > Note that inside my implementation of make-tab, the variable 'winconfig has > a different value for every tab. When :activatecode is called , > > > (lambda () > > (set-window-configuration > > (eval (cdr (assoc 'tab:env (frame-parameters) ) > > (cdr (assoc 'tab:env (frame-parameters) ) returns the variable 'winconfig, > id est sym. > > > > > > > --00151757463865b8a00496cabeee Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Try also to install the patch from Saturday and execute the code, to se= e how the tab-local variables are used to communicate between :initcode, an= d :activationcode.

I deactivated the :deactivationcode, because it i= s not useful for me, and I wanted to keep the code minimal.



Alin



2010/12/7 Alin S= oare <as1789@gmail= .com>

> The idea is that I added to struct frame a list of tabs.

Where is it? =C2=A0In the frame's parameters? =C2=A0Or is it acce= ssed via a new
frame-tabs and set-frame-tabs?

struct frame
{
...
=C2=A0=C2=A0=C2=A0= /*
=C2=A0=C2=A0=C2=A0=C2=A0 * an alist=C2=A0 of the form ((alist_tab_pa= rameters))
=C2=A0=C2=A0=C2=A0=C2=A0 */
=C2=A0=C2=A0=C2=A0 Lisp_Object= tab_bar_items;
...
}

=C2=A0
In any case, how difficult would it be to generalize your code so the
tabs can be attached to a window rather than a frame, or even to an
internal window (i.e. internal windows are those that are somewhere
along the window tree and hold various actual windows: currently your
tabs are at the root internal window).


I did not think about. Not too d= ifficult.

=C2=A0
> A tab is an alist of

> (
> =C2=A0 (:name "string-name")
> =C2=A0 (:init-code (lambda () ... code) )
> =C2=A0 (:activate-code (lambda() ... code) )
> =C2=A0 (:deactivate-code ... )
> =C2=A0 (:environment list-of-symbols)
> )

What's the init-code for?

The init= code is executed only when the tab is created. In my script it is used to = memorize the current window config into a variable 'sym. The variable s= ym must be tab-local during the tab existence.
=C2=A0
I suspect activate is run when you click on the tab and deactivate is
run when you click on some other tab.
What's environment and how is it used?


An environment keeps tab-local v= ariables. For example , every tabmust know about the window-configuration w= hen it was created , and extract from its own environment the value of that= win config.

No other tab needs to see its own windows config.
=C2=A0
> This is the function that defines a tab. It initialize a symbol sym wi= th the
> value of current-window-config. The symbol 'sym is passed to
> (make-terminal-frame), that creates the tab.

I don't understand this "symbol sym" business.



I have just explained. It is not interned in the main obarray, and it is pa= ssed to the environment of the tab.

=C2=A0
> ;; this is a definition of a tab as a window configuration
> (defun make-wc-tab (parms)
> =C2=A0 ;; save curent win config
> =C2=A0 (setq sym (make-symbol "winconfig"))

Here, you're setting a global variable, which is wrong. =C2=A0It&= #39;s also very
unclear why you want a symbol here.

It is no= t global. It is not interned, and it becomes tab-local.

=C2=A0
> =C2=A0 (set sym =C2=A0(current-window-configuration))
> =C2=A0 ;; make a tab that keeps a window configuration. When it is cre= ated,
> =C2=A0 ;; it memorizes the current win config. When it is activated, i= t
> =C2=A0 ;; restores the memorized win config
> =C2=A0 (make-terminal-frame
> =C2=A0 =C2=A0(list '(tab . t)
> =C2=A0 =C2=A0 =C2=A0'(tab:name . "WinC")
> =C2=A0 =C2=A0 =C2=A0'(tab:activate
> =C2=A0 =C2=A0 =C2=A0 =C2=A0.
> =C2=A0 =C2=A0 =C2=A0 =C2=A0(lambda ()
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(set-window-configuration
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (eval (cdr (assoc 'tab:env (fra= me-parameters) ) ) ) ) ) )

`eval' is bad. =C2=A0Stay very far away from it.

> =C2=A0 =C2=A0 =C2=A0;; save the current win config into the tab enviro= nment
> =C2=A0 =C2=A0 =C2=A0(cons 'tab:env sym) ) ) )

How do "tab:activate" and friends relate to the
previous :activate-code thingies?


Via ta= b-local variables.

In this moment I added code to modify the environ= ment of a tab only via the initialization of the tab with make-terminal-fra= me, but I can add a function to operate on tab-local variables even after t= he creation of a tab.

For example, I did not add the tab:init code to tab's alist, becaus= e it is runned only to creation, in make-tab, before calling make-terminal-= frame.

But if I want to be able to re-initialize a tab, then a funct= ion to operate on tab's environment is required.
=C2=A0

I don't understand the above call to `make-terminal-frame': does it=
create a new frame, or just a new tab? =C2=A0If the first, then I don't=
understand how it works, and if the second, it's wrong because adding a tab should have nothing to do with frame creation.
=

The fact that make-tab calls directly make-terminal-frame is just = a legacy of the old code, when a tab used to be just a frame.

Imagine that emacs had lexical binding. Then we woud not need a tab env= ironment, because that environment would be included insode the evaluation = process, when the closure that represents the tab is initialized. But becau= se emacs is not able of closures, I need a tab environment, to be able to c= ommunicate between the


(:init-code (lambda () ... code) )
(:activate-code (lambda() ... cod= e) )
(:deactivate-code ... )

of the same tab,

Note t= hat inside my implementation of make-tab, the variable 'winconfig has a= different value for every tab. When :activatecode is called ,

> (lambda ()
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(set-window-configuration
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (eval (cdr (assoc 'tab:env (fra= me-parameters) )

(cdr (assoc 'tab:env (frame-parameters)= )=C2=A0 returns the variable 'winconfig, id est sym.



<= br>


--00151757463865b8a00496cabeee--