emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r115651: * lisp/replace.el (read-regexp-defaults-fun


From: Juri Linkov
Subject: [Emacs-diffs] trunk r115651: * lisp/replace.el (read-regexp-defaults-function): New defcustom.
Date: Fri, 20 Dec 2013 19:56:20 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 115651
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/14405
committer: Juri Linkov <address@hidden>
branch nick: trunk
timestamp: Fri 2013-12-20 21:55:56 +0200
message:
  * lisp/replace.el (read-regexp-defaults-function): New defcustom.
  (read-regexp-suggestions): New function.
  (read-regexp): Use `read-regexp-defaults-function' to get default values.
  Use `read-regexp-suggestions'.  Add non-empty default to history
  for empty input.
  (occur-read-regexp-defaults-function): Remove function.
  (occur-read-primary-args): Use `regexp-history-last' instead of
  `occur-read-regexp-defaults-function'.
  
  * lisp/hi-lock.el (hi-lock-read-regexp-defaults-function): Remove function.
  (hi-lock-line-face-buffer, hi-lock-face-buffer)
  (hi-lock-face-phrase-buffer): Use `regexp-history-last' instead of
  `hi-lock-read-regexp-defaults-function'.  Doc fix.
  (hi-lock-face-symbol-at-point): Replace `find-tag-default-as-regexp'
  with `find-tag-default-as-symbol-regexp'.  Doc fix.
  (hi-lock-read-regexp-defaults): Remove function.
  (hi-lock-regexp-okay): Add check for null.
  
  * lisp/progmodes/grep.el (grep-read-regexp): Use `grep-tag-default' for
  the arg DEFAULTS.  Move formatting of the prompt to `read-regexp'.
  
  * lisp/subr.el (find-tag-default-as-symbol-regexp): New function.
  (find-tag-default-as-regexp): Move symbol regexp formatting to
  `find-tag-default-as-symbol-regexp'.
modified:
  etc/NEWS                       news-20100311060928-aoit31wvzf25yr1z-1
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/hi-lock.el                hilock.el-20091113204419-o5vbwnq5f7feedwu-1889
  lisp/progmodes/grep.el         grep.el-20091113204419-o5vbwnq5f7feedwu-2948
  lisp/replace.el                replace.el-20091113204419-o5vbwnq5f7feedwu-119
  lisp/subr.el                   subr.el-20091113204419-o5vbwnq5f7feedwu-151
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2013-12-20 18:41:31 +0000
+++ b/etc/NEWS  2013-12-20 19:55:56 +0000
@@ -331,9 +331,18 @@
 
 ** jit-lock-debug-mode lets you use the debuggers on code run via jit-lock.
 
-** completing-read-multiple's separator can now be a regexp.
+** Minibuffer
+
+*** completing-read-multiple's separator can now be a regexp.
 The default separator is changed to allow surrounding spaces around the comma.
 
+*** New option `read-regexp-defaults-function' defines the function
+that provides the default value for commands that ask for a regexp:
+`rgrep', `lgrep' `occur', `multi-occur', `multi-occur-in-matching-buffers',
+`highlight-regexp', `highlight-lines-matching-regexp', `highlight-phrase'.
+This option can be customized to values that provide a default value
+from the regexp last history element or from the symbol found at point.
+
 ** The backtrace debugger and local variables:
 *** The debugger's `e' command evaluates the code in the context at point.
 This includes using the lexical environment at point, which means that

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-12-20 19:47:01 +0000
+++ b/lisp/ChangeLog    2013-12-20 19:55:56 +0000
@@ -1,3 +1,30 @@
+2013-12-20  Juri Linkov  <address@hidden>
+
+       * replace.el (read-regexp-defaults-function): New defcustom (bug#14405).
+       (read-regexp-suggestions): New function.
+       (read-regexp): Use `read-regexp-defaults-function' to get default 
values.
+       Use `read-regexp-suggestions'.  Add non-empty default to history
+       for empty input.
+       (occur-read-regexp-defaults-function): Remove function.
+       (occur-read-primary-args): Use `regexp-history-last' instead of
+       `occur-read-regexp-defaults-function'.
+
+       * hi-lock.el (hi-lock-read-regexp-defaults-function): Remove function.
+       (hi-lock-line-face-buffer, hi-lock-face-buffer)
+       (hi-lock-face-phrase-buffer): Use `regexp-history-last' instead of
+       `hi-lock-read-regexp-defaults-function'.  Doc fix.
+       (hi-lock-face-symbol-at-point): Replace `find-tag-default-as-regexp'
+       with `find-tag-default-as-symbol-regexp'.  Doc fix.
+       (hi-lock-read-regexp-defaults): Remove function.
+       (hi-lock-regexp-okay): Add check for null.
+
+       * progmodes/grep.el (grep-read-regexp): Use `grep-tag-default' for
+       the arg DEFAULTS.  Move formatting of the prompt to `read-regexp'.
+
+       * subr.el (find-tag-default-as-symbol-regexp): New function.
+       (find-tag-default-as-regexp): Move symbol regexp formatting to
+       `find-tag-default-as-symbol-regexp'.
+
 2013-12-20  E Sabof  <address@hidden>  (tiny change)
 
        * hi-lock.el (hi-lock-set-pattern): Check for `font-lock-specified-p'.

=== modified file 'lisp/hi-lock.el'
--- a/lisp/hi-lock.el   2013-12-20 19:47:01 +0000
+++ b/lisp/hi-lock.el   2013-12-20 19:55:56 +0000
@@ -284,26 +284,6 @@
     map)
   "Key map for hi-lock.")
 
-(defvar hi-lock-read-regexp-defaults-function
-  'hi-lock-read-regexp-defaults
-  "Function that provides default regexp(s) for highlighting commands.
-This function should take no arguments and return one of nil, a
-regexp or a list of regexps for use with highlighting commands -
-`hi-lock-face-phrase-buffer', `hi-lock-line-face-buffer' and
-`hi-lock-face-buffer'.  The return value of this function is used
-as DEFAULTS param of `read-regexp' while executing the
-highlighting command.  This function is called only during
-interactive use.  
-
-For example, to highlight at symbol at point use
-
-    \(setq hi-lock-read-regexp-defaults-function 
-         'find-tag-default-as-regexp\)
-
-If you need different defaults for different highlighting
-operations, use `this-command' to identify the command under
-execution.")
-
 ;; Visible Functions
 
 ;;;###autoload
@@ -431,7 +411,7 @@
 (defun hi-lock-line-face-buffer (regexp &optional face)
   "Set face of all lines containing a match of REGEXP to FACE.
 Interactively, prompt for REGEXP then FACE.  Use
-`hi-lock-read-regexp-defaults-function' to retrieve default
+`read-regexp-defaults-function' to customize default
 value(s) of REGEXP.  Use the global history list for FACE.
 
 Use Font lock mode, if enabled, to highlight REGEXP.  Otherwise,
@@ -440,8 +420,7 @@
   (interactive
    (list
     (hi-lock-regexp-okay
-     (read-regexp "Regexp to highlight line"
-                 (funcall hi-lock-read-regexp-defaults-function)))
+     (read-regexp "Regexp to highlight line" 'regexp-history-last))
     (hi-lock-read-face-name)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
@@ -457,8 +436,8 @@
 (defun hi-lock-face-buffer (regexp &optional face)
   "Set face of each match of REGEXP to FACE.
 Interactively, prompt for REGEXP then FACE.  Use
-`hi-lock-read-regexp-defaults-function' to retrieve default
-value(s) REGEXP.  Use the global history list for FACE.
+`read-regexp-defaults-function' to customize default
+value(s) of REGEXP.  Use the global history list for FACE.
 
 Use Font lock mode, if enabled, to highlight REGEXP.  Otherwise,
 use overlays for highlighting.  If overlays are used, the
@@ -466,8 +445,7 @@
   (interactive
    (list
     (hi-lock-regexp-okay
-     (read-regexp "Regexp to highlight"
-                 (funcall hi-lock-read-regexp-defaults-function)))
+     (read-regexp "Regexp to highlight" 'regexp-history-last))
     (hi-lock-read-face-name)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
@@ -479,7 +457,7 @@
 (defun hi-lock-face-phrase-buffer (regexp &optional face)
   "Set face of each match of phrase REGEXP to FACE.
 Interactively, prompt for REGEXP then FACE.  Use
-`hi-lock-read-regexp-defaults-function' to retrieve default
+`read-regexp-defaults-function' to customize default
 value(s) of REGEXP.  Use the global history list for FACE.  When
 called interactively, replace whitespace in user provided regexp
 with arbitrary whitespace and make initial lower-case letters
@@ -492,8 +470,7 @@
    (list
     (hi-lock-regexp-okay
      (hi-lock-process-phrase
-      (read-regexp "Phrase to highlight"
-                  (funcall hi-lock-read-regexp-defaults-function))))
+      (read-regexp "Phrase to highlight" 'regexp-history-last)))
     (hi-lock-read-face-name)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
@@ -504,7 +481,7 @@
 ;;;###autoload
 (defun hi-lock-face-symbol-at-point ()
   "Set face of each match of the symbol at point.
-Use `find-tag-default-as-regexp' to retrieve the symbol at point.
+Use `find-tag-default-as-symbol-regexp' to retrieve the symbol at point.
 Use non-nil `hi-lock-auto-select-face' to retrieve the next face
 from `hi-lock-face-defaults' automatically.
 
@@ -513,7 +490,7 @@
 the highlighting will not update as you type."
   (interactive)
   (let* ((regexp (hi-lock-regexp-okay
-                 (find-tag-default-as-regexp)))
+                 (find-tag-default-as-symbol-regexp)))
         (hi-lock-auto-select-face t)
         (face (hi-lock-read-face-name)))
     (or (facep face) (setq face 'hi-yellow))
@@ -676,14 +653,12 @@
 
 Otherwise signal an error.  A pattern that matches the null string is
 not suitable."
-  (if (string-match regexp "")
-      (error "Regexp cannot match an empty string")
-    regexp))
-
-(defun hi-lock-read-regexp-defaults ()
-  "Return the latest regexp from `regexp-history'.
-See `hi-lock-read-regexp-defaults-function' for details."
-  (car regexp-history))
+  (cond
+   ((null regexp)
+    (error "Regexp cannot match nil"))
+   ((string-match regexp "")
+    (error "Regexp cannot match an empty string"))
+   (t regexp)))
 
 (defun hi-lock-read-face-name ()
   "Return face for interactive highlighting.

=== modified file 'lisp/progmodes/grep.el'
--- a/lisp/progmodes/grep.el    2013-12-06 15:34:06 +0000
+++ b/lisp/progmodes/grep.el    2013-12-20 19:55:56 +0000
@@ -819,12 +819,7 @@
 
 (defun grep-read-regexp ()
   "Read regexp arg for interactive grep."
-  (let ((default (grep-tag-default)))
-    (read-regexp
-     (concat "Search for"
-            (if (and default (> (length default) 0))
-                (format " (default \"%s\"): " default) ": "))
-     default 'grep-regexp-history)))
+  (read-regexp "Search for" 'grep-tag-default 'grep-regexp-history))
 
 (defun grep-read-files (regexp)
   "Read files arg for interactive grep."

=== modified file 'lisp/replace.el'
--- a/lisp/replace.el   2013-12-20 00:07:08 +0000
+++ b/lisp/replace.el   2013-12-20 19:55:56 +0000
@@ -626,6 +626,44 @@
 (defvar occur-collect-regexp-history '("\\1")
   "History of regexp for occur's collect operation")
 
+(defcustom read-regexp-defaults-function nil
+  "Function that provides default regexp(s) for regexp reading commands.
+This function should take no arguments and return one of nil, a
+regexp or a list of regexps.  The return value of this function is used
+as DEFAULTS param of `read-regexp'.  This function is called only during
+interactive use.
+
+If you need different defaults for different commands,
+use `this-command' to identify the command under execution.
+
+You can customize `read-regexp-defaults-function' to the value
+`find-tag-default-as-regexp' to highlight a symbol at point."
+  :type '(choice
+         (const :tag "No default regexp reading function" nil)
+         (const :tag "Latest regexp history" regexp-history-last)
+         (function-item :tag "Tag at point"
+                        find-tag-default)
+         (function-item :tag "Tag at point as regexp"
+                        find-tag-default-as-regexp)
+         (function-item :tag "Tag at point as symbol regexp"
+                        find-tag-default-as-symbol-regexp)
+         (function :tag "Function to provide default for read-regexp"))
+  :group 'matching
+  :version "24.4")
+
+(defun read-regexp-suggestions ()
+  "Return a list of standard suggestions for `read-regexp'.
+By default, the list includes the tag at point, the last isearch regexp,
+the last isearch string, and the last replacement regexp.  `read-regexp'
+appends the list returned by this function to the end of values available
+via \\<minibuffer-local-map>\\[next-history-element]."
+  (list
+   (find-tag-default-as-regexp)
+   (find-tag-default-as-symbol-regexp)
+   (car regexp-search-ring)
+   (regexp-quote (or (car search-ring) ""))
+   (car (symbol-value query-replace-from-history-variable))))
+
 (defun read-regexp (prompt &optional defaults history)
   "Read and return a regular expression as a string.
 When PROMPT doesn't end with a colon and space, it adds a final \": \".
@@ -637,29 +675,31 @@
 SUGGESTIONS is a list of strings that can be inserted into
 the minibuffer using \\<minibuffer-local-map>\\[next-history-element].  \
 The values supplied in SUGGESTIONS
-are prepended to the list of standard suggestions that include
-the tag at point, the last isearch regexp, the last isearch string,
-and the last replacement regexp.
+are prepended to the list of standard suggestions returned by
+`read-regexp-suggestions'.  The default values can be customized
+by `read-regexp-defaults-function'.
 
 Optional arg HISTORY is a symbol to use for the history list.
 If HISTORY is nil, `regexp-history' is used."
-  (let* ((default     (if (consp defaults) (car defaults) defaults))
+  (let* ((defaults
+          (if (and defaults (symbolp defaults))
+              (cond
+               ((eq (or read-regexp-defaults-function defaults)
+                    'regexp-history-last)
+                (car (symbol-value (or history 'regexp-history))))
+               ((functionp (or read-regexp-defaults-function defaults))
+                (funcall (or read-regexp-defaults-function defaults))))
+            defaults))
+        (default     (if (consp defaults) (car defaults) defaults))
         (suggestions (if (listp defaults) defaults (list defaults)))
-        (suggestions
-         (append
-          suggestions
-          (list
-           (find-tag-default-as-regexp)
-           (car regexp-search-ring)
-           (regexp-quote (or (car search-ring) ""))
-           (car (symbol-value query-replace-from-history-variable)))))
+        (suggestions (append suggestions (read-regexp-suggestions)))
         (suggestions (delete-dups (delq nil (delete "" suggestions))))
         ;; Do not automatically add default to the history for empty input.
         (history-add-new-input nil)
         (input (read-from-minibuffer
                 (cond ((string-match-p ":[ \t]*\\'" prompt)
                        prompt)
-                      (default
+                      ((and default (> (length default) 0))
                         (format "%s (default %s): " prompt
                                 (query-replace-descr default)))
                       (t
@@ -667,7 +707,9 @@
                 nil nil nil (or history 'regexp-history) suggestions t)))
     (if (equal input "")
        ;; Return the default value when the user enters empty input.
-       (or default input)
+       (prog1 (or default input)
+         (when default
+           (add-to-history (or history 'regexp-history) default)))
       ;; Otherwise, add non-empty input to the history and return input.
       (prog1 input
        (add-to-history (or history 'regexp-history) input)))))
@@ -1192,32 +1234,12 @@
   :group 'matching
   :version "22.1")
 
-(defvar occur-read-regexp-defaults-function
-  'occur-read-regexp-defaults
-  "Function that provides default regexp(s) for occur commands.
-This function should take no arguments and return one of nil, a
-regexp or a list of regexps for use with occur commands -
-`occur', `multi-occur' and `multi-occur-in-matching-buffers'.
-The return value of this function is used as DEFAULTS param of
-`read-regexp' while executing the occur command.  This function
-is called only during interactive use.
-
-For example, to check for occurrence of symbol at point use
-
-    (setq occur-read-regexp-defaults-function
-         'find-tag-default-as-regexp).")
-
-(defun occur-read-regexp-defaults ()
-  "Return the latest regexp from `regexp-history'.
-See `occur-read-regexp-defaults-function' for details."
-  (car regexp-history))
-
 (defun occur-read-primary-args ()
   (let* ((perform-collect (consp current-prefix-arg))
          (regexp (read-regexp (if perform-collect
                                   "Collect strings matching regexp"
                                 "List lines matching regexp")
-                              (funcall occur-read-regexp-defaults-function))))
+                              'regexp-history-last)))
     (list regexp
          (if perform-collect
              ;; Perform collect operation

=== modified file 'lisp/subr.el'
--- a/lisp/subr.el      2013-12-09 02:38:42 +0000
+++ b/lisp/subr.el      2013-12-20 19:55:56 +0000
@@ -2540,14 +2540,26 @@
 When in a major mode that does not provide its own
 `find-tag-default-function', return a regexp that matches the
 symbol at point exactly."
-  (let* ((tagf (or find-tag-default-function
-                  (get major-mode 'find-tag-default-function)
-                  'find-tag-default))
-        (tag (funcall tagf)))
-    (cond ((null tag) nil)
-         ((eq tagf 'find-tag-default)
-          (format "\\_<%s\\_>" (regexp-quote tag)))
-         (t (regexp-quote tag)))))
+  (let ((tag (funcall (or find-tag-default-function
+                         (get major-mode 'find-tag-default-function)
+                         'find-tag-default))))
+    (if tag (regexp-quote tag))))
+
+(defun find-tag-default-as-symbol-regexp ()
+  "Return regexp that matches the default tag at point as symbol.
+If there is no tag at point, return nil.
+
+When in a major mode that does not provide its own
+`find-tag-default-function', return a regexp that matches the
+symbol at point exactly."
+  (let ((tag-regexp (find-tag-default-as-regexp)))
+    (if (and tag-regexp
+            (eq (or find-tag-default-function
+                    (get major-mode 'find-tag-default-function)
+                    'find-tag-default)
+                'find-tag-default))
+       (format "\\_<%s\\_>" tag-regexp)
+      tag-regexp)))
 
 (defun play-sound (sound)
   "SOUND is a list of the form `(sound KEYWORD VALUE...)'.


reply via email to

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