Mercurial > emacs
annotate lisp/rfn-eshadow.el @ 47036:9d848dcc4b5d
(make_terminal_frame) [CANNOT_DUMP]: Initialize
foreground and background colors. From Joe Buehler (tiny change).
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Mon, 26 Aug 2002 09:56:07 +0000 |
parents | 820cb95c5776 |
children | 85b74c0b8ff3 |
rev | line source |
---|---|
39609 | 1 ;;; rfn-eshadow.el --- Highlight `shadowed' part of read-file-name input text |
2 ;; | |
43893
89b76ba02505
(rfn-eshadow-update-overlay): Bind `inhibit-point-motion-hooks' to t while
Miles Bader <miles@gnu.org>
parents:
41954
diff
changeset
|
3 ;; Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. |
39609 | 4 ;; |
5 ;; Author: Miles Bader <miles@gnu.org> | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
6 ;; Keywords: convenience minibuffer |
39609 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 ;; | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
27 ;; Defines the mode `file-name-shadow-mode'. |
39609 | 28 ;; |
29 ;; The `read-file-name' function passes its result through | |
30 ;; `substitute-in-file-name', so any part of the string preceding | |
31 ;; multiple slashes (or a drive indicator on MS-DOS/MS-Windows) is | |
32 ;; ignored. | |
33 ;; | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
34 ;; If `file-name-shadow-mode' is active, any part of the |
39609 | 35 ;; minibuffer text that would be ignored because of this is given the |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
36 ;; properties in `file-name-shadow-properties', which may |
39609 | 37 ;; be used to make the ignored text invisible, dim, etc. |
38 ;; | |
39 | |
40 ;;; Code: | |
41 | |
42 | |
43 ;;; Customization | |
44 | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
45 (defconst file-name-shadow-properties-custom-type |
39609 | 46 '(list |
47 (checklist :inline t | |
48 (const :tag "Invisible" | |
49 :doc "Make shadowed part of filename invisible" | |
50 :format "%t%n%h" | |
51 :inline t | |
52 (invisible t intangible t)) | |
53 (list :inline t | |
54 :format "%v" | |
55 :tag "Face" | |
56 :doc "Display shadowed part of filename using a different face" | |
57 (const :format "" face) | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
58 (face :value file-name-shadow)) |
39609 | 59 (list :inline t |
60 :format "%t: %v%h" | |
61 :tag "Brackets" | |
62 ;; Note the 4 leading spaces in the doc string; | |
63 ;; this is hack to get around the fact that the | |
64 ;; newline after the second string widget comes | |
65 ;; from the string widget, and doesn't indent | |
66 ;; correctly. We could use a :size attribute to | |
67 ;; make the second string widget not have a | |
68 ;; terminating newline, but this makes it impossible | |
69 ;; to enter trailing whitespace, and it's desirable | |
70 ;; that it be possible. | |
71 :doc " Surround shadowed part of filename with brackets" | |
72 (const :format "" before-string) | |
73 (string :format "%v" :size 4 :value "{") | |
74 (const :format "" after-string) | |
75 ;; see above about why the 2nd string doesn't use :size | |
76 (string :format " and: %v" :value "} ")) | |
77 (list :inline t | |
78 :format "%t: %v%n%h" | |
79 :tag "String" | |
80 :doc "Display a string instead of the shadowed part of filename" | |
81 (const :format "" display) | |
82 (string :format "%v" :size 15 :value "<...ignored...>")) | |
83 (const :tag "Avoid" | |
84 :doc "Try to keep cursor out of shadowed part of filename" | |
85 :format "%t%n%h" | |
86 :inline t | |
87 (field shadow))) | |
88 (repeat :inline t | |
89 :tag "Other Properties" | |
90 (list :inline t | |
91 :format "%v" | |
92 (symbol :tag "Property") | |
93 (sexp :tag "Value"))))) | |
94 | |
39610
630b24783d8b
(read-file-name-electric-shadow-properties)
Miles Bader <miles@gnu.org>
parents:
39609
diff
changeset
|
95 ;;;###autoload |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
96 (defcustom file-name-shadow-properties |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
97 '(face file-name-shadow field shadow) |
39609 | 98 "Properties given to the `shadowed' part of a filename in the minibuffer. |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
99 Only used when `file-name-shadow-mode' is active. |
39609 | 100 If emacs is not running under a window system, |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
101 `file-name-shadow-tty-properties' is used instead." |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
102 :type file-name-shadow-properties-custom-type |
39609 | 103 :group 'minibuffer) |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
104 ;; backwards compatibility |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
105 (make-obsolete-variable 'read-file-name-electric-shadow-properties |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
106 'file-name-shadow-properties "21.4") |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
107 (defvaralias 'read-file-name-electric-shadow-properties |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
108 'file-name-shadow-properties) |
39609 | 109 |
39610
630b24783d8b
(read-file-name-electric-shadow-properties)
Miles Bader <miles@gnu.org>
parents:
39609
diff
changeset
|
110 ;;;###autoload |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
111 (defcustom file-name-shadow-tty-properties |
39609 | 112 '(before-string "{" after-string "} " field shadow) |
113 "Properties given to the `shadowed' part of a filename in the minibuffer. | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
114 Only used when `file-name-shadow-mode' is active and emacs |
39609 | 115 is not running under a window-system; if emacs is running under a window |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
116 system, `file-name-shadow-properties' is used instead." |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
117 :type file-name-shadow-properties-custom-type |
39609 | 118 :group 'minibuffer) |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
119 ;; backwards compatibility |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
120 (make-obsolete-variable 'read-file-name-electric-shadow-tty-properties |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
121 'file-name-shadow-tty-properties "21.4") |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
122 (defvaralias 'read-file-name-electric-shadow-tty-properties |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
123 'file-name-shadow-tty-properties) |
39609 | 124 |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
125 (defface file-name-shadow |
39609 | 126 '((((background dark)) |
127 :foreground "grey50") | |
128 (t | |
129 :foreground "grey70")) | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
130 "Face used by `file-name-shadow-mode' for the shadow." |
39609 | 131 :group 'minibuffer) |
132 | |
133 | |
134 ;;; Internal variables | |
135 | |
136 ;; Regexp to locate dividing point between shadow and real pathname | |
137 (defconst rfn-eshadow-regexp | |
138 (cond ((memq system-type '(ms-dos windows-nt)) | |
139 ;; This horrible regexp considers the following patterns as | |
140 ;; starting an absolute pathname, when following a `/' or an `\': | |
141 ;; L: / // ~ $ \\ \\\\ | |
39714
e6ba84d67359
(rfn-eshadow-regexp): Deal correctly with escaped dollar-signs.
Miles Bader <miles@gnu.org>
parents:
39620
diff
changeset
|
142 "\\(.*[^/]+/+?\\|/*?\\|\\)\\(~\\|$[^$]\\|$\\'\\|[][\\^a-z]:\\|//?\\([^][\\^a-z/$~]\\|[^/$~][^:]\\|[^/$~]?\\'\\)\\)") |
39609 | 143 (t |
144 ;; default is for unix-style filenames | |
39714
e6ba84d67359
(rfn-eshadow-regexp): Deal correctly with escaped dollar-signs.
Miles Bader <miles@gnu.org>
parents:
39620
diff
changeset
|
145 "\\(.*/\\)\\([/~]\\|$[^$]\\|$\\'\\)")) |
39609 | 146 "Regular expression used to match shadowed filenames. |
147 There should be at least one regexp group; the end of the first one | |
148 is used as the end of the shadowed portion of the filename.") | |
149 | |
150 ;; A list of minibuffers to which we've added a post-command-hook. | |
151 (defvar rfn-eshadow-frobbed-minibufs nil) | |
152 | |
153 ;; An overlay covering the shadowed part of the filename (local to the | |
154 ;; minibuffer). | |
155 (defvar rfn-eshadow-overlay) | |
156 (make-variable-buffer-local 'rfn-eshadow-overlay) | |
157 | |
158 | |
159 ;;; Hook functions | |
160 | |
161 ;; This function goes on minibuffer-setup-hook | |
162 (defun rfn-eshadow-setup-minibuffer () | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
163 "Set up a minibuffer for `file-name-shadow-mode'. |
39609 | 164 The prompt and initial input should already have been inserted." |
165 (when minibuffer-completing-file-name | |
166 (setq rfn-eshadow-overlay | |
167 (make-overlay (minibuffer-prompt-end) (minibuffer-prompt-end))) | |
168 ;; Give rfn-eshadow-overlay the user's props. | |
169 (let ((props | |
170 (if window-system | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
171 file-name-shadow-properties |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
172 file-name-shadow-tty-properties))) |
39609 | 173 (while props |
174 (overlay-put rfn-eshadow-overlay (pop props) (pop props)))) | |
175 ;; Turn on overlay evaporation so that we don't have to worry about | |
176 ;; odd effects when the overlay sits empty at the beginning of the | |
177 ;; minibuffer. | |
178 (overlay-put rfn-eshadow-overlay 'evaporate t) | |
179 ;; Add our post-command hook, and make sure can remove it later. | |
180 (add-to-list 'rfn-eshadow-frobbed-minibufs (current-buffer)) | |
181 (add-hook 'post-command-hook #'rfn-eshadow-update-overlay nil t))) | |
182 | |
183 ;; post-command-hook to update overlay | |
184 (defun rfn-eshadow-update-overlay () | |
185 "Update `rfn-eshadow-overlay' to cover shadowed part of minibuffer input. | |
186 This is intended to be used as a minibuffer post-command-hook for | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
187 `file-name-shadow-mode'; the minibuffer should have already |
39609 | 188 been set up by `rfn-eshadow-setup-minibuffer'." |
189 ;; This is not really a correct implementation; it won't always do the | |
190 ;; right thing in the presence of environment variables that | |
191 ;; substitute-in-file-name would expand; currently it just assumes any | |
39613
32898a97e761
(rfn-eshadow-update-overlay): Use `minibuffer-prompt-end'.
Miles Bader <miles@gnu.org>
parents:
39610
diff
changeset
|
192 ;; environment variable contains an absolute filename. |
39609 | 193 (save-excursion |
43893
89b76ba02505
(rfn-eshadow-update-overlay): Bind `inhibit-point-motion-hooks' to t while
Miles Bader <miles@gnu.org>
parents:
41954
diff
changeset
|
194 (let ((inhibit-point-motion-hooks t)) |
89b76ba02505
(rfn-eshadow-update-overlay): Bind `inhibit-point-motion-hooks' to t while
Miles Bader <miles@gnu.org>
parents:
41954
diff
changeset
|
195 (goto-char (minibuffer-prompt-end)) |
89b76ba02505
(rfn-eshadow-update-overlay): Bind `inhibit-point-motion-hooks' to t while
Miles Bader <miles@gnu.org>
parents:
41954
diff
changeset
|
196 ;; Update the overlay (which will evaporate if it's empty). |
89b76ba02505
(rfn-eshadow-update-overlay): Bind `inhibit-point-motion-hooks' to t while
Miles Bader <miles@gnu.org>
parents:
41954
diff
changeset
|
197 (move-overlay rfn-eshadow-overlay |
89b76ba02505
(rfn-eshadow-update-overlay): Bind `inhibit-point-motion-hooks' to t while
Miles Bader <miles@gnu.org>
parents:
41954
diff
changeset
|
198 (point) |
89b76ba02505
(rfn-eshadow-update-overlay): Bind `inhibit-point-motion-hooks' to t while
Miles Bader <miles@gnu.org>
parents:
41954
diff
changeset
|
199 (if (looking-at rfn-eshadow-regexp) |
89b76ba02505
(rfn-eshadow-update-overlay): Bind `inhibit-point-motion-hooks' to t while
Miles Bader <miles@gnu.org>
parents:
41954
diff
changeset
|
200 (match-end 1) |
89b76ba02505
(rfn-eshadow-update-overlay): Bind `inhibit-point-motion-hooks' to t while
Miles Bader <miles@gnu.org>
parents:
41954
diff
changeset
|
201 (point)))))) |
39609 | 202 |
203 | |
204 ;;; Note this definition must be at the end of the file, because | |
205 ;;; `define-minor-mode' actually calls the mode-function if the | |
206 ;;; associated variable is non-nil, which requires that all needed | |
207 ;;; functions be already defined. [This is arguably a bug in d-m-m] | |
208 ;;;###autoload | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
209 (define-minor-mode file-name-shadow-mode |
47034 | 210 "Toggle File-Name Shadow mode. |
211 When active, any part of a filename being read in the minibuffer | |
212 that would be ignored (because the result is passed through | |
213 `substitute-in-file-name') is given the properties in | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
214 `file-name-shadow-properties', which can be used to make |
45177
3cb6d6563fba
rfn-eshadow.el (read-file-name-electric-shadow-mode): Fix typos in
Juanma Barranquero <lekktu@gmail.com>
parents:
43893
diff
changeset
|
215 that portion dim, invisible, or otherwise less visually noticeable. |
39609 | 216 |
217 With prefix argument ARG, turn on if positive, otherwise off. | |
218 Returns non-nil if the new state is enabled." | |
219 :global t | |
220 :group 'minibuffer | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
221 (if file-name-shadow-mode |
39609 | 222 ;; Enable the mode |
223 (add-hook 'minibuffer-setup-hook 'rfn-eshadow-setup-minibuffer) | |
224 ;; Disable the mode | |
225 (remove-hook 'minibuffer-setup-hook 'rfn-eshadow-setup-minibuffer) | |
226 ;; Remove our entry from any post-command-hook variable's it's still in | |
227 (dolist (minibuf rfn-eshadow-frobbed-minibufs) | |
228 (with-current-buffer minibuf | |
229 (remove-hook 'post-command-hook #'rfn-eshadow-update-overlay t))) | |
230 (setq rfn-eshadow-frobbed-minibufs nil))) | |
231 | |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
232 ;; backwards compatibility |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
233 (make-obsolete 'read-file-name-electric-shadow-mode 'file-name-shadow-mode |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
234 "21.4") |
47034 | 235 ;;;###autoload |
47028
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
236 (defalias 'read-file-name-electric-shadow-mode 'file-name-shadow-mode) |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
237 (make-obsolete-variable 'read-file-name-electric-shadow-mode |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
238 'file-name-shadow-mode "21.4") |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
239 (defvaralias 'read-file-name-electric-shadow-mode 'file-name-shadow-mode) |
0919c09730ad
(file-name-shadow-properties-custom-type): Renamed from
Miles Bader <miles@gnu.org>
parents:
45177
diff
changeset
|
240 |
39609 | 241 |
242 (provide 'rfn-eshadow) | |
243 | |
244 ;;; rfn-eshadow.el ends here |