doom-modeline icon indicating copy to clipboard operation
doom-modeline copied to clipboard

Path contraction

Open tecosaur opened this issue 4 years ago • 11 comments

Is your feature request related to a problem? Please describe. Having the file path in the modeline is great, unfortunately, it can sometimes get quite long, and squeeze out other modeline segments.

Describe the solution you’d like Some fancy shell prompts exhibit really nifty dynamic path contraction. If something like this could be implemented/enabled in doom-modeline this would be great :)

For reference, the implementation Powerline10k uses (see the gif below) seems to be contracting directories to the shortest unique string from the parent down. IMO this is quite a nice approach.

path-resize

Describe alternatives you've considered Just showing the file, or immediate parent all the time. However this seems like unnecessary information loss.

tecosaur avatar May 31 '20 10:05 tecosaur

Well, I think the similar requirements were discussed in #312. Fair enough, it's very hard to calculate the width in realtime. Negative impacts to the performance. (setq doom-modeline-buffer-file-name-style 'auto) is a good trade-off. But perhaps we can improve auto style.

seagle0128 avatar May 31 '20 14:05 seagle0128

I don't think a perfect solution exists for this. What does come to mind is having a mostly-there solution where we just add a window resize hook, and using (window-width) + a set of cutoff values to guess how agressively the path should be shortened.

tecosaur avatar May 31 '20 14:05 tecosaur

I am afraid more bugs come out If the width is inaccurate 😢 BTW, window resize hook is not enough apparently. Need more PoC here.

seagle0128 avatar May 31 '20 14:05 seagle0128

POC ?

tecosaur avatar May 31 '20 14:05 tecosaur

POC ?

Typo, PoC: Prototype of Concept

seagle0128 avatar May 31 '20 15:05 seagle0128

Ah, thanks :)

I'll happily take a look at this, I'm just not sure how to set the path to be contracted to a particular extent. If you might be willing to help with that, I'll try seeing if I can have it set sensibly with the window width.

tecosaur avatar May 31 '20 15:05 tecosaur

@seagle0128 would you be willing to help by providing a path-contraction method? From there I'd be happy to take a look a building a PoC :smiley:

tecosaur avatar Jun 02 '20 12:06 tecosaur

@tecosaur Maybe you need doom-modeline--buffer-file-name, doom-modeline--buffer-file-name-truncate and doom-modeline--buffer-file-name-relative. See doom-modeline-buffer-file-name as well.

seagle0128 avatar Jun 03 '20 01:06 seagle0128

is there any way to set doom-modeline-window-width-limit to a function to be evaluated in realtime, ie 'window-total-width? am i correct that this would address this issue, or at least would be a step in the right direction? (i'm guessing no on one or both accounts, or else this would have already been suggested. but still, thought i'd ask :))

eeshugerman avatar Sep 28 '20 19:09 eeshugerman

is there any way to set doom-modeline-window-width-limit to a function to be evaluated in realtime, ie 'window-total-width? am i correct that this would address this issue, or at least would be a step in the right direction? (i'm guessing no on one or both accounts, or else this would have already been suggested. but still, thought i'd ask :))

@eeshugerman I think it will bring negative impacts to the performance.

seagle0128 avatar Sep 30 '20 11:09 seagle0128

I think you misunderstood what I was suggesting, but I don't blame you because I now realize that my suggestion was basically nonsense. So nevermind; sorry for the diversion!

eeshugerman avatar Sep 30 '20 15:09 eeshugerman

Sorry for reviving this thread, but even if doom-modeline-buffer-file-name-style is set to auto, when the file name exceeds a certain length, all the elements to the right of it will disappear from view. Is there a way to set a maximum number of characters allotted to the element displaying the buffer name?

benthamite avatar Oct 05 '23 13:10 benthamite

Recently I added new options: doom-modeline-buffer-file-name-function and doom-modeline-buffer-file-truename-function, which allow users to pre-process the buffer names before displaying them. I don't think it's a good idea to display the buffer names dynamically as what powerline does in shell, since it will bring big performance issues.

Please refer to f06950b6c162ad89fb32c3e71d6b00c0f7296866 and #673 .

The solution is good so far. I am closing it.

seagle0128 avatar Oct 24 '23 07:10 seagle0128