While debugging a live reload issue of Clay a few days ago, I learned from Markus Agwin that we can actually add dependencies on the fly from the command line, just like this: clj -Sdeps "{:deps {org.scicloj/clay {:mvn/version \"2-beta21\"}}}".
Even better, we can add dependency from a Git repo and specify the commit hash: clj -Sdeps "{:deps {io.github.scicloj/clay {:git/url \"https://github.com/scicloj/clay.git\" :git/sha \"35a46541db66ae6b4e1af628b7c24c42d3be418f\"}}}", which is really helpful for experimenting and verifying things.
[Read More]
Bitten by Lazy Sequence of map
While impletenting the live reload feature for Clay a few weeks ago, unfortunately, I was bitten by the laziness of map. It seems quite obvious we all know that its result is a lazy sequence, but I just can't help fall into the "trap".
At that time I was adding a vector to keep track of all beholder instances watching file changes in user specified directories. So then when it's time to stop all the watchers, I used something like to achieve the goal:
[Read More]
Anonymous Functions in Thread Macros
While adding the live reload feature to Clay, I encountered a problem of applying anonymous functions to thread macros. For example, below is a simple snippet trying to wrap the input directory as a vector with the help of thread macro, but surprisingly, it errors out. After some searching, I figured out that I need to put the anonymous function into another pair of parentheses:
(-> "/tmp/" #(if (vector? %) % [%])) ;; => Syntax error (ClassCastException) compiling fn* at (simple4all.
[Read More]
Start a Clojure nREPL in the Command Line for Cider
While troubleshooting and fixing a live reload bug in Clay today, which requires to start a minimal Clojure environment, I figured out how to start a nREPL from the command line. Instead of using M-x cider-jack-in-clj directly from Emacs, actually we can manully bring up an nREPL with this: clj -Sdeps "{:deps {org.scicloj/clay {:mvn/version \"2-beta21\"} cider/cider-nrepl {:mvn/version \"0.50.2\"}}}" -m nrepl.cmdline --middleware '[cider.nrepl/cider-middleware]' (The clay part is only necessary for this debugging), and then connect to this nREPL using the Emacs command M-x cider-connect-clj.
[Read More]
Join Every N Lines By A Separator in Emacs
It has been some time since I came along the idea of the w/join-lines command to join lines. After that, sometimes I found that it would be even better to join every a few lines.
Let's see the example below, suppose we've copies some data from somewhere, and now we want to yank it into an Emacs buffer and slightly modify it to be like an matrix.
That is, make it from:
[Read More]
Emacs winner-mode to restore your window layouts
If you've been using Emacs for a while, I bet you must have encountered the annoying problem that your Emacs window layout gets messed up by some operations, such as looking for a help (e.g. C-h k), or checking things in magit.
It's ok to me if I can get back to a previous used layout. Emacs has built in a package for this package: winner-mode. It's very simple, it only has three commands:
[Read More]
Emphasize Text By Dragging Mouse in Org-mode
Long story short, I came up with an idea to emphasize content while I was reviewing an org-mode document a few months ago after I was tired of typing tedious * around the content repeatedly. And I've been longing for this feature since then, because I was unfamiliar with mouse-based key bindings, and neither did I have the time to investigate it.
Today I finally nailed it down while I was attending a boring meeting, and it turned out to be quite simple.
[Read More]
Join Lines By A Separator in Emacs
So sometimes I need to join a few lines by a separator while I'm coding, for example, turn the below lines,
foo bar baz into foo + bar + baz. (This is a silly example, I will update if I come up with a better one :-P )
When I was in a rush in the past, I usually baked a keyboard macro temporarily and then applied it to achieve this goal, thought reliable, it's a little bit cumbersome to record it.
[Read More]
Hugo Blogging in Emacs
When I started to use Hugo to write this blog last year, I noticed that there is an easy-hugo package of Emacs that there are many people use it. So I installed it that time, but I didn't use many of its features along the way. The only command I used was easy-hugo-current-time. I used it to update the Hugo timestamps manually as in the format of 2022-10-15T09:45:35+08:00.
My most desirable feature is to use it to select tags easily when I start to write a new post, but I never got it to work.
[Read More]
Auto-complete Accounts From Other Beancount Files in Emacs
Auto-complete accounts from another accounts.bean file If you're using Beancount with Emacs, you may be using beancount-mode. It can auto-complete the accounts defined in the current buffer when we are typing in new transactions so that we can do it more efficiently.
But it can only auto-complete the accounts from the current buffer, which makes it less useful when we have a stand-alone file or a few files of beancount accounts.
[Read More]