radian-software / selectrum

🔔 Better solution for incremental narrowing in Emacs.
MIT License
738 stars 33 forks source link

Need to select when using space #228

Closed gnusupport closed 3 years ago

gnusupport commented 4 years ago

It should give selection when using space.

Example is when searching for eww-mode function:

It will not select when entering: eww m

It will select when entering: eww-m

Maybe it intentionally uses space for selections. It is more useful if space is ignored.

clemera commented 4 years ago

I think we already figured that out in #227. As discussed there you need to adjust selectrum-refine-candidates-function to configure the filtering you want.

raxod502 commented 4 years ago

Selectrum uses strict substring matching by default, as mentioned in the README. As the README recommends, you can use prescient.el to improve this behavior (eww m will match eww-mode).

DivineDominion commented 3 years ago

Not that I want to have this, but couldn't a key mapping from be added to selectrum-minibuffer-map?

raxod502 commented 3 years ago

Well... one could certainly add a binding, but it's unclear to me what should happen when said binding is triggered. I guess it could insert a hyphen instead. But really I think the way to get the desired behavior is by configuring selectrum-refine-candidates-function to an appropriate value that does with spaces what is wanted.

clemera commented 3 years ago

It sounds like @gnusupport is using the default selectrum-refine-candidates-function which is very basic. You should try prescient or orderless which give you much nicer matching behaviour.

gnusupport commented 3 years ago

OK, I know orderless but I do not wish to include extra package.

For now, selectrum is not working well for me, I do not know why.

(defun rcd-completing-read-sql-hash (prompt sql &optional history) (let ((hash (rcd-sql-hash sql cf*)) (completion-ignore-case t) (choice (completing-read prompt hash nil t nil history)) (choice (string-trim choice)) (id (gethash choice hash))) (if id id (when (string-match "^>" choice) ;; disregard this choice))))

(rcd-completing-read-sql-hash "People: " "SELECT people_id, get_full_contacts_name(people_id) FROM people LIMIT 30")

then I can use the above function with ivy-mode and helm-mode, fido-mode, but I cannot use it with selectrum-mode, as I see: 0 People

clemera commented 3 years ago

What type are the keys/values of this hash table? Keys that are strings or symbols should be offered as completions as per all-completions docstring.

gnusupport commented 3 years ago

I hope this helps:

(defun rcd-sql-hash (sql pg) "Returns hash with key TEXT [ID] and value ID from SQL result in the form ID, TEXT" (let ((hash (make-hash-table :test 'equal)) (res (rcd-sql sql pg))) (dolist (i res hash) (cond ((eq (type-of i) 'vector) (puthash (format "%s [%s]" (elt i 1) (elt i 0)) (elt i 0) hash))))))

clemera commented 3 years ago

The keys are strings so this should work fine:

(completing-read "Test: "
                 (let ((table (make-hash-table :test #'equal)))
                   (puthash "test1" "res1" table)
                   (puthash "test2" "res2" table)
                   table))

Can you create test case to reproduce?

gnusupport commented 3 years ago

The function above does not give good result in selectrum. It does not work. It gives 0 completion candidates or nothing to select from.

clemera commented 3 years ago

Okay, that is good because it tells us there is probably something wrong with your configuration, it works with emacs -Q and fresh installed Selectrum with no settings. Could you check what part of your setup could cause this or post it here so we can have a look?

gnusupport commented 3 years ago

If I start with emacs -Q and then evaluate all my init.el I do not see any problem yet, so that means that function works well after evaluating init.el manually

I have this line related to selectrum in init.el '(selectrum-extend-current-candidate-highlight t)

And if I set it to nil, it does not help.

Also note that other completing read replacement packages work well, only selectrum does not work. If that is the case it is better to assume that selectrum is not handling something.

When I have changed the theme, then the function started working again. I use only built-in themes, and I used dark one.

(emacs-version) "GNU Emacs 28.0.50 (build 2, x86_64-pc-linux-gnu, X toolkit, cairo version 1.14.8, Xaw3d scroll bars) of 2020-11-25"

It is hard for me to know why, when it is sensitive and not works then I use other means to get the result.

clemera commented 3 years ago

It works with emacs-sandbox so I assume it is something in your configuration, though it might be the case that you have some setting unrelated to Selectrum which we don't handle correctly and that introduces the issue, in that case we should better figure out the underlying reason. Do you use the latest version of Selectrum?

gnusupport commented 3 years ago

I have now updated to this commit:

commit bb176a151959fb321e904deac8e0e3a90ffe276f Author: Clemens Radermacher clemera@posteo.net Date: Sat Nov 28 11:48:34 2020 +0100 he Spelling and docs

And it still does not work. After change of theme it worked for short time, then again not.

Because it sees 0 completion candidates (that is known)

(defun selectrum-completing-read (prompt collection &optional predicate require-match initial-input hist def inherit-input-method) "Read choice using Selectrum. Can be used as completing-read-function'. For PROMPT, COLLECTION, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST, DEF, and INHERIT-INPUT-METHOD, seecompleting-read'." (message "%s" collection) (ignore initial-input inherit-input-method) (selectrum-read prompt nil ;; Don't pass initial-input'. We use it internally but it's ;; deprecated incompleting-read' and doesn't work well with the ;; Selectrum paradigm except in specific cases that we control. :default-candidate (or (car-safe def) def) :require-match (eq require-match t) :history hist :may-modify-candidates t :minibuffer-completion-table collection :minibuffer-completion-predicate predicate))

It shows me:

s(hash-table size 325 test equal rehash-size 1.5 rehash-threshold 0.8125 data (AFGHANISTAN [1] 1 ÅLAND ISLANDS [2] 2 ALBANIA [3] 3 ALGERIA [4] 4 AMERICAN SAMOA [5] 5 ANDORRA [6] 6 ANGOLA [7] 7 ANGUILLA [8] 8 ANTARCTICA [9] 9 ANTIGUA AND BARBUDA [10] 10 ARGENTINA [11] 11 ARMENIA [12] 12 ARUBA [13] 13 AUSTRALIA [14] 14 AUSTRIA [15] 15 AZERBAIJAN [16] 16 BAHAMAS [17] 17 BAHRAIN [18] 18 BANGLADESH [19] 19 BARBADOS [20] 20 BELARUS [21] 21 BELGIUM [22] 22 BELIZE [23] 23 BENIN [24] 24 BERMUDA [25] 25 BHUTAN [26] 26 BOLIVIA [27] 27 BOSNIA AND HERZEGOVINA [28] 28 BOTSWANA [29] 29 BOUVET ISLAND [30] 30 BRAZIL [31] 31 BRITISH INDIAN OCEAN TERRITORY [32] 32 BRUNEI DARUSSALAM [33] 33 BULGARIA [34] 34 BURKINA FASO [35] 35 BURUNDI [36] 36 CAMBODIA [37] 37 CAMEROON [38] 38 CANADA [39] 39 CAPE VERDE [40] 40 CAYMAN ISLANDS [41] 41 CENTRAL AFRICAN REPUBLIC [42] 42 CHAD [43] 43 CHILE [44] 44 CHINA [45] 45 CHRISTMAS ISLAND [46] 46 COCOS (KEELING) ISLANDS [47] 47 COLOMBIA [48] 48 COMOROS [49] 49 CONGO [50] 50 CONGO, THE DEMOCRATIC REPUBLIC OF THE [51] 51 COOK ISLANDS [52] 52 COSTA RICA [53] 53 COTE D'IVOIRE [54] 54 COUNTRY OF CURAÇAO [247] 247 CROATIA [55] 55 CUBA [56] 56 CYPRUS [57] 57 CZECH REPUBLIC [58] 58 DENMARK [59] 59 DJIBOUTI [60] 60 DOMINICA [61] 61 DOMINICAN REPUBLIC [62] 62 ECUADOR [63] 63 EGYPT [64] 64 EL SALVADOR [65] 65 EQUATORIAL GUINEA [66] 66 ERITREA [67] 67 ESTONIA [68] 68 ESWATINI [206] 206 ETHIOPIA [69] 69 FALKLAND ISLANDS (MALVINAS) [70] 70 FAROE ISLANDS [71] 71 FIJI [72] 72 FINLAND [73] 73 FRANCE [74] 74 FRENCH GUIANA [75] 75 FRENCH POLYNESIA [76] 76 FRENCH SOUTHERN TERRITORIES [77] 77 GABON [78] 78 GAMBIA [79] 79 GEORGIA [80] 80 GERMANY [81] 81 GHANA [82] 82 GIBRALTAR [83] 83 GREECE [84] 84 GREENLAND [85] 85 GRENADA [86] 86 GUADELOUPE [87] 87 GUAM [88] 88 GUATEMALA [89] 89 GUERNSEY [248] 248 GUINEA [90] 90 GUINEA-BISSAU [91] 91 GUYANA [92] 92 HAITI [93] 93 HEARD ISLAND AND MCDONALD ISLANDS [94] 94 HOLY SEE (VATICAN CITY STATE) [95] 95 HONDURAS [96] 96 HONG KONG [97] 97 HUNGARY [98] 98 ICELAND [99] 99 INDIA [100] 100 INDONESIA [101] 101 IRAN, ISLAMIC REPUBLIC OF [102] 102 IRAQ [103] 103 IRELAND [104] 104 ISLE OF MAN [244] 244 ISRAEL [105] 105 ITALY [106] 106 JAMAICA [107] 107 JAPAN [108] 108 JERSEY [245] 245 JORDAN [109] 109 KAZAKHSTAN [110] 110 KENYA [111] 111 KIRIBATI [112] 112 KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF [113] 113 KOREA, REPUBLIC OF [114] 114 KOSOVO [242] 242 KUWAIT [115] 115 KYRGYZSTAN [116] 116 LAO PEOPLE'S DEMOCRATIC REPUBLIC [117] 117 LATVIA [118] 118 LEBANON [119] 119 LESOTHO [120] 120 LIBERIA [121] 121 LIBYAN ARAB JAMAHIRIYA [122] 122 LIECHTENSTEIN [123] 123 LITHUANIA [124] 124 LUXEMBOURG [125] 125 MACAO [126] 126 MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF [127] 127 MADAGASCAR [128] 128 MALAWI [129] 129 MALAYSIA [130] 130 MALDIVES [131] 131 MALI [132] 132 MALTA [133] 133 MARSHALL ISLANDS [134] 134 MARTINIQUE [135] 135 MAURITANIA [136] 136 MAURITIUS [137] 137 MAYOTTE [138] 138 MEXICO [139] 139 MICRONESIA, FEDERATED STATES OF [140] 140 MOLDOVA, REPUBLIC OF [141] 141 MONACO [142] 142 MONGOLIA [143] 143 MONTENEGRO [144] 144 MONTSERRAT [145] 145 MOROCCO [146] 146 MOZAMBIQUE [147] 147 MYANMAR [148] 148 NAMIBIA [149] 149 NAURU [150] 150 NEPAL [151] 151 NETHERLANDS [152] 152 NETHERLANDS ANTILLES [153] 153 NEW CALEDONIA [154] 154 NEW ZEALAND [155] 155 NICARAGUA [156] 156 NIGER [157] 157 NIGERIA [158] 158 NIUE [159] 159 NORFOLK ISLAND [160] 160 NORTHERN MARIANA ISLANDS [161] 161 NORWAY [162] 162 OMAN [163] 163 PAKISTAN [164] 164 PALAU [165] 165 PALESTINIAN TERRITORY, OCCUPIED [166] 166 PANAMA [167] 167 PAPUA NEW GUINEA [168] 168 PARAGUAY [169] 169 PERU [170] 170 PHILIPPINES [171] 171 PITCAIRN [172] 172 POLAND [173] 173 PORTUGAL [174] 174 PUERTO RICO [175] 175 QATAR [176] 176 REUNION [177] 177 ROMANIA [178] 178 RUSSIAN FEDERATION [179] 179 RWANDA [180] 180 SAINT HELENA [181] 181 SAINT KITTS AND NEVIS [182] 182 SAINT LUCIA [183] 183 SAINT PIERRE AND MIQUELON [184] 184 SAINT VINCENT AND THE GRENADINES [185] 185 SAMOA [186] 186 SAN MARINO [187] 187 SAO TOME AND PRINCIPE [188] 188 SAUDI ARABIA [189] 189 SENEGAL [190] 190 SERBIA [191] 191 SEYCHELLES [192] 192 SIERRA LEONE [193] 193 SINGAPORE [194] 194 SINT MAARTEN [249] 249 SLOVAKIA [195] 195 SLOVENIA [196] 196 SOLOMON ISLANDS [197] 197 SOMALIA [198] 198 SOUTH AFRICA [199] 199 SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS [200] 200 SOUTH SUDAN [243] 243 SPAIN [201] 201 SRI LANKA [202] 202 SUDAN [203] 203 SURINAME [204] 204 SVALBARD AND JAN MAYEN [205] 205 SWEDEN [207] 207 SWITZERLAND [208] 208 SYRIAN ARAB REPUBLIC [209] 209 TAIWAN, PROVINCE OF CHINA [210] 210 TAJIKISTAN [211] 211 TANZANIA, UNITED REPUBLIC OF [212] 212 THAILAND [213] 213 TIMOR-LESTE [214] 214 TOGO [215] 215 TOKELAU [216] 216 TONGA [217] 217 TRINIDAD AND TOBAGO [218] 218 TUNISIA [219] 219 TURKEY [220] 220 TURKMENISTAN [221] 221 TURKS AND CAICOS ISLANDS [222] 222 TUVALU [223] 223 UGANDA [224] 224 UKRAINE [225] 225 UNITED ARAB EMIRATES [226] 226 UNITED KINGDOM [227] 227 UNITED STATES [228] 228 UNITED STATES MINOR OUTLYING ISLANDS [229] 229 URUGUAY [230] 230 UZBEKISTAN [231] 231 VANUATU [232] 232 VENEZUELA [233] 233 VIET NAM [234] 234 VIRGIN ISLANDS, BRITISH [235] 235 VIRGIN ISLANDS, U.S. [236] 236 WALLIS AND FUTUNA [237] 237 WESTERN SAHARA [238] 238 YEMEN [239] 239 ZAMBIA [240] 240 ZIMBABWE [241] 241))

But it shows zero completion candidates when I run function.

clemera commented 3 years ago

Indeed back then it did not work, there was a bug in the hash table normalization please update to latest version where this is fixed.

gnusupport commented 3 years ago

I did update now, but I lost some other things, now it seem to work well. Thank you.

clemera commented 3 years ago

For filtering you should really consider using an additional package, it's much nicer with prescient or orderless. Maybe we could also provide an improved default filtering function but for now it is pretty basic. We can close this issue I guess?

minad commented 3 years ago

Maybe we could also provide an improved default filtering function but for now it is pretty basic.

Please don't. If someone wants to use a better sorting/filtering - use an additional package. @gnusupport can also write their own small package doing filtering/sorting according to their taste. If not - orderless and prescient fit the bill. But there could very well be an alternative package.

gnusupport commented 3 years ago

It probable was not my issue, I do not remember complaining about spaces, but for me is most of time faster using built-in completion.

When I need completion is when there is need for relevance search. If completion package does not offer relevance search is for 10 points down. That is what you mean with orderless.

gnusupport commented 3 years ago

Think of your users. Now it is less usable then ivy so you decide.

For me is hard and not useful to look into selectrum. It is not in GNU ELPA, I need extra measures to install it and users of software would need to. Explaining to many people is tedious. I work with teams of people on distance and I have to minimalize their installations. For me personally I have no problems.

When there is need for relevance search I use ivy as that is easiest to fetch straight form Emacs and GNU ELPA, it does not need MELPA. Ideally person would just load one file without any external packages.

Filtering and sorting was never my problem with any completion. I do that in tabulated list mode to handle databases. It took me while to understand how to express myself, but still did not get it well.

I need relevance search in completion packages. That is very well expressed. So far I use relevance search features from the PostgreSQL database as database entries are mostly that I need to complete. Then one simple function can replace all the numerous completing read functions that I would be using only for reason of relevance search. I can as well display results in tabulated-list-mode as that is best where such huge stuff better belongs.

Example is that I can discover true source of income by just doing various intersections and grouping of information from database. Discovering the number of interactions per organization, number of interactions per person and sorting so, helped me gain new income with those people that I already know, but I have lost focus on some of them. It requires sorting and reviewing by the sum of interactions upside down, by country, by organization, and that is where tabulated-list-mode is good.

clemera commented 3 years ago

@minad

Please don't. If someone wants to use a better sorting/filtering - use an additional package.

I was talking about out simple out of order matching on space, I see no harm providing that by default and it helps people for which that is already enough.

minad commented 3 years ago

@clemera

I was talking about out simple out of order matching on space, I see no harm providing that by default and it helps people for which that is already enough.

If it can replace the existing matching style without adding significantly more code, I am not totally opposed to such a change.

Generally, I would try to boil down the feature set of Selectrum - but I stated that opinion before. In particular if there are excellent external packages and in particular if the feature can naturally be provided externally, like completion styles. But obviously, this works only for features which are not highly Selectrum-dependent.

If Selectrum aims to be the freestanding solution for everything, then everything should be put here, but this does not seem the goal. And then we would just end up with another helm or ivy. I think the strong point is really the separation into components and the minimalism.

gnusupport commented 3 years ago

Just guessing that you made selectrum for programmers, not for users.

For me as user, selectrum would not be a choice at all. I have just tried to accommodate my program that it can be used by any completion package and for that reason I am testing selectrum. Not that I would recommend to user to use it. I would recommend ivy.

minad commented 3 years ago

@gnusupport Which program are you talking about?

clemera commented 3 years ago

If Selectrum aims to be the freestanding solution for everything, then everything should be put here, but this does not seem the goal. And then we would just end up with another helm or ivy. I think the strong point is really the separation into components and the minimalism.

No I agree that is not the goal, My interest is to make Selectrum a flexible solution for completions and provide a reasonable default experience out of the box. I think the current refinement default is a bit annoying and we can fix that without much change, I think.

gnusupport commented 3 years ago

Programs like website revision system, customer relationship management, accounting, enterprise resources planning, dynamic knowledge repository like by Doug Engelbart. Those programs manage database. I am using many times completion per day and I basically remove all hard coded completion so that later myself, my staff members and maybe other users may decide which completion to use.

gnusupport commented 3 years ago

I think that developers of selectrum do not give favor to users and it could be all to misunderstandings.

I see the situation for any completion package including Selectrum that it should give to user:

Let me give you comparison:

If the goal is to make something useful for users, then what does Selectrum upgrade or make more useful?

Maybe it does something technically better, but the value of it is null if I cannot use it in the manner to upgrade the built-in completion, find candidates faster, or minimize typing, or make anything easier.

Dynamic Menu Launcher: dmenu_run -fn "DejaVu:pixelsize=30" -l 10 -i -b -p "Launch: " -nb "dark goldenrod" -nb black

Major expectation is that I may put words in any order and by using spaces. That is what makes the basic relevance search feature.

By demanding from user to use exclusively one space how Selectrum does or otherwise to deny the selection is making selectrum not usable, not accessible piece of software.

By deviating from what other software does and denying user to use space to replace the wildcard * (joker) from built-in completion is another pitfall.

It looks like you want to achieve something, but it does not look it is upgrading anything, it rather looks like regression compared to other software.

dmenu, fzf, ivy, helm all do what I explained, only selectrum does not.

minad commented 3 years ago

@gnusupport can you link to your program? Is it free software?

gnusupport commented 3 years ago

It is unpublished free software due to its complexities and not being ready for public. I am using it actively. It uses PostgreSQL database. You may write me by email and tell me your specific need. bugs AT gnu.support

clemera commented 3 years ago

@gnusupport I think you are right that Selectrum in its current form is more like a component to build something like helm. Maybe some kind of meta package should compose the available packages, define default keybindings, configurations and such for end users. Maybe this should be the path we should take instead of handling it by Selectrum itself as proposed in #174. What do you think @minad @raxod502?

minad commented 3 years ago

@clemera I am going all-in with the component-based approach! I think, @oantolin agrees too. We try to avoid overlap between Consult, Embark and Marginalia and try to ensure that these work well together. And everything should also work well together with Selectrum or Icomplete-vertical.

raxod502 commented 3 years ago

Maybe this should be the path we should take instead of handling it by Selectrum itself as proposed in #174

Yeah, that makes a lot of sense. Another key advantage is we get a new package to come up with a clever name for ;)