Sublime Forum

Possibility to customize titlebar with current Vim mode

#1

I really need to have Sublime change the titlebar information based not only on file status, file path or name, but also some package conditions, including the Vim status, as seen in the picture (I’ve written the ‘- INSERT MODE’ part, of course).


I watched this, but OdatNurd’s explanation appears not to cover this possibility.

Is it possible anyhow? Plugin, PackageDev, creating some python script, anything?

0 Likes

#2

It’s not currently possible to insert arbitrary text into the title bar; there’s no API for that (hence the settings mentioned in that video being added to provide some control for people who wanted the layout to be different).

0 Likes

#3

Thanks for your kind answer OdatNurd! But allow me to a insist as long as there is any spark of hope: you say there is no way to do it (present tense), which could mean:

  1. Sublime’s program itself doesn’t support it out of the box, but somehow it can be done (plugin, third-party package, me paying for someone to write a plugin for me); or
  2. Since there is no API, then I can throw away all my hopes of getting it done unless this is taken into consideration for a future feature, which I don’t see why the devs would bother?
    Please just clarify that :smiley:
0 Likes

#4

As I mentioned above, there’s no API that allows you to do anything with the title bar other than to change the settings that alter the order of the predefined items. So plugins can’t do it directly; at best you would need some sort of hack that uses low level windows API’s to forcibly alter the window title somehow.

If you think that this is something that would be useful to others you could file a feature request (Help > Report a bug in the menu will take you to the place where you can do that).

I’m not personally sure of what the utility is of having something like that in the title bar instead of the status bar though; it doesn’t seem to buy much.

0 Likes

#5

Thanks :frowning: , But I’ll explain to you:

It’s not just some sort of eccentricity this guy here appears to display; it’s more than that. The key to that request is AutoHotkey. See, AHK is both a Windows end-user program and a fully-fledged programming language; on the user-side of AHK, one of the things it does is hotstrings: a piece of user-defined abbreviations that, when typed, they expand, like inctb -> I need to change the title bar. AHK, while running in the background, monitors the user input until it sees a pattern which was predefined as an abbreviation. When the sequence is typed, the program hits Backspace the number of times equal to the lenght of the abbreviation then types the expansion for you. So upon typing “inctb”, the program will hit Backspace 5 times, then write out “I need to change the title bar”. Pretty cool, right? There are dozens of programs which do that, both free and paid. The underrated AutoHotkey is both free, open source and the most powerful.

But there is the catch: AHK doesn’t know if the user means to actually type (INSERT MODE) text, or if he’s performing a sequence of Vim commands (COMMAND MODE). So when a user defines a hotstring like this: 50x -> Fifty times, if Sublime is accidentally with Vim set to command mode, it will perform the disastrous “erase fifty characters ahead" command instead of typing the phrase “Fifty times”. So the performance boost the user intended to have with Vim will be neutralized by AutoHotkey’s, or vice-versa.

“OK, now I know what AHK is capable of doing but I don’t know changing the titlebar would be of any help”. Thing is, among a million other functions, AHK can watch the active window's title, and have a hotstring or hotkey be enabled only if the active window’s title matches a predefined string. So we write our AutoHotkey script like this:

#IfWinActive, .* - Sublime Text - Insert mode

::mhs::my hotstring

#IfWinActive

The part enclosed by the "#IfWin… fences are only executed when the active window title matches that pattern (something followed by “Sublime Text” followed by “- Insert mode”.

That way, we would be able to have AutoHotkey do the hotstring expansions only if it detects that current window (Sublime Text’s) has a piece of text matching “- Insert mode”. Then we would have the best of the two worlds without a conflict.

See? It’s actually very important for people serious about productivity, which is something Sublime Text, Vim and AutoHotkey have in common. :slight_smile:

1 Like

#6

Could you extract the INSERT MODE or COMMAND MODE from ST using StatusBarGetText in AutoHotkey?

0 Likes

#7

Or just write a tiny plugin to write to a file when changing between vim modes and have AHK read that

0 Likes

#8

@rcopat Can’t. You can try ourself and you’ll see the resulting MsgBox will always come back blank:

SetTitleMatchMode, 2
#SingleInstance force
#NoEnv

; ATTEMPT #1 - FAILED
StatusBarGetText, liltext, 1, ahk_exe sublime_text.exe
MsgBox, % liltext

; ATTEMPT #2 - SUCCEEDED, BUT FOR NOUGHT
StatusBarGetText, RetrievedText, 1, ahk_exe Everything.exe
if InStr(RetrievedText, "Pronto")
    MsgBox, Search results have been found.

I’m using the default theme for Sublime Text. I don’t know why AutoHotkey can’t detect the status bar text. I guess it has something to do with the theme? Because, if you look at this image, in which I put Everything (the nice desktop search app) in front of Sublime, you can immediately tell Everything’s status bar is like, the Windows-defaultish, while Sublime has a customized appearance:

@kingkeith Didn’t know that we could monitor the changes between modes, but how do I do that? I’m learning Python but I’m still behind the topic on OOP (classes, which are a requirement to develop Sublime plugins :()

0 Likes

#9

Same problem here. Just as a test, I was able to extract the text of the status bar from Notepad by changing the Part# argument. When I do the same with Sublime, it does not work. I tried changing the Part# from 1 to 60 using a loop. It may be worth to post on an AutoHotKey specific forum.

I won’t be able to help you with @kingkeith’s suggestion.

0 Likes

#10

This likely doesn’t work because Sublime uses a custom UI toolkit and is rendering everything inside of the window itself.

Have you investigated just having a native Sublime package that can provide this kind of abbreviation expansion without needing external software to try and hack it into place?

0 Likes

#11

Ah… no, and this would nullify the whole purpose of AutoHotkey, which is meant to be system-wide. It’s like asking to replace AHK with Microsoft Word’s internal autocorrect. Also, my gigantic database of abbreviations predates even Sublime Text itself, so, it wouldn’t be an option, unfortunately.
@rcopat I’ll post on an AutoHotkey forum shortly, albeit being now of little hope because of what @OdatNurd said about the UI :cry:

0 Likes

#12

TLDR; Maybe take a look at: https://github.com/gwenzek/SublimeSetWindowTitle - but as mentioned, didn’t read the entire discussion here and so maybe it’s an completely other topic - it just came up in my mind :sweat_smile:

0 Likes

#13

Close! You (and the developer) almost got it, except:

  // Template for the window title.
  // The template accept the following parameters:
  // - {path}: the path of the current file
  // - {file}: the filename of the current file (without the path)
  // - {project}: the project name, or the name of the top folder
  // - {has_project}: will be replaced by the content of "has_project_true" or
  //   "has_project_false" settings, depending if a "project" has been found.
  // - {is_dirty}: will be replaced by the content of "is_dirty_true" or
  //   "is_dirty_false" settings, depending if the current view is being
  //   modified.

As you can see, there is a limited set of customizing possibilities. :cry: :cry: :cry:

0 Likes