Adding a live word count to the modeline

@ftonneau Thanks so much. It’s valuable for me to see these kinds of examples.

Btw 2: If you want word counts to be available only in markdown documents, you should probably move set-option -add global modelinefmt into hook global WinSetOption ... EDIT: in that case, globalshould be replaced by buffer.

Yeah, this is so much nicer than conditionally setting an empty string via an option declared as a string :smiling_face_with_tear:

 declare-option -hidden int modeline_buf_word_count 0
-set-option -add global modelinefmt ' - W:%opt{modeline_buf_word_count}'

# ...

 hook global WinSetOption filetype=markdown %{
+    set-option -add buffer modelinefmt ' - W:%opt{modeline_buf_word_count}'
     hook buffer InsertIdle .* update-modeline-buf-word-count
     hook buffer NormalIdle .* update-modeline-buf-word-count
 }
1 Like