all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* suggested new command `picture-mouse-set-point'
@ 2002-10-23 18:04 John Paul Wallington
  2002-10-24  0:31 ` Kim F. Storm
  2002-10-24 16:55 ` Richard Stallman
  0 siblings, 2 replies; 35+ messages in thread
From: John Paul Wallington @ 2002-10-23 18:04 UTC (permalink / raw)


Here is a patch providing a mouse command to set point to the position
clicked on in `picture-mode' making whitespace if necessary, as
suggested by Kai and others.  It seems okay, but isn't great.

Is it worth installing as is?  Can anyone suggest improvements?


--- /build-emacs/emacs/lisp/textmodes/picture.el.~1.40.~	Mon Jul  1 08:47:22 2002
+++ /build-emacs/emacs/lisp/textmodes/picture.el	Wed Oct 23 18:56:22 2002
@@ -1,6 +1,6 @@
 ;;; picture.el --- "Picture mode" -- editing using quarter-plane screen model
 
-;; Copyright (C) 1985, 1994 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1994, 2002 Free Software Foundation, Inc.
 
 ;; Author: K. Shane Hartman
 ;; Maintainer: FSF
@@ -226,6 +226,18 @@
   (interactive "p")
   (picture-motion (- arg)))
 
+(defun picture-mouse-set-point (event)
+  "Move point to the position clicked on, making whitespace if necessary."
+  (interactive "e")
+  (let* ((pos (posn-col-row (event-start event)))
+	 (x (car pos))
+	 (y (cdr pos))
+	 (current-row (count-lines (window-start) (line-beginning-position))))
+    (unless (equal x (current-column))
+      (picture-forward-column (- x (current-column))))
+    (unless (equal y current-row)
+      (picture-move-down (- y current-row)))))
+
 \f
 ;; Picture insertion and deletion.
 
@@ -602,6 +614,7 @@
       (picture-substitute 'previous-line 'picture-move-up)
       (picture-substitute 'beginning-of-line 'picture-beginning-of-line)
       (picture-substitute 'end-of-line 'picture-end-of-line)
+      (picture-substitute 'mouse-set-point 'picture-mouse-set-point)
 
       (define-key picture-mode-map "\C-c\C-d" 'delete-char)
       (define-key picture-mode-map "\e\t" 'picture-toggle-tab-state)

-- 
John Paul Wallington

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-23 18:04 suggested new command `picture-mouse-set-point' John Paul Wallington
@ 2002-10-24  0:31 ` Kim F. Storm
  2002-10-24  9:18   ` John Paul Wallington
  2002-10-25  5:35   ` Richard Stallman
  2002-10-24 16:55 ` Richard Stallman
  1 sibling, 2 replies; 35+ messages in thread
From: Kim F. Storm @ 2002-10-24  0:31 UTC (permalink / raw)
  Cc: emacs-devel

jpw@shootybangbang.com (John Paul Wallington) writes:

> Here is a patch providing a mouse command to set point to the position
> clicked on in `picture-mode' making whitespace if necessary, as
> suggested by Kai and others.  It seems okay, but isn't great.
> 
> Is it worth installing as is?  Can anyone suggest improvements?

I don't think this is specifically related to picture mode, as it may
be generally useful.  Here is the code I've written to do this:
						       
(defun mouse-set-point-rigidly (event)
  "Set mouse position at window position clicked on.	   
If window position does not correspond to a buffer position, the
buffer is modified (unless it is a read-only buffer)."
  (interactive "e")					      	   
  (let* ((line (cdr (posn-col-row (event-end event))))
         (moved (move-to-window-line line)))
     (when (and (not buffer-read-only) (< moved line))
       (end-of-line)
       (insert-char ?\n (- line moved))))
  (move-to-column (car (posn-col-row (event-end event))) (not buffer-read-only)))


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-24  0:31 ` Kim F. Storm
@ 2002-10-24  9:18   ` John Paul Wallington
  2002-10-24 21:42     ` Kim F. Storm
  2002-10-25  5:35   ` Richard Stallman
  1 sibling, 1 reply; 35+ messages in thread
From: John Paul Wallington @ 2002-10-24  9:18 UTC (permalink / raw)
  Cc: emacs-devel

> > Here is a patch providing a mouse command to set point to the position
> > clicked on in `picture-mode' making whitespace if necessary, as
> > suggested by Kai and others.  It seems okay, but isn't great.
> > 
> > Is it worth installing as is?  Can anyone suggest improvements?
> 
> I don't think this is specifically related to picture mode, as it may
> be generally useful.  

Agreed.

>Here is the code I've written to do this:
> 						       
> (defun mouse-set-point-rigidly (event)
>   "Set mouse position at window position clicked on.	   
> If window position does not correspond to a buffer position, the
> buffer is modified (unless it is a read-only buffer)."
>   (interactive "e")					      	   
>   (let* ((line (cdr (posn-col-row (event-end event))))
>          (moved (move-to-window-line line)))
>      (when (and (not buffer-read-only) (< moved line))
>        (end-of-line)
>        (insert-char ?\n (- line moved))))
>   (move-to-column (car (posn-col-row (event-end event))) (not buffer-read-only)))

Cool.  Any ideas how to better integrate it?  For example, it would
be nice if `mouse-drag-region' would call it instead of
`mouse-set-point'; presently, the cursor will "bounce".

Maybe there could be a `mouse-set-point-function' variable that would
be funcalled where `mouse-set-point' is presently called directly, or
`mouse-set-point' could call `mouse-set-point-rigidly' iff
`mouse-set-point-rigidly' variable was non-nil, or something like
that?

-- 
John Paul Wallington

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-23 18:04 suggested new command `picture-mouse-set-point' John Paul Wallington
  2002-10-24  0:31 ` Kim F. Storm
@ 2002-10-24 16:55 ` Richard Stallman
  2002-10-24 23:21   ` John Paul Wallington
  1 sibling, 1 reply; 35+ messages in thread
From: Richard Stallman @ 2002-10-24 16:55 UTC (permalink / raw)
  Cc: emacs-devel

It is a good idea.  Would you like to install it?

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-24  9:18   ` John Paul Wallington
@ 2002-10-24 21:42     ` Kim F. Storm
  2002-10-24 23:18       ` John Paul Wallington
  2002-10-26 20:13       ` Richard Stallman
  0 siblings, 2 replies; 35+ messages in thread
From: Kim F. Storm @ 2002-10-24 21:42 UTC (permalink / raw)
  Cc: emacs-devel

jpw@shootybangbang.com (John Paul Wallington) writes:

> >Here is the code I've written to do this:
> > 						       
> > (defun mouse-set-point-rigidly (event)
> 
> Cool.  Any ideas how to better integrate it?  For example, it would
> be nice if `mouse-drag-region' would call it instead of
> `mouse-set-point'; presently, the cursor will "bounce".
> 
> Maybe there could be a `mouse-set-point-function' variable that would
> be funcalled where `mouse-set-point' is presently called directly, or
> `mouse-set-point' could call `mouse-set-point-rigidly' iff
> `mouse-set-point-rigidly' variable was non-nil, or something like
> that?

It seems ok to control this behaviuor through a variable, but should it
be a customization option, or just intended for e.g. let bindings or
buffer-local (or mode-specific) setting?

One problem with this approach is that quite often you just need to
click on some window to select another window or give focus to a frame
-- and in that case you most likely don't want to modify the buffer if
you accidentally click or a TAB or after EOL or EOB.

Maybe the -rigidly functionality should only be activated if
the mouse is clicked in the selected window & frame.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-24 21:42     ` Kim F. Storm
@ 2002-10-24 23:18       ` John Paul Wallington
  2002-10-24 23:37         ` Stefan Monnier
  2002-10-26 20:14         ` Richard Stallman
  2002-10-26 20:13       ` Richard Stallman
  1 sibling, 2 replies; 35+ messages in thread
From: John Paul Wallington @ 2002-10-24 23:18 UTC (permalink / raw)
  Cc: emacs-devel

> > Maybe there could be a `mouse-set-point-function' variable that would
> > be funcalled where `mouse-set-point' is presently called directly, or
> > `mouse-set-point' could call `mouse-set-point-rigidly' iff
> > `mouse-set-point-rigidly' variable was non-nil, or something like
> > that?
> 
> It seems ok to control this behaviuor through a variable, but should it
> be a customization option, or just intended for e.g. let bindings or
> buffer-local (or mode-specific) setting?

Maybe we need a user-option expressing a general preference and a
programmatic variable that can be programmatically bound or set after
it is made a local-variable?
 
> One problem with this approach is that quite often you just need to
> click on some window to select another window or give focus to a frame
> -- and in that case you most likely don't want to modify the buffer if
> you accidentally click or a TAB or after EOL or EOB.
> 
> Maybe the -rigidly functionality should only be activated if
> the mouse is clicked in the selected window & frame.

I agree that is a problem, and your solution sounds good (or at least
the right sort of idea; I haven't tested it).

-- 
John Paul Wallington

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-24 16:55 ` Richard Stallman
@ 2002-10-24 23:21   ` John Paul Wallington
  0 siblings, 0 replies; 35+ messages in thread
From: John Paul Wallington @ 2002-10-24 23:21 UTC (permalink / raw)
  Cc: emacs-devel

> It is a good idea.  Would you like to install it?

It may be good enough for `picture-mode', but Kim's code is nicer and
more general.  Do you think a general, well-integrated
`mouse-set-point-rigidly' would be a good idea?

-- 
John Paul Wallington

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-24 23:18       ` John Paul Wallington
@ 2002-10-24 23:37         ` Stefan Monnier
  2002-10-25  1:42           ` John Paul Wallington
  2002-10-25  9:16           ` Kim F. Storm
  2002-10-26 20:14         ` Richard Stallman
  1 sibling, 2 replies; 35+ messages in thread
From: Stefan Monnier @ 2002-10-24 23:37 UTC (permalink / raw)
  Cc: storm, emacs-devel

> > One problem with this approach is that quite often you just need to
> > click on some window to select another window or give focus to a frame
> > -- and in that case you most likely don't want to modify the buffer if
> > you accidentally click or a TAB or after EOL or EOB.
> > 
> > Maybe the -rigidly functionality should only be activated if
> > the mouse is clicked in the selected window & frame.
> 
> I agree that is a problem, and your solution sounds good (or at least
> the right sort of idea; I haven't tested it).

I don't understand: this problem is not specific to this
mouse-set-point-rigidly.  Normally it is solved in a generic way
by the window-manager by making sure that the click that changes
focus is not sent to the application.
Am I missing something ?


	Stefan

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-24 23:37         ` Stefan Monnier
@ 2002-10-25  1:42           ` John Paul Wallington
  2002-10-25 14:19             ` Stefan Monnier
  2002-10-25  9:16           ` Kim F. Storm
  1 sibling, 1 reply; 35+ messages in thread
From: John Paul Wallington @ 2002-10-25  1:42 UTC (permalink / raw)
  Cc: storm, emacs-devel

> > > One problem with this approach is that quite often you just need to
> > > click on some window to select another window or give focus to a frame
> > > -- and in that case you most likely don't want to modify the buffer if
> > > you accidentally click or a TAB or after EOL or EOB.
> > > 
> > > Maybe the -rigidly functionality should only be activated if
> > > the mouse is clicked in the selected window & frame.
> > 
> > I agree that is a problem, and your solution sounds good (or at least
> > the right sort of idea; I haven't tested it).
> 
> I don't understand: this problem is not specific to this
> mouse-set-point-rigidly.  Normally it is solved in a generic way
> by the window-manager by making sure that the click that changes
> focus is not sent to the application.
> Am I missing something ?

If the window manager doesn't swallow the click then Emacs will get
it.  Lots of window managers have this behaviour.  Even with such
settings, when the user clicks on an Emacs frame her intention may not
be to position point, but merely to select the frame.

`mouse-set-point' doesn't change the buffer but rather places point
somewhere within it.  Using `mouse-set-point-rigidly' instead of it
indiscriminately may result in a change (inserting whitespace) in the
buffer that the user didn't intend, which may be an annoyance.

You have made me wonder whether I am missing something though.  Do
you think it isn't worthwhile to second-guess the user who sets her
window manager to not swallow the focus-changing click?

[apologies if you cannot parse this; I am inebriated :) ]

-- 
John Paul Wallington

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-24  0:31 ` Kim F. Storm
  2002-10-24  9:18   ` John Paul Wallington
@ 2002-10-25  5:35   ` Richard Stallman
  2002-10-25  9:49     ` Kim F. Storm
  1 sibling, 1 reply; 35+ messages in thread
From: Richard Stallman @ 2002-10-25  5:35 UTC (permalink / raw)
  Cc: jpw, emacs-devel

    I don't think this is specifically related to picture mode, as it may
    be generally useful.

It belongs in Picture mode.  The purpose of that mode is to add text
to create the positions that you try to move to.  Everything else that
gives this sort of behavior is in picture.el, and this should be there
too.

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-24 23:37         ` Stefan Monnier
  2002-10-25  1:42           ` John Paul Wallington
@ 2002-10-25  9:16           ` Kim F. Storm
  2002-10-25 14:11             ` Stefan Monnier
  1 sibling, 1 reply; 35+ messages in thread
From: Kim F. Storm @ 2002-10-25  9:16 UTC (permalink / raw)
  Cc: John Paul Wallington, emacs-devel

"Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> writes:

> > > One problem with this approach is that quite often you just need to
> > > click on some window to select another window or give focus to a frame
> > > -- and in that case you most likely don't want to modify the buffer if
> > > you accidentally click or a TAB or after EOL or EOB.
> > > 
> > > Maybe the -rigidly functionality should only be activated if
> > > the mouse is clicked in the selected window & frame.
> > 
> > I agree that is a problem, and your solution sounds good (or at least
> > the right sort of idea; I haven't tested it).
> 
> I don't understand: this problem is not specific to this
> mouse-set-point-rigidly.  Normally it is solved in a generic way
> by the window-manager by making sure that the click that changes
> focus is not sent to the application.
> Am I missing something ?

If I have just one frame with two windows, clicking the mouse in "the
other" window isn't a "focus change" event in the mind of the window
manager. So emacs must handle that case sensibly.


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-25  5:35   ` Richard Stallman
@ 2002-10-25  9:49     ` Kim F. Storm
  2002-10-26 20:15       ` Richard Stallman
  0 siblings, 1 reply; 35+ messages in thread
From: Kim F. Storm @ 2002-10-25  9:49 UTC (permalink / raw)
  Cc: jpw, emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     I don't think this is specifically related to picture mode, as it may
>     be generally useful.
> 
> It belongs in Picture mode.  The purpose of that mode is to add text
> to create the positions that you try to move to.  Everything else that
> gives this sort of behavior is in picture.el, and this should be there
> too.

I'm not religious here, but to me mouse-set-point-rigidly could be a
behaviour some users would like to use more generally - whereas the
picture-mode as such isn't something very many would use generally.

Naturally, picture-mode would use mouse-set-point-rigidly as the
default mouse click behaviour.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-25  9:16           ` Kim F. Storm
@ 2002-10-25 14:11             ` Stefan Monnier
  2002-10-26 12:34               ` Kai Großjohann
  0 siblings, 1 reply; 35+ messages in thread
From: Stefan Monnier @ 2002-10-25 14:11 UTC (permalink / raw)
  Cc: Stefan Monnier, John Paul Wallington, emacs-devel

> > I don't understand: this problem is not specific to this
> > mouse-set-point-rigidly.  Normally it is solved in a generic way
> > by the window-manager by making sure that the click that changes
> > focus is not sent to the application.
> > Am I missing something ?
> 
> If I have just one frame with two windows, clicking the mouse in "the
> other" window isn't a "focus change" event in the mind of the window
> manager. So emacs must handle that case sensibly.

Ah, I get it.
Indeed, in general it is harmless to left-click in a window,
so Emacs doesn't need to be careful to turn the click event
into a window-switch event only.  So we should indeed probably
be careful to preserve the harmlessness of left-clicking, unless
we decide to start doing what window-managers do and turn those
clicks into window-switch events, but users might be annoyed by it.


	Stefan

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-25  1:42           ` John Paul Wallington
@ 2002-10-25 14:19             ` Stefan Monnier
  2002-10-25 22:50               ` Kevin Ryde
  2002-10-25 22:57               ` John Paul Wallington
  0 siblings, 2 replies; 35+ messages in thread
From: Stefan Monnier @ 2002-10-25 14:19 UTC (permalink / raw)
  Cc: monnier+gnu/emacs, storm, emacs-devel

> > I don't understand: this problem is not specific to this
> > mouse-set-point-rigidly.  Normally it is solved in a generic way
> > by the window-manager by making sure that the click that changes
> > focus is not sent to the application.
> > Am I missing something ?
> 
> If the window manager doesn't swallow the click then Emacs will get
> it.  Lots of window managers have this behaviour.

Which window-managers ?
I would consider it a bug.  Think of the case where your Galeon window
is a bit behind showing one large imagemap, how are you going to bring
it up and give it focus without selecting something in the imagemap ?

The only time when such clicks aren't swallowed in my experience is
when the window-manager uses focus-follows-point.


	Stefan

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-25 14:19             ` Stefan Monnier
@ 2002-10-25 22:50               ` Kevin Ryde
  2002-10-25 22:57               ` John Paul Wallington
  1 sibling, 0 replies; 35+ messages in thread
From: Kevin Ryde @ 2002-10-25 22:50 UTC (permalink / raw)


"Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> writes:
>
> Which window-managers ?

It's usually an option I think.  ClickToFocusPassesClick in fvwm for
instance, if I'm not mistaken.

> I would consider it a bug.

It's purely personal preference (at the wm level).  You can think of
it as making application functionality available in non-focused
windows (without an extra click or whatever).

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-25 14:19             ` Stefan Monnier
  2002-10-25 22:50               ` Kevin Ryde
@ 2002-10-25 22:57               ` John Paul Wallington
  1 sibling, 0 replies; 35+ messages in thread
From: John Paul Wallington @ 2002-10-25 22:57 UTC (permalink / raw)
  Cc: storm, emacs-devel

> > If the window manager doesn't swallow the click then Emacs will get
> > it.  Lots of window managers have this behaviour.
> 
> Which window-managers ?

metacity, sawfish, and WindowMaker offer click-to-focus without
swallowing the click.

> I would consider it a bug.  Think of the case where your Galeon window
> is a bit behind showing one large imagemap, how are you going to bring
> it up and give it focus without selecting something in the imagemap ?

-- 
John Paul Wallington

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-25 14:11             ` Stefan Monnier
@ 2002-10-26 12:34               ` Kai Großjohann
  0 siblings, 0 replies; 35+ messages in thread
From: Kai Großjohann @ 2002-10-26 12:34 UTC (permalink / raw)


"Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> writes:

> Indeed, in general it is harmless to left-click in a window,
> so Emacs doesn't need to be careful to turn the click event
> into a window-switch event only.  So we should indeed probably
> be careful to preserve the harmlessness of left-clicking, unless
> we decide to start doing what window-managers do and turn those
> clicks into window-switch events, but users might be annoyed by it.

Actually, now that I think about it...  I've been inconvenienced (is
that a sufficiently weak term?) slightly (just to be on the safe side)
by this often enough that I now hit F2 F2 (my personal binding for
other-window) instead of clicking with the mouse just to avoid
positioning point.

So a user option to prevent point moving when switching windows with
the mouse would be cool.

(The modeline also does this, but it's a bit hard to hit.)

kai
-- 
~/.signature is: umop ap!sdn    (Frank Nobis)

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-24 21:42     ` Kim F. Storm
  2002-10-24 23:18       ` John Paul Wallington
@ 2002-10-26 20:13       ` Richard Stallman
  1 sibling, 0 replies; 35+ messages in thread
From: Richard Stallman @ 2002-10-26 20:13 UTC (permalink / raw)
  Cc: jpw, emacs-devel

    > Maybe there could be a `mouse-set-point-function' variable that would
    > be funcalled where `mouse-set-point' is presently called directly, or
    > `mouse-set-point' could call `mouse-set-point-rigidly' iff
    > `mouse-set-point-rigidly' variable was non-nil, or something like
    > that?

This is gratuitous complexity on a point that is not terribly important.
The added feature in picture.el that JPW already wrote is worth adding,
but I don't want to go any further.

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-24 23:18       ` John Paul Wallington
  2002-10-24 23:37         ` Stefan Monnier
@ 2002-10-26 20:14         ` Richard Stallman
  2002-10-28 15:20           ` Juanma Barranquero
  2002-10-28 15:31           ` Juanma Barranquero
  1 sibling, 2 replies; 35+ messages in thread
From: Richard Stallman @ 2002-10-26 20:14 UTC (permalink / raw)
  Cc: emacs-devel

    Maybe we need a user-option expressing a general preference and a
    programmatic variable that can be programmatically bound or set after
    it is made a local-variable?

We don't actually *need* any change in this particular area.
Could people please turn attention to some of the changes
in etc/TODO that would make a real difference to users?
Or to fixing some of the more difficult real problems that we have?

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-25  9:49     ` Kim F. Storm
@ 2002-10-26 20:15       ` Richard Stallman
  0 siblings, 0 replies; 35+ messages in thread
From: Richard Stallman @ 2002-10-26 20:15 UTC (permalink / raw)
  Cc: jpw, emacs-devel

    I'm not religious here, but to me mouse-set-point-rigidly could be a
    behaviour some users would like to use more generally - whereas the
    picture-mode as such isn't something very many would use generally.

Someone might perhaps want this, but we should not add features merely
because of that.  My decision is that it isn't useful enough,
and it should only go in picture.el.

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-26 20:14         ` Richard Stallman
@ 2002-10-28 15:20           ` Juanma Barranquero
  2002-10-28 18:26             ` Eli Zaretskii
  2002-10-29  3:01             ` Richard Stallman
  2002-10-28 15:31           ` Juanma Barranquero
  1 sibling, 2 replies; 35+ messages in thread
From: Juanma Barranquero @ 2002-10-28 15:20 UTC (permalink / raw)
  Cc: jpw, emacs-devel

On Sat, 26 Oct 2002 16:14:12 -0400, Richard Stallman <rms@gnu.org> wrote:

> Could people please turn attention to some of the changes
> in etc/TODO that would make a real difference to users?

Speaking of that...

> * Write an INTRO_CVS file with basic instructions how to build emacs
>   from CVS (make bootstrap), some information on how the config
>   and build system is tied together, and all sorts of tips and tricks
>   (FAQ) which may be of interest to new (and old) emacs hackers.

Wasn't someone writing something like that, I seem to remember?

> * Program Enriched mode to read and save in RTF.  [Is there actually a
>   decent single definition of RTF?]

Somewhere in msdn.microsoft.com, I've heard :(

> * Get some major packages installed: W3/url (development version needs
>   significant work), PSGML, Mule-UCS, Tramp (?).

Tramp should be taken out of the list, shouldn't?

> * Highlight rectangles (`mouse-track-rectangle-p' in XEmacs).

Already done by CUA, more or less.

> * Eliminate the storm of warnings concerning char/unsigned char
>   mismatches that we get with proprietary compilers on various systems.
>   They make it difficult to spot the important warnings.

Which platforms? On Windows there are quite a few "unary minus operator
applied to unsigned type" warnings, but there are still more of the
"differs in parameter lists from" kind.

> * Re-implement emacs-server in lisp as an internal server using
>   make-network-process instead of using an external program.

Wasn't that done already?

> * Rewrite make-docfile to something sane.

What does that mean? In which sense is make-docfile insane?
 
                                                           /L/e/k/t/u

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-26 20:14         ` Richard Stallman
  2002-10-28 15:20           ` Juanma Barranquero
@ 2002-10-28 15:31           ` Juanma Barranquero
  2002-10-29  3:02             ` Richard Stallman
  1 sibling, 1 reply; 35+ messages in thread
From: Juanma Barranquero @ 2002-10-28 15:31 UTC (permalink / raw)
  Cc: jpw, emacs-devel

On Sat, 26 Oct 2002 16:14:12 -0400, Richard Stallman <rms@gnu.org> wrote:

> Could people please turn attention to some of the changes
> in etc/TODO

Another question:

> * If you do an insert-file and that file is currently modified in
>   another buffer but not written yet, print a warning.

Which other insert-file-like functions should be affected? I assume it's
only interactive commands, and not `insert-file-contents' nor
`inset-file-contents-literally', but what with `insert-file-literally',
and the gazillion `find-file*' functions?

                                                           /L/e/k/t/u

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-28 15:20           ` Juanma Barranquero
@ 2002-10-28 18:26             ` Eli Zaretskii
  2002-10-29  7:23               ` Juanma Barranquero
  2002-10-29  3:01             ` Richard Stallman
  1 sibling, 1 reply; 35+ messages in thread
From: Eli Zaretskii @ 2002-10-28 18:26 UTC (permalink / raw)
  Cc: jpw, emacs-devel

> From: Juanma Barranquero <lektu@terra.es>
> Date: Mon, 28 Oct 2002 16:20:29 +0100
> 
> > * Write an INTRO_CVS file with basic instructions how to build emacs
> >   from CVS (make bootstrap), some information on how the config
> >   and build system is tied together, and all sorts of tips and tricks
> >   (FAQ) which may be of interest to new (and old) emacs hackers.
> 
> Wasn't someone writing something like that, I seem to remember?

It's done already, see INSTALL-CVS in the top-level directory.

> > * Eliminate the storm of warnings concerning char/unsigned char
> >   mismatches that we get with proprietary compilers on various systems.
> >   They make it difficult to spot the important warnings.
> 
> Which platforms?

I've seen many warnings on Solaris 9 and on Irix 6.5 when using native
compilers.

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-28 15:20           ` Juanma Barranquero
  2002-10-28 18:26             ` Eli Zaretskii
@ 2002-10-29  3:01             ` Richard Stallman
  1 sibling, 0 replies; 35+ messages in thread
From: Richard Stallman @ 2002-10-29  3:01 UTC (permalink / raw)
  Cc: jpw, emacs-devel

    > * Get some major packages installed: W3/url (development version needs
    >   significant work), PSGML, Mule-UCS, Tramp (?).

    Tramp should be taken out of the list, shouldn't?

Thanks.

    > * Highlight rectangles (`mouse-track-rectangle-p' in XEmacs).

    Already done by CUA, more or less.

This feature is worth making more general.

    > * Re-implement emacs-server in lisp as an internal server using
    >   make-network-process instead of using an external program.

    Wasn't that done already?

Yes, it has been.  Thanks.

    > * Rewrite make-docfile to something sane.

    What does that mean? In which sense is make-docfile insane?

It would be good if that were a cleaner program.

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-28 15:31           ` Juanma Barranquero
@ 2002-10-29  3:02             ` Richard Stallman
  2002-10-29 17:59               ` Juanma Barranquero
  0 siblings, 1 reply; 35+ messages in thread
From: Richard Stallman @ 2002-10-29  3:02 UTC (permalink / raw)
  Cc: jpw, emacs-devel

    > * If you do an insert-file and that file is currently modified in
    >   another buffer but not written yet, print a warning.

    Which other insert-file-like functions should be affected? I assume it's
    only interactive commands, and not `insert-file-contents' nor
    `inset-file-contents-literally', but what with `insert-file-literally',
    and the gazillion `find-file*' functions?

The find-file functions will simply use that buffer, so this issue
does not apply to them.  It does apply to insert-file-literally.

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-28 18:26             ` Eli Zaretskii
@ 2002-10-29  7:23               ` Juanma Barranquero
  2002-10-29 19:38                 ` Eli Zaretskii
  0 siblings, 1 reply; 35+ messages in thread
From: Juanma Barranquero @ 2002-10-29  7:23 UTC (permalink / raw)
  Cc: jpw, emacs-devel

On Mon, 28 Oct 2002 21:26:05 +0300, "Eli Zaretskii" <eliz@is.elta.co.il> wrote:

> It's done already, see INSTALL-CVS in the top-level directory.

Ah, OK.

> I've seen many warnings on Solaris 9 and on Irix 6.5 when using native
> compilers.

At least the ones I've seen in Windows are pretty correct: a variable is
defined as being unsigned and then its negative is taken, or things to
that effect. I suppose the large number of warnings (in other platforms)
will happen with system-header-defined types which are signed/unsigned
according to the platform...


                                                           /L/e/k/t/u

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-29  3:02             ` Richard Stallman
@ 2002-10-29 17:59               ` Juanma Barranquero
  2002-10-30 11:55                 ` Kim F. Storm
  2002-10-30 17:18                 ` Richard Stallman
  0 siblings, 2 replies; 35+ messages in thread
From: Juanma Barranquero @ 2002-10-29 17:59 UTC (permalink / raw)
  Cc: jpw, emacs-devel

On Mon, 28 Oct 2002 22:02:02 -0500, Richard Stallman <rms@gnu.org> wrote:

> The find-file functions will simply use that buffer, so this issue
> does not apply to them.  It does apply to insert-file-literally.

OK.

The following patch implements the functionality for `insert-file' and
`insert-file-literally'.

Before commiting it, three questions/issues:

 - I've made it to ask before inserting, instead of blindingly inserting
*and* issuing a warning.  Which way is preferred?

 - As implemented, it only warns about the first modified buffer visiting
the file, even if there are more.  It seems a bit ugly to show many
buffers in the question, and, OTOH, I'd bet is not very usual to have
multiple modified buffers visiting the very same file.

 - I've extracted code from `find-buffer-visiting' into an internal
`find-buffer-visiting-1' because it already has a lot of good logic to
detect when a file is being visited.  Basically I've added it a
predicate so I can search for a file visited *and* modified.
`find-buffer-visiting' calls the internal one and its interface is not
modified in any way.

Comments?

                                                           /L/e/k/t/u



Index: files.el
===================================================================
RCS file: /cvs/emacs/lisp/files.el,v
retrieving revision 1.620
diff -u -2 -r1.620 files.el
--- files.el	26 Oct 2002 22:34:14 -0000	1.620
+++ files.el	29 Oct 2002 17:55:36 -0000
@@ -1048,4 +1048,36 @@
   :group 'find-file)
 
+(defun find-buffer-visiting-1 (truename &optional predicate)
+  (or (let ((list (buffer-list)) found)
+        (while (and (not found) list)
+          (save-excursion
+            (set-buffer (car list))
+            (if (and buffer-file-name
+                     (string= buffer-file-truename truename)
+                     (or (not predicate)
+                         (funcall predicate (current-buffer))))
+                (setq found (car list))))
+          (setq list (cdr list)))
+        found)
+      (let* ((attributes (file-attributes truename))
+             (number (nthcdr 10 attributes))
+             (list (buffer-list)) found)
+        (and buffer-file-numbers-unique
+             number
+             (while (and (not found) list)
+               (with-current-buffer (car list)
+                 (if (and buffer-file-name
+                          (equal buffer-file-number number)
+                          ;; Verify this buffer's file number
+                          ;; still belongs to its file.
+                          (file-exists-p buffer-file-name)
+                          (equal (file-attributes buffer-file-truename)
+                                 attributes)
+                          (or (not predicate)
+                              (funcall predicate (current-buffer))))
+                     (setq found (car list))))
+               (setq list (cdr list))))
+        found)))
+
 (defun find-buffer-visiting (filename)
   "Return the buffer visiting file FILENAME (a string).
@@ -1056,30 +1088,5 @@
 	(truename (abbreviate-file-name (file-truename filename))))
     (or buf
-	(let ((list (buffer-list)) found)
-	  (while (and (not found) list)
-	    (save-excursion
-	      (set-buffer (car list))
-	      (if (and buffer-file-name
-		       (string= buffer-file-truename truename))
-		  (setq found (car list))))
-	    (setq list (cdr list)))
-	  found)
-	(let* ((attributes (file-attributes truename))
-	       (number (nthcdr 10 attributes))
-	       (list (buffer-list)) found)
-	  (and buffer-file-numbers-unique
-	       number
-	       (while (and (not found) list)
-		 (with-current-buffer (car list)
-		   (if (and buffer-file-name
-			    (equal buffer-file-number number)
-			    ;; Verify this buffer's file number
-			    ;; still belongs to its file.
-			    (file-exists-p buffer-file-name)
-			    (equal (file-attributes buffer-file-truename)
-				   attributes))
-		       (setq found (car list))))
-		 (setq list (cdr list))))
-	  found))))
+        (find-buffer-visiting-1 truename))))
 \f
 (defcustom find-file-wildcards t
@@ -1336,4 +1343,16 @@
 	(fmakunbound 'find-buffer-file-type)))))
 
+(defun insert-file-1 (filename insert-func)
+  (if (file-directory-p filename)
+      (signal 'file-error (list "Opening input file" "file is a directory"
+                                filename)))
+  (let ((buffer (find-buffer-visiting-1 (abbreviate-file-name (file-truename filename))
+                                        #'buffer-modified-p)))
+    (when (or (not buffer)
+              (yes-or-no-p (format "File %s already visited and modified in buffer %s.  Insert? "
+                                   filename (buffer-name buffer))))
+      (let ((tem (funcall insert-func filename)))
+        (push-mark (+ (point) (car (cdr tem))))))))
+
 (defun insert-file-literally (filename)
   "Insert contents of file FILENAME into buffer after point with no conversion.
@@ -1343,9 +1362,5 @@
 \(Its calling sequence is different; see its documentation)."
   (interactive "*fInsert file literally: ")
-  (if (file-directory-p filename)
-      (signal 'file-error (list "Opening input file" "file is a directory"
-				filename)))
-  (let ((tem (insert-file-contents-literally filename)))
-    (push-mark (+ (point) (car (cdr tem))))))
+  (insert-file-1 filename #'insert-file-contents-literally))
 
 (defvar find-file-literally nil
@@ -3148,9 +3163,5 @@
 \(Its calling sequence is different; see its documentation)."
   (interactive "*fInsert file: ")
-  (if (file-directory-p filename)
-      (signal 'file-error (list "Opening input file" "file is a directory"
-				filename)))
-  (let ((tem (insert-file-contents filename)))
-    (push-mark (+ (point) (car (cdr tem))))))
+  (insert-file-1 filename #'insert-file-contents))
 
 (defun append-to-file (start end filename)

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-29  7:23               ` Juanma Barranquero
@ 2002-10-29 19:38                 ` Eli Zaretskii
  0 siblings, 0 replies; 35+ messages in thread
From: Eli Zaretskii @ 2002-10-29 19:38 UTC (permalink / raw)
  Cc: jpw, emacs-devel

> Date: Tue, 29 Oct 2002 08:23:35 +0100
> From: Juanma Barranquero <lektu@terra.es>
> 
> I suppose the large number of warnings (in other platforms)
> will happen with system-header-defined types which are signed/unsigned
> according to the platform...

There are many warnings about unsigned char * being passed to library
functions that expect a char *.

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

* Re: suggested new command `picture-mouse-set-point'
@ 2002-10-30 11:55                 ` Kim F. Storm
  2002-10-30 12:47                   ` Juanma Barranquero
  0 siblings, 1 reply; 35+ messages in thread
From: Kim F. Storm @ 2002-10-30 11:55 UTC (permalink / raw)



Juanma Barranquero wrote:

> The following patch implements the functionality for `insert-file' and
> `insert-file-literally'.
> 
> Before commiting it, three questions/issues:
> 
>  - I've made it to ask before inserting, instead of blindingly inserting
> *and* issuing a warning.  Which way is preferred?

Well, I would prefer -- now that it has found that modified buffer --
if it would offer to insert that buffer's contents instead of the
original file.

Something like:

File XXX is modified in buffer B.  Insert anyway [ynb]?

where responding 'b' inserts the buffer's contents.

-- 
Kim F. Storm  <storm@cua.dk>      http://www.cua.dk

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-30 11:55                 ` Kim F. Storm
@ 2002-10-30 12:47                   ` Juanma Barranquero
  0 siblings, 0 replies; 35+ messages in thread
From: Juanma Barranquero @ 2002-10-30 12:47 UTC (permalink / raw)
  Cc: emacs-devel

On Wed, 30 Oct 2002 11:55:06 +0000 (GMT), "Kim F. Storm" <storm@cua.dk> wrote:

> Well, I would prefer -- now that it has found that modified buffer --
> if it would offer to insert that buffer's contents instead of the
> original file.

I think that's a good idea but, what do we do if there are several such
buffers?


                                                           /L/e/k/t/u

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-29 17:59               ` Juanma Barranquero
  2002-10-30 11:55                 ` Kim F. Storm
@ 2002-10-30 17:18                 ` Richard Stallman
  2002-10-30 17:51                   ` Juanma Barranquero
  2002-11-04 11:13                   ` Juanma Barranquero
  1 sibling, 2 replies; 35+ messages in thread
From: Richard Stallman @ 2002-10-30 17:18 UTC (permalink / raw)
  Cc: jpw, emacs-devel

     - I've made it to ask before inserting, instead of blindingly inserting
    *and* issuing a warning.  Which way is preferred?

A warning is better.  The user can always undo the insertion,
so it is harmless to go ahead; but the question would be annoying.

One could argue that it should insert from the buffer instead, but
there's another command insert-buffer, so insert-file should always
insert from the file.

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-30 17:18                 ` Richard Stallman
@ 2002-10-30 17:51                   ` Juanma Barranquero
  2002-11-04 11:13                   ` Juanma Barranquero
  1 sibling, 0 replies; 35+ messages in thread
From: Juanma Barranquero @ 2002-10-30 17:51 UTC (permalink / raw)
  Cc: jpw, emacs-devel

On Wed, 30 Oct 2002 12:18:04 -0500, Richard Stallman <rms@gnu.org> wrote:

> A warning is better.

OK. Next monday I'll rework the patch and install it.

                                                           /L/e/k/t/u

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

* Re: suggested new command `picture-mouse-set-point'
  2002-10-30 17:18                 ` Richard Stallman
  2002-10-30 17:51                   ` Juanma Barranquero
@ 2002-11-04 11:13                   ` Juanma Barranquero
  2002-11-04 15:02                     ` Juanma Barranquero
  1 sibling, 1 reply; 35+ messages in thread
From: Juanma Barranquero @ 2002-11-04 11:13 UTC (permalink / raw)
  Cc: emacs-devel

On Wed, 30 Oct 2002 12:18:04 -0500, Richard Stallman <rms@gnu.org> wrote:

> A warning is better.  The user can always undo the insertion,
> so it is harmless to go ahead; but the question would be annoying.

OK, here's the (still uncommited) "definitive" patch.

I assume when you say "a warning" you mean through `message', not `warn'.

The only controversial issue in this new patch is that I've decided to
add an optional PREDICATE argument to `find-buffer-visiting' instead of
adding a new `find-buffer-visiting-1' function as in the previous one.
As `find-buffer-visiting' is not a command but a function to be called
from lisp programs, it seems better to me.  Calls to
`find-buffer-visiting' with no PREDICATE do now a funcall to the
`identity' built-in, but that shouldn't be that expensive.

Comments?

                                                           /L/e/k/t/u



Index: files.el
===================================================================
RCS file: /cvs/emacs/lisp/files.el,v
retrieving revision 1.620
diff -u -2 -r1.620 files.el
--- files.el	26 Oct 2002 22:34:14 -0000	1.620
+++ files.el	4 Nov 2002 11:05:26 -0000
@@ -1048,38 +1048,42 @@
   :group 'find-file)
 
-(defun find-buffer-visiting (filename)
+(defun find-buffer-visiting (filename &optional predicate)
   "Return the buffer visiting file FILENAME (a string).
 This is like `get-file-buffer', except that it checks for any buffer
 visiting the same file, possibly under a different name.
+If PREDICATE is non-nil, only a buffer satisfying it can be returned.
 If there is no such live buffer, return nil."
-  (let ((buf (get-file-buffer filename))
-	(truename (abbreviate-file-name (file-truename filename))))
-    (or buf
-	(let ((list (buffer-list)) found)
-	  (while (and (not found) list)
-	    (save-excursion
-	      (set-buffer (car list))
-	      (if (and buffer-file-name
-		       (string= buffer-file-truename truename))
-		  (setq found (car list))))
-	    (setq list (cdr list)))
-	  found)
-	(let* ((attributes (file-attributes truename))
-	       (number (nthcdr 10 attributes))
-	       (list (buffer-list)) found)
-	  (and buffer-file-numbers-unique
-	       number
-	       (while (and (not found) list)
-		 (with-current-buffer (car list)
-		   (if (and buffer-file-name
-			    (equal buffer-file-number number)
-			    ;; Verify this buffer's file number
-			    ;; still belongs to its file.
-			    (file-exists-p buffer-file-name)
-			    (equal (file-attributes buffer-file-truename)
-				   attributes))
-		       (setq found (car list))))
-		 (setq list (cdr list))))
-	  found))))
+  (let ((predicate (or predicate #'identity))
+        (filename (abbreviate-file-name (file-truename filename))))
+    (or (let ((buf (get-file-buffer filename)))
+          (when (and buf (funcall predicate buf)) buf))
+        (let ((list (buffer-list)) found)
+          (while (and (not found) list)
+            (save-excursion
+              (set-buffer (car list))
+              (if (and buffer-file-name
+                       (string= buffer-file-truename filename)
+                       (funcall predicate (current-buffer)))
+                  (setq found (car list))))
+            (setq list (cdr list)))
+          found)
+        (let* ((attributes (file-attributes filename))
+               (number (nthcdr 10 attributes))
+               (list (buffer-list)) found)
+          (and buffer-file-numbers-unique
+               number
+               (while (and (not found) list)
+                 (with-current-buffer (car list)
+                   (if (and buffer-file-name
+                            (equal buffer-file-number number)
+                            ;; Verify this buffer's file number
+                            ;; still belongs to its file.
+                            (file-exists-p buffer-file-name)
+                            (equal (file-attributes buffer-file-truename)
+                                   attributes)
+                            (funcall predicate (current-buffer)))
+                       (setq found (car list))))
+                 (setq list (cdr list))))
+          found))))
 \f
 (defcustom find-file-wildcards t
@@ -1336,4 +1340,16 @@
 	(fmakunbound 'find-buffer-file-type)))))
 
+(defun insert-file-1 (filename insert-func)
+  (if (file-directory-p filename)
+      (signal 'file-error (list "Opening input file" "file is a directory"
+                                filename)))
+  (let* ((buffer (find-buffer-visiting (abbreviate-file-name (file-truename filename))
+                                       #'buffer-modified-p))
+         (tem (funcall insert-func filename)))
+    (push-mark (+ (point) (car (cdr tem))))
+    (when buffer
+      (message "File %s already visited and modified in buffer %s"
+               filename (buffer-name buffer)))))
+
 (defun insert-file-literally (filename)
   "Insert contents of file FILENAME into buffer after point with no conversion.
@@ -1343,9 +1359,5 @@
 \(Its calling sequence is different; see its documentation)."
   (interactive "*fInsert file literally: ")
-  (if (file-directory-p filename)
-      (signal 'file-error (list "Opening input file" "file is a directory"
-				filename)))
-  (let ((tem (insert-file-contents-literally filename)))
-    (push-mark (+ (point) (car (cdr tem))))))
+  (insert-file-1 filename #'insert-file-contents-literally))
 
 (defvar find-file-literally nil
@@ -3148,9 +3160,5 @@
 \(Its calling sequence is different; see its documentation)."
   (interactive "*fInsert file: ")
-  (if (file-directory-p filename)
-      (signal 'file-error (list "Opening input file" "file is a directory"
-				filename)))
-  (let ((tem (insert-file-contents filename)))
-    (push-mark (+ (point) (car (cdr tem))))))
+  (insert-file-1 filename #'insert-file-contents))
 
 (defun append-to-file (start end filename)

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

* Re: suggested new command `picture-mouse-set-point'
  2002-11-04 11:13                   ` Juanma Barranquero
@ 2002-11-04 15:02                     ` Juanma Barranquero
  2002-11-05  5:13                       ` Richard Stallman
  0 siblings, 1 reply; 35+ messages in thread
From: Juanma Barranquero @ 2002-11-04 15:02 UTC (permalink / raw)
  Cc: emacs-devel

On Mon, 04 Nov 2002 12:13:48 +0100, Juanma Barranquero <lektu@terra.es> wrote:

> OK, here's the (still uncommited) "definitive" patch.

Er, *this* one I mean.  Little change, but I prefer not to mess with the
filename passed to `get-file-buffer'.


                                                           /L/e/k/t/u



Index: files.el
===================================================================
RCS file: /cvs/emacs/lisp/files.el,v
retrieving revision 1.620
diff -u -2 -r1.620 files.el
--- files.el	26 Oct 2002 22:34:14 -0000	1.620
+++ files.el	4 Nov 2002 14:47:17 -0000
@@ -1048,38 +1048,42 @@
   :group 'find-file)
 
-(defun find-buffer-visiting (filename)
+(defun find-buffer-visiting (filename &optional predicate)
   "Return the buffer visiting file FILENAME (a string).
 This is like `get-file-buffer', except that it checks for any buffer
 visiting the same file, possibly under a different name.
+If PREDICATE is non-nil, only a buffer satisfying it can be returned.
 If there is no such live buffer, return nil."
-  (let ((buf (get-file-buffer filename))
-	(truename (abbreviate-file-name (file-truename filename))))
-    (or buf
-	(let ((list (buffer-list)) found)
-	  (while (and (not found) list)
-	    (save-excursion
-	      (set-buffer (car list))
-	      (if (and buffer-file-name
-		       (string= buffer-file-truename truename))
-		  (setq found (car list))))
-	    (setq list (cdr list)))
-	  found)
-	(let* ((attributes (file-attributes truename))
-	       (number (nthcdr 10 attributes))
-	       (list (buffer-list)) found)
-	  (and buffer-file-numbers-unique
-	       number
-	       (while (and (not found) list)
-		 (with-current-buffer (car list)
-		   (if (and buffer-file-name
-			    (equal buffer-file-number number)
-			    ;; Verify this buffer's file number
-			    ;; still belongs to its file.
-			    (file-exists-p buffer-file-name)
-			    (equal (file-attributes buffer-file-truename)
-				   attributes))
-		       (setq found (car list))))
-		 (setq list (cdr list))))
-	  found))))
+  (let ((predicate (or predicate #'identity))
+        (truename (abbreviate-file-name (file-truename filename))))
+    (or (let ((buf (get-file-buffer filename)))
+          (when (and buf (funcall predicate buf)) buf))
+        (let ((list (buffer-list)) found)
+          (while (and (not found) list)
+            (save-excursion
+              (set-buffer (car list))
+              (if (and buffer-file-name
+                       (string= buffer-file-truename truename)
+                       (funcall predicate (current-buffer)))
+                  (setq found (car list))))
+            (setq list (cdr list)))
+          found)
+        (let* ((attributes (file-attributes truename))
+               (number (nthcdr 10 attributes))
+               (list (buffer-list)) found)
+          (and buffer-file-numbers-unique
+               number
+               (while (and (not found) list)
+                 (with-current-buffer (car list)
+                   (if (and buffer-file-name
+                            (equal buffer-file-number number)
+                            ;; Verify this buffer's file number
+                            ;; still belongs to its file.
+                            (file-exists-p buffer-file-name)
+                            (equal (file-attributes buffer-file-truename)
+                                   attributes)
+                            (funcall predicate (current-buffer)))
+                       (setq found (car list))))
+                 (setq list (cdr list))))
+          found))))
 \f
 (defcustom find-file-wildcards t
@@ -1336,4 +1340,16 @@
 	(fmakunbound 'find-buffer-file-type)))))
 
+(defun insert-file-1 (filename insert-func)
+  (if (file-directory-p filename)
+      (signal 'file-error (list "Opening input file" "file is a directory"
+                                filename)))
+  (let* ((buffer (find-buffer-visiting (abbreviate-file-name (file-truename filename))
+                                       #'buffer-modified-p))
+         (tem (funcall insert-func filename)))
+    (push-mark (+ (point) (car (cdr tem))))
+    (when buffer
+      (message "File %s already visited and modified in buffer %s"
+               filename (buffer-name buffer)))))
+
 (defun insert-file-literally (filename)
   "Insert contents of file FILENAME into buffer after point with no conversion.
@@ -1343,9 +1359,5 @@
 \(Its calling sequence is different; see its documentation)."
   (interactive "*fInsert file literally: ")
-  (if (file-directory-p filename)
-      (signal 'file-error (list "Opening input file" "file is a directory"
-				filename)))
-  (let ((tem (insert-file-contents-literally filename)))
-    (push-mark (+ (point) (car (cdr tem))))))
+  (insert-file-1 filename #'insert-file-contents-literally))
 
 (defvar find-file-literally nil
@@ -3148,9 +3160,5 @@
 \(Its calling sequence is different; see its documentation)."
   (interactive "*fInsert file: ")
-  (if (file-directory-p filename)
-      (signal 'file-error (list "Opening input file" "file is a directory"
-				filename)))
-  (let ((tem (insert-file-contents filename)))
-    (push-mark (+ (point) (car (cdr tem))))))
+  (insert-file-1 filename #'insert-file-contents))
 
 (defun append-to-file (start end filename)

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

* Re: suggested new command `picture-mouse-set-point'
  2002-11-04 15:02                     ` Juanma Barranquero
@ 2002-11-05  5:13                       ` Richard Stallman
  0 siblings, 0 replies; 35+ messages in thread
From: Richard Stallman @ 2002-11-05  5:13 UTC (permalink / raw)
  Cc: emacs-devel

    > OK, here's the (still uncommited) "definitive" patch.

    Er, *this* one I mean.  Little change, but I prefer not to mess with the
    filename passed to `get-file-buffer'.

This version looks good.  Please install it.

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

end of thread, other threads:[~2002-11-05  5:13 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-23 18:04 suggested new command `picture-mouse-set-point' John Paul Wallington
2002-10-24  0:31 ` Kim F. Storm
2002-10-24  9:18   ` John Paul Wallington
2002-10-24 21:42     ` Kim F. Storm
2002-10-24 23:18       ` John Paul Wallington
2002-10-24 23:37         ` Stefan Monnier
2002-10-25  1:42           ` John Paul Wallington
2002-10-25 14:19             ` Stefan Monnier
2002-10-25 22:50               ` Kevin Ryde
2002-10-25 22:57               ` John Paul Wallington
2002-10-25  9:16           ` Kim F. Storm
2002-10-25 14:11             ` Stefan Monnier
2002-10-26 12:34               ` Kai Großjohann
2002-10-26 20:14         ` Richard Stallman
2002-10-28 15:20           ` Juanma Barranquero
2002-10-28 18:26             ` Eli Zaretskii
2002-10-29  7:23               ` Juanma Barranquero
2002-10-29 19:38                 ` Eli Zaretskii
2002-10-29  3:01             ` Richard Stallman
2002-10-28 15:31           ` Juanma Barranquero
2002-10-29  3:02             ` Richard Stallman
2002-10-29 17:59               ` Juanma Barranquero
2002-10-30 11:55                 ` Kim F. Storm
2002-10-30 12:47                   ` Juanma Barranquero
2002-10-30 17:18                 ` Richard Stallman
2002-10-30 17:51                   ` Juanma Barranquero
2002-11-04 11:13                   ` Juanma Barranquero
2002-11-04 15:02                     ` Juanma Barranquero
2002-11-05  5:13                       ` Richard Stallman
2002-10-26 20:13       ` Richard Stallman
2002-10-25  5:35   ` Richard Stallman
2002-10-25  9:49     ` Kim F. Storm
2002-10-26 20:15       ` Richard Stallman
2002-10-24 16:55 ` Richard Stallman
2002-10-24 23:21   ` John Paul Wallington

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.