all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#27341: eww-search-words should prompt if region inactive
@ 2017-06-12 11:21 Alex Branham
  2017-06-13  9:24 ` bug#27341: updated patch to fix docstring Alex Branham
  0 siblings, 1 reply; 15+ messages in thread
From: Alex Branham @ 2017-06-12 11:21 UTC (permalink / raw)
  To: 27341

[-- Attachment #1: Type: text/plain, Size: 205 bytes --]

eww-search-words (M-S M-w) searches for the active region and doesn't do anything useful if the region isn't active. This patch has it prompt the user for a search string if the region isn't active.

Alex

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-eww-earch-prefix-prompt-for-query-if-region-inactive.patch --]
[-- Type: text/x-diff, Size: 876 bytes --]

From bf8cda29c442fa773ce59fe7bf7760887399c8fd Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Mon, 12 Jun 2017 13:10:27 +0200
Subject: [PATCH] eww-earch-prefix: prompt for query if region inactive

---
 lisp/net/eww.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index fe31657914..dd64dc81eb 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -316,7 +316,9 @@ word(s) will be searched for via `eww-search-prefix'."
   "Search the web for the text between BEG and END.
 See the `eww-search-prefix' variable for the search engine used."
   (interactive "r")
-  (eww (buffer-substring beg end)))
+  (if (region-active-p)
+      (eww (buffer-substring beg end))
+    (eww (read-string "Query: "))))
 
 (defun eww-open-in-new-buffer ()
   "Fetch link at point in a new EWW buffer."
-- 
2.13.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-06-12 11:21 bug#27341: eww-search-words should prompt if region inactive Alex Branham
@ 2017-06-13  9:24 ` Alex Branham
  2017-06-25 14:29   ` npostavs
  0 siblings, 1 reply; 15+ messages in thread
From: Alex Branham @ 2017-06-13  9:24 UTC (permalink / raw)
  To: 27341

[-- Attachment #1: Type: text/plain, Size: 1171 bytes --]

Hi -

I realized I forgot to update the docstring; this patch incorporates that change as well

Alex




From 4545b2fb1d6f047b05cbb1e19a50fb09809d5a31 Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Tue, 13 Jun 2017 11:21:35 +0200
Subject: [PATCH] eww-search-words prompts user for search if region inactive

---
 lisp/net/eww.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index fe31657914..aa358dce0f 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -313,10 +313,13 @@ word(s) will be searched for via `eww-search-prefix'."

 ;;;###autoload
 (defun eww-search-words (&optional beg end)
-  "Search the web for the text between BEG and END.
+  "If region is active, search the web for the text between BEG and END.
+Else, prompt the user for a search string.
 See the `eww-search-prefix' variable for the search engine used."
   (interactive "r")
-  (eww (buffer-substring beg end)))
+  (if (region-active-p)
+      (eww (buffer-substring beg end))
+    (eww (read-string "Query: "))))

 (defun eww-open-in-new-buffer ()
   "Fetch link at point in a new EWW buffer."
--
2.13.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-eww-search-words-prompt-user-for-search-if-region.patch --]
[-- Type: text/x-diff, Size: 1069 bytes --]

From 4545b2fb1d6f047b05cbb1e19a50fb09809d5a31 Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Tue, 13 Jun 2017 11:21:35 +0200
Subject: [PATCH] eww-search-words prompts user for search if region inactive

---
 lisp/net/eww.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index fe31657914..aa358dce0f 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -313,10 +313,13 @@ word(s) will be searched for via `eww-search-prefix'."
 
 ;;;###autoload
 (defun eww-search-words (&optional beg end)
-  "Search the web for the text between BEG and END.
+  "If region is active, search the web for the text between BEG and END.
+Else, prompt the user for a search string.
 See the `eww-search-prefix' variable for the search engine used."
   (interactive "r")
-  (eww (buffer-substring beg end)))
+  (if (region-active-p)
+      (eww (buffer-substring beg end))
+    (eww (read-string "Query: "))))
 
 (defun eww-open-in-new-buffer ()
   "Fetch link at point in a new EWW buffer."
-- 
2.13.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-06-13  9:24 ` bug#27341: updated patch to fix docstring Alex Branham
@ 2017-06-25 14:29   ` npostavs
  2017-06-26 14:00     ` Alex Branham
  0 siblings, 1 reply; 15+ messages in thread
From: npostavs @ 2017-06-25 14:29 UTC (permalink / raw)
  To: Alex Branham; +Cc: 27341

Alex Branham <branham@utexas.edu> writes:

> -  (eww (buffer-substring beg end)))
> +  (if (region-active-p)

If think we should use `use-region-p' instead.  Or perhaps just check
directly if region is empty?  I guess searching for an empty string
doesn't make much sense even if `use-empty-active-region' is t.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-06-25 14:29   ` npostavs
@ 2017-06-26 14:00     ` Alex Branham
  2017-06-26 23:50       ` npostavs
  0 siblings, 1 reply; 15+ messages in thread
From: Alex Branham @ 2017-06-26 14:00 UTC (permalink / raw)
  To: npostavs; +Cc: 27341

[-- Attachment #1: Type: text/plain, Size: 1739 bytes --]

Here's a new patch that checks the region directly, ignoring `use-empty-active-region'.

From c3babb73d8f29ff3f27aacbac99c7226ef4b32a0 Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Mon, 26 Jun 2017 15:57:15 +0200
Subject: [PATCH] eww-search-words prompt user for query if region active and
 not empty

---
 lisp/net/eww.el | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index fe31657914..cf46530d35 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -314,9 +314,15 @@ word(s) will be searched for via `eww-search-prefix'."
 ;;;###autoload
 (defun eww-search-words (&optional beg end)
   "Search the web for the text between BEG and END.
-See the `eww-search-prefix' variable for the search engine used."
+  If region is active (and not whitespace), search the web for
+the text between BEG and END. Else, prompt the user for a search
+string. See the `eww-search-prefix' variable for the search
+engine used."
   (interactive "r")
-  (eww (buffer-substring beg end)))
+  (let ((region-string (buffer-substring beg end)))
+    (if (not (string-match-p "\\`[ \n\t\r\v\f]*\\'" region-string))
+        (eww region-string)
+      (eww (read-string "Query: ")))))

 (defun eww-open-in-new-buffer ()
   "Fetch link at point in a new EWW buffer."
--
2.13.1


On Sun 25 Jun 2017 at 14:29, npostavs@users.sourceforge.net wrote:

> Alex Branham <branham@utexas.edu> writes:
>
>> -  (eww (buffer-substring beg end)))
>> +  (if (region-active-p)
>
> If think we should use `use-region-p' instead.  Or perhaps just check
> directly if region is empty?  I guess searching for an empty string
> doesn't make much sense even if `use-empty-active-region' is t.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-eww-search-words-prompt-user-for-query-if-region-act.patch --]
[-- Type: text/x-diff, Size: 1258 bytes --]

From c3babb73d8f29ff3f27aacbac99c7226ef4b32a0 Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Mon, 26 Jun 2017 15:57:15 +0200
Subject: [PATCH] eww-search-words prompt user for query if region active and
 not empty

---
 lisp/net/eww.el | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index fe31657914..cf46530d35 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -314,9 +314,15 @@ word(s) will be searched for via `eww-search-prefix'."
 ;;;###autoload
 (defun eww-search-words (&optional beg end)
   "Search the web for the text between BEG and END.
-See the `eww-search-prefix' variable for the search engine used."
+  If region is active (and not whitespace), search the web for
+the text between BEG and END. Else, prompt the user for a search
+string. See the `eww-search-prefix' variable for the search
+engine used."
   (interactive "r")
-  (eww (buffer-substring beg end)))
+  (let ((region-string (buffer-substring beg end)))
+    (if (not (string-match-p "\\`[ \n\t\r\v\f]*\\'" region-string))
+        (eww region-string)
+      (eww (read-string "Query: ")))))
 
 (defun eww-open-in-new-buffer ()
   "Fetch link at point in a new EWW buffer."
-- 
2.13.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-06-26 14:00     ` Alex Branham
@ 2017-06-26 23:50       ` npostavs
  2017-06-27  5:32         ` Alex Branham
  0 siblings, 1 reply; 15+ messages in thread
From: npostavs @ 2017-06-26 23:50 UTC (permalink / raw)
  To: Alex Branham; +Cc: 27341

Alex Branham <branham@utexas.edu> writes:

> Here's a new patch that checks the region directly, ignoring `use-empty-active-region'.

Looks good, I'll push in a few days.  You haven't assigned copyright,
have you?





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-06-26 23:50       ` npostavs
@ 2017-06-27  5:32         ` Alex Branham
  2017-06-27 13:23           ` Alex Branham
  2017-06-27 14:40           ` Eli Zaretskii
  0 siblings, 2 replies; 15+ messages in thread
From: Alex Branham @ 2017-06-27  5:32 UTC (permalink / raw)
  To: npostavs; +Cc: 27341

[-- Attachment #1: Type: text/plain, Size: 389 bytes --]

No, I haven't. Do I need to for something this small? Happy to do so if
it's necessary.

Alex

On Jun 27, 2017 1:49 AM, <npostavs@users.sourceforge.net> wrote:

> Alex Branham <branham@utexas.edu> writes:
>
> > Here's a new patch that checks the region directly, ignoring
> `use-empty-active-region'.
>
> Looks good, I'll push in a few days.  You haven't assigned copyright,
> have you?
>

[-- Attachment #2: Type: text/html, Size: 814 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-06-27  5:32         ` Alex Branham
@ 2017-06-27 13:23           ` Alex Branham
  2017-06-30  0:54             ` npostavs
  2017-07-02 18:32             ` npostavs
  2017-06-27 14:40           ` Eli Zaretskii
  1 sibling, 2 replies; 15+ messages in thread
From: Alex Branham @ 2017-06-27 13:23 UTC (permalink / raw)
  To: npostavs; +Cc: 27341

[-- Attachment #1: Type: text/plain, Size: 1880 bytes --]

Actually, we need to check (use-region-p) anyway in case the mark hasn't been activated yet in the buffer:


From 685f3d0d2bfea7b3d6aad03d46a247fac25702d0 Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Tue, 27 Jun 2017 15:20:27 +0200
Subject: [PATCH] eww-search-words prompt for query if region inactive or blank

---
 lisp/net/eww.el | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index fe31657914..a90caa7fc4 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -314,9 +314,16 @@ word(s) will be searched for via `eww-search-prefix'."
 ;;;###autoload
 (defun eww-search-words (&optional beg end)
   "Search the web for the text between BEG and END.
-See the `eww-search-prefix' variable for the search engine used."
+    If region is active (and not whitespace), search the web for
+  the text between BEG and END. Else, prompt the user for a search
+  string. See the `eww-search-prefix' variable for the search
+  engine used."
   (interactive "r")
-  (eww (buffer-substring beg end)))
+  (if (use-region-p)
+      (let ((region-string (buffer-substring beg end)))
+        (if (not (string-match-p "\\`[ \n\t\r\v\f]*\\'" region-string))
+            (eww region-string)))
+    (eww (read-string "Query: "))))

 (defun eww-open-in-new-buffer ()
   "Fetch link at point in a new EWW buffer."
--
2.13.2



On Tue 27 Jun 2017 at 05:32, Alex Branham <branham@utexas.edu> wrote:

> No, I haven't. Do I need to for something this small? Happy to do so if
> it's necessary.
>
> Alex
>
> On Jun 27, 2017 1:49 AM, <npostavs@users.sourceforge.net> wrote:
>
>> Alex Branham <branham@utexas.edu> writes:
>>
>> > Here's a new patch that checks the region directly, ignoring
>> `use-empty-active-region'.
>>
>> Looks good, I'll push in a few days.  You haven't assigned copyright,
>> have you?
>>


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0004-eww-search-words-prompt-user-for-query-if-region-inactive.patch --]
[-- Type: text/x-diff, Size: 1291 bytes --]

From 685f3d0d2bfea7b3d6aad03d46a247fac25702d0 Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Tue, 27 Jun 2017 15:20:27 +0200
Subject: [PATCH] eww-search-words prompt for query if region inactive or blank

---
 lisp/net/eww.el | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index fe31657914..a90caa7fc4 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -314,9 +314,16 @@ word(s) will be searched for via `eww-search-prefix'."
 ;;;###autoload
 (defun eww-search-words (&optional beg end)
   "Search the web for the text between BEG and END.
-See the `eww-search-prefix' variable for the search engine used."
+    If region is active (and not whitespace), search the web for
+  the text between BEG and END. Else, prompt the user for a search
+  string. See the `eww-search-prefix' variable for the search
+  engine used."
   (interactive "r")
-  (eww (buffer-substring beg end)))
+  (if (use-region-p)
+      (let ((region-string (buffer-substring beg end)))
+        (if (not (string-match-p "\\`[ \n\t\r\v\f]*\\'" region-string))
+            (eww region-string)))
+    (eww (read-string "Query: "))))
 
 (defun eww-open-in-new-buffer ()
   "Fetch link at point in a new EWW buffer."
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-06-27  5:32         ` Alex Branham
  2017-06-27 13:23           ` Alex Branham
@ 2017-06-27 14:40           ` Eli Zaretskii
  1 sibling, 0 replies; 15+ messages in thread
From: Eli Zaretskii @ 2017-06-27 14:40 UTC (permalink / raw)
  To: Alex Branham; +Cc: 27341, npostavs

> From: Alex Branham <branham@utexas.edu>
> Date: Tue, 27 Jun 2017 07:32:06 +0200
> Cc: 27341@debbugs.gnu.org
> 
> No, I haven't. Do I need to for something this small? Happy to do so if it's necessary. 

No, you don't.  But it's good to start the ball rolling anyway, so
that we could accept your future contributions without limitations.

Thanks.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-06-27 13:23           ` Alex Branham
@ 2017-06-30  0:54             ` npostavs
  2017-06-30  6:25               ` Alex Branham
  2017-07-02 18:32             ` npostavs
  1 sibling, 1 reply; 15+ messages in thread
From: npostavs @ 2017-06-30  0:54 UTC (permalink / raw)
  To: Alex Branham; +Cc: 27341

Alex Branham <branham@utexas.edu> writes:

> Actually, we need to check (use-region-p) anyway in case the mark
> hasn't been activated yet in the buffer:

Oops, good catch, I hadn't thought of that.

> Subject: [PATCH] eww-search-words prompt for query if region inactive or blank
>
> ---

Could you add a ChangeLog entry to the commit message as described in
CONTRIBUTE, please?

>  (defun eww-search-words (&optional beg end)
>    "Search the web for the text between BEG and END.
> -See the `eww-search-prefix' variable for the search engine used."
> +    If region is active (and not whitespace), search the web for
> +  the text between BEG and END. Else, prompt the user for a search
> +  string. See the `eww-search-prefix' variable for the search
> +  engine used."

Doc strings shouldn't be indented like that, and there should be a
double space between sentences.

>    (interactive "r")
> -  (eww (buffer-substring beg end)))
> +  (if (use-region-p)
> +      (let ((region-string (buffer-substring beg end)))
> +        (if (not (string-match-p "\\`[ \n\t\r\v\f]*\\'" region-string))
> +            (eww region-string)))
> +    (eww (read-string "Query: "))))

This silently does nothing if the region is active but just blanks, did
you mean to fallback to querying in that case?






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-06-30  0:54             ` npostavs
@ 2017-06-30  6:25               ` Alex Branham
  0 siblings, 0 replies; 15+ messages in thread
From: Alex Branham @ 2017-06-30  6:25 UTC (permalink / raw)
  To: npostavs; +Cc: 27341

[-- Attachment #1: Type: text/plain, Size: 1179 bytes --]


On Fri 30 Jun 2017 at 00:54, npostavs@users.sourceforge.net wrote:

> Could you add a ChangeLog entry to the commit message as described in
> CONTRIBUTE, please?

Yes, I have done so. Let me know if it's not right.

>
>>  (defun eww-search-words (&optional beg end)
>>    "Search the web for the text between BEG and END.
>> -See the `eww-search-prefix' variable for the search engine used."
>> +    If region is active (and not whitespace), search the web for
>> +  the text between BEG and END. Else, prompt the user for a search
>> +  string. See the `eww-search-prefix' variable for the search
>> +  engine used."
>
> Doc strings shouldn't be indented like that, and there should be a
> double space between sentences.

Fixed.

>
>>    (interactive "r")
>> -  (eww (buffer-substring beg end)))
>> +  (if (use-region-p)
>> +      (let ((region-string (buffer-substring beg end)))
>> +        (if (not (string-match-p "\\`[ \n\t\r\v\f]*\\'" region-string))
>> +            (eww region-string)))
>> +    (eww (read-string "Query: "))))
>
> This silently does nothing if the region is active but just blanks, did
> you mean to fallback to querying in that case?

Fixed, thanks


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0005-Make-eww-search-words-prompt-for-query-if-nothing-se.patch --]
[-- Type: text/x-diff, Size: 1513 bytes --]

From 1d036b16903dd18268c499c4617d430172b08ffe Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Fri, 30 Jun 2017 08:16:13 +0200
Subject: [PATCH] Make eww-search-words prompt for query if nothing selected

* lisp/net/eww.el (eww-search-words): Make eww-search-words prompt the
user for a search query if the region is inactive or if the region is
just whitespace.

Copyright-paperwork-exempt: yes
---
 lisp/net/eww.el | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index fe31657914..757e738a18 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -314,9 +314,17 @@ word(s) will be searched for via `eww-search-prefix'."
 ;;;###autoload
 (defun eww-search-words (&optional beg end)
   "Search the web for the text between BEG and END.
-See the `eww-search-prefix' variable for the search engine used."
+If region is active (and not whitespace), search the web for
+the text between BEG and END. Else, prompt the user for a search
+string.  See the `eww-search-prefix' variable for the search
+engine used."
   (interactive "r")
-  (eww (buffer-substring beg end)))
+  (if (use-region-p)
+      (let ((region-string (buffer-substring beg end)))
+        (if (not (string-match-p "\\`[ \n\t\r\v\f]*\\'" region-string))
+            (eww region-string)
+          (eww (read-string "Query: "))))
+    (eww (read-string "Query: "))))
 
 (defun eww-open-in-new-buffer ()
   "Fetch link at point in a new EWW buffer."
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-06-27 13:23           ` Alex Branham
  2017-06-30  0:54             ` npostavs
@ 2017-07-02 18:32             ` npostavs
  2017-07-02 18:45               ` Alex Branham
  1 sibling, 1 reply; 15+ messages in thread
From: npostavs @ 2017-07-02 18:32 UTC (permalink / raw)
  To: Alex Branham; +Cc: 27341


Alex Branham <branham@utexas.edu> writes:

> On Fri 30 Jun 2017 at 00:54, npostavs@users.sourceforge.net wrote:
>
>> Could you add a ChangeLog entry to the commit message as described in
>> CONTRIBUTE, please?
>
> Yes, I have done so. Let me know if it's not right.

Looks good, thanks.

>> Doc strings shouldn't be indented like that, and there should be a
>> double space between sentences.
>
> Fixed.

You missed the double spacing before the "Else,".

> Actually, we need to check (use-region-p) anyway in case the mark
> hasn't been activated yet in the buffer:

Hmm, I just tried this and it doesn't quite do the job.  I believe the
problem is that the (interactive "r") form throws an error when the mark
hasn't been activated yet.  To handle this case correctly you need to
replace the "r" with some lisp code that produces the argument list.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-07-02 18:32             ` npostavs
@ 2017-07-02 18:45               ` Alex Branham
  2017-07-02 19:13                 ` npostavs
  0 siblings, 1 reply; 15+ messages in thread
From: Alex Branham @ 2017-07-02 18:45 UTC (permalink / raw)
  To: npostavs; +Cc: 27341

[-- Attachment #1: Type: text/plain, Size: 903 bytes --]


On Sun 02 Jul 2017 at 18:32, npostavs@users.sourceforge.net wrote:

> Alex Branham <branham@utexas.edu> writes:
>
>> On Fri 30 Jun 2017 at 00:54, npostavs@users.sourceforge.net wrote:
>
>>> Doc strings shouldn't be indented like that, and there should be a
>>> double space between sentences.
>>
>> Fixed.
>
> You missed the double spacing before the "Else,".

D'oh! Fixed this time, sorry!

>> Actually, we need to check (use-region-p) anyway in case the mark
>> hasn't been activated yet in the buffer:
>
> Hmm, I just tried this and it doesn't quite do the job.  I believe the
> problem is that the (interactive "r") form throws an error when the mark
> hasn't been activated yet.  To handle this case correctly you need to
> replace the "r" with some lisp code that produces the argument list.

Ok, now I don't use "r" and just get the region directly. I think that'll do the trick?

Thanks,
Alex


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0006-Make-eww-search-words-prompt-for-query-if-nothing-se.patch --]
[-- Type: text/x-diff, Size: 1564 bytes --]

From 9dc5deec743d827e6d099f0f46b257ab8e7142c1 Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Sun, 2 Jul 2017 20:43:12 +0200
Subject: [PATCH] Make eww-search-words prompt for query if nothing selected

* lisp/net/eww.el (eww-search-words): Make eww-search-words prompt the
user for a search query if the region is inactive or if the region is
just whitespace.

Copyright-paperwork-exempt: yes
---
 lisp/net/eww.el | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index fe31657914..438f635c5e 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -314,9 +314,17 @@ word(s) will be searched for via `eww-search-prefix'."
 ;;;###autoload
 (defun eww-search-words (&optional beg end)
   "Search the web for the text between BEG and END.
-See the `eww-search-prefix' variable for the search engine used."
-  (interactive "r")
-  (eww (buffer-substring beg end)))
+  If region is active (and not whitespace), search the web for
+  the text between BEG and END.  Else, prompt the user for a search
+  string.  See the `eww-search-prefix' variable for the search
+  engine used."
+  (interactive)
+  (if (use-region-p)
+      (let ((region-string (buffer-substring (region-beginning) (region-end))))
+        (if (not (string-match-p "\\`[ \n\t\r\v\f]*\\'" region-string))
+            (eww region-string)
+          (eww (read-string "Query: "))))
+    (eww (read-string "Query: "))))
 
 (defun eww-open-in-new-buffer ()
   "Fetch link at point in a new EWW buffer."
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-07-02 18:45               ` Alex Branham
@ 2017-07-02 19:13                 ` npostavs
  2017-07-02 19:25                   ` Alex Branham
  0 siblings, 1 reply; 15+ messages in thread
From: npostavs @ 2017-07-02 19:13 UTC (permalink / raw)
  To: Alex Branham; +Cc: 27341

Alex Branham <branham@utexas.edu> writes:

>> You missed the double spacing before the "Else,".
>
> D'oh! Fixed this time, sorry!

Oh, the funny indentation came back, do you have some Emacs setting
that's doing that?

>>> Actually, we need to check (use-region-p) anyway in case the mark
>>> hasn't been activated yet in the buffer:
>>
>> Hmm, I just tried this and it doesn't quite do the job.  I believe the
>> problem is that the (interactive "r") form throws an error when the mark
>> hasn't been activated yet.  To handle this case correctly you need to
>> replace the "r" with some lisp code that produces the argument list.
>
> Ok, now I don't use "r" and just get the region directly. I think that'll do the trick?

Oh yeah, that works.  We should try not to add compiler warnings though:

  ELC      net/eww.elc

In toplevel form:
../../emacs-master/lisp/net/eww.el:315:1:Warning: Unused lexical argument
    ‘end’
../../emacs-master/lisp/net/eww.el:315:1:Warning: Unused lexical argument
    ‘beg’

I think we can just drop the arguments as well, lisp programs can always
do (eww (buffer-substring BEG END)) instead.

Do you think the prompt string should be a bit more detailed?  "Query"
seems a bit vague (e.g., consider if you hit M-s M-w by accident).
Maybe we should just do (call-interactively 'eww) and then we'll get the
prompt from there.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-07-02 19:13                 ` npostavs
@ 2017-07-02 19:25                   ` Alex Branham
  2017-07-02 20:23                     ` npostavs
  0 siblings, 1 reply; 15+ messages in thread
From: Alex Branham @ 2017-07-02 19:25 UTC (permalink / raw)
  To: npostavs; +Cc: 27341

[-- Attachment #1: Type: text/plain, Size: 1197 bytes --]


On Sun 02 Jul 2017 at 19:13, npostavs@users.sourceforge.net wrote:

> Alex Branham <branham@utexas.edu> writes:
>
>>> You missed the double spacing before the "Else,".
>>
>> D'oh! Fixed this time, sorry!
>
> Oh, the funny indentation came back, do you have some Emacs setting
> that's doing that?

Ugh. Fixed. I think it has to do with how I'm copy/pasting from my own init file.

>> Ok, now I don't use "r" and just get the region directly. I think that'll do the trick?
>
> Oh yeah, that works.  We should try not to add compiler warnings though:
>
>   ELC      net/eww.elc
>
> In toplevel form:
> ../../emacs-master/lisp/net/eww.el:315:1:Warning: Unused lexical argument
>     ‘end’
> ../../emacs-master/lisp/net/eww.el:315:1:Warning: Unused lexical argument
>     ‘beg’
>
> I think we can just drop the arguments as well, lisp programs can always
> do (eww (buffer-substring BEG END)) instead.

Dropped.

> Do you think the prompt string should be a bit more detailed?  "Query"
> seems a bit vague (e.g., consider if you hit M-s M-w by accident).
> Maybe we should just do (call-interactively 'eww) and then we'll get the
> prompt from there.

Yes, that's much better. Done, thanks.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0007-Make-eww-search-words-prompt-for-query-if-nothing-se.patch --]
[-- Type: text/x-diff, Size: 1617 bytes --]

From 71e4329943541325f59a224b494e5ca82f07fdef Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Sun, 2 Jul 2017 21:18:47 +0200
Subject: [PATCH] Make eww-search-words prompt for query if nothing selected

* lisp/net/eww.el (eww-search-words): Make eww-search-words prompt the
user for a search query if the region is inactive or if the region is
just whitespace.

Copyright-paperwork-exempt: yes
---
 lisp/net/eww.el | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index fe31657914..2fc36e180e 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -312,11 +312,19 @@ word(s) will be searched for via `eww-search-prefix'."
 	       (expand-file-name file))))
 
 ;;;###autoload
-(defun eww-search-words (&optional beg end)
+(defun eww-search-words ()
   "Search the web for the text between BEG and END.
-See the `eww-search-prefix' variable for the search engine used."
-  (interactive "r")
-  (eww (buffer-substring beg end)))
+If region is active (and not whitespace), search the web for
+the text between BEG and END.  Else, prompt the user for a search
+string.  See the `eww-search-prefix' variable for the search
+engine used."
+  (interactive)
+  (if (use-region-p)
+      (let ((region-string (buffer-substring (region-beginning) (region-end))))
+        (if (not (string-match-p "\\`[ \n\t\r\v\f]*\\'" region-string))
+            (eww region-string)
+          (call-interactively 'eww)))
+    (call-interactively 'eww)))
 
 (defun eww-open-in-new-buffer ()
   "Fetch link at point in a new EWW buffer."
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#27341: updated patch to fix docstring
  2017-07-02 19:25                   ` Alex Branham
@ 2017-07-02 20:23                     ` npostavs
  0 siblings, 0 replies; 15+ messages in thread
From: npostavs @ 2017-07-02 20:23 UTC (permalink / raw)
  To: Alex Branham; +Cc: 27341

tags 27341 fixed
close 27341 26.1
quit

Alex Branham <branham@utexas.edu> writes:
>
>> Do you think the prompt string should be a bit more detailed?  "Query"
>> seems a bit vague (e.g., consider if you hit M-s M-w by accident).
>> Maybe we should just do (call-interactively 'eww) and then we'll get the
>> prompt from there.
>
> Yes, that's much better. Done, thanks.

Okay, pushed to master [1: 1fd6ca40fd], thanks for hanging in there! :)

[1: 1fd6ca40fd]: 2017-07-02 16:19:57 -0400
  Make eww-search-words prompt for query if nothing selected
  http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=1fd6ca40fd50989b8f82b287c04a5079a051ed09





^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-07-02 20:23 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-12 11:21 bug#27341: eww-search-words should prompt if region inactive Alex Branham
2017-06-13  9:24 ` bug#27341: updated patch to fix docstring Alex Branham
2017-06-25 14:29   ` npostavs
2017-06-26 14:00     ` Alex Branham
2017-06-26 23:50       ` npostavs
2017-06-27  5:32         ` Alex Branham
2017-06-27 13:23           ` Alex Branham
2017-06-30  0:54             ` npostavs
2017-06-30  6:25               ` Alex Branham
2017-07-02 18:32             ` npostavs
2017-07-02 18:45               ` Alex Branham
2017-07-02 19:13                 ` npostavs
2017-07-02 19:25                   ` Alex Branham
2017-07-02 20:23                     ` npostavs
2017-06-27 14:40           ` Eli Zaretskii

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.