Mercurial > hg > xemacs-beta
comparison lisp/prim/files.el @ 2:ac2d302a0011 r19-15b2
Import from CVS: tag r19-15b2
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:46:35 +0200 |
parents | 376386a54a3c |
children | b82b59fe008d |
comparison
equal
deleted
inserted
replaced
1:c0c6a60d29db | 2:ac2d302a0011 |
---|---|
274 ; (cons 'ange-ftp-completion-hook-function | 274 ; (cons 'ange-ftp-completion-hook-function |
275 ; (and (eq inhibit-file-name-operation op) | 275 ; (and (eq inhibit-file-name-operation op) |
276 ; inhibit-file-name-handlers))) | 276 ; inhibit-file-name-handlers))) |
277 ; (inhibit-file-name-operation op)) | 277 ; (inhibit-file-name-operation op)) |
278 ; (apply op args)) | 278 ; (apply op args)) |
279 | |
280 (defun convert-standard-filename (filename) | |
281 "Convert a standard file's name to something suitable for the current OS. | |
282 This function's standard definition is trivial; it just returns the argument. | |
283 However, on some systems, the function is redefined | |
284 with a definition that really does change some file names." | |
285 filename) | |
279 | 286 |
280 (defun pwd () | 287 (defun pwd () |
281 "Show the current default directory." | 288 "Show the current default directory." |
282 (interactive nil) | 289 (interactive nil) |
283 (message "Directory %s" default-directory)) | 290 (message "Directory %s" default-directory)) |
284 | 291 |
285 (defvar cd-path nil | 292 (defvar cd-path nil |
286 "Value of the CDPATH environment variable, as a list. | 293 "Value of the CDPATH environment variable, as a list. |
287 Not actually set up until the first time you you use it.") | 294 Not actually set up until the first time you use it.") |
288 | 295 |
289 (defvar path-separator ":" | 296 (defvar path-separator ":" |
290 "Character used to separate concatenated paths.") | 297 "Character used to separate concatenated paths.") |
291 | 298 |
292 (defun parse-colon-path (cd-path) | 299 (defun parse-colon-path (cd-path) |
542 (interactive "BSwitch to buffer in other window: ") | 549 (interactive "BSwitch to buffer in other window: ") |
543 (let ((pop-up-windows t)) | 550 (let ((pop-up-windows t)) |
544 ;; XEmacs: this used to have (selected-frame) as the third argument, | 551 ;; XEmacs: this used to have (selected-frame) as the third argument, |
545 ;; but this is obnoxious. If the user wants the buffer in a | 552 ;; but this is obnoxious. If the user wants the buffer in a |
546 ;; different frame, then it should be this way. | 553 ;; different frame, then it should be this way. |
547 (pop-to-buffer buffer t))) | 554 |
555 ;; Change documented above undone --mrb | |
556 (pop-to-buffer buffer t (selected-frame)))) | |
548 | 557 |
549 (defun switch-to-buffer-other-frame (buffer) | 558 (defun switch-to-buffer-other-frame (buffer) |
550 "Switch to buffer BUFFER in a newly-created frame." | 559 "Switch to buffer BUFFER in a newly-created frame." |
551 (interactive "BSwitch to buffer in other frame: ") | 560 (interactive "BSwitch to buffer in other frame: ") |
552 (let* ((name (get-frame-name-for-buffer buffer)) | 561 (let* ((name (get-frame-name-for-buffer buffer)) |
1015 (condition-case err | 1024 (condition-case err |
1016 (hack-local-variables (not find-file)) | 1025 (hack-local-variables (not find-file)) |
1017 (error (message "File local-variables error: %s" | 1026 (error (message "File local-variables error: %s" |
1018 (prin1-to-string err)))))) | 1027 (prin1-to-string err)))))) |
1019 | 1028 |
1020 (defvar auto-mode-alist (mapcar 'purecopy | 1029 (defvar auto-mode-alist |
1021 '(("\\.te?xt\\'" . text-mode) | 1030 (mapcar |
1022 ("\\.c\\'" . c-mode) | 1031 'purecopy |
1023 ("\\.h\\'" . c-mode) | 1032 '(("\\.te?xt\\'" . text-mode) |
1024 ("\\.tex\\'" . tex-mode) | 1033 ("\\.[ch]\\'" . c-mode) |
1025 ("\\.ltx\\'" . latex-mode) | 1034 ("\\.ltx\\'" . latex-mode) |
1026 ("\\.e\\'" . eiffel-mode) | 1035 ("\\.el\\'" . emacs-lisp-mode) |
1027 ("\\.el\\'" . emacs-lisp-mode) | 1036 ("\\.l\\(i?sp\\)?\\'" . lisp-mode) |
1028 ("\\.mm\\'" . nroff-mode) | 1037 ("\\.f\\(or\\)?\\'" . fortran-mode) |
1029 ("\\.me\\'" . nroff-mode) | 1038 ("\\.p\\(as\\)?\\'" . pascal-mode) |
1030 ("\\.ms\\'" . nroff-mode) | 1039 ("\\.ad[abs]\\'" . ada-mode) |
1031 ("\\.man\\'" . nroff-mode) | 1040 ("\\.pl\\'" . perl-mode) |
1032 ("\\.scm\\'" . scheme-mode) | 1041 ("\\.\\([CH]\\|cc\\|hh\\)\\'" . c++-mode) |
1033 ("\\.l\\'" . lisp-mode) | 1042 ("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode) |
1034 ("\\.lisp\\'" . lisp-mode) | 1043 ("\\.java\\'" . java-mode) |
1035 ("\\.f\\'" . fortran-mode) | 1044 ("\\.ma?k\\'" . makefile-mode) |
1036 ("\\.for\\'" . fortran-mode) | 1045 ("[Mm]akefile\\(.in\\)?\\(.in\\)?\\'" . makefile-mode) |
1037 ("\\.p\\'" . pascal-mode) | |
1038 ("\\.pas\\'" . pascal-mode) | |
1039 ("\\.mss\\'" . scribe-mode) | |
1040 ("\\.ad[abs]\\'" . ada-mode) | |
1041 ("\\.icn\\'" . icon-mode) | |
1042 ("\\.pl\\'" . perl-mode) | |
1043 ("\\.cc\\'" . c++-mode) | |
1044 ("\\.hh\\'" . c++-mode) | |
1045 ("\\.C\\'" . c++-mode) | |
1046 ("\\.H\\'" . c++-mode) | |
1047 ("\\.cpp\\'" . c++-mode) | |
1048 ("\\.cxx\\'" . c++-mode) | |
1049 ("\\.hxx\\'" . c++-mode) | |
1050 ("\\.c\\+\\+\\'" . c++-mode) | |
1051 ("\\.h\\+\\+\\'" . c++-mode) | |
1052 ("\\.java\\'" . java-mode) | |
1053 ("\\.mk\\'" . makefile-mode) | |
1054 ("\\.mak\\'" . makefile-mode) | |
1055 ("[Mm]akefile\\(.in\\)?\\'" . makefile-mode) | |
1056 ;;; Less common extensions come here | 1046 ;;; Less common extensions come here |
1057 ;;; so more common ones above are found faster. | 1047 ;;; so more common ones above are found faster. |
1058 ("\\.texinfo\\'" . texinfo-mode) | 1048 ("\\.texi\\(nfo\\)?\\'" . texinfo-mode) |
1059 ("\\.texi\\'" . texinfo-mode) | 1049 ("\\.s\\'" . asm-mode) |
1060 ("\\.s\\'" . asm-mode) | 1050 ("[Cc]hange.?[Ll]og?\\(.[0-9]+\\)?\\'" . change-log-mode) |
1061 ("ChangeLog\\'" . change-log-mode) | 1051 ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode) |
1062 ("change.log\\'" . change-log-mode) | 1052 ("\\.scm\\(\\.[0-9]*\\)?\\'" . scheme-mode) |
1063 ("changelo\\'" . change-log-mode) | 1053 ("\\.py\\'" . python-mode) |
1064 ("ChangeLog.[0-9]+\\'" . change-log-mode) | 1054 ("\\.e\\'" . eiffel-mode) |
1065 ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode) | 1055 ("\\.mss\\'" . scribe-mode) |
1066 ("\\.scm\\.[0-9]*\\'" . scheme-mode) | 1056 ("\\.m\\([mes]\\|an\\)\\'" . nroff-mode) |
1057 ("\\.icn\\'" . icon-mode) | |
1067 ;;; The following should come after the ChangeLog pattern | 1058 ;;; The following should come after the ChangeLog pattern |
1068 ;;; for the sake of ChangeLog.1, etc. | 1059 ;;; for the sake of ChangeLog.1, etc. |
1069 ;;; and after the .scm.[0-9] pattern too. | 1060 ;;; and after the .scm.[0-9] pattern too. |
1070 ("\\.[12345678]\\'" . nroff-mode) | 1061 ("\\.[12345678]\\'" . nroff-mode) |
1071 ("\\.TeX\\'" . tex-mode) | 1062 ("\\.[tT]e[xX]\\'" . tex-mode) |
1072 ("\\.sty\\'" . latex-mode) | 1063 ("\\.\\(sty\\|cls\\|bbl\\)\\'" . latex-mode) |
1073 ("\\.cls\\'" . latex-mode) ;LaTeX 2e class | 1064 ("\\.bib\\'" . bibtex-mode) |
1074 ("\\.bbl\\'" . latex-mode) | 1065 ("\\.article\\'" . text-mode) |
1075 ("\\.bib\\'" . bibtex-mode) | 1066 ("\\.letter\\'" . text-mode) |
1076 ("\\.article\\'" . text-mode) | 1067 ("\\.\\(tcl\\|exp\\)\\'" . tcl-mode) |
1077 ("\\.letter\\'" . text-mode) | 1068 ("\\.wrl\\'" . vrml-mode) |
1078 ("\\.tcl\\'" . tcl-mode) | 1069 ("\\.f90\\'" . f90-mode) |
1079 ("\\.wrl\\'" . vrml-mode) | 1070 ("\\.awk\\'" . awk-mode) |
1080 ("\\.f90\\'" . f90-mode) | 1071 ("\\.prolog\\'" . prolog-mode) |
1081 ("\\.lsp\\'" . lisp-mode) | 1072 ("\\.tar\\'" . tar-mode) |
1082 ("\\.awk\\'" . awk-mode) | 1073 ("\\.\\(arc\\|zip\\|lzh\\|zoo\\)\\'" . archive-mode) |
1083 ("\\.prolog\\'" . prolog-mode) | 1074 ;; Mailer puts message to be edited in |
1084 ("\\.tar\\'" . tar-mode) | 1075 ;; /tmp/Re.... or Message |
1085 ("\\.\\(arc\\|zip\\|lzh\\|zoo\\)\\'" . archive-mode) | 1076 ("^/tmp/Re" . text-mode) |
1086 ;; Mailer puts message to be edited in | 1077 ("/Message[0-9]*\\'" . text-mode) |
1087 ;; /tmp/Re.... or Message | 1078 ("/drafts/[0-9]+\\'" . mh-letter-mode) |
1088 ("^/tmp/Re" . text-mode) | 1079 ;; some news reader is reported to use this |
1089 ("/Message[0-9]*\\'" . text-mode) | 1080 ("^/tmp/fol/" . text-mode) |
1090 ("/drafts/[0-9]+\\'" . mh-letter-mode) | 1081 ("\\.y\\'" . c-mode) |
1091 ;; some news reader is reported to use this | 1082 ("\\.lex\\'" . c-mode) |
1092 ("^/tmp/fol/" . text-mode) | 1083 ("\\.oak\\'" . scheme-mode) |
1093 ("\\.y\\'" . c-mode) | 1084 ("\\.s?html?\\'" . html-mode) |
1094 ("\\.lex\\'" . c-mode) | 1085 ("\\.htm?l?3\\'" . html3-mode) |
1095 ("\\.oak\\'" . scheme-mode) | 1086 ("\\.\\(sgml?\\|dtd\\)\\'" . sgml-mode) |
1096 ("\\.html\\'" . html-mode) | 1087 ("\\.c?ps\\'" . postscript-mode) |
1097 ("\\.htm\\'" . html-mode) | 1088 ;; .emacs following a directory delimiter |
1098 ("\\.shtml\\'" . html-mode) | 1089 ;; in either Unix or VMS syntax. |
1099 ("\\.html3\\'" . html3-mode) | 1090 ("[]>:/]\\..*emacs\\'" . emacs-lisp-mode) |
1100 ("\\.ht3\\'" . html3-mode) | 1091 ;; _emacs following a directory delimiter |
1101 ("\\.sgm\\'" . sgml-mode) | 1092 ;; in MsDos syntax |
1102 ("\\.sgml\\'" . sgml-mode) | 1093 ("[:/]_emacs\\'" . emacs-lisp-mode) |
1103 ("\\.dtd\\'" . sgml-mode) | 1094 ("\\.ml\\'" . lisp-mode))) |
1104 ("\\.c?ps\\'" . postscript-mode) | 1095 "Alist of filename patterns vs. corresponding major mode functions. |
1105 ;; .emacs following a directory delimiter | |
1106 ;; in either Unix or VMS syntax. | |
1107 ("[]>:/]\\..*emacs\\'" . emacs-lisp-mode) | |
1108 ;; _emacs following a directory delimiter | |
1109 ;; in MsDos syntax | |
1110 ("[:/]_emacs\\'" . emacs-lisp-mode) | |
1111 ("\\.ml\\'" . lisp-mode))) | |
1112 "Alist of filename patterns vs corresponding major mode functions. | |
1113 Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL). | 1096 Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL). |
1114 \(NON-NIL stands for anything that is not nil; the value does not matter.) | 1097 \(NON-NIL stands for anything that is not nil; the value does not matter.) |
1115 Visiting a file whose name matches REGEXP specifies FUNCTION as the | 1098 Visiting a file whose name matches REGEXP specifies FUNCTION as the |
1116 mode function to use. FUNCTION will be called, unless it is nil. | 1099 mode function to use. FUNCTION will be called, unless it is nil. |
1117 | 1100 |
1118 If the element has the form (REGEXP FUNCTION NON-NIL), then after | 1101 If the element has the form (REGEXP FUNCTION NON-NIL), then after |
1119 calling FUNCTION (if it's not nil), we delete the suffix that matched | 1102 calling FUNCTION (if it's not nil), we delete the suffix that matched |
1120 REGEXP and search the list again for another match.") | 1103 REGEXP and search the list again for another match.") |
1121 | 1104 |
1122 (defconst interpreter-mode-alist (mapcar 'purecopy | 1105 (defconst interpreter-mode-alist |
1123 '(("perl" . perl-mode) | 1106 (mapcar 'purecopy |
1124 ("suidperl" . perl-mode) | 1107 '(("^#!.*csh" . csh-mode) |
1125 ("taintperl" . perl-mode) | 1108 ("^#!.*sh\\b" . ksh-mode) |
1126 ("sh" . ksh-mode) | 1109 ("^#!.*\\b\\(scope\\|wish\\|tcl\\|expect\\)" . tcl-mode) |
1127 ("bash" . ksh-mode) | 1110 ("perl" . perl-mode) |
1128 ("ksh" . ksh-mode) | 1111 ("python" . python-mode) |
1129 ("scope" . tcl-mode) | 1112 ("awk\\b" . awk-mode) |
1130 ("wish" . tcl-mode) | 1113 ("rexx" . rexx-mode) |
1131 ("wishx" . tcl-mode) | 1114 ("scm" . scheme-mode) |
1132 ("tcl" . tcl-mode) | 1115 ("^:" . ksh-mode) |
1133 ("tclsh" . tcl-mode) | 1116 )) |
1134 ("expect" . tcl-mode) | |
1135 ("rexx" . rexx-mode) | |
1136 ("awk" . awk-mode) | |
1137 ("nawk" . awk-mode) | |
1138 ("gawk" . awk-mode) | |
1139 ("mawk" . awk-mode) | |
1140 ("scm" . scheme-mode))) | |
1141 "Alist mapping interpreter names to major modes. | 1117 "Alist mapping interpreter names to major modes. |
1142 This alist applies to files whose first line starts with `#!'. | 1118 This alist is used to guess the major mode of a file based on the |
1143 Each element looks like (INTERPRETER . MODE). | 1119 contents of the first line. This line often contains something like: |
1144 The car of each element is compared with | 1120 #!/bin/sh |
1145 the name of the interpreter specified in the first line. | 1121 but may contain something more imaginative like |
1122 #! /bin/env python | |
1123 or | |
1124 eval 'exec perl -w -S $0 ${1+\"$@\"}'. | |
1125 | |
1126 Each alist element looks like (INTERPRETER . MODE). | |
1127 The car of each element is a regular expression which is compared | |
1128 with the name of the interpreter specified in the first line. | |
1146 If it matches, mode MODE is selected.") | 1129 If it matches, mode MODE is selected.") |
1147 | 1130 |
1148 (defconst inhibit-first-line-modes-regexps (purecopy '("\\.tar\\'")) | 1131 (defconst inhibit-first-line-modes-regexps (purecopy '("\\.tar\\'")) |
1149 "List of regexps; if one matches a file name, don't look for `-*-'.") | 1132 "List of regexps; if one matches a file name, don't look for `-*-'.") |
1150 | 1133 |
1197 name (substring name 0 (match-beginning 0)) | 1180 name (substring name 0 (match-beginning 0)) |
1198 keep-going t)) | 1181 keep-going t)) |
1199 (setq mode (cdr (car alist)) | 1182 (setq mode (cdr (car alist)) |
1200 keep-going nil))) | 1183 keep-going nil))) |
1201 (setq alist (cdr alist)))) | 1184 (setq alist (cdr alist)))) |
1202 (if mode | 1185 ;; If we can't deduce a mode from the file name, |
1203 (funcall mode) | 1186 ;; look for an interpreter specified in the first line. |
1204 ;; If we can't deduce a mode from the file name, | 1187 (if (null mode) |
1205 ;; look for an interpreter specified in the first line. | 1188 (let ((firstline |
1206 (let ((interpreter | 1189 (buffer-substring |
1207 (save-excursion | 1190 (point-min) |
1208 (goto-char (point-min)) | 1191 (save-excursion |
1209 (if (looking-at "#! *\\([^ \t\n]+\\)") | 1192 (goto-char (point-min)) (end-of-line) (point))))) |
1210 (buffer-substring (match-beginning 1) | 1193 (setq alist interpreter-mode-alist) |
1211 (match-end 1)) | 1194 (while alist |
1212 ""))) | 1195 (if (string-match (car (car alist)) firstline) |
1213 elt) | 1196 (progn |
1214 ;; Map interpreter name to a mode. | 1197 (setq mode (cdr (car alist))) |
1215 (setq elt (assoc (file-name-nondirectory interpreter) | 1198 (setq alist nil)) |
1216 interpreter-mode-alist)) | 1199 (setq alist (cdr alist)))))) |
1217 (if elt | 1200 (if mode |
1218 (funcall (cdr elt))))))))))) | 1201 (funcall mode)) |
1202 )))))) | |
1219 | 1203 |
1220 (defun hack-local-variables (&optional force) | 1204 (defun hack-local-variables (&optional force) |
1221 "Parse, and bind or evaluate as appropriate, any local variables | 1205 "Parse, and bind or evaluate as appropriate, any local variables |
1222 for current buffer." | 1206 for current buffer." |
1223 ;; Don't look for -*- if this file name matches any | 1207 ;; Don't look for -*- if this file name matches any |
1353 | 1337 |
1354 | 1338 |
1355 (defun hack-local-variables-prop-line (&optional force) | 1339 (defun hack-local-variables-prop-line (&optional force) |
1356 ;; Set local variables specified in the -*- line. | 1340 ;; Set local variables specified in the -*- line. |
1357 ;; Returns t if mode was set. | 1341 ;; Returns t if mode was set. |
1358 (let (modes mode-p) | 1342 (let ((result nil)) |
1359 (save-excursion | 1343 (save-excursion |
1360 (goto-char (point-min)) | 1344 (goto-char (point-min)) |
1361 (skip-chars-forward " \t\n\r") | 1345 (skip-chars-forward " \t\n\r") |
1362 (let ((result nil) | 1346 (let ((end (save-excursion |
1363 (end (save-excursion | |
1364 ;; If the file begins with "#!" | 1347 ;; If the file begins with "#!" |
1365 ;; (un*x exec interpreter magic), look | 1348 ;; (un*x exec interpreter magic), look |
1366 ;; for mode frobs in the first two | 1349 ;; for mode frobs in the first two |
1367 ;; lines. You cannot necessarily | 1350 ;; lines. You cannot necessarily |
1368 ;; put them in the first line of | 1351 ;; put them in the first line of |
1400 (match-beginning 1) | 1383 (match-beginning 1) |
1401 (match-end 1)))) | 1384 (match-end 1)))) |
1402 (val (save-restriction | 1385 (val (save-restriction |
1403 (narrow-to-region (point) end) | 1386 (narrow-to-region (point) end) |
1404 (read (current-buffer))))) | 1387 (read (current-buffer))))) |
1388 ;; Case sensitivity! Icepicks in my forehead! | |
1389 (if (equal (downcase (symbol-name key)) "mode") | |
1390 (setq key 'mode)) | |
1405 (setq result (cons (cons key val) result)) | 1391 (setq result (cons (cons key val) result)) |
1406 (skip-chars-forward " \t;"))) | 1392 (skip-chars-forward " \t;"))) |
1407 (setq result (nreverse result)))) | 1393 (setq result (nreverse result)))))) |
1408 | 1394 |
1409 ;; Mode is magic. | 1395 (let ((set-any-p (or force (hack-local-variables-p t))) |
1410 (let (mode) | 1396 (mode-p nil)) |
1411 ;; with the removal of the downcase above, we have to | 1397 (while result |
1412 ;; add a check for Mode:, which is common. | 1398 (let ((key (car (car result))) |
1413 (while (setq mode (or (assq 'mode result) | 1399 (val (cdr (car result)))) |
1414 (assq 'Mode result))) | 1400 (cond ((eq key 'mode) |
1415 (setq result (delq mode result)) | 1401 (setq mode-p t) |
1416 (setq modes (cons (intern (concat (downcase (symbol-name | 1402 (funcall (intern (concat (downcase (symbol-name val)) |
1417 (cdr mode))) | 1403 "-mode")))) |
1418 "-mode")) | 1404 (set-any-p |
1419 modes)))) | 1405 (hack-one-local-variable key val)) |
1420 | 1406 (t |
1421 (if (and result | 1407 nil))) |
1422 (or force (hack-local-variables-p t))) | 1408 (setq result (cdr result))) |
1423 (while result | 1409 mode-p))) |
1424 (let ((key (car (car result))) | |
1425 (val (cdr (car result)))) | |
1426 ;; 'mode has already been removed from this list. | |
1427 (hack-one-local-variable key val)) | |
1428 (setq result (cdr result)))))) | |
1429 ;; If we found modes to use, invoke them now, | |
1430 ;; outside the save-excursion. | |
1431 (if modes | |
1432 (progn (mapcar 'funcall modes) | |
1433 (setq mode-p t))) | |
1434 mode-p)) | |
1435 | 1410 |
1436 (defconst ignored-local-variables | 1411 (defconst ignored-local-variables |
1437 (list 'enable-local-eval) | 1412 (list 'enable-local-eval) |
1438 "Variables to be ignored in a file's local variable spec.") | 1413 "Variables to be ignored in a file's local variable spec.") |
1439 | 1414 |