abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.3k stars 338 forks source link

Documentation/Symbol support for ivy #2072

Open otadmor opened 5 years ago

otadmor commented 5 years ago

I would like to implement document/symbol/summary to ivy like auto-complete has. The auto-complete is based on the popup.el code which calculates manually the spaces needed to be on the line (see popup.el:popup-create-line-string). I was wondering if ivy already has this kind of support on one of the packages I still not aware of, or if it is already implemented on ivy master branch. If not - im looking for the best way for me to implement it. Does manually spacing is must, or there is a magic text-property I should use? Should I implement it on one of the default display function? A different ivy "generic" method (highlight?). This is kind of open discussion I would like to have before implementing it.

Thanks.

PS I dont want to use auto-complete as it seem to me like a bad practice to have more than one package being able to do the same thing. If you have any thoughts of why should I keep auto-complete I would like to hear it. PS2 counsel-colors-emacs does manually spacing also.

otadmor commented 5 years ago

Just saw https://github.com/Yevgnen/ivy-rich I will work with it. Still, need support for docs.

abo-abo commented 5 years ago

I will work with ivy-rich.

I suggest also looking at https://github.com/expez/company-quickhelp.

Still, need support for docs.

PRs welcome.

otadmor commented 5 years ago

I will do a pr and need some pointers. Do you think overlay like popup is ok or to do some other method of showing the docs? Maybe use a tooltip? Should I use ivy-posframe?

abo-abo commented 5 years ago

@otadmor

Do you think overlay like popup is ok or to do some other method of showing the docs? Maybe use a tooltip? Should I use ivy-posframe?

Overlay popup is OK, although it's a bit harder to implement that a posframe-like popup. I suggest first implementing the easier posframe-like popup.

NightMachinery commented 3 years ago

@abo-abo Is there a way to just open the doc buffer of the current selection in counsel-company?

The problem is that counsel-company just manually gets all the candidates, and doesn't rely on company's UI, so calling (company-call-backend 'doc-buffer selected) does not work and says:

Debugger entered--Lisp error: (void-function nil)
  nil(doc-buffer "&key")
  apply(nil doc-buffer "&key")
  company--multi-backend-adapter(nil doc-buffer "&key")
  apply(company--multi-backend-adapter nil (doc-buffer "&key"))
  company-call-backend-raw(doc-buffer "&key")
  apply(company-call-backend-raw (doc-buffer "&key"))
  company--force-sync(company-call-backend-raw (doc-buffer "&key") nil)
  company-call-backend(doc-buffer "&key")
  (or (company-call-backend 'doc-buffer selected) (user-error "No documentation available"))
  (let* ((selected (progn (or (and (memq (type-of ivy-last) cl-struct-ivy-state-tags) t) (signal 'wrong-type-argument (list 'ivy-state ivy-last))) (aref ivy-last 23))) (doc-buffer (or (company-call-backend 'doc-buffer selected) (user-error "No documentation available"))) start) (if (consp doc-buffer) (progn (setq start (cdr doc-buffer) doc-buffer (car doc-buffer)))) (setq other-window-scroll-buffer (get-buffer doc-buffer)) (let ((win (display-buffer doc-buffer t))) (set-window-start win (if start start (point-min)))))
  (progn (let* ((selected (progn (or (and (memq ... cl-struct-ivy-state-tags) t) (signal 'wrong-type-argument (list ... ivy-last))) (aref ivy-last 23))) (doc-buffer (or (company-call-backend 'doc-buffer selected) (user-error "No documentation available"))) start) (if (consp doc-buffer) (progn (setq start (cdr doc-buffer) doc-buffer (car doc-buffer)))) (setq other-window-scroll-buffer (get-buffer doc-buffer)) (let ((win (display-buffer doc-buffer t))) (set-window-start win (if start start (point-min))))))
  (let ((other-window-scroll-buffer)) (progn (let* ((selected (progn (or (and ... t) (signal ... ...)) (aref ivy-last 23))) (doc-buffer (or (company-call-backend 'doc-buffer selected) (user-error "No documentation available"))) start) (if (consp doc-buffer) (progn (setq start (cdr doc-buffer) doc-buffer (car doc-buffer)))) (setq other-window-scroll-buffer (get-buffer doc-buffer)) (let ((win (display-buffer doc-buffer t))) (set-window-start win (if start start (point-min)))))))
  night/ivy-show-doc-buffer()
  funcall-interactively(night/ivy-show-doc-buffer)
  call-interactively(night/ivy-show-doc-buffer nil nil)
  command-execute(night/ivy-show-doc-buffer)
  read-from-minibuffer("Candidate: " nil (keymap (keymap (11 . night/ivy-show-doc-buffer) (10 . night/ivy-doc-popup) (tab . ivy-next-line) (9 . ivy-next-line)) keymap (61 . ivy-call-and-recenter) (12 . ivy-call-and-recenter) (67108896 . ivy-call-and-recenter) (67108903 . ivy-avy) (M-right . night/ivy-set-to-sel) (S-down . night/ivy-mark-toggle-down) (S-up . night/ivy-mark-toggle-up) (left . night/ivy--directory-out) (insert-state keymap "Auxiliary keymap for Insert state" (11 . previous-line) (10 . next-line)) (33554443 . scroll-down-command) (33554442 . scroll-up-command) (11 . previous-line) (26 closure (t) (&rest _) (interactive) (condition-case nil (progn (call-interactively #'undo)) (error nil))) (23 . doom/delete-backward-word) (21 . evil-delete-back-to-indentation) (1 . move-beginning-of-line) (escape . abort-recursive-edit) (19 . counsel-minibuffer-history) (36 . ivy-magic-read-file-env) (3 keymap (5 . +ivy/woccur) (19 . ivy-rotate-sort) (1 . ivy-toggle-ignore) (15 . ivy-occur)) (33554464 . ivy-restrict-to-matches) (15 . ivy-dispatching-done) (22 . yank) (prior . ivy-scroll-down-command) (next . ivy-scroll-up-command) (7 . minibuffer-keyboard-quit) (right . night/ivy--directory-enter) (32 . self-insert-command) (18 . evil-paste-from-register) (remap keymap (doom/delete-backward-word . ivy-backward-kill-word) (describe-mode . ivy-help) (kill-ring-save . ivy-kill-ring-save) (kill-whole-line . ivy-kill-whole-line) (kill-line . ivy-kill-line) (scroll-down-command . ivy-scroll-down-command) (scroll-up-command . ivy-scroll-up-command) (end-of-buffer . ivy-end-of-buffer) (beginning-of-buffer . ivy-beginning-of-buffer) (kill-word . ivy-kill-word) (forward-char . ivy-forward-char) (delete-char . ivy-delete-char) (backward-kill-word . ivy-backward-kill-word) (backward-delete-char-untabify . ivy-backward-delete-char) (delete-backward-char . ivy-backward-delete-char) (previous-line . ivy-previous-line) (next-line . ivy-next-line)) (9 . night/ivy-mark-toggle) (10 . next-line) (27 keymap (1 . ivy-read-action) (15 . ivy-dispatching-call) (111 . hydra-ivy/body) (25 . ivy-insert-current-full) (105 . ivy-insert-current) (106 . ivy-yank-word) (114 . ivy-toggle-regexp-quote) (97 . ivy-toggle-marks) (16 . ivy-previous-line-and-call) (14 . ivy-next-line-and-call) (118 . ivy-scroll-down-command) (112 . ivy-previous-history-element) (110 . ivy-next-history-element) (10 . ivy-immediate-done) (13 . ivy-call)) (mouse-3 . ivy-mouse-dispatching-done) (mouse-1 . ivy-mouse-done) (down-mouse-1 . ignore) (13 . ivy-done)) nil ivy-history)
  ivy-read("Candidate: " ("&key" "&optional" "&rest" "+company-backend-alist" "+helm-file-search" "+ivy-file-search" "+lookup--jump-to" "+lookup--run-handler" "+lookup--run-handlers" "+lookup--set-handler" "+lookup--xref-show" "+lookup-async" "+lookup-bug-reference-backend-fn" "+lookup-definition-functions" "+lookup-dictionary-definition-backend-fn" "+lookup-dictionary-prefer-offline" "+lookup-documentation-functions" "+lookup-dumb-jump-backend-fn" "+lookup-evil-goto-definition-backend-fn" "+lookup-ffap-backend-fn" "+lookup-file-functions" "+lookup-implementations-functions" "+lookup-project-search-backend-fn" "+lookup-references-functions" "+lookup-thesaurus-definition-backend-fn" "+lookup-type-definition-functions" "+lookup-xref-definitions-backend-fn" "+lookup-xref-references-backend-fn" "+lookup/definition" "+lookup/dictionary-definition" "+lookup/documentation" "+lookup/file" "+lookup/implementations" "+lookup/references" "+lookup/synonyms" "+lookup/type-definition" ":action" ":async" ":bind" ":bind*" ":caller" ":columns" ":completion" ":config" ":definition" ":documentation" ":face" ":file" ":filter" ":implementations" ...) :action ivy-completion-in-region-action :caller counsel-company :keymap (keymap (11 . night/ivy-show-doc-buffer) (10 . night/ivy-doc-popup) (tab . ivy-next-line) (9 . ivy-next-line)))
  (cond ((= (length company-candidates) 1) (ivy-completion-in-region-action (car company-candidates))) (t (ivy-read "Candidate: " company-candidates :action #'ivy-completion-in-region-action :caller 'counsel-company :keymap counsel-company-map)))
  (progn (setq ivy-completion-beg (- (point) len)) (setq ivy-completion-end (point)) (cond ((= (length company-candidates) 1) (ivy-completion-in-region-action (car company-candidates))) (t (ivy-read "Candidate: " company-candidates :action #'ivy-completion-in-region-action :caller 'counsel-company :keymap counsel-company-map))))
  (if len (progn (setq ivy-completion-beg (- (point) len)) (setq ivy-completion-end (point)) (cond ((= (length company-candidates) 1) (ivy-completion-in-region-action (car company-candidates))) (t (ivy-read "Candidate: " company-candidates :action #'ivy-completion-in-region-action :caller 'counsel-company :keymap counsel-company-map)))))
  (let ((len (cond ((let (l) (and company-common (string= company-common ...) l))) (company-prefix (length company-prefix))))) (if len (progn (setq ivy-completion-beg (- (point) len)) (setq ivy-completion-end (point)) (cond ((= (length company-candidates) 1) (ivy-completion-in-region-action (car company-candidates))) (t (ivy-read "Candidate: " company-candidates :action #'ivy-completion-in-region-action :caller 'counsel-company :keymap counsel-company-map))))))
  counsel-company()
  funcall-interactively(counsel-company)
  call-interactively(counsel-company nil nil)
  command-execute(counsel-company)