unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* TODO: insert-file should warn if the file is modified
@ 2002-04-19 12:58 Pavel Janík
  2002-04-19 13:47 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Pavel Janík @ 2002-04-19 12:58 UTC (permalink / raw)


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= 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? " filename buffer)))
	(let ((tem (insert-file-contents filename)))
	  (push-mark (+ (point) (car (cdr tem))))))))


What do you think?
-- 
Pavel Janík

Use recursive procedures for recursively-defined data structures.
                  --  The Elements of Programming Style (Kernighan & Plaugher)

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

end of thread, other threads:[~2002-04-22  7:46 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-19 12:58 TODO: insert-file should warn if the file is modified Pavel Janík
2002-04-19 13:47 ` Eli Zaretskii
2002-04-19 14:33   ` Andreas Schwab
2002-04-19 15:08     ` Pavel Janík
2002-04-19 15:07   ` Pavel Janík
2002-04-19 14:16 ` Kim F. Storm
2002-04-19 14:53   ` Pavel Janík
2002-04-20 17:26 ` Richard Stallman
2002-04-20 18:12   ` Pavel Janík
2002-04-21 13:29     ` Kim F. Storm
2002-04-22  7:46     ` Richard Stallman

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).