From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Pavel@Janik.cz (Pavel =?iso-8859-2?q?Jan=EDk?=) Newsgroups: gmane.emacs.devel Subject: TODO: insert-file should warn if the file is modified Date: Fri, 19 Apr 2002 14:58:37 +0200 Sender: emacs-devel-admin@gnu.org Message-ID: NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable X-Trace: main.gmane.org 1019221591 24537 127.0.0.1 (19 Apr 2002 13:06:31 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 19 Apr 2002 13:06:31 +0000 (UTC) Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 16yY5v-0006Ne-00 for ; Fri, 19 Apr 2002 15:06:31 +0200 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 16yYPH-0007jr-00 for ; Fri, 19 Apr 2002 15:26:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16yY5e-0002lq-00; Fri, 19 Apr 2002 09:06:14 -0400 Original-Received: from p0012.as-l043.contactel.cz ([194.108.242.12] helo=SnowWhite.SuSE.cz) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16yY4S-0002c3-00 for ; Fri, 19 Apr 2002 09:05:01 -0400 Original-Received: by SnowWhite.SuSE.cz (PJ, from userid 500) id F2D89183D5; Fri, 19 Apr 2002 15:07:21 +0200 (CEST) Original-To: emacs-devel@gnu.org Mail-Copies-To: never X-Face: $"d&^B_IKlTHX!y2d,3;grhwjOBqOli]LV`6d]58%5'x/kBd7.MO&n3bJ@Zkf&RfBu|^qL+ ?/Re{MpTqanXS2'~Qp'J2p^M7uM:zp[1Xq#{|C!*'&NvCC[9!|=>#qHqIhroq_S"MH8nSH+d^9*BF: iHiAs(t(~b#1.{w.d[=Z User-Agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2.50 (i386-suse-linux-gnu) Original-Lines: 48 Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:2774 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:2774 Hi, we have this entry in TODO: * If you do an insert-file and that file is currently modified in another buffer but not written yet, print a warning. I think that it is pretty simple: (defun file-is-modified-somewhere (filename) "Check if the file FILENAME is modified inside Emacs. Return buffer visiting the file FILENAME marked as modified. Otherwise, return nil." (let ((result)) (dolist (buffer (buffer-list) result) (if (and (string=3D filename (buffer-file-name buffer)) (buffer-modified-p buffer)) (setq result buffer))))) (defun insert-file (filename) "Insert contents of file FILENAME into buffer after point. Set mark after the inserted text. If the file is modified in some buffer, warn user. This function is meant for the user to run interactively. Don't call it from programs! Use `insert-file-contents' instead. \(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 ((buffer (file-is-modified-somewhere filename))) (if (or (not buffer) (y-or-n-p (format "File %s is modified in buffer %s. Insert it? " file= name buffer))) (let ((tem (insert-file-contents filename))) (push-mark (+ (point) (car (cdr tem)))))))) What do you think? --=20 Pavel Jan=EDk Use recursive procedures for recursively-defined data structures. -- The Elements of Programming Style (Kernighan & Plaugh= er)