comparison lisp/files.el @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 576fb035e263
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
871 found)))) 871 found))))
872 872
873 (defun insert-file-contents-literally (filename &optional visit beg end replace) 873 (defun insert-file-contents-literally (filename &optional visit beg end replace)
874 "Like `insert-file-contents', q.v., but only reads in the file. 874 "Like `insert-file-contents', q.v., but only reads in the file.
875 A buffer may be modified in several ways after reading into the buffer due 875 A buffer may be modified in several ways after reading into the buffer due
876 to advanced Emacs features, such as file-name-handlers, format decoding, 876 to advanced Emacs features, such as format decoding, character code
877 find-file-hooks, etc. 877 conversion,find-file-hooks, automatic uncompression, etc.
878
878 This function ensures that none of these modifications will take place." 879 This function ensures that none of these modifications will take place."
879 (let ((file-name-handler-alist nil) 880 (let ((wrap-func (find-file-name-handler filename
880 (format-alist nil) 881 'insert-file-contents-literally)))
881 (after-insert-file-functions nil) 882 (if wrap-func
882 (find-buffer-file-type-function 883 (funcall wrap-func 'insert-file-contents-literally filename
883 (if (fboundp 'find-buffer-file-type) 884 visit beg end replace)
884 (symbol-function 'find-buffer-file-type) 885 (let ((file-name-handler-alist nil)
885 nil))) 886 (format-alist nil)
886 (unwind-protect 887 (after-insert-file-functions nil)
887 (progn 888 (coding-system-for-read 'binary)
888 (fset 'find-buffer-file-type (lambda (filename) t)) 889 (coding-system-for-write 'binary)
889 (insert-file-contents filename visit beg end replace)) 890 (find-buffer-file-type-function
890 (if find-buffer-file-type-function 891 (if (fboundp 'find-buffer-file-type)
891 (fset 'find-buffer-file-type find-buffer-file-type-function) 892 (symbol-function 'find-buffer-file-type)
892 (fmakunbound 'find-buffer-file-type))))) 893 nil)))
894 (unwind-protect
895 (progn
896 (fset 'find-buffer-file-type (lambda (filename) t))
897 (insert-file-contents filename visit beg end replace))
898 (if find-buffer-file-type-function
899 (fset 'find-buffer-file-type find-buffer-file-type-function)
900 (fmakunbound 'find-buffer-file-type)))))))
893 901
894 (defun find-file-noselect (filename &optional nowarn rawfile) 902 (defun find-file-noselect (filename &optional nowarn rawfile)
895 "Read file FILENAME into a buffer and return the buffer. 903 "Read file FILENAME into a buffer and return the buffer.
896 If a buffer exists visiting FILENAME, return that one, but 904 If a buffer exists visiting FILENAME, return that one, but
897 verify that the file has not changed since visited or saved. 905 verify that the file has not changed since visited or saved.
1026 nil 1034 nil
1027 (after-find-file error (not nowarn)) 1035 (after-find-file error (not nowarn))
1028 (setq buf (current-buffer)))) 1036 (setq buf (current-buffer))))
1029 (t 1037 (t
1030 (kill-buffer buf) 1038 (kill-buffer buf)
1031 (signal (car data) (cdr data)))))) 1039 (signal (car data) (cdr data))))
1040 ))
1032 buf))) 1041 buf)))
1033 1042
1034 ;; FSF has `insert-file-literally' and `find-file-literally' here. 1043 ;; FSF has `insert-file-literally' and `find-file-literally' here.
1035 1044
1036 (defvar after-find-file-from-revert-buffer nil) 1045 (defvar after-find-file-from-revert-buffer nil)
1167 ("\\.pro\\'" . idlwave-mode) 1176 ("\\.pro\\'" . idlwave-mode)
1168 ;; #### Unix-specific! 1177 ;; #### Unix-specific!
1169 ("/\\.\\(?:bash_\\|z\\)?\\(profile\\|login\\|logout\\)\\'" . sh-mode) 1178 ("/\\.\\(?:bash_\\|z\\)?\\(profile\\|login\\|logout\\)\\'" . sh-mode)
1170 ("/\\.\\(?:[ckz]sh\\|bash\\|tcsh\\|es\\|xinit\\|startx\\)rc\\'" . sh-mode) 1179 ("/\\.\\(?:[ckz]sh\\|bash\\|tcsh\\|es\\|xinit\\|startx\\)rc\\'" . sh-mode)
1171 ("/\\.\\(?:[kz]shenv\\|xsession\\)\\'" . sh-mode) 1180 ("/\\.\\(?:[kz]shenv\\|xsession\\)\\'" . sh-mode)
1181 ("\\.m?spec$" .sh-mode)
1172 ;; The following come after the ChangeLog pattern for the sake of 1182 ;; The following come after the ChangeLog pattern for the sake of
1173 ;; ChangeLog.1, etc. and after the .scm.[0-9] pattern too. 1183 ;; ChangeLog.1, etc. and after the .scm.[0-9] pattern too.
1174 ("\\.[12345678]\\'" . nroff-mode) 1184 ("\\.[12345678]\\'" . nroff-mode)
1175 ("\\.[tT]e[xX]\\'" . tex-mode) 1185 ("\\.[tT]e[xX]\\'" . tex-mode)
1176 ("\\.\\(?:sty\\|cls\\|bbl\\)\\'" . latex-mode) 1186 ("\\.\\(?:sty\\|cls\\|bbl\\)\\'" . latex-mode)
1191 ("^/tmp/fol/" . text-mode) 1201 ("^/tmp/fol/" . text-mode)
1192 ("\\.y\\'" . c-mode) 1202 ("\\.y\\'" . c-mode)
1193 ("\\.lex\\'" . c-mode) 1203 ("\\.lex\\'" . c-mode)
1194 ("\\.m\\'" . objc-mode) 1204 ("\\.m\\'" . objc-mode)
1195 ("\\.oak\\'" . scheme-mode) 1205 ("\\.oak\\'" . scheme-mode)
1196 ("\\.s?html?\\'" . html-mode) 1206 ("\\.[sj]?html?\\'" . html-mode)
1207 ("\\.jsp\\'" . html-mode)
1208 ("\\.xml\\'" . xml-mode)
1197 ("\\.htm?l?3\\'" . html3-mode) 1209 ("\\.htm?l?3\\'" . html3-mode)
1198 ("\\.\\(?:sgml?\\|dtd\\)\\'" . sgml-mode) 1210 ("\\.\\(?:sgml?\\|dtd\\)\\'" . sgml-mode)
1199 ("\\.c?ps\\'" . postscript-mode) 1211 ("\\.c?ps\\'" . postscript-mode)
1200 ;; .emacs following a directory delimiter in either Unix or 1212 ;; .emacs following a directory delimiter in either Unix or
1201 ;; Windows syntax. 1213 ;; Windows syntax.
1202 ("[/\\][._].*emacs\\'" . emacs-lisp-mode) 1214 ("[/\\][._].*emacs\\'" . emacs-lisp-mode)
1203 ("\\.m4\\'" . autoconf-mode) 1215 ("\\.m4\\'" . autoconf-mode)
1204 ("configure\\.in\\'" . autoconf-mode) 1216 ("configure\\.in\\'" . autoconf-mode)
1205 ("\\.ml\\'" . lisp-mode) 1217 ("\\.ml\\'" . lisp-mode)
1206 ("\\.ma?k\\'" . makefile-mode) 1218 ("\\.ma?ke?\\'" . makefile-mode)
1207 ("[Mm]akefile\\(\\.\\|\\'\\)" . makefile-mode) 1219 ("[Mm]akefile\\(\\.\\|\\'\\)" . makefile-mode)
1208 ("\\.X\\(defaults\\|environment\\|resources\\|modmap\\)\\'" . xrdb-mode) 1220 ("\\.X\\(defaults\\|environment\\|resources\\|modmap\\)\\'" . xrdb-mode)
1209 ;; #### The following three are Unix-specific (but do we care?) 1221 ;; #### The following three are Unix-specific (but do we care?)
1210 ("/app-defaults/" . xrdb-mode) 1222 ("/app-defaults/" . xrdb-mode)
1211 ("\\.[^/]*wm2?\\(?:rc\\)?\\'" . winmgr-mode) 1223 ("\\.[^/]*wm2?\\(?:rc\\)?\\'" . winmgr-mode)
1537 (point)))) 1549 (point))))
1538 ;; Parse the -*- line into the `result' alist. 1550 ;; Parse the -*- line into the `result' alist.
1539 (cond ((not (search-forward "-*-" end t)) 1551 (cond ((not (search-forward "-*-" end t))
1540 ;; doesn't have one. 1552 ;; doesn't have one.
1541 (setq force t)) 1553 (setq force t))
1542 ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)") 1554 ((looking-at "[ \t]*\\([^ \t\n\r:;]+?\\)\\([ \t]*-\\*-\\)")
1543 ;; Antiquated form: "-*- ModeName -*-". 1555 ;; Antiquated form: "-*- ModeName -*-".
1544 (setq result 1556 (setq result
1545 (list (cons 'mode 1557 (list (cons 'mode
1546 (intern (buffer-substring 1558 (intern (buffer-substring
1547 (match-beginning 1) 1559 (match-beginning 1)
1829 (read-file-name "Write file: " 1841 (read-file-name "Write file: "
1830 (cdr (assq 'default-directory 1842 (cdr (assq 'default-directory
1831 (buffer-local-variables))) 1843 (buffer-local-variables)))
1832 nil nil (buffer-name))) 1844 nil nil (buffer-name)))
1833 t 1845 t
1834 (if (and current-prefix-arg (featurep 'mule)) 1846 (if (and current-prefix-arg (featurep 'file-coding))
1835 (read-coding-system "Coding system: ")))) 1847 (read-coding-system "Coding system: "))))
1836 (and (eq (current-buffer) mouse-grabbed-buffer) 1848 (and (eq (current-buffer) mouse-grabbed-buffer)
1837 (error "Can't write minibuffer window")) 1849 (error "Can't write minibuffer window"))
1838 (or (null filename) (string-equal filename "") 1850 (or (null filename) (string-equal filename "")
1839 (progn 1851 (progn
2078 2090
2079 (defun file-relative-name (filename &optional directory) 2091 (defun file-relative-name (filename &optional directory)
2080 "Convert FILENAME to be relative to DIRECTORY (default: default-directory). 2092 "Convert FILENAME to be relative to DIRECTORY (default: default-directory).
2081 This function returns a relative file name which is equivalent to FILENAME 2093 This function returns a relative file name which is equivalent to FILENAME
2082 when used with that default directory as the default. 2094 when used with that default directory as the default.
2083 If this is impossible (which can happen on MSDOS and Windows 2095 If this is impossible (which can happen on MS Windows when the file name
2084 when the file name and directory use different drive names) 2096 and directory use different drive names) then it returns FILENAME."
2085 then it returns FILENAME."
2086 (save-match-data 2097 (save-match-data
2087 (let ((fname (expand-file-name filename))) 2098 (let ((fname (expand-file-name filename)))
2088 (setq directory (file-name-as-directory 2099 (setq directory (file-name-as-directory
2089 (expand-file-name (or directory default-directory)))) 2100 (expand-file-name (or directory default-directory))))
2090 ;; On Microsoft OSes, if FILENAME and DIRECTORY have different 2101 ;; On Microsoft OSes, if FILENAME and DIRECTORY have different
2457 (lambda (ignore) 2468 (lambda (ignore)
2458 (exit-recursive-edit))) 2469 (exit-recursive-edit)))
2459 (recursive-edit) 2470 (recursive-edit)
2460 ;; Return nil to ask about BUF again. 2471 ;; Return nil to ask about BUF again.
2461 nil) 2472 nil)
2462 "display the current buffer")))) 2473 "%_Display Buffer"))))
2463 (abbrevs-done 2474 (abbrevs-done
2464 (and save-abbrevs abbrevs-changed 2475 (and save-abbrevs abbrevs-changed
2465 (progn 2476 (progn
2466 (if (or arg 2477 (if (or arg
2467 (y-or-n-p (format "Save abbrevs in %s? " abbrev-file-name))) 2478 (y-or-n-p (format "Save abbrevs in %s? " abbrev-file-name)))