all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: 14405@debbugs.gnu.org
Subject: bug#14405: 24.3.50; read-regexp-defaults-function
Date: Wed, 15 May 2013 02:51:20 +0300	[thread overview]
Message-ID: <87ppwtw1zq.fsf@mail.jurta.org> (raw)

This is a continuation from bug#13892 and bug#13687
closed and archived two months ago.  As the unfinished
discussion indicates there are pending enhancements
to create a single option to define the same defaulting
behavior for all regexp-reading commands and to group
the existing defaults to separate functions that can be
overridden by customizing that option.

This is a preliminary implementation:

=== modified file 'lisp/replace.el'
--- lisp/replace.el	2013-04-22 04:17:30 +0000
+++ lisp/replace.el	2013-05-14 23:50:29 +0000
@@ -580,6 +580,41 @@ (defvar regexp-history nil
 (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.
+
+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)
+          (choice :tag "Function to provide default for read-regexp"
+		  (function-item :tag "Tag at point" find-tag-default)
+		  (function-item :tag "Symbol at point" find-tag-default-as-regexp)
+		  (function-item :tag "Latest history" (lambda () (car regexp-history)))
+		  function))
+  :group 'matching
+  :version "24.4")
+
+(defun read-regexp-defaults ()
+  (if (functionp read-regexp-defaults-function)
+      (funcall read-regexp-defaults-function)))
+
+(defun read-regexp-defaults-history ()
+  "Return the latest regexp from `regexp-history'.
+See `read-regexp-defaults-function' for details."
+  (or (read-regexp-defaults)
+      (car regexp-history)))
+
+(defun read-regexp-defaults-tag ()
+  "Return the regexp that matches the default tag at point.
+See `read-regexp-defaults-function' for details."
+  (or (read-regexp-defaults)
+      (find-tag-default-as-regexp)))
+
 (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 \": \".
@@ -636,7 +671,7 @@ (defun keep-lines-read-args (prompt)
   "Read arguments for `keep-lines' and friends.
 Prompt for a regexp with PROMPT.
 Value is a list, (REGEXP)."
-  (list (read-regexp prompt) nil nil t))
+  (list (read-regexp prompt (read-regexp-defaults-history)) nil nil t))
 
 (defun keep-lines (regexp &optional rstart rend interactive)
   "Delete all lines except those containing matches for REGEXP.
@@ -1143,32 +1178,35 @@ (defcustom occur-excluded-properties
   :group 'matching
   :version "22.1")
 
-(defvar occur-read-regexp-defaults-function
-  'occur-read-regexp-defaults
+(defun 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
+This function takes no arguments and returns 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))
+You can customize `read-regexp-defaults-function' to the value
+`find-tag-default-as-regexp' to highlight a symbol at point."
+  (read-regexp-defaults-history))
+
+(defun occur-collect-read-regexp-defaults ()
+  "Return the latest regexp from `occur-collect-regexp-history'.
+This function is used to read a regexp to collect.
+See `read-regexp-defaults-function' for details.
+
+You can customize `read-regexp-defaults-function' to the value
+`find-tag-default-as-regexp' to highlight a symbol at point."
+  (or (read-regexp-defaults)
+      (car occur-collect-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))))
+                              (occur-read-regexp-defaults))))
     (list regexp
 	  (if perform-collect
 	      ;; Perform collect operation
@@ -1176,7 +1214,7 @@ (defun occur-read-primary-args ()
 		  ;; No subexpression so collect the entire match.
 		  "\\&"
 		;; Get the regexp for collection pattern.
-		(let ((default (car occur-collect-regexp-history)))
+		(let ((default (occur-collect-read-regexp-defaults)))
 		  (read-regexp
 		   (format "Regexp to collect (default %s): " default)
 		   default 'occur-collect-regexp-history)))

=== modified file 'lisp/hi-lock.el'
--- lisp/hi-lock.el	2013-04-22 04:17:30 +0000
+++ lisp/hi-lock.el	2013-05-14 23:50:37 +0000
@@ -279,26 +279,6 @@ (defvar hi-lock-map
     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
@@ -422,7 +402,7 @@ (defalias 'highlight-lines-matching-rege
 (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
+`hi-lock-read-regexp-defaults' to retrieve default
 value(s) of REGEXP.  Use the global history list for FACE.
 
 Use Font lock mode, if enabled, to highlight REGEXP.  Otherwise,
@@ -432,7 +412,7 @@ (defun hi-lock-line-face-buffer (regexp
    (list
     (hi-lock-regexp-okay
      (read-regexp "Regexp to highlight line"
-		  (funcall hi-lock-read-regexp-defaults-function)))
+		  (hi-lock-read-regexp-defaults)))
     (hi-lock-read-face-name)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
@@ -448,7 +428,7 @@ (defalias 'highlight-regexp 'hi-lock-fac
 (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
+`hi-lock-read-regexp-defaults' to retrieve default
 value(s) REGEXP.  Use the global history list for FACE.
 
 Use Font lock mode, if enabled, to highlight REGEXP.  Otherwise,
@@ -458,7 +438,7 @@ (defun hi-lock-face-buffer (regexp &opti
    (list
     (hi-lock-regexp-okay
      (read-regexp "Regexp to highlight"
-		  (funcall hi-lock-read-regexp-defaults-function)))
+		  (hi-lock-read-regexp-defaults)))
     (hi-lock-read-face-name)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
@@ -470,7 +450,7 @@ (defalias 'highlight-phrase 'hi-lock-fac
 (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
+`hi-lock-read-regexp' to retrieve 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
@@ -484,7 +464,7 @@ (defun hi-lock-face-phrase-buffer (regex
     (hi-lock-regexp-okay
      (hi-lock-process-phrase
       (read-regexp "Phrase to highlight"
-		   (funcall hi-lock-read-regexp-defaults-function))))
+		   (hi-lock-read-regexp-defaults))))
     (hi-lock-read-face-name)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
@@ -651,9 +631,22 @@ (defun hi-lock-regexp-okay (regexp)
     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))
+  "Function that provides default regexp(s) for highlighting commands.
+This function takes no arguments and returns 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.
+
+You can customize `read-regexp-defaults-function' to the value
+`find-tag-default-as-regexp' to highlight a symbol at point.
+
+If you need different defaults for different highlighting
+operations, redefine this function and use `this-command'
+to identify the command under execution."
+  (read-regexp-defaults-history))
 
 (defun hi-lock-read-face-name ()
   "Return face for interactive highlighting.

=== modified file 'lisp/progmodes/grep.el'
--- lisp/progmodes/grep.el	2013-02-12 07:57:04 +0000
+++ lisp/progmodes/grep.el	2013-05-14 23:50:07 +0000
@@ -829,9 +829,13 @@ (defun grep-expand-template (template &o
 		     "")
 		 t t command))))))
 
+(defun grep-read-regexp-defaults ()
+  (or (read-regexp-defaults)
+      (grep-tag-default)))
+
 (defun grep-read-regexp ()
   "Read regexp arg for interactive grep."
-  (let ((default (grep-tag-default)))
+  (let ((default (grep-read-regexp-defaults)))
     (read-regexp
      (concat "Search for"
 	     (if (and default (> (length default) 0))






             reply	other threads:[~2013-05-14 23:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-14 23:51 Juri Linkov [this message]
2013-05-15 22:58 ` bug#14405: 24.3.50; read-regexp-defaults-function Juri Linkov
2013-05-18 23:28 ` Juri Linkov
     [not found] ` <87mwjvwb1u.fsf@mail.jurta.org>
2013-12-21  2:39   ` Jambunathan K
2013-12-21 21:25     ` Juri Linkov
2013-12-21 22:28       ` Jambunathan K
2013-12-22 21:39         ` Juri Linkov
2013-12-23  2:38           ` Jambunathan K
2013-12-24 18:25             ` Jambunathan K
2013-12-25 20:56               ` Juri Linkov
2013-12-27  5:22                 ` Jambunathan K

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ppwtw1zq.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=14405@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.