* Tweak company completions order
@ 2015-12-03 22:14 Lele Gaifax
2015-12-04 3:04 ` Dmitry Gutov
0 siblings, 1 reply; 3+ messages in thread
From: Lele Gaifax @ 2015-12-03 22:14 UTC (permalink / raw)
To: help-gnu-emacs
Hi all,
by default the company frontend orders the items alphabetically. I wonder if
there is a way to perturb it taking into account the current prefix, so that
the first items shown are those having its same case.
Example: I'm writing this post and at this point I insert the word "word#"
where the # represent the cursor; company shows its list, where the items are
"WORD", "WORDCHARS", "Word", "Words", "word", "wordpos" and "words". I'd
prefer having instead them ordered like "word", "wordpos", "words", "WORD"...
I browsed the company source, and read about "transformers", but they does not
seem able to reach the "prefix" from which the completion started.
Thanks in advance for any hint,
ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it | -- Fortunato Depero, 1929.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Tweak company completions order
2015-12-03 22:14 Tweak company completions order Lele Gaifax
@ 2015-12-04 3:04 ` Dmitry Gutov
2015-12-04 12:43 ` Lele Gaifax
0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Gutov @ 2015-12-04 3:04 UTC (permalink / raw)
To: Lele Gaifax, help-gnu-emacs
Hi Lele,
On 12/04/2015 12:14 AM, Lele Gaifax wrote:
> I browsed the company source, and read about "transformers", but they does not
> seem able to reach the "prefix" from which the completion started.
You can refer to the global variable `company-prefix'. It should already
be set by the time company-transformers are used.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Tweak company completions order
2015-12-04 3:04 ` Dmitry Gutov
@ 2015-12-04 12:43 ` Lele Gaifax
0 siblings, 0 replies; 3+ messages in thread
From: Lele Gaifax @ 2015-12-04 12:43 UTC (permalink / raw)
To: help-gnu-emacs
Thank you Dmitry!
For the record, this is what I've come up:
(defun esk/company-sort-preferring-exact-or-same-case (candidates)
(let ((exact nil)
(sameprefix nil)
(others nil)
(plen (length company-prefix)))
(mapc (lambda (candidate)
(if (equal company-prefix candidate)
(push candidate exact)
(if (equal company-prefix (substring candidate 0 plen))
(push candidate sameprefix)
(push candidate others))))
candidates)
(append exact sameprefix others)))
(add-to-list 'company-transformers #'esk/company-sort-preferring-exact-or-same-case)
ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it | -- Fortunato Depero, 1929.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-12-04 12:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-03 22:14 Tweak company completions order Lele Gaifax
2015-12-04 3:04 ` Dmitry Gutov
2015-12-04 12:43 ` Lele Gaifax
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.