Custom syntax highlight on pattern/regex? #362
-
Is there a way to syntax highlight a user defined pattern in a special way? Example: Custom highlight regex Similar example in zsh, link |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I'm sorry for my late reply. I missed your post since I was busy that week. There is currently no easy interface to configure highlighting patterns. In principle, you could implement a custom layer as shell functions ( Maybe, when I have time, I can implement a new layer that offers a simple interface for configuring highlighting by patterns. |
Beta Was this translation helpful? Give feedback.
-
I have implemented a new layer class in ble-import layer/pattern
# Create a layer with the name "pattern1".
# The patterns in this layer are by default interpreted as regular expressions.
ble/highlight/layer:{pattern}/declare pattern1
ble/highlight/layer:{pattern}/register pattern1 'rm -rf [^;&|]*' 'fg=white,bold,bg=red' # add a pattern in a regular expression
ble/array#insert-after _ble_highlight_layer_list syntax pattern1 # register the layer "pattern1" to the layer list.
# Create another layer with the name "pattern2".
# The argument "glob" specifies that the patterns in this layer should be treated as glob patterns.
ble/highlight/layer:{pattern}/declare pattern2 glob
ble/highlight/layer:{pattern}/register pattern2 "$USER" 'fg=blue,bold'
ble/highlight/layer:{pattern}/register pattern2 "$HOSTNAME" 'fg=green,bold' # one can add multiple patterns in a pattern layer
ble/highlight/layer:{pattern}/register pattern2 '[0-9]+' 'bg=216,fg=black'
ble/array#insert-after _ble_highlight_layer_list pattern1 pattern2 Detailed descriptions on the functions can be found in the beginning comment of |
Beta Was this translation helpful? Give feedback.
I'm sorry for my late reply. I missed your post since I was busy that week.
There is currently no easy interface to configure highlighting patterns. In principle, you could implement a custom layer as shell functions (
ble/highlight/layer:<LAYER>/*
with<LAYER>
being the name of the new layer). The details of implementing a layer is described in a code comment, but it's written in Japanese (so please use machine translations if you are really interested). I think the implementation of theregion
layer can be referenced as an example.Maybe, when I have time, I can implement a new layer that offers a simple interface for configuring highlighting by patterns.