From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.devel Subject: Re: suggested new command `picture-mouse-set-point' Date: Tue, 29 Oct 2002 18:59:04 +0100 Sender: emacs-devel-admin@gnu.org Message-ID: <20021029185552.A0B9.LEKTU@terra.es> References: <20021028162541.9CE4.LEKTU@terra.es> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1035914408 22692 80.91.224.249 (29 Oct 2002 18:00:08 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 29 Oct 2002 18:00:08 +0000 (UTC) Cc: jpw@shootybangbang.com, emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 186aen-0005tb-00 for ; Tue, 29 Oct 2002 19:00:01 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 186ajV-0002vm-00 for ; Tue, 29 Oct 2002 19:04:53 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 186afB-0002PF-00; Tue, 29 Oct 2002 13:00:25 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 186ae3-000222-00 for emacs-devel@gnu.org; Tue, 29 Oct 2002 12:59:15 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 186adx-00020h-00 for emacs-devel@gnu.org; Tue, 29 Oct 2002 12:59:14 -0500 Original-Received: from [62.22.27.141] (helo=mail.peoplecall.com) by monty-python.gnu.org with esmtp (Exim 4.10) id 186adx-0001z3-00; Tue, 29 Oct 2002 12:59:09 -0500 Original-Received: from [62.22.27.143] (jbarranquero.ofi.peoplecall.com [62.22.27.143]) by mail.peoplecall.com (8.11.6/8.11.6) with ESMTP id g9THx4b05527; Tue, 29 Oct 2002 18:59:04 +0100 Original-To: rms@gnu.org In-Reply-To: X-Mailer: Becky! ver. 2.05.06 Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:8921 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:8921 On Mon, 28 Oct 2002 22:02:02 -0500, Richard Stallman 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)