emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r110213: * lisp/minibuf-eldef.el: Mak


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r110213: * lisp/minibuf-eldef.el: Make it possible to replace (default ...) with [...].
Date: Wed, 26 Sep 2012 22:10:54 -0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 110213
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Wed 2012-09-26 22:10:54 -0400
message:
  * 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.
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/minibuf-eldef.el
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2012-09-26 15:19:10 +0000
+++ b/etc/NEWS  2012-09-27 02:10:54 +0000
@@ -86,6 +86,9 @@
 
 * Changes in Emacs 24.3
 
+** minibuffer-electric-default-mode can rewrite (default ...) to [...].
+Just set minibuffer-eldef-shorten-default to t before enabling the mode.
+
 ** Most y-or-n prompts now allow you to scroll the selected window.
 Typing C-v or M-v at a y-or-n prompt scrolls forward or backward
 respectively, without exiting from the prompt.

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-09-26 22:42:54 +0000
+++ b/lisp/ChangeLog    2012-09-27 02:10:54 +0000
@@ -1,3 +1,11 @@
+2012-09-27  Stefan Monnier  <address@hidden>
+
+       * 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.
+
 2012-09-26  Juanma Barranquero  <address@hidden>
 
        * international/uni-bidi.el:

=== modified file 'lisp/minibuf-eldef.el'
--- a/lisp/minibuf-eldef.el     2012-04-09 13:05:48 +0000
+++ b/lisp/minibuf-eldef.el     2012-09-27 02:10:54 +0000
@@ -1,4 +1,4 @@
-;;; minibuf-eldef.el --- Only show defaults in prompts when applicable
+;;; minibuf-eldef.el --- Only show defaults in prompts when applicable  -*- 
lexical-binding: t -*-
 ;;
 ;; Copyright (C) 2000-2012 Free Software Foundation, Inc.
 ;;
@@ -33,16 +33,22 @@
 
 ;;; Code:
 
+(defvar minibuffer-eldef-shorten-default nil
+  "If non-nil, shorten \"(default ...)\" to \"[...]\" in minibuffer prompts.")
+
 (defvar minibuffer-default-in-prompt-regexps
-  '(("\\( (default\\>.*)\\):? \\'" . 1) ("\\( \\[.*\\]\\):? *\\'" . 1))
+  `(("\\( (default\\(?: is\\)? \\(.*\\))\\):? \\'"
+     1 ,(if minibuffer-eldef-shorten-default " [\\2]"))
+    ("\\( \\[.*\\]\\):? *\\'" 1))
   "A list of regexps matching the parts of minibuffer prompts showing defaults.
 When `minibuffer-electric-default-mode' is active, these regexps are
 used to identify the portions of prompts to elide.
 
-Each entry is either a string, which should be a regexp matching the
-default portion of the prompt, or a cons cell, who's car is a regexp
-matching the default part of the prompt, and who's cdr indicates the
-regexp subexpression that matched.")
+Each entry is of the form (REGEXP MATCH-NUM &optional REWRITE),
+where REGEXP should match the default part of the prompt,
+MATCH-NUM is the subgroup that matched the actual default indicator,
+and REWRITE, if present, is a string to pass to `replace-match' that
+should be displayed in its place.")
 
 
 ;;; Internal variables
@@ -79,21 +85,42 @@
        (inhibit-point-motion-hooks t))
     (save-excursion
       (save-restriction
-       ;; Narrow to only the prompt
+       ;; Narrow to only the prompt.
        (goto-char (point-min))
        (narrow-to-region (point) (minibuffer-prompt-end))
-       ;; See the prompt contains a default input indicator
+       ;; See if the prompt contains a default input indicator.
        (while regexps
          (setq match (pop regexps))
-         (if (re-search-forward (if (stringp match) match (car match)) nil t)
-             (setq regexps nil)
-           (setq match nil)))))
+         (cond
+           ((not (re-search-forward (if (stringp match) match (car match))
+                                    nil t))
+            ;; No match yet, try the next rule.
+           (setq match nil))
+           ((and (consp (cdr-safe match)) (nth 2 match))
+            ;; Matched a replacement rule.
+            (let* ((inhibit-read-only t)
+                   (buffer-undo-list t)
+                   (submatch (nth 1 match))
+                   (replacement (nth 2 match))
+                   (props (text-properties-at (match-beginning submatch))))
+              (replace-match replacement nil nil nil submatch)
+              (set-text-properties (match-beginning submatch)
+                                   (match-end submatch)
+                                   props)
+              ;; Replacement done, now keep trying with subsequent rules.
+              (setq match nil)
+              (goto-char (point-min))))
+           ;; Matched a non-replacement (i.e. electric hide) rule, no need to
+           ;; keep trying.
+           (t (setq regexps nil))))))
     (if (not match)
-       ;; Nope, so just make sure our post-command-hook isn't left around.
+       ;; No match for electric hiding, so just make sure our
+       ;; post-command-hook isn't left around.
        (remove-hook 'post-command-hook #'minibuf-eldef-update-minibuffer t)
       ;; Yup; set things up so we can frob the prompt as the state of
       ;; the input string changes.
       (setq match (if (consp match) (cdr match) 0))
+      (setq match (if (consp match) (car match) match))
       (setq minibuf-eldef-overlay
            (make-overlay (match-beginning match) (match-end match)))
       (setq minibuf-eldef-showing-default-in-prompt t)
@@ -124,10 +151,6 @@
           (overlay-put minibuf-eldef-overlay 'intangible t)))))
 
 
-;;; Note this definition must be at the end of the file, because
-;;; `define-minor-mode' actually calls the mode-function if the
-;;; associated variable is non-nil, which requires that all needed
-;;; functions be already defined.  [This is arguably a bug in d-m-m]
 ;;;###autoload
 (define-minor-mode minibuffer-electric-default-mode
   "Toggle Minibuffer Electric Default mode.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]