aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2012-09-26 22:10:54 -0400
committerStefan Monnier2012-09-26 22:10:54 -0400
commita2e770db7f66fad562ba6cad5d21e6dcf6006973 (patch)
tree3a1eab83ad46063f7e42ecce15ff1c4e66e50076
parenta615a3aeef0fb1469dcf89e2217a027a6dce82c1 (diff)
downloademacs-a2e770db7f66fad562ba6cad5d21e6dcf6006973.tar.gz
emacs-a2e770db7f66fad562ba6cad5d21e6dcf6006973.zip
* lisp/minibuf-eldef.el: Make it possible to replace (default ...) with [...].
Set lexical-binding. (minibuffer-eldef-shorten-default): New var. (minibuffer-default-in-prompt-regexps): Use it for new default. (minibuf-eldef-setup-minibuffer): Add replacement functionality.
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/minibuf-eldef.el55
3 files changed, 50 insertions, 16 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 123ca4de93c..d860baa014b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -86,6 +86,9 @@ been adding them there, put them somewhere else, eg site-lisp.
86 86
87* Changes in Emacs 24.3 87* Changes in Emacs 24.3
88 88
89** minibuffer-electric-default-mode can rewrite (default ...) to [...].
90Just set minibuffer-eldef-shorten-default to t before enabling the mode.
91
89** Most y-or-n prompts now allow you to scroll the selected window. 92** Most y-or-n prompts now allow you to scroll the selected window.
90Typing C-v or M-v at a y-or-n prompt scrolls forward or backward 93Typing C-v or M-v at a y-or-n prompt scrolls forward or backward
91respectively, without exiting from the prompt. 94respectively, without exiting from the prompt.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 56d31f3875a..a000f3240a3 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12012-09-27 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * minibuf-eldef.el: Make it possible to replace (default ...) with [...].
4 Set lexical-binding.
5 (minibuffer-eldef-shorten-default): New var.
6 (minibuffer-default-in-prompt-regexps): Use it for new default.
7 (minibuf-eldef-setup-minibuffer): Add replacement functionality.
8
12012-09-26 Juanma Barranquero <lekktu@gmail.com> 92012-09-26 Juanma Barranquero <lekktu@gmail.com>
2 10
3 * international/uni-bidi.el: 11 * international/uni-bidi.el:
diff --git a/lisp/minibuf-eldef.el b/lisp/minibuf-eldef.el
index 4387fc625c6..92d5ec821b0 100644
--- a/lisp/minibuf-eldef.el
+++ b/lisp/minibuf-eldef.el
@@ -1,4 +1,4 @@
1;;; minibuf-eldef.el --- Only show defaults in prompts when applicable 1;;; minibuf-eldef.el --- Only show defaults in prompts when applicable -*- lexical-binding: t -*-
2;; 2;;
3;; Copyright (C) 2000-2012 Free Software Foundation, Inc. 3;; Copyright (C) 2000-2012 Free Software Foundation, Inc.
4;; 4;;
@@ -33,16 +33,22 @@
33 33
34;;; Code: 34;;; Code:
35 35
36(defvar minibuffer-eldef-shorten-default nil
37 "If non-nil, shorten \"(default ...)\" to \"[...]\" in minibuffer prompts.")
38
36(defvar minibuffer-default-in-prompt-regexps 39(defvar minibuffer-default-in-prompt-regexps
37 '(("\\( (default\\>.*)\\):? \\'" . 1) ("\\( \\[.*\\]\\):? *\\'" . 1)) 40 `(("\\( (default\\(?: is\\)? \\(.*\\))\\):? \\'"
41 1 ,(if minibuffer-eldef-shorten-default " [\\2]"))
42 ("\\( \\[.*\\]\\):? *\\'" 1))
38 "A list of regexps matching the parts of minibuffer prompts showing defaults. 43 "A list of regexps matching the parts of minibuffer prompts showing defaults.
39When `minibuffer-electric-default-mode' is active, these regexps are 44When `minibuffer-electric-default-mode' is active, these regexps are
40used to identify the portions of prompts to elide. 45used to identify the portions of prompts to elide.
41 46
42Each entry is either a string, which should be a regexp matching the 47Each entry is of the form (REGEXP MATCH-NUM &optional REWRITE),
43default portion of the prompt, or a cons cell, who's car is a regexp 48where REGEXP should match the default part of the prompt,
44matching the default part of the prompt, and who's cdr indicates the 49MATCH-NUM is the subgroup that matched the actual default indicator,
45regexp subexpression that matched.") 50and REWRITE, if present, is a string to pass to `replace-match' that
51should be displayed in its place.")
46 52
47 53
48;;; Internal variables 54;;; Internal variables
@@ -79,21 +85,42 @@ The prompt and initial input should already have been inserted."
79 (inhibit-point-motion-hooks t)) 85 (inhibit-point-motion-hooks t))
80 (save-excursion 86 (save-excursion
81 (save-restriction 87 (save-restriction
82 ;; Narrow to only the prompt 88 ;; Narrow to only the prompt.
83 (goto-char (point-min)) 89 (goto-char (point-min))
84 (narrow-to-region (point) (minibuffer-prompt-end)) 90 (narrow-to-region (point) (minibuffer-prompt-end))
85 ;; See the prompt contains a default input indicator 91 ;; See if the prompt contains a default input indicator.
86 (while regexps 92 (while regexps
87 (setq match (pop regexps)) 93 (setq match (pop regexps))
88 (if (re-search-forward (if (stringp match) match (car match)) nil t) 94 (cond
89 (setq regexps nil) 95 ((not (re-search-forward (if (stringp match) match (car match))
90 (setq match nil))))) 96 nil t))
97 ;; No match yet, try the next rule.
98 (setq match nil))
99 ((and (consp (cdr-safe match)) (nth 2 match))
100 ;; Matched a replacement rule.
101 (let* ((inhibit-read-only t)
102 (buffer-undo-list t)
103 (submatch (nth 1 match))
104 (replacement (nth 2 match))
105 (props (text-properties-at (match-beginning submatch))))
106 (replace-match replacement nil nil nil submatch)
107 (set-text-properties (match-beginning submatch)
108 (match-end submatch)
109 props)
110 ;; Replacement done, now keep trying with subsequent rules.
111 (setq match nil)
112 (goto-char (point-min))))
113 ;; Matched a non-replacement (i.e. electric hide) rule, no need to
114 ;; keep trying.
115 (t (setq regexps nil))))))
91 (if (not match) 116 (if (not match)
92 ;; Nope, so just make sure our post-command-hook isn't left around. 117 ;; No match for electric hiding, so just make sure our
118 ;; post-command-hook isn't left around.
93 (remove-hook 'post-command-hook #'minibuf-eldef-update-minibuffer t) 119 (remove-hook 'post-command-hook #'minibuf-eldef-update-minibuffer t)
94 ;; Yup; set things up so we can frob the prompt as the state of 120 ;; Yup; set things up so we can frob the prompt as the state of
95 ;; the input string changes. 121 ;; the input string changes.
96 (setq match (if (consp match) (cdr match) 0)) 122 (setq match (if (consp match) (cdr match) 0))
123 (setq match (if (consp match) (car match) match))
97 (setq minibuf-eldef-overlay 124 (setq minibuf-eldef-overlay
98 (make-overlay (match-beginning match) (match-end match))) 125 (make-overlay (match-beginning match) (match-end match)))
99 (setq minibuf-eldef-showing-default-in-prompt t) 126 (setq minibuf-eldef-showing-default-in-prompt t)
@@ -124,10 +151,6 @@ been set up by `minibuf-eldef-setup-minibuffer'."
124 (overlay-put minibuf-eldef-overlay 'intangible t))))) 151 (overlay-put minibuf-eldef-overlay 'intangible t)))))
125 152
126 153
127;;; Note this definition must be at the end of the file, because
128;;; `define-minor-mode' actually calls the mode-function if the
129;;; associated variable is non-nil, which requires that all needed
130;;; functions be already defined. [This is arguably a bug in d-m-m]
131;;;###autoload 154;;;###autoload
132(define-minor-mode minibuffer-electric-default-mode 155(define-minor-mode minibuffer-electric-default-mode
133 "Toggle Minibuffer Electric Default mode. 156 "Toggle Minibuffer Electric Default mode.