Mercurial > hg > xemacs-beta
comparison lisp/files.el @ 844:047d37eb70d7
[xemacs-hg @ 2002-05-16 13:30:23 by ben]
ui fixes for things that were bothering me
bytecode.c, editfns.c, lisp.h, lread.c: Fix save-restriction to use markers rather than pseudo-markers
(integers representing the amount of text on either side of the
region). That way, all inserts are handled correctly, not just
those inside old restriction.
Add buffer argument to save_restriction_save().
process.c: Clean up very dirty and kludgy code that outputs into a buffer --
use proper unwind protects, etc.
font-lock.c: Do save-restriction/widen around the function -- otherwise, incorrect
results will ensue when a buffer has been narrowed before a call to
e.g. `buffer-syntactic-context' -- something that happens quite often.
fileio.c: Look for a handler for make-temp-name.
window.c, winslots.h: Try to solve this annoying problem: have two frames displaying the
buffer, in different places; in one, temporarily switch away to
another buffer and then back -- and you've lost your position;
it's reset to the other one in the other frame. My current
solution involves window-level caches of buffers and points (also
a cache for window-start); when set-window-buffer is called, it
looks to see if the buffer was previously visited in the window,
and if so, uses the most recent point at that time. (It's a
marker, so it handles changes.)
#### Note: It could be argued that doing it on the frame level
would be better -- e.g. if you visit a buffer temporarily through
a grep, and then go back to that buffer, you presumably want the
grep's position rather than some previous position provided
everything was in the same frame, even though the grep was in
another window in the frame. However, doing it on the frame level
fails when you have two windows on the same frame. Perhaps we
keep both a window and a frame cache, and use the frame cache if
there are no other windows on the frame showing the buffer, else
the window's cache? This is probably something to be configurable
using a specifier. Suggestions please please please?
window.c: Clean up a bit code that deals with the annoyance of window-point
vs. point.
dialog.el: Function to ask a
multiple-choice question, automatically choosing a dialog box or
minibuffer representation as necessary. Generalized version of
yes-or-no-p, y-or-n-p.
files.el: Use get-user-response to ask "yes/no/diff" question when recovering.
"diff" means that a diff is displayed between the current file and the
autosave. (Converts/deconverts escape-quoted as necessary. No more
complaints from you, Mr. Turnbull!) One known problem: when a dialog
is used, it's modal, so you can't scroll the diff. Will fix soon.
lisp-mode.el: If we're filling a string, don't treat semicolon as a comment,
which would give very unfriendly results.
Uses `buffer-syntactic-context'.
simple.el: all changes back to the beginning. (Useful if you've saved the file
in the middle of the changes.)
simple.el: Add option kill-word-into-kill-ring, which controls whether words
deleted with kill-word, backward-kill-word, etc. are "cut" into the
kill ring, or "cleared" into nothingness. (My preference is the
latter, by far. I'd almost go so far as suggesting we make it the
default, as you can always select a word and then cut it if you want
it cut.)
menubar-items.el: Add option corresponding to kill-word-into-kill-ring.
author | ben |
---|---|
date | Thu, 16 May 2002 13:30:58 +0000 |
parents | bf645ed7cfe3 |
children | 503b6a57cf47 |
comparison
equal
deleted
inserted
replaced
843:f46864126a0d | 844:047d37eb70d7 |
---|---|
2993 (eq (compare-buffer-substrings | 2993 (eq (compare-buffer-substrings |
2994 newbuf bmin bmax (current-buffer) bmin bmax) 0))) | 2994 newbuf bmin bmax (current-buffer) bmin bmax) 0))) |
2995 newbuf | 2995 newbuf |
2996 nil))) | 2996 nil))) |
2997 | 2997 |
2998 (defvar recover-file-diff-program "diff" | |
2999 "Absolute or relative name of the `diff' program used by `recover-file'.") | |
3000 (defvar recover-file-diff-arguments '("-c") | |
3001 "List of arguments (switches) to pass to `diff' by `recover-file'.") | |
3002 | |
2998 (defun recover-file (file) | 3003 (defun recover-file (file) |
2999 "Visit file FILE, but get contents from its last auto-save file." | 3004 "Visit file FILE, but get contents from its last auto-save file." |
3000 ;; Actually putting the file name in the minibuffer should be used | 3005 ;; Actually putting the file name in the minibuffer should be used |
3001 ;; only rarely. | 3006 ;; only rarely. |
3002 ;; Not just because users often use the default. | 3007 ;; Not just because users often use the default. |
3015 (make-auto-save-file-name)))) | 3020 (make-auto-save-file-name)))) |
3016 (cond ((if (file-exists-p file) | 3021 (cond ((if (file-exists-p file) |
3017 (not (file-newer-than-file-p file-name file)) | 3022 (not (file-newer-than-file-p file-name file)) |
3018 (not (file-exists-p file-name))) | 3023 (not (file-exists-p file-name))) |
3019 (error "Auto-save file %s not current" file-name)) | 3024 (error "Auto-save file %s not current" file-name)) |
3020 ((save-window-excursion | 3025 (t |
3026 (save-window-excursion | |
3021 ;; XEmacs change: use insert-directory instead of | 3027 ;; XEmacs change: use insert-directory instead of |
3022 ;; calling ls directly. | 3028 ;; calling ls directly. Add option for diff. |
3023 (with-output-to-temp-buffer "*Directory*" | 3029 (with-output-to-temp-buffer "*Directory*" |
3024 (buffer-disable-undo standard-output) | 3030 (buffer-disable-undo standard-output) |
3025 (save-excursion | 3031 (save-excursion |
3026 (set-buffer "*Directory*") | 3032 (set-buffer "*Directory*") |
3027 (setq default-directory (file-name-directory file)) | 3033 (setq default-directory (file-name-directory file)) |
3028 (insert-directory file | 3034 (insert-directory file |
3029 (if (file-symlink-p file) "-lL" "-l")) | 3035 (if (file-symlink-p file) "-lL" "-l")) |
3030 (setq default-directory (file-name-directory file-name)) | 3036 (setq default-directory (file-name-directory file-name)) |
3031 (insert-directory file-name "-l"))) | 3037 (insert-directory file-name "-l"))) |
3032 (yes-or-no-p (format "Recover auto save file %s? " file-name))) | 3038 (block nil |
3033 (switch-to-buffer (find-file-noselect file t)) | 3039 (while t |
3034 (let ((buffer-read-only nil)) | 3040 (case (get-user-response |
3035 (erase-buffer) | 3041 nil |
3036 (let ((coding-system-for-read 'escape-quoted)) | 3042 ;; Formerly included file name. Useless now that |
3037 (insert-file-contents file-name nil))) | 3043 ;; we display an ls of the files, and potentially |
3038 (after-find-file nil nil t)) | 3044 ;; fills up the minibuffer, esp. with autosaves |
3039 (t (error "Recover-file cancelled."))))))) | 3045 ;; all in one directory. |
3046 "Recover auto save file? " | |
3047 '(("yes" "%_Yes" yes) | |
3048 ("no" "%_No" no) | |
3049 ("diff" "%_Diff" diff))) | |
3050 (no (error "Recover-file cancelled.")) | |
3051 (yes | |
3052 (switch-to-buffer (find-file-noselect file t)) | |
3053 (let ((buffer-read-only nil)) | |
3054 (erase-buffer) | |
3055 (let ((coding-system-for-read 'escape-quoted)) | |
3056 (insert-file-contents file-name nil))) | |
3057 (after-find-file nil nil t) | |
3058 (return nil)) | |
3059 (diff | |
3060 ;; rather than just diff the two files (which would | |
3061 ;; be easy), we have to deal with the fact that | |
3062 ;; they may be in different formats, since | |
3063 ;; auto-saves are always in escape-quoted. so, we | |
3064 ;; read the file into a buffer (#### should we look | |
3065 ;; at or use a file if it's already in a buffer? | |
3066 ;; maybe we would find hints as to the encoding of | |
3067 ;; the file?), then we save the resulting buffer in | |
3068 ;; escape-quoted, do the diff (between two files | |
3069 ;; both in escape-quoted) and read in the results | |
3070 ;; using coding system escape-quoted. That way, we | |
3071 ;; should get what's correct most of the time. | |
3072 (let ((buffer (generate-new-buffer "*recover*")) | |
3073 (temp | |
3074 (make-temp-name | |
3075 (concat (file-name-as-directory | |
3076 (temp-directory)) | |
3077 (file-name-nondirectory file) "-")))) | |
3078 (unwind-protect | |
3079 (progn | |
3080 (save-current-buffer | |
3081 (set-buffer buffer) | |
3082 (insert-file-contents file) | |
3083 (let ((coding-system-for-write | |
3084 'escape-quoted)) | |
3085 (write-region (point-min) (point-max) | |
3086 temp nil 'silent))) | |
3087 (with-output-to-temp-buffer "*Autosave Diff*" | |
3088 (buffer-disable-undo standard-output) | |
3089 (let ((coding-system-for-read | |
3090 'escape-quoted)) | |
3091 (condition-case ferr | |
3092 (apply #'call-process | |
3093 recover-file-diff-program | |
3094 nil standard-output nil | |
3095 (append | |
3096 recover-file-diff-arguments | |
3097 (list temp file-name))) | |
3098 (io-error | |
3099 (save-excursion | |
3100 (set-buffer standard-output) | |
3101 (setq default-directory | |
3102 (file-name-directory file)) | |
3103 (insert-directory | |
3104 file | |
3105 (if (file-symlink-p file) "-lL" | |
3106 "-l")) | |
3107 (setq default-directory | |
3108 (file-name-directory file-name)) | |
3109 (insert-directory file-name "-l") | |
3110 (terpri) | |
3111 (princ "Error during diff: ") | |
3112 (display-error ferr | |
3113 standard-output))))))) | |
3114 (ignore-errors (kill-buffer buffer)) | |
3115 (ignore-file-errors | |
3116 (delete-file temp))))))))))))))) | |
3040 | 3117 |
3041 (defun recover-session () | 3118 (defun recover-session () |
3042 "Recover auto save files from a previous Emacs session. | 3119 "Recover auto save files from a previous Emacs session. |
3043 This command first displays a Dired buffer showing you the | 3120 This command first displays a Dired buffer showing you the |
3044 previous sessions that you could recover from. | 3121 previous sessions that you could recover from. |