Wilfred / ag.el

An Emacs frontend to The Silver Searcher
http://agel.readthedocs.org/en/latest/
525 stars 61 forks source link

Provide a tip if user just re-types the string at point #112

Open Wilfred opened 8 years ago

Wilfred commented 8 years ago

If the region is active, we should probably pre-populate the input anyway. The M-down shortcut is not discoverable.

Wilfred commented 7 years ago

Other thoughts: we should truncate the default input if it's too long. If there's nothing at point, and nothing selected, offer the previous search input as the default.

wbolster commented 7 years ago

i've been using this hack locally for a few days and i'm actually quite happy with how it works in practice:

modified   Emacs/elpa/ag-20160731.1323/ag.el
@@ -112,6 +112,12 @@ If set to nil, fall back to finding VCS root directories."
   :type '(repeat (string))
   :group 'ag)

+(defcustom ag-editable-default nil
+  "Non-nil means the default search string is editable when reading
+from the minibuffer."
+  :type 'boolean
+  :group 'ag)
+
 (require 'compile)

 ;; Although ag results aren't exactly errors, we treat them as errors
@@ -476,14 +482,15 @@ If called with a prefix, prompts for flags to pass to ag."
 If there's a string at point, offer that as a default."
   (let* ((suggested (ag/dwim-at-point))
          (final-prompt
-          (if suggested
+          (if (and suggested (not ag-editable-default))
               (format "%s (default %s): " prompt suggested)
             (format "%s: " prompt)))
          ;; Ask the user for input, but add `suggested' to the history
          ;; so they can use M-n if they want to modify it.
          (user-input (read-from-minibuffer
                       final-prompt
-                      nil nil nil nil suggested)))
+                      (when ag-editable-default suggested)
+                      nil nil nil suggested)))
     ;; Return the input provided by the user, or use `suggested' if
     ;; the input was empty.
     (if (> (length user-input) 0)

to delete the whole line from the minibuffer, i use C-u (readline/bash style) so for me it's quite simple to replace the suggested search string.