-
Notifications
You must be signed in to change notification settings - Fork 33
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
Make truncation/replacement indicators customizable. #147
Conversation
- selectrum-horizontal-whitespace-indicator: ".." - selectrum-matching-line-indicator: " -> " - selectrum-newline-indicator: "\\\\n" - selectrum-truncated-candidate-indicator: "..."
I wouldn't like that this would introduce four additional user options (+ maybe faces). The scope of those is very small (multi lines aren't used by built-in commands). Maybe we could introduce one option holding a |
I like that idea. |
I have tried to do that by renaming the function I am unsure of the phrasing of the following function description. I feel like there is a better way of writing the final sentence.
|
Thanks, I think it would be nicer to narrow the scope of the function to the multi line strings. With the current approach user functions need to deal with the passed candidate list which means they would need to include the first cond clause and the logic to walk through the candidates in their custom functions: ...
(dolist...
((not (string-match "\n" cand))
cand)
... Another approach could be to keep the
Maybe we could cut that down to |
In that case, how would one customize the indicator for the matching line? What if a list is used as a customizable variable, that contains the four indicators, in a way like the below diff? That way, there is only one user option created, but all indicators and their faces are still customizable. @@ -276,6 +276,13 @@
wrapping."
:type 'integer)
+(defcustom selectrum-candidate-transformations
+ '((match :display "->" :face success)
+ (truncation :display "..." :face shadow)
+ (newline :display "\\\\n" :face warning)
+ (whitespace :display ".." :face shadow))
+ "Transformation indicators.")
+
;;;; Utility functions
;;;###autoload
@@ -751,7 +758,24 @@
(defun selectrum--first-lines (candidates)
"Return list of single line CANDIDATES.
Multiline canidates are merged into a single line."
- (let ((onelines ()))
+ (let* ((onelines ())
+ (match-transformation (alist-get 'match selectrum-candidate-transformations))
+ (match-display (plist-get match-transformation :display))
+ (match-face (plist-get match-transformation :face))
+
+ (truncation-transformation (alist-get 'truncation selectrum-candidate-transformations))
+ (truncation-display (plist-get truncation-transformation :display))
+ (truncation-face (plist-get truncation-transformation :face))
+
+ (newline-transformation (alist-get 'newline selectrum-candidate-transformations))
+ (newline-display (plist-get newline-transformation :display))
+ (newline-face (plist-get newline-transformation :face))
+
+ (whitespace-transformation (alist-get 'whitespace selectrum-candidate-transformations))
+ (whitespace-display (plist-get whitespace-transformation :display))
+ (whitespace-face (plist-get whitespace-transformation :face)))
+
+
(dolist (cand candidates (nreverse onelines))
(push
(cond ((not (string-match "\n" cand))
@@ -762,17 +786,19 @@
;; Show first matched line.
(concat
(replace-regexp-in-string
- "[ \t][ \t]+" (propertize ".." 'face 'shadow)
+ "[ \t][ \t]+"
+ (propertize whitespace-display 'face whitespace-face)
(car
(funcall selectrum-refine-candidates-function
(minibuffer-contents)
(split-string cand "\n"))))
- (propertize " -> " 'face 'success)))
+ (propertize match-display 'face match-face)))
;; Truncate the rest.
(replace-regexp-in-string
- "\n" (propertize "\\\\n" 'face 'warning)
+ "\n" (propertize newline-display 'face newline-face)
(replace-regexp-in-string
- "[ \t][ \t]+" (propertize ".." 'face 'shadow)
+ "[ \t][ \t]+"
+ (propertize whitespace-display 'face whitespace-face)
(if (< (length cand) 1000)
cand
(concat |
It's currently adjusted in the second cond clause which I thought to replace with the function. In this case you can do this with the function, too. But it would be another repetition so we would better pass the function two arguments where the second one is the optional first matched line: (defun selectrum-format-multi-line (cand &optional match)
(when match
(concat
(replace-regexp-in-string
"[ \t][ \t]+" (propertize ".." 'face 'shadow)
match)
(propertize " -> " 'face 'success)))
(replace-regexp-in-string
"\n" (propertize "\\\\n" 'face 'warning)
(replace-regexp-in-string
"[ \t][ \t]+" (propertize ".." 'face 'shadow)
;; TODO: the truncation is also repetitive and should therfore also be passed as an argument
(if (< (length cand) 1000)
cand
(concat
(substring cand 0 1000)
(propertize "..." 'face 'warning)))))) But I think your approach is a good idea, too and it would give the user less opportunity to shoot himself in the foot. |
If it's acceptable, I would like to try just having the options as a list for now, and seeing whether that is sufficient. One challenge I am having is figuring out the correct type for use in the |
You mean pressing the DEL button on it? I don't know if that can be restricted (I don't use customize myself), the relevant info node is |
I decided to use the Is there any problem with using normal lists instead of plists in the customizable variable? |
I don't think so, as I doubt there are more customization settings added later to this option I think a normal list should be fine. |
…string. Helps with readability.
I've tried to improve the wording. Do you see any other places for improvement? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your efforts, I think the only thing left is to improve the docs a bit more.
This looks great! I like how thorough the docstring is :) |
The last sentence is changed. |
Thanks for your patience and great work! |
I think it makes sense to be able to customize these settings. These are the options made:
Should the faces applied to the strings also be customizable?