From: Pavel@Janik.cz (Pavel Janík)
Subject: TODO: insert-file should warn if the file is modified
Date: Fri, 19 Apr 2002 14:58:37 +0200 [thread overview]
Message-ID: <m3adrzalqa.fsf@Janik.cz> (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)
next reply other threads:[~2002-04-19 12:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-19 12:58 Pavel Janík [this message]
2002-04-19 13:47 ` TODO: insert-file should warn if the file is modified 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3adrzalqa.fsf@Janik.cz \
--to=pavel@janik.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.