unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* make-indirect-buffer
@ 2004-04-12  5:19 Luc Teirlinck
  2004-04-12 21:01 ` make-indirect-buffer Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Luc Teirlinck @ 2004-04-12  5:19 UTC (permalink / raw)


I noticed a second (less serious, but still confusing) bug in
`make-indirect-buffer'.

After emacs -q, we run ielm:

===File ~/namebug===========================================
*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (make-indirect-buffer "nosuchbuffer" "indi")
*** Eval error ***  No such buffer: `indi'
ELISP> ============================================================

There is not supposed to be an `indi' buffer, we are trying to
construct one.  The problem is that "nosuchbuffer" does not exist.

After the following patch:

===File ~/buffer.c-newdiff==================================
*** buffer.c	11 Apr 2004 10:08:04 -0500	1.448
--- buffer.c	11 Apr 2004 23:41:23 -0500	
***************
*** 536,544 ****
    if (!NILP (buf))
      error ("Buffer name `%s' is in use", SDATA (name));
  
    base_buffer = Fget_buffer (base_buffer);
!   if (NILP (base_buffer))
!     error ("No such buffer: `%s'", SDATA (name));
  
    if (SCHARS (name) == 0)
      error ("Empty string for buffer name is not allowed");
--- 536,547 ----
    if (!NILP (buf))
      error ("Buffer name `%s' is in use", SDATA (name));
  
+   if (NILP (Fget_buffer (base_buffer)))
+     error ("No such buffer: `%s'", SDATA (base_buffer));
+ 
    base_buffer = Fget_buffer (base_buffer);
!   if (NILP (XBUFFER (base_buffer)->name))
!     error ("Base buffer has been killed");
  
    if (SCHARS (name) == 0)
      error ("Empty string for buffer name is not allowed");
============================================================

We get:

===File ~/namebug-after-patch===============================
*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (make-indirect-buffer "nosuchbuffer" "indi")
*** Eval error ***  No such buffer: `nosuchbuffer'
ELISP> 
============================================================

Note that base_buffer could be either an existing buffer or a string,
but if `Fget_buffer (base_buffer)' returns nil, it has to be a string.
I could install if desired.

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* make-indirect-buffer
@ 2004-04-12  4:58 Luc Teirlinck
  2004-04-13 17:45 ` make-indirect-buffer Richard Stallman
  0 siblings, 1 reply; 17+ messages in thread
From: Luc Teirlinck @ 2004-04-12  4:58 UTC (permalink / raw)


Executing the following ielm run after `emacs -q' makes Emacs crash:

===File ~/indi-after-crash==================================
*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (setq apr (get-buffer-create "april"))
#<buffer april>
ELISP> (with-current-buffer apr (insert "123"))
nil
ELISP> (kill-buffer apr)
t
ELISP> (make-indirect-buffer apr "indi")
#<buffer indi>
ELISP> (buffer-base-buffer (get-buffer "indi"))
#<killed buffer>
ELISP> (buffer-size (get-buffer "indi"))
3
ELISP> (switch-to-buffer "indi")
#<buffer indi>
ELISP> 
============================================================

(The last two lines are from the auto-save file.)

I do not understand how it could possibly be useful to make an
indirect buffer with a killed base buffer, especially since killing a
base buffer automatically kills all indirect buffers.  So my solution
is to throw an error if one tries to make an indirect buffer with
killed base buffer.  The following trivial patch would do that.  I
could install if desired.

===File ~/buffer.c-diff=====================================
*** buffer.c	11 Apr 2004 10:08:04 -0500	1.448
--- buffer.c	11 Apr 2004 23:08:34 -0500	
***************
*** 539,544 ****
--- 539,546 ----
    base_buffer = Fget_buffer (base_buffer);
    if (NILP (base_buffer))
      error ("No such buffer: `%s'", SDATA (name));
+   if (NILP (XBUFFER (base_buffer)->name))
+     error ("Base buffer has been killed");
  
    if (SCHARS (name) == 0)
      error ("Empty string for buffer name is not allowed");
============================================================

After the patch we get:

===File ~/indi-after-patch==================================
*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (setq apr (get-buffer-create "april"))
#<buffer april>
ELISP> (with-current-buffer apr (insert "123"))
nil
ELISP> (kill-buffer apr)
t
ELISP> (make-indirect-buffer apr "indi")
*** Eval error ***  Base buffer has been killed
ELISP> (make-indirect-buffer apr "indi" t)
*** Eval error ***  Base buffer has been killed
ELISP> 
============================================================

^ permalink raw reply	[flat|nested] 17+ messages in thread
* make-indirect-buffer
@ 2004-03-13 23:23 Luc Teirlinck
  2004-03-15  4:56 ` make-indirect-buffer Richard Stallman
  0 siblings, 1 reply; 17+ messages in thread
From: Luc Teirlinck @ 2004-03-13 23:23 UTC (permalink / raw)


I am currently checking buffers.texi.  The CLONE argument to
`make-indirect-buffer' is currently not documented in the Elisp
manual.  No problem there, I will document it.  However, I do not want
to document bugs and I believe the behavior illustrated in the ielm
run below is a bug.  I believe that the intent of the CLONE argument
to `make-indirect-buffer' is to _initialize_ the "state" of the
indirect buffer from the base buffer, but nevertheless return a "true"
indirect buffer, with its own buffer-local-variables.  That would be a
useful thing to do.  What happens instead is that we wind up with shared
local variables, whose value when set in either buffer also affects
the value in the other.  (On the other hand, newly created local
variables are _not_ shared in this way.)  I believe this is a bug and
that no local variables should be "shared" in that fashion.
Ielm run illustrating this:

===File ~/indi-ielm=========================================
*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (set-buffer "*scratch*")
#<buffer *scratch*>
ELISP> (make-local-variable 'aa)
aa
ELISP> (setq aa 1)
1
ELISP> (make-indirect-buffer "*scratch*" "clone" t)
#<buffer clone>
ELISP> (set-buffer "clone")
#<buffer clone>
ELISP> (make-local-variable 'bb)
bb
ELISP> (setq aa 2)
2
ELISP> (setq bb 2)
2
ELISP> (set-buffer "*scratch*")
#<buffer *scratch*>
ELISP> aa
2  ;;  This is what I believe is a bug.  I expected `1'.
ELISP> bb
*** Eval error ***  Symbol's value as variable is void: bb
ELISP> (default-value 'aa)
*** Eval error ***  Symbol's value as variable is void: aa
ELISP> ============================================================

Doc string of `make-indirect-buffer':

make-indirect-buffer is an interactive built-in function.
(make-indirect-buffer BASE-BUFFER NAME &optional CLONE)

Create and return an indirect buffer for buffer BASE-BUFFER, named NAME.
BASE-BUFFER should be an existing buffer (or buffer name).
NAME should be a string which is not the name of an existing buffer.
Optional argument CLONE non-nil means preserve BASE-BUFFER's state,
such as major and minor modes, in the indirect buffer.
CLONE nil means the indirect buffer's state is reset to default values.

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

end of thread, other threads:[~2004-04-13 17:45 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-12  5:19 make-indirect-buffer Luc Teirlinck
2004-04-12 21:01 ` make-indirect-buffer Stefan Monnier
2004-04-12 21:04   ` make-indirect-buffer Miles Bader
2004-04-12 21:12     ` make-indirect-buffer Luc Teirlinck
2004-04-12 21:22     ` make-indirect-buffer Luc Teirlinck
2004-04-12 21:35       ` make-indirect-buffer Luc Teirlinck
2004-04-12 21:37         ` make-indirect-buffer Luc Teirlinck
2004-04-12 22:53       ` make-indirect-buffer Stefan Monnier
2004-04-12 23:36         ` make-indirect-buffer Luc Teirlinck
2004-04-12 21:27   ` make-indirect-buffer Luc Teirlinck
2004-04-12 21:49 ` make-indirect-buffer Kim F. Storm
2004-04-13 17:45 ` make-indirect-buffer Richard Stallman
  -- strict thread matches above, loose matches on Subject: below --
2004-04-12  4:58 make-indirect-buffer Luc Teirlinck
2004-04-13 17:45 ` make-indirect-buffer Richard Stallman
2004-03-13 23:23 make-indirect-buffer Luc Teirlinck
2004-03-15  4:56 ` make-indirect-buffer Richard Stallman
2004-03-15 22:37   ` make-indirect-buffer Luc Teirlinck

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).