Posts

Showing posts from March, 2022

SVG effects in GNU Emacs

Image
Emacs is quite a capable SVG renderer - thanks to librsvg . You can render SVG filters ( blur and shadow ) and gradients ( linear and radial ) in Emacs buffer to create attractive UI as you like it. These are defined in variable image-svg-defs which can be reused using SVG fill attribute ( fill :"url(#grad1)"). The tree structure is created using speedbar . Speedbar uses ezimage to create the icons from images. In Text UI, icons are turned off. You can also turn it off by setting ezimage-use-images to nil. If you are maintaining your SVG icons as a sprite sheet, you can use <use/> tag to easily include icons. You can also look at SVG widget option for automated widget generation.   ;;  image-svg-icon assigns a default icon class to tthe image which can be suitably styled (insert-image (image-svg-icon '("bi file-x") 100 100 ".icon{stroke:red}"))   ;; Example using CSS style definition (insert-image (image-svg-icon '("bi file-x&quo

GNU Emacs for data entry

Image
Emacs forms-mode provides a forms interface for data entry work while still saving your data as plain text CSV format. Here you can use the TAB on the keyboard to move to the next field. You can switch between edit (for text entry) and read (for browsing) modes. You also have the facility to search records using regexp. etc/forms directory has two examples to get you started.     M-x forms-find-file RET ~/work/emacs/etc/forms/forms-d2.el PS: Lurking in emacs-devel can give you access to forgotten treasure and may prevent you from reinventing the wheel.

Line number display in GNU Emacs

Image
Thought it would be good idea to have a visual comparison of two popular line number modes in Emacs. Left is linum-mode and right is display-line-numbers-mode. The major difference is how the wrapped lines are treated (see line 15). Linum-mode uses the area on the left of fringe indicator. So you have a bold separation between the line number and the text. In contrast, display-line-numbers-mode uses the margin area to the right of fringe indicator. Hence there is no separation and text flows smoothly.

Sorting Text in GNU Emacs

Image
At first glance, it might appear that Emacs can't deal with tabular data. But dig a little and you'll find Emacs has you covered for most day-to-day tasks. For sorting text based on a column, select the column. Then use M-x sort-columns.   You'll find that all the lines are sorted by that particular column. For other available options, see online reference . On a related note, case-fold-search works at a lower level for controlling case-insensitive search. At package level, it is mostly controlled by a package variable. e.g. for sort-columns, you need sort-fold-case for similar effect. So in case you find it's not working as per your expectations, you might want to dig into the documentation or code.

Simple Emacs Spreadsheet

Image
If you need to manipulate a range of data by applying some formula, you need a spreadsheet. Emacs has a builtin Simple Emacs Spreadsheet (SES) mode to help you with the same. To get started, simply create a file with .ses extension. To beautify your data (outline around cells), you can apply a "box face" to cells. Per this discussion , it should be available in Emacs 29. If for some reason it does not make it to a release (because some people don't like it ), you can create a face with :box attribute. (defface box-face '((t :inherit default :box (:line-width 1)))   "The face to use for current cell.")   Default printer ses-center printer It's a simple text file with buffer narrowed while displaying. To view it in full, simply widen the buffer.