Posts

Showing posts from April, 2022

LG WebOS TV and GNU Emacs

Image
Modern LG TVs with WebOS allow remote control via websockets. Since this is a web technology, you might want to automate this using Node JS [1] . However, if you want a fair balance between scripting and interactive use, Emacs will serve you better. Toast (top right) sent from Emacs   Completing LG TV commands in Emacs Steps Install package websocket from ELPA. M-x package-install RET websocket RET  Download tv.el and pairing.json Load tv.el M-x load-library RET tv RET  Ensure variable lgtv--pairing-json is pointing to pairing.json file. Run M-x lgtv-command Enter a command for LG TV. Use TAB for completion. Enter a JSON object for command parameter. Leave empty if the command doesn't require a parameter. ( Note: Remember to quote the keys in JSON.) ;; Sample payload passed to TV. You need to provide URI (without ssap://) and payload parts   ;; Show toast { "id": "0c8b18a10002", "type": "request", "uri": "ssap://system...

Multi-select Tree widget in GNU Emacs

Image
Here's an example of multi-select tree widget in GNU Emacs. It is cobbled up from visibility and option widgets. If you want different icons, see . (widget-create 'tree            :name "Tree" :checkbox t            '(item "One") '(item "Two"))   ;; Uncomment if you don't need images ;; (setq widget-image-enable nil)   ;; Following two lines are necessary to interact with the widget (use-local-map widget-keymap) (widget-setup)   ;; This is a list of values of effectively selected leaf nodes. (widget-tree-flat-value widget) ;; Create tree widget from a list of values (widget-create (widget-tree-from-list '("One" "Two") "Tree"))   For placement, you can use :indent property on parent. For indentation of children, either use :offset on parent or :extra-offset on child. Code: https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/wid-edit.el          

Emacs widget icons

Image
Emacs has few important widgets built-in. If you are using them, it would be helpful to know that you can customize their icons. You should look for :tag-glyph (buttons), :on-glyph and :off-glyph (radio, checkboxes and visibility) support in the widget. The value for these attributes should be a file name sans extension (xpm, xbm, gif, jpg, or png) located in ` widget-image-directory' or otherwise where ` find-image' will find it. You can create an insert button with plus.png image as an icon using following code: ;; Use widget-convert to assign an instance of a widget to a variable (setq w (widget-convert 'insert-button :tag-glyph "plus")) (widget-create w)   ;; Use widget-create to insert the widget into the buffer (widget-create 'insert-button :tag-glyph "plus")   ;; Following two lines are necessary to interact with the widget (use-local-map widget-keymap) (widget-setup) Below is a slightly modified version of the example in Emacs online doc...