From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#14405: 24.3.50; read-regexp-defaults-function Date: Wed, 15 May 2013 02:51:20 +0300 Organization: JURTA Message-ID: <87ppwtw1zq.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1368576130 3459 80.91.229.3 (15 May 2013 00:02:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 15 May 2013 00:02:10 +0000 (UTC) To: 14405@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed May 15 02:02:08 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UcPAW-0003K7-0u for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 May 2013 02:02:08 +0200 Original-Received: from localhost ([::1]:46518 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcPAV-0006aw-M4 for geb-bug-gnu-emacs@m.gmane.org; Tue, 14 May 2013 20:02:07 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:43106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcPAQ-0006ai-9k for bug-gnu-emacs@gnu.org; Tue, 14 May 2013 20:02:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UcPAO-0004v3-Hz for bug-gnu-emacs@gnu.org; Tue, 14 May 2013 20:02:02 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcPAO-0004uz-FK for bug-gnu-emacs@gnu.org; Tue, 14 May 2013 20:02:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UcPAP-00020s-OR for bug-gnu-emacs@gnu.org; Tue, 14 May 2013 20:02:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 15 May 2013 00:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 14405 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13685761087673 (code B ref -1); Wed, 15 May 2013 00:02:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 May 2013 00:01:48 +0000 Original-Received: from localhost ([127.0.0.1]:44828 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UcPAA-0001zg-Mc for submit@debbugs.gnu.org; Tue, 14 May 2013 20:01:48 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:59911) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UcPA7-0001zD-HS for submit@debbugs.gnu.org; Tue, 14 May 2013 20:01:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UcP9z-0004sA-5r for submit@debbugs.gnu.org; Tue, 14 May 2013 20:01:36 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:56083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcP9z-0004s6-3O for submit@debbugs.gnu.org; Tue, 14 May 2013 20:01:35 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:43033) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcP9w-0006aI-EZ for bug-gnu-emacs@gnu.org; Tue, 14 May 2013 20:01:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UcP9u-0004ra-Se for bug-gnu-emacs@gnu.org; Tue, 14 May 2013 20:01:32 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:46202 helo=ps18281.dreamhostps.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcP9u-0004rW-KL for bug-gnu-emacs@gnu.org; Tue, 14 May 2013 20:01:30 -0400 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 2DE1E258B9E91C for ; Tue, 14 May 2013 17:01:27 -0700 (PDT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:74281 Archived-At: 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))