aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Olson <mwolson@gnu.org>2009-08-05 08:07:03 -0700
committerMichael Olson <mwolson@gnu.org>2009-08-05 08:07:03 -0700
commit2c1c56d553df6ee1973134fdb90543454b1146ca (patch)
tree24c99ac1faa709960a83a5922ddcd176ea4082e3
parent8176350744ebefe066478bfc3de9a00e34261b77 (diff)
Introduce emms-insert-file-contents.
This function is a safe way to insert the contents of a file without triggering major mode detection, and has been tested on several versions of Emacs and XEmacs.
-rw-r--r--lisp/emms-history.el2
-rw-r--r--lisp/emms-lyrics.el2
-rw-r--r--lisp/emms-player-mpd.el2
-rw-r--r--lisp/emms-score.el2
-rw-r--r--lisp/emms-source-playlist.el8
-rw-r--r--lisp/emms-streams.el2
-rw-r--r--lisp/emms.el21
7 files changed, 30 insertions, 9 deletions
diff --git a/lisp/emms-history.el b/lisp/emms-history.el
index 7526e87..feba6c7 100644
--- a/lisp/emms-history.el
+++ b/lisp/emms-history.el
@@ -112,7 +112,7 @@ Emacs."
(file-exists-p emms-history-file))
(let (history buf)
(with-temp-buffer
- (insert-file-contents emms-history-file)
+ (emms-insert-file-contents emms-history-file)
(setq history (read (current-buffer)))
(dolist (playlist (cadr history))
(with-current-buffer (emms-playlist-new (car playlist))
diff --git a/lisp/emms-lyrics.el b/lisp/emms-lyrics.el
index 1645351..1e15c2e 100644
--- a/lisp/emms-lyrics.el
+++ b/lisp/emms-lyrics.el
@@ -254,7 +254,7 @@ FILE should be under the same directory as the music file, or under
(when (and file (file-exists-p file))
(with-temp-buffer
(let ((coding-system-for-read emms-lyrics-coding-system))
- (insert-file-contents file)
+ (emms-insert-file-contents file)
(while (search-forward-regexp "\\[[0-9:.]+\\].*" nil t)
(let ((lyric-string (match-string 0))
(time 0)
diff --git a/lisp/emms-player-mpd.el b/lisp/emms-player-mpd.el
index 539dce6..fa8f911 100644
--- a/lisp/emms-player-mpd.el
+++ b/lisp/emms-player-mpd.el
@@ -775,7 +775,7 @@ Execute CALLBACK with CLOSURE as its first argument when done.
This handles both m3u and pls type playlists."
;; This is useful for playlists of playlists
(with-temp-buffer
- (insert-file-contents playlist)
+ (emms-insert-file-contents playlist)
(emms-player-mpd-add-buffer-contents (current-buffer) closure callback)))
(defun emms-player-mpd-add-streamlist (url closure callback)
diff --git a/lisp/emms-score.el b/lisp/emms-score.el
index a606c25..71e65a3 100644
--- a/lisp/emms-score.el
+++ b/lisp/emms-score.el
@@ -249,7 +249,7 @@ See also `emms-next-noerror'."
(puthash (car elt) (cdr elt) emms-score-hash))
(read
(with-temp-buffer
- (insert-file-contents emms-score-file)
+ (emms-insert-file-contents emms-score-file)
(buffer-string))))
;; when file not exists, make empty but valid score file
(emms-score-save-hash)))
diff --git a/lisp/emms-source-playlist.el b/lisp/emms-source-playlist.el
index 57a299d..b7677ec 100644
--- a/lisp/emms-source-playlist.el
+++ b/lisp/emms-source-playlist.el
@@ -177,7 +177,7 @@ See `emms-source-playlist-formats' for a list of supported formats."
t)))
(mapc #'emms-playlist-insert-track
(with-temp-buffer
- (insert-file-contents file)
+ (emms-insert-file-contents file)
(goto-char (point-min))
(let ((format (emms-source-playlist-determine-format)))
(if format
@@ -234,7 +234,7 @@ OUT should be the buffer where tracks are stored in the native EMMS format."
t)))
(mapc #'emms-playlist-insert-track
(with-temp-buffer
- (insert-file-contents file)
+ (emms-insert-file-contents file)
(goto-char (point-min))
(when (not (emms-source-playlist-native-p))
(error "Not a native EMMS playlist file."))
@@ -307,7 +307,7 @@ OUT should be the buffer where tracks are stored in m3u format."
t)))
(mapc #'emms-playlist-insert-track
(with-temp-buffer
- (insert-file-contents file)
+ (emms-insert-file-contents file)
(goto-char (point-min))
(when (not (emms-source-playlist-m3u-p))
(error "Not an m3u playlist file."))
@@ -388,7 +388,7 @@ OUT should be the buffer where tracks are stored in pls format."
t)))
(mapc #'emms-playlist-insert-track
(with-temp-buffer
- (insert-file-contents file)
+ (emms-insert-file-contents file)
(goto-char (point-min))
(when (not (emms-source-playlist-pls-p))
(error "Not a pls playlist file."))
diff --git a/lisp/emms-streams.el b/lisp/emms-streams.el
index bece71e..b81abe7 100644
--- a/lisp/emms-streams.el
+++ b/lisp/emms-streams.el
@@ -323,7 +323,7 @@ POPUP-HEIGHT is the height of the new frame, defaulting to
(let ((file (expand-file-name file)))
(if (file-readable-p file)
(with-temp-buffer
- (insert-file-contents-literally file)
+ (emms-insert-file-contents file)
(goto-char (point-min))
(read (current-buffer)))
emms-stream-default-list)))
diff --git a/lisp/emms.el b/lisp/emms.el
index 750781d..3c5402d 100644
--- a/lisp/emms.el
+++ b/lisp/emms.el
@@ -528,6 +528,27 @@ See `completing-read' for a description of ARGS."
(require 'emms-compat)
+;;; Utility functions
+
+(defun emms-insert-file-contents (filename &optional visit)
+ "Insert the contents of file FILENAME after point.
+Do character code conversion and end-of-line conversion, but none
+of the other unnecessary things like format decoding or
+`find-file-hook'.
+
+If VISIT is non-nil, the buffer's visited filename
+and last save file modtime are set, and it is marked unmodified.
+If visiting and the file does not exist, visiting is completed
+before the error is signaled."
+ (let ((format-alist nil)
+ (after-insert-file-functions nil)
+ (inhibit-file-name-handlers
+ (append '(jka-compr-handler image-file-handler epa-file-handler)
+ inhibit-file-name-handlers))
+ (inhibit-file-name-operation 'insert-file-contents))
+ (insert-file-contents filename visit)))
+
+
;;; Dictionaries
;; This is a simple helper data structure, used by both players