Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description to search engines (fixing #1144) #1169

Closed
wants to merge 2 commits into from

Conversation

mijoharas
Copy link
Contributor

Adding description to search engines to fix #1144

@smblott-github
Copy link
Collaborator

Hey, @mijoharas. You know the tests are failing on this, yes? Shouldn't be too hard to fix up.

@mijoharas
Copy link
Contributor Author

alright, tests are fixed for me.

mrmr1993 added a commit to mrmr1993/vimium that referenced this pull request Oct 13, 2014
suggestion = new Suggestion(queryTerms, "search", searchEngineMatch, queryTerms[0] + ": " + queryTerms[1..].join(" "), @computeRelevancy)
searchEngineMatch[0] = searchEngineMatch[0].replace(/%s/g, queryTerms[1..].join(" "))
suggestion = new Suggestion(queryTerms, "search", searchEngineMatch[0],
searchEngineMatch[1] + ": " + queryTerms[1..].join(" "), @computeRelevancy)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're doing queryTerms[1..].join(" ") twice; here, and in the line two above. Surely that's not necessary?

And, if you refactor it, can you fix the indentation on this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sure, I could factor the queryTerms[1..].join(" ") out onto the previous line, I just wrote it quickly.

Could you tell me what you mean about the indentation? if it's the line starting searchEngineMatch[1], that is an argument to suggestion, I could obviously change the indentation if you think that'd be better (indent it further) but I just left it where it was. (would you indent it further?

@smblott-github
Copy link
Collaborator

Might this be more complicated than necessary?

I'd have thought that the common use case is to temporarily disable the use of a search engine (i.e. just comment it out) rather than to explain it. For that, whole-line comments would suffice.

Also, currently and previously comments in vimium have been signalled by either a leading # or a leading ". It would be good to be consistent

Edit: That's all bogus.

@smblott-github
Copy link
Collaborator

Ah. I think I get what you're doing now.

But what if I start with:

foo: http://www.foo.com/?q=%s
bar: http://www.bar.com/?q=%s

then decide I want to temporarily disable the foo search engine?

# foo: http://www.foo.com/?q=%s
bar: http://www.bar.com/?q=%s

Now the foo line becomes the description for the bar search engine, right? Or am I getting this wrong?

@mrmr1993
Copy link
Contributor

Couldn't this ambiguity be resolved by adding something like #1154?

@smblott-github
Copy link
Collaborator

Yes, @mrmr1993. Something like this might work:

# foo: http://www.foo.com/?q=%s
bar: http://www.bar.com/?q=%s
foobar: http://www.foobar.com/?q=%s Foobar super search engine

foo is disabled, bar has no description, and foobar has a description. All of which would have to be concisely described in the help text.

What do you think, @mijoharas?

@mrmr1993
Copy link
Contributor

Not sure if they were ever intended as possibilities, but this suggestion breaks some

  • searches through the default engine:
reddit: site:reddit.com %s
  • data: URIs:
quickedit: data:text/html, <!DOCTYPE html><html><head><script src="http://tinymce.cachefly.net/4.1/tinymce.min.js"></script><script>tinymce.init({selector: 'textarea'});</script></head><body><textarea>%s</textarea></body></html>
  • javascript: URIs:
nextlikeby: javascript:void(window.find("%s liked this", true, false, true, false, false, false));

@smblott-github
Copy link
Collaborator

This started (over in #1009) as a vimium equivalent to chrome's search-engine support. Probably best to keep it simple, clear and clean, for now.

@mijoharas
Copy link
Contributor Author

Ah. I think I get what you're doing now.

But what if I start with:

foo: http://www.foo.com/?q=%s
bar: http://www.bar.com/?q=%s
then decide I want to temporarily disable the foo search engine?

foo: http://www.foo.com/?q=%s

bar: http://www.bar.com/?q=%s
Now the foo line becomes the description for the bar search engine, right? Or am I getting this wrong?

You're right, that case would have foo: http://www.foo.com/?q=%s come out as the comment (which would show up when you search for bar). However, doing:

# foo: http://www.foo.com/?q=%s

bar: http://www.bar.com/?q=%s

should be fine (bar will not have a comment). That is unless I messed something up...

@mijoharas
Copy link
Contributor Author

Yes, @mrmr1993. Something like this might work:

foo: http://www.foo.com/?q=%s

bar: http://www.bar.com/?q=%s
foobar: http://www.foobar.com/?q=%s Foobar super search engine
foo is disabled, bar has no description, and foobar has a description. All of which would have to be concisely described in the help text.

What do you think, @mijoharas?

Something similar is supported:

foobar: http://www.foobaricus.co.uk/?q=%s #anything after space-# is comment

will have anything after space-# is comment: my search query terms come up upon searching foobar my query search terms.
I break the line on # (note space-#) in order to not mess up things as suggested by @mrmr1993 .

I decided to use both as a comment syntax because I don't particularly like making the comments at the end of the lines as it makes my file with all of my searchengines in it difficult to parse. I personally prefer the first (comment on immediately previous line) syntax which is why I made it the main comment-description syntax

@mijoharas
Copy link
Contributor Author

Also, currently and previously comments in vimium have been signalled by either a leading # or a leading ". It would be good to be consistent

That is a good point, I hadn't used the " comment syntax myself (which makes obvious sense given this is vimium) so hadn't included it. I'd be happy to make the change.

If you aren't a fan of the comments-as-descriptions features, we could always make an alternative markup (e.g. single > at start of line) be used for explanation, what do you think @smblott-github and @mrmr1993?

@smblott-github
Copy link
Collaborator

My sense, @mijoharas, is to keep it simple and mirror what chrome does. I suggest we go with:

# foo: http://www.foo.com/?q=%s
" foo: http://www.foo.com/?q=%s
bar: http://www.bar.com/?q=%s
foobar: http://www.foobar.com/?q=%s Foobar super search engine

being two comments, a search engine without a description, and a search engine with a description.

So no special meaning to an extra newline, and very little extra syntax, and comments are treated the same as they are elsewhere.

@mijoharas
Copy link
Contributor Author

As pointed out by @mrmr1993 this suggestion breaks several different possible searches:

Not sure if they were ever intended as possibilities, but this suggestion breaks some

searches through the default engine:

reddit: site:reddit.com %s

data: URIs:

quickedit: data:text/html, <!DOCTYPE html><html><head><script src="http://tinymce.cachefly.net/4.1/tinymce.min.js"></script><script>tinymce.init({selector: 'textarea'});</script></head><body><textarea>%s</textarea></body></html>

javascript: URIs:

nextlikeby: javascript:void(window.find("%s liked this", true, false, true, false, false, false));

We support all of these currently, and breaking on space would stop them working (at least we support top and bottom, not sure about quickedit but I have no reason to think it shouldn't work).

If you want to have an inline search engine with description would the current inline syntax:

foobar: http://www.foobaricus.co.uk/?q=%s #anything after space-# is comment

be ok? this way we break on space-# and not just space which would mean we wouldn't break the currently working searches.

@mrmr1993
Copy link
Contributor

I've had a think, could we not just take a double comment symbol (followed by a space?) to be the start of a description?

Then we'd have

#foo: http://www.foo.com/?q=%s
bar: http://www.bar.com/?q=%s

giving no description to bar, but

#foo: http://www.foo.com/?q=%s
## Do a search on bar.com
bar: http://www.bar.com/?q=%s

giving the description "Do a search on bar.com" to bar.

Similarly, if we use " as a comment too,

"foo1: http://www.foo.com/?q=%s
bar1: http://www.bar.com/?q=%s
"foo2: http://www.foo.com/?q=%s
"" Do a search on bar.com
bar2: http://www.bar.com/?q=%s

would only give a description to bar2.

In any case, I much prefer preceding line comments to inline comments for this, since I feel

## Search Wikipedia
w: http://en.wikipedia.org/w/index.php?title=Special:Search&search=%s

is vastly clearer on a glance than

w: http://en.wikipedia.org/w/index.php?title=Special:Search&search=%s # Search Wikipedia

or any variant (especially if the line wraps in the options page text box, as this example does).

else
split_pair = pair.split(/: (.+)/, 2)
command_name = split_pair[0]
inline_comment = split_pair[1].split(/\s#/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a line doesn't contain the string :, won't this error out (since split_pair[1] === undefined, so we're calling undefined.split)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reading it now it does look that way... I'm sure I've tested it with blank lines e.t.c. (as they're in my own search-engines page which I checked to ensure there weren't any regressions) but that may have been before I changed something else.

I'll take another pass at cleaning this up when I get a chance.

Out of interest, if we go with the double-comment-space idea that you suggested, would that be in addition to the inline comment or instead of? (currently it supports two syntaxes, comment on line before and inline comment, with the first taking priority over the second)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that @smblott-github agrees that using ## and "" for description lines is ok, I would say just drop the inline comment version (and inline comments altogether):

  • It breaks any search engine whose definition inadvertently uses # somewhere.
  • It's confusing to have multiple ways to do the same thing (and to remember the order of precedence).
  • I genuinely can't think of a situation (for this form field!) where an inline comment would have any advantage over a comment on one of the surrounding lines.
  • It makes the code simpler.

Did you have any particular reason for wanting to keep it?

@mijoharas
Copy link
Contributor Author

@mrmr1993 I like your idea of double comment space for description. I'll implement it that way when I get some time (provided other people agree that it's a good way to go?).

@smblott-github
Copy link
Collaborator

What we're doing here is essentially inventing a language for describing search engines. In vim, there's a real language with a parser, data types, an execution engine and so on. In vimium, we don't have all of that. We just map the text to some JavaScript data structure (with no feedback in the case of errors) and hope for the best.

Whatever "language" we come up with, it must be easy for users to understand (without reference to a wiki page), and not likely to confuse or be the source of errors.

I'm concerned that # for a comment and ## for a description (but only if there isn't an intervening newline) is all too cryptic.

Perhaps it's time to accept that we're trying to push too much complexity into a plain old text box. Instead, we could bite the bullet and implement the search-engine setting as an HTML table, with each row having three fields. It would look very-much like the equivalent chrome setting (and the new exclusion-rule setting).

@mijoharas
Copy link
Contributor Author

@smblott-github you're right that that's an option, but personally I'm opposed to it.

Firstly the reason I'm opposed is that I can copy/paste lots of search engines at once, if someone else has a bunch of handy search engines that are useful I can copy all of his. One of the things I like about vim and emacs (and sublime text with it's json config files) is that I can see parts of other peoples configs that I like and take those as a whole. I much prefer that to something like visual studio where I have to enter things in gui config screens line by line or the chrome search engines input.

Secondly, I imagine the primary users of vimium are developers, who firstly won't find the markup difficult to understand (simpler even than markdown which github/stackoverflow use, only two types of markup) and will appreciate the flexibility of config files. In addition, since it's a config file I can trivially write an extension to vim/emacs so I can use my search-engines config file for that and search gh: vimium to go straight to a vimium github search starting a chrome instance from my emacs, copying across my config file.

This is just one datapoint but I would definitely like easily copyable flat config files (partially because I want to write an extension for emacs/vim to open chrome pages from my editor and wanted to use the same config file).

Let me know what you guys think.

@mijoharas
Copy link
Contributor Author

Again, this is a personal preference, and I'll agree with whatever you guys go with in the end but I do prefer flat text (also it's more vim-ish 😄 )

@mrmr1993
Copy link
Contributor

👍 for text configs.

If we add more text-based fields, we could embed a parser framework in Vimium and just store parse rules for each, which should actually our code's reduce complexity.

@smblott-github
Copy link
Collaborator

Hi @mijoharas. It would be great to make progress on this with a next release on the horizon.

We really need something which is easy to use and hard to break. I think that rules out definitions spanning multiple lines, or giving the comment marker # a special meaning as ##.

Suggestions:

  • Support a simple, single-line syntax such as shortcut URL description words, or shortcut URL "description text".
  • Support a structured user interface with input boxes for each part of the definition (a la exclusion rules).

While it might be nice to have, support for exotic mappings (such as javascript: URIs) is not a priority.

@mrmr1993
Copy link
Contributor

mrmr1993 commented Nov 2, 2014

@smblott-github the structured user interfaces are a pain compared to plain text. Not being able to comment out, comment about, group and reorder lines is a big feature loss, which makes it much harder to come back to the setting after some time and change/manage them.

I still really cannot see the issue with ##:

  • The user isn't going to type it by accident.
  • It's easy/clear to read.
  • It's no more complicated for a user to understand than #.
  • It doesn't adversely affect existing functionality.
  • A description is a type of comment anyway.
  • Extra markings within comments to denote documentation etc. have precedent (eg. this documentation generated from comment blocks beginning -- | in this source code).

@philc do you have any thoughts on this?

@mijoharas
Copy link
Contributor Author

I'd like to point out that this breaks existing functionality, examples that I personally use are:

# down for everyone or just me
down: javascript:location='http://www.downforeveryoneorjustme.com/' + escape(location.hostname) + ' ' ;
# use google to search your current site
site: javascript:location='http://www.google.com/search?num=100&q=site:'%20+%20escape(location.hostname)%20+%20'%20%s'%20;%20void%200

With the first example you can just type down into the vomnibar which will then add the root of the current url to downforeveryoneorjustme.com to tell you whether the url is down.

note that the second example is already escaped but could be unescaped with:

#google search for things on this site
googleonsite: javascript:location='http://www.google.com/search?num=100&q=site:' + escape(location.hostname) + ' %s' ; void 0

this allows you to use google to search whatever site you are on for whatever your query is (e.g. on this page type site: vimium into vomnibar to be taken to here

These examples are currently supported and with this we can recreate lots of bookmarklets and add them to the vomnibar under our searchengine use case, I find this powerful and extensible and wouldn't want to lose that.

@smblott-github
Copy link
Collaborator

The feature we're discussing is search engine support, not execute arbitrary JavaScript here. We should not compromise the common case in order to accommodate the exotic.

We can already do site specific searches:

reddit: http://www.google.com/search?q=site:reddit.com+%s

If you substituted %h with location.hostname, you could do things like:

here: http://www.google.com/search?q=site:%h+%s
down: http://www.downforeveryoneorjustme.com/%h

So, with descriptions, it would look something like:

w: http://www.wikipedia.org/w/index.php?title=Special:Search&search=%s Search wikipedia
here: http://www.google.com/search?q=site:%h+%s                        Search the current site
down: http://www.downforeveryoneorjustme.com/%h                        Check if the current site is down
downagain: http://www.downforeveryoneorjustme.com/%h                   Down? # But this is a comment

# This is a comment.
## This is a comment too.
" So is this.
"" And so is this.

This doesn't capture all of the examples in this thread. But it captures a fair few. And, it doesn't compromise the common case.

(Can execute arbitrary JavaScript here not be accommodated by simply defining your own bookmarklet?)

@philc
Copy link
Owner

philc commented Nov 4, 2014

Great discussion guys, but I think we should take the simplest version and
ship it!
On Nov 3, 2014 10:56 PM, "Stephen Blott" notifications@github.com wrote:

The feature we're discussing is search engine support, not execute
arbitrary JavaScript here
. We should not compromise the common case in
order to accommodate the exotic.

We can already do site specific searches:

reddit: http://www.google.com/search?q=site:reddit.com+%s

If you substituted %h with location.hostname, you could do things like:

here: http://www.google.com/search?q=site:%h+%s
down: http://www.downforeveryoneorjustme.com/%h

So, with descriptions, it would look something like:

w: http://www.wikipedia.org/w/index.php?title=Special:Search&search=%s Search wikipedia
here: http://www.google.com/search?q=site:%h+%s Search the current site
down: http://www.downforeveryoneorjustme.com/%h Check if the current site is down
downagain: http://www.downforeveryoneorjustme.com/%h Down? # But this is a comment

This is a comment.

This is a comment too.

" So is this.
"" And so is this.

This doesn't capture all of the examples in this thread. But it captures a
fair few. And, it doesn't compromise the common case.

(Can execute arbitrary JavaScript here not be accommodated by simply
defining your own bookmarklet?)


Reply to this email directly or view it on GitHub
#1169 (comment).

@mijoharas
Copy link
Contributor Author

You could write your own bookmarklet. But what we are writing here is the vomnibar. It is intended to emulate extend and improve upon the omnibar. I wrote the search engine feature because I didn't want to type o for some use cases and ctrl+l for others.

All of the "execute arbitrary javascript" examples that you posted work perfectly well in the omnibar and work perfectly well right now in the vomnibar. I don't see why we would reduce the available features and introduce a new syntax %h which doesn't exist anywhere else in order to avoid adding a different syntax. In addition this is a feature regression which puts us behind the omnibar.

I use chrome and vimium for their flexibility, I don't want to constrain what I can do. I don't often use javascript but it is supported in the omnibar, it is supported in the chrome search engine features, it is supported in the vomnibar and I don't want to do anything to break it.

@mijoharas
Copy link
Contributor Author

also @philc, what do you think's simple. obviously the simplest is to not ship the feature, if that's so then we shipped it last release :shipit: . Otherwise personally I think the simplest is @mrmr1993's suggestion, which was:

## this is a description
# this is a comment
"" this is a description
" this is a comment

what do you think?

@philc
Copy link
Owner

philc commented Nov 4, 2014

In most programming languages (and vimscript), both of those lines would be
comments, but we're treating one of them in a special way. That's very
surprising. We shouldn't need to invent and document our own DSL for this
feature. I think we should go with Stephen's suggestion, because it's
unsurprising and meets the core use case.

On Mon, Nov 3, 2014 at 11:46 PM, Michael Hauser-Raspe <
notifications@github.com> wrote:

also @philc https://github.com/philc, what do you think's simple.
obviously the simplest is to not ship the feature, if that's so then we
shipped it last release [image: :shipit:] . Otherwise personally I think
the simplest is @mrmr1993 https://github.com/mrmr1993's suggestion,
which was:

this is a description

this is a comment

"" this is a description
" this is a comment

what do you think?


Reply to this email directly or view it on GitHub
#1169 (comment).

@mijoharas
Copy link
Contributor Author

Hmmm... I understand the point and it does make sense to go with a "principle of least surprise". My main reservation is that we would be reducing the feature set and introducing breaking changes (and the worst kind of breaking changes, those that affect me! 😄 ). e.g. the javascript bookmarklets above, which work in chrome search, work in the omnibar and vomnibar but this change would break in the vomnibar.

Would you consider something like docstrings, e.g:

#@doc this is a description, no one can type it by accident
# this is a comment
"@doc another description
" another comment which is ignored

obviously, there are alternate docstring syntaxes, too.

Again, I just really don't want to break (my and possibly other peoples) code. Otherwise I suppose that descriptions aren't really too important and don't really need to be added.

One other point is that if you are worried about code complexity (as that code I checked in does look a bit on the ugly side) I can assure you that's just from trying to support both inline and line-before comments at once (and admittedly writing it somewhat unclearly). Changing to this syntax will give clear intuitive code.

Again, I am sorry for being contrary and you do make good points, but I don't want to break things for a feature that I don't think is too important (the descriptions).

@smblott-github
Copy link
Collaborator

Closed in light of #1389.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add description to search engine feature.
4 participants