:type 'boolean
:group 'backup)
(make-variable-buffer-local 'buffer-offer-save)
+(put 'buffer-offer-save 'permanent-local t)
(defcustom find-file-existing-other-name t
"Non-nil means find a file under alternative names, in existing buffers.
'confirm)
(t nil)))
-(defun read-buffer-to-switch (prompt)
- "Read the name of a buffer to switch to and return as a string.
-It is intended for `switch-to-buffer' family of commands since they
-need to omit the name of current buffer from the list of completions
-and default values."
- (let ((rbts-completion-table (internal-complete-buffer-except)))
- (minibuffer-with-setup-hook
- (lambda ()
- (setq minibuffer-completion-table rbts-completion-table)
- ;; Since rbts-completion-table is built dynamically, we
- ;; can't just add it to the default value of
- ;; icomplete-with-completion-tables, so we add it
- ;; here manually.
- (if (and (boundp 'icomplete-with-completion-tables)
- (listp icomplete-with-completion-tables))
- (set (make-local-variable 'icomplete-with-completion-tables)
- (cons rbts-completion-table
- icomplete-with-completion-tables))))
- (read-buffer prompt (other-buffer (current-buffer))
- (confirm-nonexistent-file-or-buffer)))))
-
-(defun switch-to-buffer-other-window (buffer-or-name &optional norecord)
- "Select the buffer specified by BUFFER-OR-NAME in another window.
-BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
-nil. Return the buffer switched to.
-
-If called interactively, prompt for the buffer name using the
-minibuffer. The variable `confirm-nonexistent-file-or-buffer'
-determines whether to request confirmation before creating a new
-buffer.
-
-If BUFFER-OR-NAME is a string and does not identify an existing
-buffer, create a new buffer with that name. If BUFFER-OR-NAME is
-nil, switch to the buffer returned by `other-buffer'.
-
-Optional second argument NORECORD non-nil means do not put this
-buffer at the front of the list of recently selected ones.
-
-This uses the function `display-buffer' as a subroutine; see its
-documentation for additional customization information."
- (interactive
- (list (read-buffer-to-switch "Switch to buffer in other window: ")))
- (let ((pop-up-windows t)
- same-window-buffer-names same-window-regexps)
- (pop-to-buffer buffer-or-name t norecord)))
-
-(defun switch-to-buffer-other-frame (buffer-or-name &optional norecord)
- "Switch to buffer BUFFER-OR-NAME in another frame.
-BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
-nil. Return the buffer switched to.
-
-If called interactively, prompt for the buffer name using the
-minibuffer. The variable `confirm-nonexistent-file-or-buffer'
-determines whether to request confirmation before creating a new
-buffer.
-
-If BUFFER-OR-NAME is a string and does not identify an existing
-buffer, create a new buffer with that name. If BUFFER-OR-NAME is
-nil, switch to the buffer returned by `other-buffer'.
-
-Optional second arg NORECORD non-nil means do not put this
-buffer at the front of the list of recently selected ones.
-
-This uses the function `display-buffer' as a subroutine; see its
-documentation for additional customization information."
- (interactive
- (list (read-buffer-to-switch "Switch to buffer in other frame: ")))
- (let ((pop-up-frames t)
- same-window-buffer-names same-window-regexps)
- (pop-to-buffer buffer-or-name t norecord)))
-
-(defun display-buffer-other-frame (buffer)
- "Display buffer BUFFER in another frame.
-This uses the function `display-buffer' as a subroutine; see
-its documentation for additional customization information."
- (interactive "BDisplay buffer in other frame: ")
- (let ((pop-up-frames t)
- same-window-buffer-names same-window-regexps
- ;;(old-window (selected-window))
- new-window)
- (setq new-window (display-buffer buffer t))
- ;; This may have been here in order to prevent the new frame from hiding
- ;; the old frame. But it does more harm than good.
- ;; Maybe we should call `raise-window' on the old-frame instead? --Stef
- ;;(lower-frame (window-frame new-window))
-
- ;; This may have been here in order to make sure the old-frame gets the
- ;; focus. But not only can it cause an annoying flicker, with some
- ;; window-managers it just makes the window invisible, with no easy
- ;; way to recover it. --Stef
- ;;(make-frame-invisible (window-frame old-window))
- ;;(make-frame-visible (window-frame old-window))
- ))
-
(defmacro minibuffer-with-setup-hook (fun &rest body)
"Temporarily add FUN to `minibuffer-setup-hook' while executing BODY.
BODY should use the minibuffer at most once.
(substring filename (match-end 0)))))
filename)))
-(defcustom find-file-not-true-dirname-list nil
- "List of logical names for which visiting shouldn't save the true dirname."
- :type '(repeat (string :tag "Name"))
- :group 'find-file)
-
(defun find-buffer-visiting (filename &optional predicate)
"Return the buffer visiting file FILENAME (a string).
This is like `get-file-buffer', except that it checks for any buffer
((not warn) nil)
((and error (file-attributes buffer-file-name))
(setq buffer-read-only t)
- "File exists, but cannot be read")
+ (if (and (file-symlink-p buffer-file-name)
+ (not (file-exists-p
+ (file-chase-links buffer-file-name))))
+ "Symbolic link that points to nonexistent file"
+ "File exists, but cannot be read"))
((not buffer-read-only)
(if (and warn
;; No need to warn if buffer is auto-saved
("\\.icn\\'" . icon-mode)
("\\.sim\\'" . simula-mode)
("\\.mss\\'" . scribe-mode)
+ ;; The Fortran standard does not say anything about file extensions.
+ ;; .f90 was widely used for F90, now we seem to be trapped into
+ ;; using a different extension for each language revision.
+ ;; Anyway, the following extensions are supported by gfortran.
("\\.f9[05]\\'" . f90-mode)
+ ("\\.f0[38]\\'" . f90-mode)
("\\.indent\\.pro\\'" . fundamental-mode) ; to avoid idlwave-mode
("\\.\\(pro\\|PRO\\)\\'" . idlwave-mode)
("\\.srt\\'" . srecode-template-mode)
("\\.ebrowse\\'" . ebrowse-tree-mode)
("#\\*mail\\*" . mail-mode)
("\\.g\\'" . antlr-mode)
+ ("\\.mod\\'" . m2-mode)
("\\.ses\\'" . ses-mode)
("\\.docbook\\'" . sgml-mode)
("\\.com\\'" . dcl-mode)
See also `auto-mode-alist'.")
-(defvar inhibit-first-line-modes-regexps (mapcar 'purecopy '("\\.tar\\'" "\\.tgz\\'"))
+(defvar inhibit-first-line-modes-regexps
+ (mapcar 'purecopy '("\\.tar\\'" "\\.tgz\\'" "\\.tiff?\\'"
+ "\\.gif\\'" "\\.png\\'" "\\.jpe?g\\'"))
"List of regexps; if one matches a file name, don't look for `-*-'.")
(defvar inhibit-first-line-modes-suffixes nil
;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*-
(let (end done mode modes)
;; Once we drop the deprecated feature where mode: is also allowed to
- ;; specify minor-modes (ie, there can be more than one "mode:), we can
+ ;; specify minor-modes (ie, there can be more than one "mode:"), we can
;; remove this section and just let (hack-local-variables t) handle it.
;; Find a -*- mode tag.
(save-excursion
(if (looking-at auto-mode-interpreter-regexp)
(match-string 2)
""))
- ;; Map interpreter name to a mode, signalling we're done at the
+ ;; Map interpreter name to a mode, signaling we're done at the
;; same time.
done (assoc (file-name-nondirectory mode)
interpreter-mode-alist))
(if buffer-file-name
(let ((name buffer-file-name)
(remote-id (file-remote-p buffer-file-name)))
+ ;; Remove backup-suffixes from file name.
+ (setq name (file-name-sans-versions name))
;; Remove remote file name identification.
(when (and (stringp remote-id)
(string-match (regexp-quote remote-id) name))
(setq name (substring name (match-end 0))))
- ;; Remove backup-suffixes from file name.
- (setq name (file-name-sans-versions name))
(while name
;; Find first matching alist entry.
(setq mode
(setq char nil)))
(kill-buffer buf)
(when (and offer-save (= char ?!) unsafe-vars)
- (dolist (elt unsafe-vars)
- (add-to-list 'safe-local-variable-values elt))
- ;; When this is called from desktop-restore-file-buffer,
- ;; coding-system-for-read may be non-nil. Reset it before
- ;; writing to .emacs.
- (if (or custom-file user-init-file)
- (let ((coding-system-for-read nil))
- (customize-save-variable
- 'safe-local-variable-values
- safe-local-variable-values))))
+ (customize-push-and-save 'safe-local-variable-values unsafe-vars))
(memq char '(?! ?\s ?y))))))
(defun hack-local-variables-prop-line (&optional mode-only)
and VAL is the specified value. Ignores any specification for
`mode:' and `coding:' (which should have already been handled
by `set-auto-mode' and `set-auto-coding', respectively).
-Throws an error if the -*- line is malformed.
+Return nil if the -*- line is malformed.
If MODE-ONLY is non-nil, just returns the symbol specifying the
mode, if there is one, otherwise nil."
- (save-excursion
- (goto-char (point-min))
- (let ((end (set-auto-mode-1))
- result)
- (cond ((not end)
- nil)
- ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)")
- ;; Simple form: "-*- MODENAME -*-".
- (if mode-only
- (intern (concat (match-string 1) "-mode"))))
- (t
- ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-'
- ;; (last ";" is optional).
- ;; If MODE-ONLY, just check for `mode'.
- ;; Otherwise, parse the -*- line into the RESULT alist.
- (while (and (or (not mode-only)
- (not result))
- (< (point) end))
- (or (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*")
- (error "Malformed -*- line"))
- (goto-char (match-end 0))
- ;; There used to be a downcase here,
- ;; but the manual didn't say so,
- ;; and people want to set var names that aren't all lc.
- (let* ((key (intern (match-string 1)))
- (val (save-restriction
- (narrow-to-region (point) end)
- (let ((read-circle nil))
- (read (current-buffer)))))
- ;; It is traditional to ignore
- ;; case when checking for `mode' in set-auto-mode,
- ;; so we must do that here as well.
- ;; That is inconsistent, but we're stuck with it.
- ;; The same can be said for `coding' in set-auto-coding.
- (keyname (downcase (symbol-name key))))
- (if mode-only
- (and (equal keyname "mode")
- (setq result
- (intern (concat (downcase (symbol-name val))
- "-mode"))))
- (or (equal keyname "coding")
- (condition-case nil
- (push (cons (if (eq key 'eval)
- 'eval
- (indirect-variable key))
- val) result)
- (error nil))))
- (skip-chars-forward " \t;")))
- result)))))
+ (catch 'malformed-line
+ (save-excursion
+ (goto-char (point-min))
+ (let ((end (set-auto-mode-1))
+ result)
+ (cond ((not end)
+ nil)
+ ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)")
+ ;; Simple form: "-*- MODENAME -*-".
+ (if mode-only
+ (intern (concat (match-string 1) "-mode"))))
+ (t
+ ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-'
+ ;; (last ";" is optional).
+ ;; If MODE-ONLY, just check for `mode'.
+ ;; Otherwise, parse the -*- line into the RESULT alist.
+ (while (and (or (not mode-only)
+ (not result))
+ (< (point) end))
+ (unless (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*")
+ (message "Malformed mode-line")
+ (throw 'malformed-line nil))
+ (goto-char (match-end 0))
+ ;; There used to be a downcase here,
+ ;; but the manual didn't say so,
+ ;; and people want to set var names that aren't all lc.
+ (let* ((key (intern (match-string 1)))
+ (val (save-restriction
+ (narrow-to-region (point) end)
+ (let ((read-circle nil))
+ (read (current-buffer)))))
+ ;; It is traditional to ignore
+ ;; case when checking for `mode' in set-auto-mode,
+ ;; so we must do that here as well.
+ ;; That is inconsistent, but we're stuck with it.
+ ;; The same can be said for `coding' in set-auto-coding.
+ (keyname (downcase (symbol-name key))))
+ (if mode-only
+ (and (equal keyname "mode")
+ (setq result
+ (intern (concat (downcase (symbol-name val))
+ "-mode"))))
+ (or (equal keyname "coding")
+ (condition-case nil
+ (push (cons (cond ((eq key 'eval) 'eval)
+ ;; Downcase "Mode:".
+ ((equal keyname "mode") 'mode)
+ (t (indirect-variable key)))
+ val) result)
+ (error nil))))
+ (skip-chars-forward " \t;")))
+ result))))))
(defun hack-local-variables-filter (variables dir-name)
"Filter local variable settings, querying the user if necessary.
(var (let ((read-circle nil))
(read str)))
val val2)
+ (and (equal (downcase (symbol-name var)) "mode")
+ (setq var 'mode))
;; Read the variable value.
(skip-chars-forward "^:")
(forward-char 1)
(and (symbolp (car exp))
;; Allow (minor)-modes calls with no arguments.
;; This obsoletes the use of "mode:" for such things. (Bug#8613)
- (or (and (null (cdr exp))
+ (or (and (member (cdr exp) '(nil (1) (-1)))
(string-match "-mode\\'" (symbol-name (car exp))))
(let ((prop (get (car exp) 'safe-local-eval-function)))
(cond ((eq prop t)
(get major-mode 'mode-class)
;; Don't change the mode if the local variable list specifies it.
(hack-local-variables t)
- (set-auto-mode t))
+ ;; TODO consider making normal-mode handle this case.
+ (let ((old major-mode))
+ (set-auto-mode t)
+ (or (eq old major-mode)
+ (hack-local-variables))))
(error nil)))
(defun write-file (filename &optional confirm)
"Change whether this buffer is read-only.
With prefix argument ARG, make the buffer read-only if ARG is
positive, otherwise make it writable. If buffer is read-only
-and `view-read-only' is non-nil, enter view mode."
+and `view-read-only' is non-nil, enter view mode.
+
+This function is usually the wrong thing to use in a Lisp program.
+It can have side-effects beyond changing the read-only status of a buffer
+\(e.g., enabling view mode), and does not affect read-only regions that
+are caused by text properties. To make a buffer read-only in Lisp code,
+set `buffer-read-only'. To ignore read-only status (whether due to text
+properties or buffer state) and make changes, temporarily bind
+`inhibit-read-only'."
(interactive "P")
(if (and arg
(if (> (prefix-numeric-value arg) 0) buffer-read-only
(not (eq (get major-mode 'mode-class) 'special)))
(view-mode-enter))
(t (setq buffer-read-only (not buffer-read-only))
- (force-mode-line-update)))
- (if (vc-backend buffer-file-name)
- (message "%s" (substitute-command-keys
- (concat "File is under version-control; "
- "use \\[vc-next-action] to check in/out"))))))
+ (force-mode-line-update)))))
(defun insert-file (filename)
"Insert contents of file FILENAME into buffer after point.
Noninteractively, the second (optional) argument PARENTS, if
non-nil, says whether to create parent directories that don't
-exist. Interactively, this happens by default."
+exist. Interactively, this happens by default.
+
+If creating the directory or directories fail, an error will be
+raised."
(interactive
(list (read-file-name "Make directory: " default-directory default-directory
nil nil)
directory 'full directory-files-no-dot-files-regexp))
(error "Directory is not empty, not moving to trash")
(move-file-to-trash directory)))
- ;; Otherwise, call outselves recursively if needed.
+ ;; Otherwise, call ourselves recursively if needed.
(t
(if (and recursive (not (file-symlink-p directory)))
(mapc (lambda (file)
(copy-file file target t keep-time)))))
;; Set directory attributes.
- (set-file-modes newname (file-modes directory))
- (if keep-time
- (set-file-times newname (nth 5 (file-attributes directory)))))))
+ (let ((modes (file-modes directory))
+ (times (and keep-time (nth 5 (file-attributes directory)))))
+ (if modes (set-file-modes newname modes))
+ (if times (set-file-times newname times))))))
\f
(put 'revert-buffer-function 'permanent-local t)
(defvar revert-buffer-function nil
(save-excursion
(let ((switches dired-listing-switches))
(if (file-symlink-p file)
- (setq switches (concat switches "L")))
+ (setq switches (concat switches " -L")))
(set-buffer standard-output)
;; Use insert-directory-safely, not insert-directory,
;; because these files might not exist. In particular,
(error "No previous sessions to recover")))
(let ((ls-lisp-support-shell-wildcards t))
(dired (concat auto-save-list-file-prefix "*")
- (concat dired-listing-switches "t")))
+ (concat dired-listing-switches " -t")))
(save-excursion
(goto-char (point-min))
(or (looking-at " Move to the session you want to recover,")
contents)
(while dirs
(when (or (null (car dirs)) ; Possible if DIRPART is not wild.
- (file-directory-p (directory-file-name (car dirs))))
+ (and (file-directory-p (directory-file-name (car dirs)))
+ (file-readable-p (car dirs))))
(let ((this-dir-contents
;; Filter out "." and ".."
(delq nil
;; vc dired listings provide the state or blanks between file
;; permissions and date. The state is always surrounded by
- ;; parantheses:
+ ;; parentheses:
;; -rw-r--r-- (modified) 2005-10-22 21:25 files.el
;; This is not supported yet.
(purecopy (concat "\\([0-9][BkKMGTPEZY]? " iso
(defvar kill-emacs-query-functions nil
"Functions to call with no arguments to query about killing Emacs.
-If any of these functions returns nil, killing Emacs is cancelled.
+If any of these functions returns nil, killing Emacs is canceled.
`save-buffers-kill-emacs' calls these functions, but `kill-emacs',
the low level primitive, does not. See also `kill-emacs-hook'.")
"Convert symbolic file modes to numeric file modes.
MODES is the string to convert, it should match
\"[ugoa]*([+-=][rwxXstugo]*)+,...\".
-See (info \"(coreutils)File permissions\") for more information on this
+See Info node `(coreutils)File permissions' for more information on this
notation.
FROM (or 0 if nil) gives the mode bits on which to base permissions if
MODES request to add, remove, or set permissions based on existing ones,
(setq tries 0 success t))
(file-already-exists nil))
(setq tries (1- tries))
- ;; Uniqify new-fn. (Some file managers do not
+ ;; Uniquify new-fn. (Some file managers do not
;; like Emacs-style backup file names---e.g. bug
;; 170956 in Konqueror bug tracker.)
(setq new-fn (make-temp-name (concat base-fn "_")))))