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. So I wonder maybe it would be a good idea to have a command for it.

[Read More]
Emacs 

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 many people use. So I installed it at that time, but I didn't use many of its features since then. In fact, 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
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]

A Bookmarklet for Copying a Link as an Org-mode Link

In this blog post, I'd like to share a bookmarklet for copying a web page's URL as an org-mode link on Firefox, Chrome, or whatever web browsers support bookmarklets.

It's handy when the URL isn't SEO-friendly, which means you can't tell what its content is about at first glance of the URL. So a little description text on the link would help.

Here is the bookmarklet:

javascript:window.prompt("Copy to clipboard: Ctrl+C, Esc", "[[" + document.location.href + "][" + document.title + " - " + document.location.hostname + "]]");

// Don't know why the page becomes blank after using it on Firefox, so use alert instead.
javascript:alert("[[" + document.location.href + "][" + document.title + " - " + document.location.hostname + "]]");

Add a new bookmark on the browser, give it a name, such as (org-link), and then copy and paste the content as URL, just like below on Firefox:

[Read More]

Emacs Debugging Techniques

If you are new to Emacs, you may run into some errors, especially after you copied some elisp snippets from the Internet or elsewhere. Don't panic! It happens, it's just part of the learning process. Even an experienced Emacs user could run into there issues from time to time.

BTW, I'm improving my English by watching YouTube videos every single day; If you're also learning English, or any languages, LanguagePuppy can definitely help you. It's a Chrome extension I developed using Clojure. Check it out:

[Read More]

Duplicate the current line in Emacs

Duplicate the current in Emacs
Duplicate the current in Emacs

Duplicating the current line is frequent editing for me when I am coding. Initially, I copied a snippet as a command in Emacs from the Internet:

(defun w/duplicate-line()
  "Duplicate the current line."
  (interactive)
  (move-beginning-of-line 1)
  (kill-line)
  (yank)
  (open-line 1)
  (next-line 1)
  (yank))

Most of the time, I was happy with it, but it has mainly two drawbacks:

  1. It cannot keep the column position when moving to the next line
  2. It messes up with the yank ring as it yanks the text under the hood

So today, I took some time to fix these two problems, and I also want it to be capable of commenting the current line out if I prefix the command.

[Read More]
Emacs 

Adjust the laptop's screen brightness in Emacs

Adjust the screen brightness in Emacs
Adjust the screen brightness in Emacs

If you're using i3wm on Linux, how do you adjust the laptop's screen brightness?

Most of the time, I use the laptop with an external monitor. But when I am out, I have no monitors. And it seems no easy way to adjust the brightness in i3wm. Being too bright or dim is terrible for the eyes.

[Read More]

How to Kill a "Visible" Buffer Quickly in Emacs

Selecting Emacs windows using ace-window
Selecting Emacs windows using ace-window

Recently I've been building a simple Emacs config for myself, along the way I re-discovered some fantastic packages, for example, I found that ace-window is a simple yet powerful package to enhance the default other-window command to select other windows quickly when it has more than two windows in a frame.

I replaced the key binding of other-window to ace-window by simply doing (global-set-key (kbd "C-x o") #'ace-window), then when there are >2 windows, it will show a white-in-red number at the top-left corner for every window, hit the number (1, 2, 3, …) and then Emacs will select the corresponding window (as demonstrated in the above screenshot).

[Read More]
Emacs 

How to append items to the CSV file without header row?

Scrapy Architecture
Scrapy Architecture

Scrapy provides a few item exporters by default to export items in commonly used file formats like CSV/JSON/XML. I usually use CSV to export items, it is pretty convenient, and it comes in two ways:

  • appending mode, for example, scrapy crawl foo -o test.csv
  • overwriting mode with -O option, like scrapy crawl foo -O test.csv

But in the appending mode, it's a bit annoying that it always appends the header row before the newly scraped items, which is not correctly in terms of CSV format.

[Read More]

Eglot for Better Programming Experience in Emacs

LSP, or Language Server Protocol, makes programming easier by introducing features like more precise auto-completion and definition lookup. It may have scratched your itches, and you may wonder what the experience is like in Emacs.

BTW, I'm improving my English by watching YouTube videos every single day; If you're also learning English, or any languages, LanguagePuppy can definitely help you. It's a Chrome extension I developed using Clojure. Check it out:

[Read More]