From d86ef9fc4a45bd1f3c79c4814b9e1e545ce0a07c Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Tue, 26 May 2015 19:28:38 +0300 Subject: [PATCH] xref-prompt-for-identifier: Use a list value * lisp/progmodes/xref.el (xref-prompt-for-identifier): Allow list value, to be interpreted as a list of commands. (xref--prompt-p): New function. (xref--read-identifier): Use it. --- lisp/progmodes/xref.el | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 3bb4fde0d0c..c9bffc6fc6f 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -283,13 +283,25 @@ backward." :type 'integer :version "25.1") -(defcustom xref-prompt-for-identifier nil - "When non-nil, always prompt for the identifier name. +(defcustom xref-prompt-for-identifier '(not xref-find-definitions + xref-find-definitions-other-window + xref-find-definitions-other-frame) + "When t, always prompt for the identifier name. -Otherwise, only prompt when there's no value at point we can use, -or when the command has been called with the prefix argument." +When nil, prompt only when there's no value at point we can use, +or when the command has been called with the prefix argument. + +Otherwise, it's a list of xref commands which will prompt +anyway (the value at point, if any, will be used as the default). + +If the list starts with `not', the meaning of the rest of the +elements is negated." :type '(choice (const :tag "always" t) - (const :tag "auto" nil)) + (const :tag "auto" nil) + (set :menu-tag "command specific" :tag "commands" + :value (not) + (const :tag "Except" not) + (repeat :inline t (symbol :tag "command")))) :version "25.1") (defcustom xref-pulse-on-jump t @@ -621,10 +633,18 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." `((window . ,window) (temporary-buffers . ,tb))))))) +(defun xref--prompt-p (command) + (or (eq xref-prompt-for-identifier t) + (if (eq (car xref-prompt-for-identifier) 'not) + (not (memq command (cdr xref-prompt-for-identifier))) + (memq command xref-prompt-for-identifier)))) + (defun xref--read-identifier (prompt) "Return the identifier at point or read it from the minibuffer." (let ((id (funcall xref-identifier-at-point-function))) - (cond ((or current-prefix-arg xref-prompt-for-identifier (not id)) + (cond ((or current-prefix-arg + (not id) + (xref--prompt-p this-command)) (completing-read prompt (funcall xref-identifier-completion-table-function) nil nil nil @@ -667,6 +687,7 @@ With prefix argument, prompt for the identifier." ;;;###autoload (defun xref-find-regexp (regexp) "Find all matches for REGEXP." + ;; FIXME: Prompt for directory. (interactive (list (xref--read-identifier "Find regexp: "))) (xref--show-xrefs regexp 'matches regexp nil)) @@ -736,6 +757,9 @@ details on which tools are used, and when." (cl-assert (directory-name-p dir)) (when (null kind) (setq input (regexp-quote input))) + ;; FIXME: When regexp, search in all files, except + ;; `grep-find-ignored-directories' and `grep-find-ignored-files', + ;; like `rgrep' does. (let* ((default-directory dir) (semantic-symref-tool 'detect) (res (if (eq kind 'symbol) -- 2.39.2