emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/files.el [lexbind]


From: Miles Bader
Subject: [Emacs-diffs] Changes to emacs/lisp/files.el [lexbind]
Date: Thu, 04 Nov 2004 08:32:20 -0500

Index: emacs/lisp/files.el
diff -c emacs/lisp/files.el:1.583.2.23 emacs/lisp/files.el:1.583.2.24
*** emacs/lisp/files.el:1.583.2.23      Fri Oct 29 02:05:09 2004
--- emacs/lisp/files.el Thu Nov  4 13:12:39 2004
***************
*** 977,982 ****
--- 977,990 ----
          (mapcar 'switch-to-buffer (cdr value)))
        (switch-to-buffer-other-frame value))))
  
+ (defun find-file-existing (filename &optional wildcards)
+   "Edit the existing file FILENAME.
+ Like \\[find-file] but only allow files that exists."
+   (interactive (find-file-read-args "Find existing file: " t))
+   (unless (file-exists-p filename) (error "%s does not exist" filename))
+   (find-file filename wildcards)
+   (current-buffer))
+ 
  (defun find-file-read-only (filename &optional wildcards)
    "Edit file FILENAME but don't allow changes.
  Like \\[find-file] but marks buffer as read-only.
***************
*** 1225,1230 ****
--- 1233,1239 ----
  When nil, never request confirmation."
    :group 'files
    :group 'find-file
+   :version "21.4"
    :type '(choice integer (const :tag "Never request confirmation" nil)))
  
  (defun find-file-noselect (filename &optional nowarn rawfile wildcards)
***************
*** 1836,1855 ****
  regular expression.  The mode is then determined as the mode associated
  with that interpreter in `interpreter-mode-alist'.")
  
! (defvar xml-based-modes '(html-mode)
!   "Modes that override an XML declaration.
! When `set-auto-mode' sees an <?xml or <!DOCTYPE declaration, that
! buffer will be in some XML mode.  If `auto-mode-alist' associates
! the file with one of the modes in this list, that mode will be
! used.  Else `xml-mode' or `sgml-mode' is used.")
  
  (defun set-auto-mode (&optional keep-mode-if-same)
    "Select major mode appropriate for current buffer.
  This checks for a -*- mode tag in the buffer's text, checks the
  interpreter that runs this file against `interpreter-mode-alist',
! looks for an <?xml or <!DOCTYPE declaration (see
! `xml-based-modes'), or compares the filename against the entries
! in `auto-mode-alist'.
  
  It does not check for the `mode:' local variable in the
  Local Variables section of the file; for that, use `hack-local-variables'.
--- 1845,1871 ----
  regular expression.  The mode is then determined as the mode associated
  with that interpreter in `interpreter-mode-alist'.")
  
! (defvar magic-mode-alist
!   '(;; The < comes before the groups (but the first) to reduce backtracking.
!     ;; Is there a nicer way of getting . including \n?
!     ;; TODO: UTF-16 <?xml may be preceded by a BOM 0xff 0xfe or 0xfe 0xff.
!     ("\\(?:<\\?xml\\s +[^>]*>\\)?\\s *<\\(?:!--\\(?:.\\|\n\\)*?-->\\s 
*<\\)*\\(?:!DOCTYPE\\s +[^>]*>\\s *<\\)?\\s *\\(?:!--\\(?:.\\|\n\\)*?-->\\s 
*<\\)*[Hh][Tt][Mm][Ll]" . html-mode)
!     ;; These two must come after html, because they are more general:
!     ("<\\?xml " . xml-mode)
!     ("\\s *<\\(?:!--\\(?:.\\|\n\\)*?-->\\s *<\\)*!DOCTYPE " . sgml-mode)
!     ("%![^V]" . ps-mode))
!   "Alist of buffer beginnings vs corresponding major mode functions.
! Each element looks like (REGEXP . FUNCTION).  FUNCTION will be
! called, unless it is nil.")
  
  (defun set-auto-mode (&optional keep-mode-if-same)
    "Select major mode appropriate for current buffer.
+ 
  This checks for a -*- mode tag in the buffer's text, checks the
  interpreter that runs this file against `interpreter-mode-alist',
! compares the buffer beginning against `magic-mode-alist',
! or compares the filename against the entries in
! `auto-mode-alist'.
  
  It does not check for the `mode:' local variable in the
  Local Variables section of the file; for that, use `hack-local-variables'.
***************
*** 1895,1901 ****
            (if (not (functionp mode))
                (message "Ignoring unknown mode `%s'" mode)
              (setq done t)
!             (or (set-auto-mode-0 mode)
                  (throw 'nop nil)))))
        ;; If we didn't, look for an interpreter specified in the first line.
        ;; As a special case, allow for things like "#!/bin/env perl", which
--- 1911,1917 ----
            (if (not (functionp mode))
                (message "Ignoring unknown mode `%s'" mode)
              (setq done t)
!             (or (set-auto-mode-0 mode keep-mode-if-same)
                  (throw 'nop nil)))))
        ;; If we didn't, look for an interpreter specified in the first line.
        ;; As a special case, allow for things like "#!/bin/env perl", which
***************
*** 1908,1955 ****
            ;; Map interpreter name to a mode, signalling we're done at the
            ;; same time.
            done (assoc (file-name-nondirectory mode)
!                       interpreter-mode-alist))
!       ;; If we found an interpreter mode to use, invoke it now.
!       (if done (set-auto-mode-0 (cdr done))))
!     (if (and (not done) buffer-file-name)
!       (let ((name buffer-file-name))
!         ;; Remove backup-suffixes from file name.
!         (setq name (file-name-sans-versions name))
!         (while name
!           ;; Find first matching alist entry.
!           (let ((case-fold-search
!                  (memq system-type '(vax-vms windows-nt cygwin))))
!             (if (and (setq mode (assoc-default name auto-mode-alist
                                                 'string-match))
!                      (consp mode)
!                      (cadr mode))
!                 (setq mode (car mode)
!                       name (substring name 0 (match-beginning 0)))
!               (setq name)))
!           (when mode
!             (if xml (or (memq mode xml-based-modes)
!                         (setq mode 'xml-mode)))
!             (set-auto-mode-0 mode)
!             (setq done t)))))
!     (and xml
!        (not done)
!        (set-auto-mode-0 'xml-mode))))
  
  
  ;; When `keep-mode-if-same' is set, we are working on behalf of
  ;; set-visited-file-name.  In that case, if the major mode specified is the
  ;; same one we already have, don't actually reset it.  We don't want to lose
  ;; minor modes such as Font Lock.
! (defun set-auto-mode-0 (mode)
    "Apply MODE and return it.
! If `keep-mode-if-same' is non-nil MODE is chased of any aliases and
! compared to current major mode.  If they are the same, do nothing
! and return nil."
    (when keep-mode-if-same
      (while (symbolp (symbol-function mode))
        (setq mode (symbol-function mode)))
      (if (eq mode major-mode)
!       (setq mode)))
    (when mode
      (funcall mode)
      mode))
--- 1924,1972 ----
            ;; Map interpreter name to a mode, signalling we're done at the
            ;; same time.
            done (assoc (file-name-nondirectory mode)
!                       interpreter-mode-alist)))
!     ;; If we found an interpreter mode to use, invoke it now.
!     (if done
!       (set-auto-mode-0 (cdr done) keep-mode-if-same)
!       (if (setq done (save-excursion
!                      (goto-char (point-min))
!                      (assoc-default nil magic-mode-alist
!                                     (lambda (re dummy)
!                                       (looking-at re)))))
!         (set-auto-mode-0 done keep-mode-if-same)
!       (if buffer-file-name
!           (let ((name buffer-file-name))
!             ;; Remove backup-suffixes from file name.
!             (setq name (file-name-sans-versions name))
!             (while name
!               ;; Find first matching alist entry.
!               (let ((case-fold-search
!                      (memq system-type '(vax-vms windows-nt cygwin))))
!                 (if (and (setq mode (assoc-default name auto-mode-alist
                                                 'string-match))
!                          (consp mode)
!                          (cadr mode))
!                     (setq mode (car mode)
!                           name (substring name 0 (match-beginning 0)))
!                   (setq name)))
!               (when mode
!                 (set-auto-mode-0 mode keep-mode-if-same)))))))))
  
  
  ;; When `keep-mode-if-same' is set, we are working on behalf of
  ;; set-visited-file-name.  In that case, if the major mode specified is the
  ;; same one we already have, don't actually reset it.  We don't want to lose
  ;; minor modes such as Font Lock.
! (defun set-auto-mode-0 (mode &optional keep-mode-if-same)
    "Apply MODE and return it.
! If optional arg KEEP-MODE-IF-SAME is non-nil, MODE is chased of
! any aliases and compared to current major mode.  If they are the
! same, do nothing and return nil."
    (when keep-mode-if-same
      (while (symbolp (symbol-function mode))
        (setq mode (symbol-function mode)))
      (if (eq mode major-mode)
!       (setq mode nil)))
    (when mode
      (funcall mode)
      mode))
***************
*** 3813,3819 ****
  
  (defun kill-some-buffers (&optional list)
    "Kill some buffers.  Asks the user whether to kill each one of them.
! Non-interactively, if optional argument LIST is non-`nil', it
  specifies the list of buffers to kill, asking for approval for each one."
    (interactive)
    (if (null list)
--- 3830,3836 ----
  
  (defun kill-some-buffers (&optional list)
    "Kill some buffers.  Asks the user whether to kill each one of them.
! Non-interactively, if optional argument LIST is non-nil, it
  specifies the list of buffers to kill, asking for approval for each one."
    (interactive)
    (if (null list)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]