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:47:33 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001517574638f6727f0496cab338 X-Trace: dough.gmane.org 1291697272 21767 80.91.229.12 (7 Dec 2010 04:47:52 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 7 Dec 2010 04:47:52 +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:47:48 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 1PPpSt-0002mZ-6V for ged-emacs-devel@m.gmane.org; Tue, 07 Dec 2010 05:47:48 +0100 Original-Received: from localhost ([127.0.0.1]:34752 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPpSs-0004Gl-Lk for ged-emacs-devel@m.gmane.org; Mon, 06 Dec 2010 23:47:46 -0500 Original-Received: from [140.186.70.92] (port=38431 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPpSi-0004Fm-9L for emacs-devel@gnu.org; Mon, 06 Dec 2010 23:47:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPpSg-0007Sl-J2 for emacs-devel@gnu.org; Mon, 06 Dec 2010 23:47:36 -0500 Original-Received: from mail-gx0-f180.google.com ([209.85.161.180]:47538) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPpSg-0007SW-Bc for emacs-devel@gnu.org; Mon, 06 Dec 2010 23:47:34 -0500 Original-Received: by gxk19 with SMTP id 19so7052799gxk.39 for ; Mon, 06 Dec 2010 20:47:33 -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=2HAobMf0Mz7zHP1ZeGtNSs7DWuoJBRTVww1epebvViU=; b=Gn1XvjdT/ft0yazSCrJWCoGo30XiiNOgMU4lMWMm1d6npGV5OP2RTp8d2JLDq/UmpG +2biU1RMy76ilBxAe44UeZI0G3YMKBIZZ2gxohOOp6oDZYAxfeEJBFxzPQ+N2kKZiCYo JOIw4HS4MYuIpRJDoprJw3LdxnH9QlzS54wD0= 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=PLkaxd8lD32QzzJDsnDstWHIV+rZmsej/aGbPYL2qYv69AGsl+7Zrc+EMJIaySWj6v axAVp8sQyPErD1MMfAV5BvxSanf8uI5zI4BUj6OSP9Hngo/W82PnusR8B3Yl1jKy7jXp dKiRHCXqZ1/iDJYz+z3Yfx1l2I3Kcftn+S0yI= Original-Received: by 10.151.110.10 with SMTP id n10mr970163ybm.160.1291697253675; Mon, 06 Dec 2010 20:47:33 -0800 (PST) Original-Received: by 10.150.218.9 with HTTP; Mon, 6 Dec 2010 20:47:33 -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:133485 Archived-At: --001517574638f6727f0496cab338 Content-Type: text/plain; charset=UTF-8 > > 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. --001517574638f6727f0496cab338 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
> 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_paramete= rs))
=C2=A0=C2=A0=C2=A0=C2=A0 */
=C2=A0=C2=A0=C2=A0 Lisp_Object tab_b= ar_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. No= t too difficult.

=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 memori= ze the current window config into a variable 'sym. The variable sym mus= t 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 variables. For example , every tabmust know about the window-configur= ation 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.
=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 not glob= al. It is not interned, and it becomes tab-local.

=C2=A0<= /div>
> =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 tab-loca= l variables.

In this moment I added code to modify the environment o= f a tab only via the initialization of the tab with make-terminal-frame, bu= t I can add a function to operate on tab-local variables even after the cre= ation 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.
<= br>The fact that make-tab calls directly make-terminal-frame is just a lega= cy 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 that in= side my implementation of make-tab, the variable 'winconfig has a diffe= rent 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.





--001517574638f6727f0496cab338--