all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Eric M. Ludlam" <eric@siege-engine.com>
To: rms@gnu.org
Cc: jasonr@gnu.org, lennart.borgman@gmail.com, sdl.web@gmail.com,
	monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re[2]: Multiple major modes
Date: Wed, 4 Jul 2007 22:29:04 -0400	[thread overview]
Message-ID: <200707050229.l652T4LR023273@projectile.siege-engine.com> (raw)
In-Reply-To: <E1I56DM-0006bO-6a@fencepost.gnu.org> (message from Richard Stallman on Sun, 01 Jul 2007 16:40:12 -0400)

>>> Richard Stallman <rms@gnu.org> seems to think that:
>Please forgive my delay in studying your message and responding.
>
>    >Currently, the idea is that major modes can make any global variable
>    >buffer-local.  Are you suggesting we divide all variables into two
>    >classes, those that can be and those that can't be?  If so, what is
>    >the benefit of that?
>
>    There would be two classes.
>
>I don't entirely follow.  Two classes of what?  Two classes of variables?
>
>If so, could you describe each of the two classes?

Sorry for being vague.  There would be "buffer-local variables", and
"mode-local variables".  I was distinguishing those two from "global
variables". In reading the "Elisp" manual to check my phrases, I see
there are also "frame-local variables", and many other ways to bind
variables, so I am just wrong in saying there are only two classes of
variables.

>				 There would be values that are specific
>    to the major mode, and variables that are local to just some buffer.
>    The buffer local value would trump the mode-specific value, and any
>    mode-specific value would trump the global value.
>
>That part makes sense to me; but can't we make all kinds of bindings
>possible for every variable?

Correct.  When trying to resolve the value of some symbol, mode-local
values would fit into the current scheme of determining the value in
some way, and I am suggesting that buffer local values would be used
before mode-local values.

>    The mode-local feature I wrote (with a lot of help from David Ponce)
>    works in all versions of Emacs commonly used today.  It does this work
>    by modifying the buffer-local values for different major-modes.  It
>    provides the concept of what a mode-local variable might be.  Ideally
>    it would not operate this way, and instead have built-in support for
>    real mode-local values and method tables.
>
>That makes sense.  We could implement mode-local bindings at the low
>level if that is what we want.
>
>What should their semantics be?

If you have a variable defined:

(defvar my-var nil)

and then set a mode-local value for a mojor mode:

;; programmatic
(setq-mode-local 'c-mode my-var t)
;; or declarative
(defvar-mode-local c-mode my-var t "Description about C value")
;; or a constant for that mode, if `defconst' was used instead of `defvar'.
(defconst-mode-local c-mode my-var t "Description here...")

then all buffers in c-mode would get the new value of my-var.

If any of those buffers have a buffer-local version of my-var, then
that value would be used instead.  I'm not sure about frame-local
variables.

If a c-mode buffer switched to fundamental-mode, then the value of
my-var would go back to nil, (the default value).

>      A side effect is that
>    you could have minor modes that operate across both major modes in a
>    single buffer, and that minor mode won't get tromped.
>
>How would this work?

A minor mode which works in an HTML buffer with embedded php in it
could use `mode-local-symbol-value' to get the value of some HTML
variable when inside a PHP block for, perhaps, fill-column, or other
variable even though the effective major mode is PHP.

Basically, any code could be written to be aware of the combination of
two modes for a specific case, and have access to both sets of
mode-local variable bindings, regardless of cursor position.

>    It is obvious that if a mode-local type tool or syntax were adopted
>    into Emacs, that it would be a big effort to transition everything to
>    it.
>
>I hope we can design the mechanism to avoid the need for pervasive
>changes in the code of major modes.  Perhaps we would need to change
>some of the current calls to make-local-variable to call some new
>primitive, make-mode-variable, instead.  But even that would be a pain
>if every major mode HAD to do it.

I think it can be completely optional.  Whichever multiple major-mode
tool that is chosen could take advantage of mode-local variables, and
major modes would adopt the use of them because of performance and
usage enhancement.

If a multi-major-mode tool knows a particular major-mode doesn't use
buffer-local variables, then it would not need to run the major-mode
function (which could call `kill-all-local-variables') for every
section switch and lots of work needed to save and restore
buffer-local values that may or may not be mode-specific would be
saved.


I like providing the mode-local values in a declarative way outside of
the mode function.  It provides a place to add documentation and talk
about the change.  That alone, I think, is worthwhile.

Eric

-- 
          Eric Ludlam:                 zappo@gnu.org, eric@siege-engine.com
   Home: http://www.ludlam.net            Siege: www.siege-engine.com
Emacs: http://cedet.sourceforge.net               GNU: www.gnu.org

  reply	other threads:[~2007-07-05  2:29 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-11 23:27 Should nXML be included Leo
2007-06-12 10:50 ` Lennart Borgman (gmail)
2007-06-12 11:21   ` Jason Rumney
2007-06-12 12:57     ` Lennart Borgman (gmail)
2007-06-12 13:42       ` Peter Heslin
2007-06-12 14:20       ` Jason Rumney
2007-06-12 15:06         ` Multiple major modes (was: Should nXML be included) Stefan Monnier
2007-06-12 15:15           ` Multiple major modes Leo
2007-06-12 18:48           ` Lennart Borgman (gmail)
2007-06-12 20:14             ` Re[2]: " Eric M. Ludlam
2007-06-12 21:04               ` Lennart Borgman (gmail)
2007-06-12 23:10                 ` Stefan Monnier
2007-06-13 16:22                   ` Richard Stallman
2007-06-13 16:22               ` Richard Stallman
2007-06-19  2:09                 ` Re[2]: " Eric M. Ludlam
2007-06-24 14:41                   ` Richard Stallman
2007-06-25 14:04                     ` Re[2]: " Eric M. Ludlam
2007-07-01 20:40                       ` Richard Stallman
2007-07-05  2:29                         ` Eric M. Ludlam [this message]
2007-07-05 20:34                           ` Richard Stallman
2007-07-01 20:40                       ` Richard Stallman
2007-07-04 16:35                         ` T. V. Raman
2007-07-04 17:01                           ` David Kastrup
2007-07-05  1:31                           ` Richard Stallman
2007-07-05 14:49                             ` Stefan Monnier
2007-07-06  4:38                               ` Richard Stallman
2007-07-06  6:01                                 ` Stephen J. Turnbull
2007-07-07 13:07                                   ` Richard Stallman
2007-07-07 14:13                                     ` Lennart Borgman (gmail)
2007-07-08 16:56                                       ` Richard Stallman
2007-09-04  9:03                                         ` Highlight advice (was: Multiple major modes) Johan Bockgård
2007-07-07 17:43                                     ` Multiple major modes Stephen J. Turnbull
2007-07-06 16:00                                 ` Stefan Monnier
2007-07-06 16:10                                   ` Drew Adams
2007-07-07 13:06                                     ` Richard Stallman
2007-07-07 17:21                                       ` Stephen J. Turnbull
2007-07-08 16:55                                         ` Richard Stallman
2007-07-09  5:29                                           ` Stephen J. Turnbull
2007-07-09 17:21                                             ` Richard Stallman
2007-07-07  0:48                             ` Johan Bockgård
2007-07-05  1:44                         ` Re[2]: " Eric M. Ludlam
2007-07-08 22:23                           ` Richard Stallman
2007-07-09  0:49                             ` Re[2]: " Eric M. Ludlam
2007-07-09 17:21                               ` Richard Stallman
2007-06-12 13:26   ` Should nXML be included Stefan Monnier
2007-06-12 13:16 ` Peter Heslin
2007-06-12 13:11   ` Leo
2007-06-12 13:59     ` joakim
2007-06-12 14:17       ` Peter Heslin
2007-06-12 14:14         ` David Kastrup
2007-06-12 15:11           ` Stefan Monnier
2007-06-13  8:06           ` Richard Stallman
2007-06-13 17:45             ` Claus
2007-06-14 16:19               ` Richard Stallman
2007-06-14 16:28                 ` Leo
2007-06-15 19:21                   ` Richard Stallman
2007-06-14 17:44                 ` Eric Hanchrow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200707050229.l652T4LR023273@projectile.siege-engine.com \
    --to=eric@siege-engine.com \
    --cc=emacs-devel@gnu.org \
    --cc=jasonr@gnu.org \
    --cc=lennart.borgman@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    --cc=rms@gnu.org \
    --cc=sdl.web@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.