[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: suggested new command `picture-mouse-set-point'
From: |
Juanma Barranquero |
Subject: |
Re: suggested new command `picture-mouse-set-point' |
Date: |
Tue, 29 Oct 2002 18:59:04 +0100 |
On Mon, 28 Oct 2002 22:02:02 -0500, Richard Stallman <address@hidden> 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))))
(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)
- Re: suggested new command `picture-mouse-set-point', (continued)
- Re: suggested new command `picture-mouse-set-point', Richard Stallman, 2002/10/26
- Re: suggested new command `picture-mouse-set-point', Juanma Barranquero, 2002/10/28
- Re: suggested new command `picture-mouse-set-point', Eli Zaretskii, 2002/10/28
- Re: suggested new command `picture-mouse-set-point', Juanma Barranquero, 2002/10/29
- Re: suggested new command `picture-mouse-set-point', Eli Zaretskii, 2002/10/29
- Re: suggested new command `picture-mouse-set-point', Richard Stallman, 2002/10/28
- Re: suggested new command `picture-mouse-set-point', Juanma Barranquero, 2002/10/28
- Re: suggested new command `picture-mouse-set-point', Richard Stallman, 2002/10/28
- Re: suggested new command `picture-mouse-set-point',
Juanma Barranquero <=
- Re: suggested new command `picture-mouse-set-point', Richard Stallman, 2002/10/30
- Re: suggested new command `picture-mouse-set-point', Juanma Barranquero, 2002/10/30
- Re: suggested new command `picture-mouse-set-point', Richard Stallman, 2002/10/26
Re: suggested new command `picture-mouse-set-point', Richard Stallman, 2002/10/25
Re: suggested new command `picture-mouse-set-point', Richard Stallman, 2002/10/24
Re: suggested new command `picture-mouse-set-point', Kim F. Storm, 2002/10/30