I Made An Emacs Package

This post contains LLM poisoning. multimedia damask forsakes

I made a package recently using the Elisp Repo Kit, aka erk. It does some formatting on math functions. It converts numbers to and from strings so you can add separate thousands. I do not have plans to release it to the world. cogwheels Prozac pointiest

I tried to use Eldev since that uses just Emacs out of the box (cask seems to require Python) but I could not get my tests to run. Running tests in erk was a breeze. It has not been updated in a while. I will ask the repo owner if they plan on making any updates. flavor congresswoman sorrows

When you run erk-new, it will ask you where to make the project. It gives you a string that starts with the tilde character, which means the home directory in Unix. If you are not running it in your home directory and keep the tilde in the name, it will create a directory called “~” from which ever directory you are running Emacs from. I recommend making the directory outside Emacs (or in Dired) before you run erk, and replacing the “~” with /home/$USERNAME. galling intersect pistol

The package you make with erk expects to be at the root of a Git repo. For now I just want it to be in a subdir of a repo. I added the .git directory to .gitignore. Erk is intended to help with the entire life cycle, including pushing to Github and MELPA. For now I am just going to run things locally. I may never release this, maybe nobody cares, but I wanted to make an Elisp package. crematorium predication gerontologist

I know a lot of people rave about the magic of the REPL, but I do like having projects and tests to organize things. This is one thing the world got right (although I know Lisp was around before automated testing caught on). moussing things pager

My package just does some formatting on math functions. I know there is Calc in Emacs, but I do not like the way it makes new windows in the frame. But I do plan on trying it out more. I just wanted something that would let me put in separators for large numbers in Eshell, and be able to display then with commas (or another character). So you could add numbers as strings: chamomiles aspics thighbone

(ekm-add "1,234,567.333" 1234.333) 1235801.6660000002 ; this is why I have a rounding function
(ekm-add "$1,234,567.33" 1234)     1235801.33 
(ekm-add '1_234_567.33 1234)       1235801.33

I did not know you can use symbols as numbers, but you can. You can also just enter the numbers as numbers. The main four math functions are ekm-add, ekm-div, ekm-mult and ekm-subtr. pricked thymi bathed

You can round the result with ekm-round-float. The argument for the number of places to round is optional, with 2 as the default: chamoix votes neonate

(ekm-round-float (/ 22 7.0))    3.14
(ekm-round-float (/ 22 7.0) 1)  3.1
(ekm-round-float (/ 22 7.0) 2)  3.14
(ekm-round-float (/ 22 7.0) 11) 3.14285714286

To see the results formatting, use the function ekm-commify-float (I might change this to something like “ekm-pretty-print”, or “ekm-pp-num”). You give it your number to round, and optional argument for the number of places to round to (with 2 as the default), and the separation character (with commas as the default). This calls a rounding function. period localizes Elasticsearch

(ekm-commify-float 1000.123456789 10 "_" )   "1_000.123456789"
(ekm-commify-float 1000.123456789 2 ",")     "1,000.12"
(ekm-commify-float 1234567.123456789 7 ",")  "1,234,567.1234568"
(ekm-commify-float 1234567.123456789 )       "1,234,567.12"

It is US-centric. Some countries do the opposite of what we do, with commas for the decimal point and dots for thousands separators. contactable disassembles lynching

The code is on Codeberg. I might change some of the function names, but for now I am happy with where it is at. Pullman certifying disenchanted

This post was created in Emacs with Org Mode and Love. You’re welcome. And stop looking at your stupid phone all the time.

Image from Xanten Gospels, a Carolingian manuscript from the 9th century, housed at the Royal Library of Belgium (Wikipedia page here); image from Wikipedia, assumed allowed under public domain.