Mercurial > emacs
annotate lisp/minibuf-eldef.el @ 51195:3cbf29813eea
(struct frame): Rename members height to text_lines,
width to text_cols, window_height to total_lines, window_width to
total_cols, new_height to new_text_lines, new_width to
new_text_cols. All uses changed.
(struct frame): New members which consolidate common members of
x_output, w32_output, and mac_output structures: left_pos,
top_pos, pixel_height, pixel_width, x_pixels_diff, y_pixels_diff,
win_gravity, size_hint_flags, border_width, internal_border_width,
line_height, fringe_cols, left_fringe_width, right_fringe_width,
want_fullscreen. All uses changed.
(struct frame): New member column_width contaning the canonical
column width, analogue to line_height. All uses changed.
(struct frame): Rename members scroll_bar_pixel_width to
config_scroll_bar_width, and scroll_bar_cols to
config_scroll_bar_cols. All uses changed.
(struct frame): New member scroll_bar_actual_width which
consolidates and renames the vertical_scroll_bar_extra member of
x_output, w32_output, and mac_output structures. All uses changed.
(FRAME_PIXEL_HEIGHT): Renamed from PIXEL_HEIGHT and moved
from x/w32/macterm.h files. All uses changed. Also change code
which referred to f->output_data...->pixel_height.
(FRAME_PIXEL_WIDTH): Renamed from PIXEL_WIDTH and moved
from x/w32/macterm.h files. All uses changed. Also change code
which referred to f->output_data...->pixel_width.
(FRAME_LINES): Renamed from FRAME_HEIGHT. All uses changed.
Also change code which referred to f->height.
(FRAME_COLS): Renamed from FRAME_WIDTH. All uses changed.
Also change code which referred to f->width.
(FRAME_NEW_HEIGHT, FRAME_NEW_WIDTH): Remove macros; change uses
to update new_text_lines and new_text_cols members directly.
(FRAME_CONFIG_SCROLL_BAR_WIDTH): Renamed from
FRAME_SCROLL_BAR_PIXEL_WIDTH. All uses changed.
(FRAME_CONFIG_SCROLL_BAR_COLS): Renamed from
FRAME_SCROLL_BAR_COLS. All uses changed.
(FRAME_LEFT_SCROLL_BAR_COLS, FRAME_RIGHT_SCROLL_BAR_COLS):
Renamed from FRAME_LEFT_SCROLL_BAR_WIDTH and
FRAME_RIGHT_SCROLL_BAR_WIDTH, resp. All uses changed.
(FRAME_SCROLL_BAR_AREA_WIDTH, FRAME_LEFT_SCROLL_BAR_AREA_WIDTH)
(FRAME_RIGHT_SCROLL_BAR_AREA_WIDTH): New macros.
(FRAME_TOTAL_COLS): Renamed from FRAME_WINDOW_WIDTH.
(SET_FRAME_COLS): Renamed from SET_FRAME_WIDTH.
(FRAME_TOTAL_COLS_ARG): Renamed from FRAME_WINDOW_WIDTH_ARG.
(WINDOW_VERTICAL_SCROLL_BAR_COLUMN): Remove unused macro.
(WINDOW_VERTICAL_SCROLL_BAR_HEIGHT): Remove unused macro.
(FRAME_LINE_HEIGHT): Renamed from CANON_Y_UNIT. Unconditionally
return line_height member (it now has proper value also for
non-window frames).
(FRAME_COLUMN_WIDTH): Renamed from CANON_X_UNIT. Unconditionally
return new column_width member (rather than the default font width).
(FRAME_FRINGE_COLS, FRAME_LEFT_FRINGE_WIDTH)
(FRAME_RIGHT_FRINGE_WIDTH): Renamed from FRAME_X_... and moved
from x/w32/macterm.h files. Unconditionally return corresponding
member of frame structure (they now have proper values also for
non-window frames).
(FRAME_TOTAL_FRINGE_WIDTH): Renamed from FRAME_FRINGE_WIDTH.
Calculate return value from left and right widths.
(FRAME_INTERNAL_BORDER_WIDTH): Unconditionally return
internal_border_width member (has proper value for non-window frame).
(FRAME_PIXEL_X_FROM_CANON_X): Renamed from PIXEL_X_FROM_CANON_X.
(FRAME_PIXEL_Y_FROM_CANON_Y): Renamed from PIXEL_Y_FROM_CANON_Y.
(FRAME_CANON_X_FROM_PIXEL_X): Renamed from CANON_X_FROM_PIXEL_X.
(FRAME_CANON_Y_FROM_PIXEL_Y): Renamed from CANON_Y_FROM_PIXEL_Y.
(FRAME_LINE_TO_PIXEL_Y): Renamed from CHAR_TO_PIXEL_ROW,
consolidated from xterm.h, macterm.h, and w32term.h.
(FRAME_COL_TO_PIXEL_X): Renamed from CHAR_TO_PIXEL_COL,
consolidated from xterm.h, macterm.h, and w32term.h.
(FRAME_TEXT_COLS_TO_PIXEL_WIDTH): Renamed from
CHAR_TO_PIXEL_WIDTH consolidated from x/mac/w32term.h.
(FRAME_TEXT_LINES_TO_PIXEL_HEIGHT): Renamed from
CHAR_TO_PIXEL_HEIGHT consolidated from x/mac/w32term.h.
(FRAME_PIXEL_Y_TO_LINE): Renamed from PIXEL_TO_CHAR_ROW
consolidated from x/mac/w32term.h.
(FRAME_PIXEL_X_TO_COL): Renamed from PIXEL_TO_CHAR_COL
consolidated from x/mac/w32term.h.
(FRAME_PIXEL_WIDTH_TO_TEXT_COLS): Renamed from
PIXEL_TO_CHAR_WIDTH consolidated from x/mac/w32term.h.
(FRAME_PIXEL_HEIGHT_TO_TEXT_LINES): Renamed from
PIXEL_TO_CHAR_HEIGHT consolidated from x/mac/w32term.h.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Sat, 24 May 2003 21:58:07 +0000 |
parents | e88404e8f2cf |
children | 695cf19ef79e d7ddb3e565de |
rev | line source |
---|---|
34392 | 1 ;;; minibuf-eldef.el --- Only show defaults in prompts when applicable |
2 ;; | |
39596
fc100d4d02bc
(minibuf-eldef-setup-minibuffer)
Miles Bader <miles@gnu.org>
parents:
34392
diff
changeset
|
3 ;; Copyright (C) 2000, 2001 Free Software Foundation, Inc. |
34392 | 4 ;; |
5 ;; Author: Miles Bader <miles@gnu.org> | |
6 ;; Keywords: convenience | |
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 ;; | |
27 ;; Defines the mode `minibuffer-electric-default-mode'. | |
28 ;; | |
29 ;; When active, minibuffer prompts that show a default value only show | |
30 ;; the default when it's applicable -- that is, when hitting RET would | |
31 ;; yield the default value. If the user modifies the input such that | |
32 ;; hitting RET would enter a non-default value, the prompt is modified | |
33 ;; to remove the default indication (which is restored if the input is | |
34 ;; ever restore to the match the initial input). | |
35 | |
36 ;;; Code: | |
37 | |
38 (defvar minibuffer-default-in-prompt-regexps | |
39 '(("\\( (default\\>.*)\\):? \\'" . 1)) | |
40 "*A list of regexps matching the parts of minibuffer prompts showing defaults. | |
41 When `minibuffer-electric-default-mode' is active, these regexps are | |
42 used to identify the portions of prompts to elide. | |
43 | |
44 Each entry is either a string, which should be a regexp matching the | |
45 default portion of the prompt, or a cons cell, who's car is a regexp | |
46 matching the default part of the prompt, and who's cdr indicates the | |
47 regexp subexpression that matched.") | |
48 | |
49 | |
50 ;;; Internal variables | |
51 | |
52 ;; A list of minibuffers to which we've added a post-command-hook. | |
53 (defvar minibuf-eldef-frobbed-minibufs nil) | |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41953
diff
changeset
|
54 |
34392 | 55 ;;; The following are all local variables in the minibuffer |
56 | |
57 ;; Input pre-inserted into the minibuffer before the user can edit it. | |
58 (defvar minibuf-eldef-initial-input) | |
59 (make-variable-buffer-local 'minibuf-eldef-initial-input) | |
60 ;; and the length of the buffer with it inserted. | |
61 (defvar minibuf-eldef-initial-buffer-length) | |
62 (make-variable-buffer-local 'minibuf-eldef-initial-buffer-length) | |
63 | |
64 ;; True if the current minibuffer prompt contains the default spec. | |
65 (defvar minibuf-eldef-showing-default-in-prompt) | |
66 (make-variable-buffer-local 'minibuf-eldef-showing-default-in-prompt) | |
67 | |
68 ;; An overlay covering the default portion of the prompt | |
69 (defvar minibuf-eldef-overlay) | |
70 (make-variable-buffer-local 'minibuf-eldef-overlay) | |
71 | |
72 | |
73 ;;; Hook functions | |
74 | |
75 ;; This function goes on minibuffer-setup-hook | |
76 (defun minibuf-eldef-setup-minibuffer () | |
77 "Set up a minibuffer for `minibuffer-electric-default-mode'. | |
78 The prompt and initial input should already have been inserted." | |
39596
fc100d4d02bc
(minibuf-eldef-setup-minibuffer)
Miles Bader <miles@gnu.org>
parents:
34392
diff
changeset
|
79 (let ((regexps minibuffer-default-in-prompt-regexps) |
34392 | 80 (match nil) |
81 (inhibit-point-motion-hooks t)) | |
82 (save-excursion | |
83 (save-restriction | |
84 ;; Narrow to only the prompt | |
85 (goto-char (point-min)) | |
39596
fc100d4d02bc
(minibuf-eldef-setup-minibuffer)
Miles Bader <miles@gnu.org>
parents:
34392
diff
changeset
|
86 (narrow-to-region (point) (minibuffer-prompt-end)) |
34392 | 87 ;; See the prompt contains a default input indicator |
88 (while regexps | |
89 (setq match (pop regexps)) | |
90 (if (re-search-forward (if (stringp match) match (car match)) nil t) | |
91 (setq regexps nil) | |
92 (setq match nil))))) | |
93 (if (not match) | |
94 ;; Nope, so just make sure our post-command-hook isn't left around. | |
95 (remove-hook 'post-command-hook #'minibuf-eldef-update-minibuffer t) | |
96 ;; Yup; set things up so we can frob the prompt as the state of | |
97 ;; the input string changes. | |
98 (setq match (if (consp match) (cdr match) 0)) | |
99 (setq minibuf-eldef-overlay | |
100 (make-overlay (match-beginning match) (match-end match))) | |
101 (setq minibuf-eldef-showing-default-in-prompt t) | |
102 (setq minibuf-eldef-initial-input | |
39596
fc100d4d02bc
(minibuf-eldef-setup-minibuffer)
Miles Bader <miles@gnu.org>
parents:
34392
diff
changeset
|
103 (minibuffer-contents-no-properties)) |
34392 | 104 (setq minibuf-eldef-initial-buffer-length (point-max)) |
105 (add-to-list 'minibuf-eldef-frobbed-minibufs (current-buffer)) | |
106 (add-hook 'post-command-hook #'minibuf-eldef-update-minibuffer nil t)))) | |
107 | |
108 ;; post-command-hook to swap prompts when necessary | |
109 (defun minibuf-eldef-update-minibuffer () | |
110 "Update a minibuffer's prompt to include a default only when applicable. | |
111 This is intended to be used as a minibuffer post-command-hook for | |
112 `minibuffer-electric-default-mode'; the minibuffer should have already | |
113 been set up by `minibuf-eldef-setup-minibuffer'." | |
114 (unless (eq minibuf-eldef-showing-default-in-prompt | |
115 (and (= (point-max) minibuf-eldef-initial-buffer-length) | |
39596
fc100d4d02bc
(minibuf-eldef-setup-minibuffer)
Miles Bader <miles@gnu.org>
parents:
34392
diff
changeset
|
116 (string-equal (minibuffer-contents-no-properties) |
34392 | 117 minibuf-eldef-initial-input))) |
118 ;; swap state | |
119 (setq minibuf-eldef-showing-default-in-prompt | |
120 (not minibuf-eldef-showing-default-in-prompt)) | |
121 (cond (minibuf-eldef-showing-default-in-prompt | |
122 (overlay-put minibuf-eldef-overlay 'invisible nil) | |
123 (overlay-put minibuf-eldef-overlay 'intangible nil)) | |
124 (t | |
125 (overlay-put minibuf-eldef-overlay 'invisible t) | |
126 (overlay-put minibuf-eldef-overlay 'intangible t))))) | |
127 | |
128 | |
129 ;;; Note this definition must be at the end of the file, because | |
130 ;;; `define-minor-mode' actually calls the mode-function if the | |
131 ;;; associated variable is non-nil, which requires that all needed | |
132 ;;; functions be already defined. [This is arguably a bug in d-m-m] | |
133 ;;;###autoload | |
134 (define-minor-mode minibuffer-electric-default-mode | |
41953
395d420d4f73
(minibuffer-electric-default-mode): Doc fix.
Pavel Janík <Pavel@Janik.cz>
parents:
39596
diff
changeset
|
135 "Toggle Minibuffer Electric Default mode. |
34392 | 136 When active, minibuffer prompts that show a default value only show the |
137 default when it's applicable -- that is, when hitting RET would yield | |
138 the default value. If the user modifies the input such that hitting RET | |
139 would enter a non-default value, the prompt is modified to remove the | |
140 default indication. | |
141 | |
142 With prefix argument ARG, turn on if positive, otherwise off. | |
143 Returns non-nil if the new state is enabled." | |
144 :global t | |
145 :group 'minibuffer | |
146 (if minibuffer-electric-default-mode | |
147 ;; Enable the mode | |
148 (add-hook 'minibuffer-setup-hook 'minibuf-eldef-setup-minibuffer) | |
149 ;; Disable the mode | |
150 (remove-hook 'minibuffer-setup-hook 'minibuf-eldef-setup-minibuffer) | |
151 ;; Remove our entry from any post-command-hook variable's it's still in | |
152 (dolist (minibuf minibuf-eldef-frobbed-minibufs) | |
153 (with-current-buffer minibuf | |
154 (remove-hook 'post-command-hook #'minibuf-eldef-update-minibuffer t))) | |
155 (setq minibuf-eldef-frobbed-minibufs nil))) | |
156 | |
157 | |
158 (provide 'minibuf-eldef) | |
159 | |
160 ;;; minibuf-eldef.el ends here |