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

How to wrap long lines of tooltip #1040

Closed
crotoc opened this issue Dec 17, 2020 · 19 comments
Closed

How to wrap long lines of tooltip #1040

crotoc opened this issue Dec 17, 2020 · 19 comments
Milestone

Comments

@crotoc
Copy link

crotoc commented Dec 17, 2020

Thanks for the great plugin!

I use company to auto complete file path. However, it's usually very long and the lines appearing in the tooltip doesn't wrap so very hard to select the right choice. Is it possbile to wrap the lines? Please advice. Thanks!

image

@dgutov
Copy link
Member

dgutov commented Dec 20, 2020

Hi!

Wrap how?

The best we could do for this particular case, I guess, is to only treat the last path segment as "prefix".

@crotoc
Copy link
Author

crotoc commented Dec 20, 2020

How to setup up ignore the prefix you mentioned to show the next part of path? Current setup shows each file/directory in a line, if it's too long I don't know which line is the correct one to complete. Wrapping means show the each line in two lines to show the whole path. Thanks!

@crotoc
Copy link
Author

crotoc commented Dec 23, 2020

@dgutov For example, if the file path I need is:

Can I setup to just show "dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disTRUE_max20_ws1e6" when I try to auto complete at "~/fs0/subgwas/scz/145loci/gibbs_result/" or can it is shown as:

~/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic
_disTRUE_max20_ws1e6/a_file
~/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic
_disTRUE_max20_ws1e6/b_file
~/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic
_disTRUE_max20_ws1e6/c_file

so that I can know which selection is right. I have searched for so many times and don't identify a way to workaround. Please give me some advice. Thanks!

@dgutov
Copy link
Member

dgutov commented Dec 24, 2020

There's no existing option, it will be a change in the implementation.

For instance, like this:

diff --git a/company-files.el b/company-files.el
index 8859266..a6339d0 100644
--- a/company-files.el
+++ b/company-files.el
@@ -98,15 +98,15 @@ The values should use the same format as `completion-ignored-extensions'."
 (defvar company-files--completion-cache nil)
 
 (defun company-files--complete (prefix)
-  (let* ((dir (file-name-directory prefix))
-         (file (file-name-nondirectory prefix))
+  (let* ((dir (file-name-directory
+               (company-files--grab-existing-name)))
+         (file prefix)
          (key (list file
                     (expand-file-name dir)
                     (nth 5 (file-attributes dir))))
          (completion-ignore-case read-file-name-completion-ignore-case))
     (unless (company-file--keys-match-p key (car company-files--completion-cache))
-      (let* ((candidates (mapcar (lambda (f) (concat dir f))
-                                 (company-files--directory-files dir file)))
+      (let* ((candidates (company-files--directory-files dir file))
              (directories (unless (file-remote-p dir)
                             (cl-remove-if-not (lambda (f)
                                                 (and (company-files--trailing-slash-p f)
@@ -116,7 +116,9 @@ The values should use the same format as `completion-ignored-extensions'."
              (children (and directories
                             (cl-mapcan (lambda (d)
                                          (mapcar (lambda (c) (concat d c))
-                                                 (company-files--directory-files d "")))
+                                                 (company-files--directory-files
+                                                  (concat dir d)
+                                                  "")))
                                        directories))))
         (setq company-files--completion-cache
               (cons key (append candidates children)))))
@@ -139,7 +141,7 @@ File paths with spaces are only supported inside strings."
   (interactive (list 'interactive))
   (cl-case command
     (interactive (company-begin-backend 'company-files))
-    (prefix (company-files--grab-existing-name))
+    (prefix (file-name-nondirectory (company-files--grab-existing-name)))
     (candidates (company-files--complete arg))
     (location (cons (dired-noselect
                      (file-name-directory (directory-file-name arg))) 1))

I'm tempted to push this, but it does call company-files--grab-existing-name one extra time, which could lead to slower performance over Tramp. Or not, if file-exists-p hits some kind of cache. Should test it out.

@crotoc
Copy link
Author

crotoc commented Dec 29, 2020

Happy holidays! Just have several days off! Thanks for your reply!

I just merge the changes to the company-files.el in my installed dir but no wrapping or no ignoring of prefix. Am I doing something wrong? Thanks!

@dgutov
Copy link
Member

dgutov commented Dec 29, 2020

Let's see.

What does M-x company-diag say, at that position in the buffer?

(And happy holidays!)

@crotoc
Copy link
Author

crotoc commented Dec 29, 2020

The command shows:

Emacs 26.3 (x86_64-pc-linux-gnu) of 2020-03-25 on c418c5199a0f
Company 0.9.13

company-backends: (company-emacs-eclim company-bbdb company-semantic company-clang company-xcode company-cmake company-capf company-files
(company-dabbrev-code company-gtags company-etags company-keywords)
company-oddmuse company-dabbrev)

Used backend: company-files
Major mode: perl-mode
Prefix: "/fs0/subgwas/scz/145loci/gibbs_result/"
Completions:
"
/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/"
"/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws5e5/"
"
/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disTRUE_max20_ws1e6/"
"/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disTRUE_max20_ws5e5/"
"
/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.5e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/"
"/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.5e-6.5e5.bed.fmt_generic_disFALSE_max20_ws5e5/"
"
/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.5e-6.5e5.bed.fmt_generic_disTRUE_max20_ws1e6/"
"/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.5e-6.5e5.bed.fmt_generic_disTRUE_max20_ws5e5/"
"
/fs0/subgwas/scz/145loci/gibbs_result/evaluateTRUE/"
"/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/20191127-1315-UIHVO.param"
"
/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/all.pp"
"/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/all.pp_Q5/"
"
/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/ldsc_10000.pdf"
"/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/ldsc_100000.pdf"
"
/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/rlt_nearest/"
"/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/scz.145.sub.1e-6.5e5.bed.fmt.evi.processed"
"
/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/scz.145.sub.1e-6.5e5.bed.fmt.evi.pvalue"
"/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/scz.145.sub.1e-6.5e5.bed.fmt.evi.weight"
"
/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/scz.145.sub.1e-6.5e5.bed.fmt.generic.processed"
"/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/scz.145.sub.1e-6.5e5.bed.fmt.generic.weight"
"
/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/scz.145.sub.1e-6.5e5.bed.fmt.genesInRegion"
"/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/scz.145.sub.1e-6.5e5.bed.fmt_gibbs_sampling_go_rp_0.3_posterior_probability"
"
/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/scz.145.sub.1e-6.5e5.bed.fmt_gibbs_sampling_go_rp_0.3_posterior_probability.RData"
"~/fs0/subgwas/scz/145loci/gibbs_result/dir_scz.145.sub.1e-6.5e5.bed.fmt_generic_disFALSE_max20_ws1e6/scz.145.sub.1e-6.5e5.bed.fmt_gibbs_sampling_go_rp_0.3_posterior_probability.training.
RData"
......

The buffer of completion shows:
image

Let me know if you need more info! Thanks!

@dgutov
Copy link
Member

dgutov commented Dec 29, 2020

Okay, that looks legit.

Did you apply the patch? And re-evaluated the definitions? Or restarted Emacs?

@crotoc
Copy link
Author

crotoc commented Dec 29, 2020

I installed company through EPLA and it's located in ~/.emacs.d/elpa/company-20200725.2348/. So I opened the company-fiiles.el in this dir and shows:
image
image

And then, I closed emas and reopened a file and tried the command you mentioned. Is it the correct way to apply the patch?

LISP is hard to read because of so manny brackets:)

@dgutov
Copy link
Member

dgutov commented Dec 29, 2020

And then, I closed emas and reopened a file and tried the command you mentioned. Is it the correct way to apply the patch?

There are roughly three options:

  1. Apply the patch, don't restart Emacs, but visit every affected definition and press C-M-x to re-evaluate the definition.
  2. M-x byte-compile-file after applying the patch and saving the file.
  3. Set load-prefer-newer to t early in the init file, then you don't have to byte-compile the new version to get it loaded.

@crotoc
Copy link
Author

crotoc commented Dec 29, 2020

Many thanks!! I use the secend option and it shows:
image

This is exactly what I want! Appreciate very much!

At last, happy new year, buddy!

@dgutov
Copy link
Member

dgutov commented Jan 2, 2021

After some testing, there are a couple of problems with this patch (in particular, seeing the Matching input is required error from time to time). You're welcome to use it (though be aware that the direct changes to the files will be overwritten when the package updates), but I'll avoid pushing this change for now.

A better solution is in the works.

@crotoc
Copy link
Author

crotoc commented Jan 4, 2021

Thanks for the remind! The current patch is enought for me! Looking forward to the perfect solution. 👍

@crotoc crotoc closed this as completed Jan 4, 2021
@dgutov
Copy link
Member

dgutov commented Jan 4, 2021

Let's keep this open in the meantime. 👍

@dgutov dgutov reopened this Jan 4, 2021
@crotoc
Copy link
Author

crotoc commented Jan 5, 2021

Sure! I hope I can help but I am still learning lisp.

@crotoc
Copy link
Author

crotoc commented May 8, 2023

Hi, is there any update about this issue? Has it been pushed to the main so that this works instantly after installation without patching? Thanks!

@dgutov
Copy link
Member

dgutov commented Oct 12, 2023

Not yet, but thanks for the bump.

@dgutov dgutov added this to the 1.0 milestone Oct 12, 2023
@dgutov dgutov closed this as completed in 10e9d6e Dec 8, 2023
@dgutov
Copy link
Member

dgutov commented Dec 8, 2023

Pushed after some more tweaking.

Let me know if you see any problems.

@crotoc
Copy link
Author

crotoc commented Dec 8, 2023

Thanks very much! Will try :) Can't believe you are still monitoring!

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

No branches or pull requests

2 participants