annotate lisp/dired/gmhist-mh.el @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;;; gmhist-mh.el - emulate proposed Emacs 19 builtin Minibuffer History
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;;; Id: gmhist-mh.el,v 4.8 1991/09/20 13:15:40 sk RelBeta
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;;; This package redefines the functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;;; read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;;; completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;;; write-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;;; delete-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;;; read-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;;; read-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;;; switch-to-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;;; to implement the variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;;; minibuffer-history-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;;; file-history-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;;; buffer-history-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;;; buffer-history-lru-order
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;;; max-minibuffer-history-length
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;;; and the hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;;; after-write-region-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;;; after-delete-file-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (require 'gmhist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (provide 'gmhist-mh)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (defvar max-minibuffer-history-length 'not-implemented)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;;; Redefining basic Emacs functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defun gmhist-overwrite (fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; Overwrite FUN (a symbol, the name of a function) with gmhist-new-FUN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; Save the old def of FUN in gmhist-old-FUN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; Conventions: gmhist-FUN emulates FUN, but with history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; gmhist-new-FUN may take additional care of the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; that history is disabled before calling gmhist-FUN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; to do the real work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (let* ((fun-name (symbol-name fun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (old-name (intern (concat "gmhist-old-" fun-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (new-name (intern (concat "gmhist-new-" fun-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (or (fboundp old-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (fset old-name (symbol-function fun)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (fset fun new-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; Minibuffer history (not specialized like file or buffer history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; Should perhaps modify minibuffer keymaps directly:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; minibuffer-local-completion-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; minibuffer-local-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; minibuffer-local-must-match-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; minibuffer-local-ns-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defun gmhist-new-read-string (gnrs-prompt &optional initial-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 "Read a string from the minibuffer, prompting with string PROMPT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 If non-nil second arg INITIAL-INPUT is a string to insert before reading.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 See also `minibuffer-history-symbol'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (if minibuffer-history-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (gmhist-read-from-minibuffer gnrs-prompt initial-input gmhist-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (gmhist-old-read-string gnrs-prompt initial-input)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (gmhist-overwrite 'read-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (defun gmhist-new-completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (gncr-prompt table &optional predicate mustmatch initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 "Read a string in the minibuffer, with completion and history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 Args are PROMPT, TABLE, PREDICATE, REQUIRE-MATCH and INITIAL-INPUT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 PROMPT is a string to prompt with; normally it ends in a colon and a space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 TABLE is an alist whose elements' cars are strings, or an obarray (see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 try-completion).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 PREDICATE limits completion to a subset of TABLE see try-completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 for details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 the input is (or completes to) an element of TABLE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 If it is also not t, Return does not exit if it does non-null completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 Case is ignored if ambient value of completion-ignore-case is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 *** This is the gmhist version ***
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 See variable `minibuffer-history-symbol'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (if minibuffer-history-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (gmhist-completing-read gncr-prompt table predicate mustmatch initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (gmhist-old-completing-read gncr-prompt table predicate mustmatch initial)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (gmhist-overwrite 'completing-read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;; File history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defvar file-history (get file-history-symbol 'initial-hist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "Default history of file names read with read-file-name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 This symbol is the default value of file-history-symbol (q.v.).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (defvar insert-file-default nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 "*If non-nil, defaults for filenames will be inserted into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 minibuffer prompt. This has the advantage of putting the default onto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 the file-history (which see).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defun gmhist-new-read-file-name (gnrfn-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 &optional dir default mustmatch initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "Read file name, maintaining history in value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 file-history-symbol, prompting with PROMPT, completing in directory DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 Value is not expanded! You must call expand-file-name yourself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 Default name to third arg DEFAULT if user enters a null string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 \(If DEFAULT is omitted, the visited file name is used.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 Fourth arg MUSTMATCH non-nil means require existing file's name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 Non-nil and non-t means also require confirmation after completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 Fifth arg INITIAL specifies text to start with.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 DIR defaults to current buffer's default-directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 *** This is the gmhist version ***
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 It differs from the original read-file-name in providing a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 history of filenames in the variable whose name is the value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 file-history-symbol (usually 'file-history) (both of which see).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 INITIAL defaults to default-directory's value if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 insert-default-directory is non-nil. Also, if insert-file-default is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 non-nil, it inserts the DEFAULT string if no INITIAL is given, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 has the advantage of putting the default onto the file-history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 However, setting INITIAL to a string is a way for providing an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 editable default, something not possible with (pre Emacs-19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 read-file-name. Setting INITIAL and insert-default-directory to nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 will yield a basename for the file, relative to default-directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 See function read-with-history-in for a list of properties you can put
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 on file-history-symbol."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (if (null file-history-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (gmhist-old-read-file-name gnrfn-prompt dir default mustmatch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (gmhist-read-file-name gnrfn-prompt dir default mustmatch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (if (and insert-file-default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (not initial))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 initial))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; It is a shame that none of the standard hooks are defvar'd!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; Also, the coexistence of `hooks' vs `hook' is annoying.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;; The singular seems to be the majority, so I'll use that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defvar after-write-region-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "Run after the gmhist version of `write-region'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 The variables `start', `end', `filename', `append', `visit' are bound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 around the call to the hook.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; Don't use &rest args, as the hook may want to take advantage of our
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; arglist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (defun gmhist-new-write-region (start end filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 &optional append visit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 "Write current region into specified file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 When called from a program, takes three arguments:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 START, END and FILENAME. START and END are buffer positions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 Optional fourth argument APPEND if non-nil means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 append to existing file contents (if any).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 Optional fifth argument VISIT if t means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 set last-save-file-modtime of buffer to this file's modtime
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 and mark buffer not modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 If VISIT is neither t nor nil, it means do not print
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 the \"Wrote file\" message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 *** This is the gmhist version ***
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 See variable `after-write-region-hook'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (interactive "r\nFWrite region to file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (gmhist-old-write-region start end filename append visit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; basic-save-buffer would assume an error to mean
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;; write-region failed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (run-hooks 'after-write-region-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (error (message "Error in after-write-region-hook %s" err)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (sit-for 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (defvar after-delete-file-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 "Run after the gmhist version of `delete-file'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 The hook is run with `filename' bound to the filename.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (defun gmhist-new-delete-file (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 "Delete specified file. One argument, a file name string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 If file has multiple names, it continues to exist with the other names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 *** This is the gmhist version ***
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 See variable `after-delete-file-hook'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (interactive "fDelete file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (gmhist-old-delete-file filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; We don't want callers to assume an error in the hook to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; mean delete-file failed - or do we?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (run-hooks 'after-delete-file-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (error (message "Error in after-delete-file-hook %s" err)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (sit-for 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (gmhist-overwrite 'read-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (gmhist-overwrite 'write-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (gmhist-overwrite 'delete-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;; Redefining read-file-name does not suffice as interactive "f"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; calls the C version of read-file-name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; gmhist-interactive of gmhist.el,v 4.4 and later understands the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; indirection from file-history-symbol to 'file-history (or whatever
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; the current value may be).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (gmhist-make-magic 'find-file 'file-history-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (gmhist-make-magic 'find-file-other-window 'file-history-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (gmhist-make-magic 'find-file-read-only 'file-history-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (gmhist-make-magic 'insert-file 'file-history-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (gmhist-make-magic 'load-file 'file-history-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (gmhist-make-magic 'set-visited-file-name 'file-history-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (gmhist-make-magic 'append-to-file 'file-history-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;; write-region is wrapped by gmhist, no longer a subr, thus this works:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (gmhist-make-magic 'write-region 'file-history-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;; ditto for delete-file:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (gmhist-make-magic 'delete-file 'file-history-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (if gmhist-emacs-19-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;; In Emacs 19, these call the redefined read-file-name inside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;; interactive, so we don't need to do anything
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (gmhist-make-magic 'write-file 'file-history-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (gmhist-make-magic 'find-alternate-file 'file-history-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ;;; Buffer history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (defvar buffer-history-lru-order nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 "*If non-nil, the buffer history will be the complete buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 list in most recently used order (as returned by buffer-list).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 Usually, the buffer history is in the order entered using read-buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (defvar buffer-history (get 'buffer-history 'initial-hist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 "History of all buffer names read with read-buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (defun gmhist-new-read-buffer (gnrb-prompt &optional default existing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 "One arg PROMPT, a string. Read the name of a buffer and return as a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 Prompts with PROMPT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 Optional second arg is value to return if user enters an empty line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 If optional third arg REQUIRE-MATCH is non-nil, only existing buffer names are allowed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 *** This is the gmhist version ***
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 See variables `buffer-history-symbol' and `buffer-history-lru-order'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (if (and buffer-history-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 buffer-history-lru-order)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (set buffer-history-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (mapcar (function buffer-name) (buffer-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (gmhist-read-buffer gnrb-prompt default existing))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (defun gmhist-new-switch-to-buffer (buffer &optional norecord)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 "Select buffer BUFFER in the current window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 BUFFER may be a buffer or a buffer name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 Optional second arg NORECORD non-nil means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 do not put this buffer at the front of the list of recently selected ones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 WARNING: This is NOT the way to work on another buffer temporarily
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 within a Lisp program! Use `set-buffer' instead. That avoids messing with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 the window-buffer correspondences.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 *** This is the gmhist version ***
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 It adds buffer-history to switch-to-buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; should perhaps bypass gmhist if NORECORD is given?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (list (gmhist-new-read-buffer "Switch to buffer: " (other-buffer) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (gmhist-old-switch-to-buffer buffer norecord))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (gmhist-overwrite 'read-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;; switch-to-buffer is a subr:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (gmhist-overwrite 'switch-to-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ;; Redefining read-buffer does not suffice as interactive "b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; calls the C version of read-buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ;; gmhist-interactive of gmhist.el,v 4.4 and later understands the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;; indirection from buffer-history-symbol to 'buffer-history (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 ;; whatever the current value may be).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (mapcar (function (lambda (fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (gmhist-make-magic fun 'buffer-history-symbol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 '(switch-to-buffer-other-window ; files.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 append-to-buffer ; the rest from simple.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 prepend-to-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 copy-to-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;;; read-from-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;;; saved and defined in gmhist.el, just need to overwrite:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (fset 'read-from-minibuffer 'gmhist-new-read-from-minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ;; Now that we've redefined read-from-minibuffer we need to make sure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ;; that repeat-complex-command (C-x ESC), which calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 ;; read-from-minibuffer, adds the command to command-history and not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ;; to the ambient value of minibuffer-history-symbol. The latter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ;; could be confusing if e.g. inside a C-x C-f a C-x ESC is done (with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ;; enable-recursive-minibuffers t): it would add a command to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ;; file-history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ;(defun repeat-complex-command (repeat-complex-command-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ; "Edit and re-evaluate last complex command, or ARGth from last.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;A complex command is one which used the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;The command is placed in the minibuffer as a Lisp form for editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;The result is executed, repeating the command as changed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;If the command has been changed or is not the most recent previous command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;it is added to the front of the command history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ;Whilst editing the command, the following commands are available:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;\\{repeat-complex-command-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 ; (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ; (let ((elt (nth (1- repeat-complex-command-arg) command-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ; newcmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ; (if elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 ; (setq newcmd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 ; (let ((minibuffer-history-symbol nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ; ;; Don't let gmhist interfere with command-history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ; ;; command-history is special because it's builtin to M-x.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ; ;; Also, gmhist would store commands as strings, not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 ; ;; as s-exprs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ; ;; When gmhist is implemented in C, M-x must be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 ; ;; fixed to store strings, too.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 ; (read-from-minibuffer "Redo: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ; (prin1-to-string elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ; repeat-complex-command-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 ; t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 ; ;; If command to be redone does not match front of history,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 ; ;; add it to the history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ; (or (equal newcmd (car command-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ; (setq command-history (cons newcmd command-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ; (eval newcmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ; (ding))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ;; Actually, it's easier to just use the gmhist re-implementation instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (define-key ctl-x-map "\e" 'gmhist-repeat-complex-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (defun gmhist-repeat-complex-command (arg) ; C-x ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ;; This function from Mike Williams <Mike.Williams@comp.vuw.ac.nz>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 "Edit and re-evaluate last complex command, or ARGth from last.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 A complex command is one which used the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 The command is placed in the minibuffer as a Lisp form for editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 The result is executed, repeating the command as changed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 If the command has been changed or is not the most recent previous command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 it is added to the front of the command history."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (let ((print-escape-newlines t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (put 'command-history 'backup arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (put 'command-history 'cursor-end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (eval (read-with-history-in 'command-history "Redo: " nil 'lisp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (put 'command-history 'backup nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ;; TODO:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;; read-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ;; eval-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 ;; read-no-blanks-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ;; read-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;; read-variable