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

add: a text property for display string in the right margin #44

Merged
merged 1 commit into from
Apr 12, 2020

Conversation

AmaiKinono
Copy link
Contributor

See #14

The right margin text is displayed in the same line:

image

or in a new line, when the space is not enough:

image

Copy link
Member

@raxod502 raxod502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature is fine, but text display based on window width calculations is too flaky (what happens if you resize the window during a session?). A better approach is to use a text overlay, as in radian-software/ctrlf#32 (comment).

@AmaiKinono
Copy link
Contributor Author

I failed to figure it out. The code I gave in radian-software/ctrlf#32 (comment) displays a very wide space, and from the manual, seems that's its only usage. I didn't find other display property of overlay that allows right aligning text.

Could you explain a bit more about how this should be done?

@raxod502
Copy link
Member

Sorry, didn't realize that example was not an appropriate one. It is in fact possible, though: lsp-ui does this to display its in-buffer error messages. Here's the code:

https://github.com/emacs-lsp/lsp-ui/blob/bf3966e87c91c5d825c483ce0883f30dd2272b62/lsp-ui-sideline.el#L257-L259

It uses a "pixel specification" in the :align-to property. This allows the alignment to be recomputed on every redisplay, solving the window resizing problem.

Here's what the overlays look like in that package:

image

@AmaiKinono
Copy link
Contributor Author

Thanks for the example, the trick is neat :D

Please see if this can be merged.

Copy link
Member

@raxod502 raxod502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • looks good
  • some minor suggestions
  • can you suggest a code snippet that demonstrates the functionality so I can test it?
  • we should have an entry in the CHANGELOG

Thank you for the help!

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
selectrum.el Outdated Show resolved Hide resolved
selectrum.el Outdated Show resolved Hide resolved
selectrum.el Show resolved Hide resolved
selectrum.el Outdated Show resolved Hide resolved
selectrum.el Outdated Show resolved Hide resolved
@AmaiKinono AmaiKinono force-pushed the right-margin-property branch from fed5830 to d4b7cb4 Compare April 12, 2020 05:39
@AmaiKinono
Copy link
Contributor Author

an entry in the CHANGELOG

Done.

can you suggest a code snippet that demonstrates the functionality so I can test it?

This is a simple test:

(completing-read
 "Hi: "
 (list
  (propertize "item1"
              'selectrum-candidate-display-right-margin "annotation1"
              'selectrum-candidate-display-prefix "prefix1 ")
  (propertize "item2"
              'selectrum-candidate-display-right-margin "annotation2"
              'selectrum-candidate-display-prefix "prefix2 ")))

And this is a command I want to implement using this feature:

(defun insert-unicode-char (&optional count)
  (interactive "p")
  (let ((selectrum-preprocess-candidates-function
         (lambda (collection)
           (selectrum--map-destructive
            (lambda (name)
              (let ((code (char-from-name name)))
                (propertize
                 name
                 'selectrum-candidate-full
                 (format "%c" code name code)
                 'selectrum-candidate-display-prefix
                 (format "%06X " code)
                 'selectrum-candidate-display-right-margin
                 (format "%c" code))))
            collection))))
    (call-interactively #'insert-char)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants