astoff / devdocs.el

Emacs viewer for DevDocs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make it possible to match $ in regexp with ivy

kisp opened this issue · comments

Thank you for this package, it's immensely useful.

I am using ivy and I notices that I can use ^ in my regexp query, where $ does not work (I do not get any matches where there should be matches).

As a more concrete example I would like search in Ruby on Rails 6.1 for

#update$

That should give me the following results:

ActiveRecord::ConnectionAdapters::DatabaseStatements#update
ActiveRecord::Persistence#update
ActiveRecord::Persistence::ClassMethods#update
ActiveStorage::DiskController#update
ActiveSupport::HashWithIndifferentAccess#update
Rails::Generators::ActiveModel#update

But I do not get any results.

I noticed that this is due to the disambiguation cookies that are being added to each entry.

I can probably write my own function to search just in the Rails documentation and leave off the disambiguation cookies.

But I wanted to ask if there could be a more general solution that could be useful for everybody?

I could image changing the way how candidates are computed:

(mapcan #'devdocs--entries devdocs-current-docs)

How about using a hash-table to check for duplicates and add disambiguation cookies only when they are needed?

As an aside: I cannot see the annotation generated from devdocs--annotate when using Ivy, so I wouldn't be able to choose the right documentation when two entries have the same name.

Binding completion-extra-properties like in https://emacs.stackexchange.com/questions/42099/how-can-i-ask-a-user-to-choose-from-a-list-of-options-while-showing-her-a-long seems to work.

(defun foo ()
  (interactive)
  (let ((completion-extra-properties '(:annotation-function my-annot-fn)))
(completing-read "Choose: " '(("aa" . AA-value)
                  ("ab" . AB-value)
                  ("bb" . BB-value)))))

(defun my-annot-fn (candidate)
  (cdr (assoc candidate '(("aa" . " Description of AA")
              ("ab" . " Description of AB")
              ("bb" . " Description of BB")))))

This is a tricky one, and there may not be a good solution for this limitation. completing-read just returns the selected string value (in your example, "aa", not ("aa" . AA-value)), so the disambiguation cookie is necessary.

The best I can say at the moment is that the null character (you can enter it with C-q C-@) matches the faked end of line.

How about using a hash-table to check for duplicates and add disambiguation cookies only when they are needed?

Well, this will not solve the problem, only make it rare...

Binding completion-extra-properties seems to work.

I believe this is the old API for annotations. Or at least it doesn't allow to specify a completion category, which is sometimes useful. The method used to pass an annotation function works with the other completion frameworks, so Ivy should support it too...

I still don't see a better solution than what I described above, so I'll close this issue.